Subject Re: Invalid reference to delete
Author Rick Roen
Here are the things that might be relevant:

When I delete using the TIBO_Query interface in design mode there is
no problem.

I eliminated the DeleteSQL in the Query and rolled my own using the
same SQL text. That works with no problem. The procedure is below.

My guess is that somehow the something is trying to delete the same
row twice, but I can't figure out how this might be happening. This
is based on the error message "Invalid reference to delete" and the
fact that the row is actually deleted when I refresh after the
delete and error.

SQL for deleting row outside of Query:

try
Cur := TIB_Cursor.Create( self );
Cur.IB_Connection := DMLG1.IBC0;
Cur.IB_Transaction := DMOrders1.Trans_Orders;
Cur.IB_Transaction.AutoCommit := True;
Cur.SQL.Add( 'Delete from ORDERITEMS where IDNUM = :IDNUM' );
Cur.Prepare;
Cur.ParamByName( 'IDNUM' ).AsInteger :=
DMORders1.QOrderItems.FindField( 'IDNUM' ).AsInteger;
Cur.ExecSQL;
//ShowMessage( 'deleted: ' + Inttostr( Cur.RowsAffected ));
DMOrders1.QOrderItems.RefreshKeys ;
finally
FreeAndNil( Cur );
end;

SQL from the TIBO_Query component:

SELECT OI.IDNUM
, OI.ORDERNUM
, OI.INVOICENUM
, OI.ITEMNAME
, OI.ITEMNUM
, OI.ETD_DATE
, OI.QTY_ORDER
, OI.QTY_SHIP
, OI.UNITS
, OI.COST
, (OI.QTY_ORDER * OI.COST) AS COST_ORDER
, (OI.QTY_SHIP * OI.COST) AS COST_INVOICE
, NULLIF(OI.LOTNUM, 0) AS LOTNUM
, OI.TREATMENT
, OI.PACKING
, OI.GERM
, OI.DATEGERM
, OI.NOTE
, OI.COMPLETE
FROM ORDERITEMS OI
ORDER BY (SELECT I.NON_SEED_ITEM FROM
ITEMS I WHERE I.ITEMNUM = OI.ITEMNUM ), OI.ITEMNAME


--- In IBObjects@yahoogroups.com, "Jason Wharton" <jwharton@i...>
wrote:
> I agree what you are showing here looks correct.
>
> Do you have any more clues?
>
> Jason
>
> > -----Original Message-----
> > From: IBObjects@yahoogroups.com
[mailto:IBObjects@yahoogroups.com]On
> > Behalf Of Rick Roen
> > Sent: Tuesday, April 26, 2005 5:16 PM
> > To: IBObjects@yahoogroups.com
> > Subject: [IBO] Invalid reference to delete
> >
> >
> >
> >
> > I'm getting an error I can't figure out.
> >
> > I have a TIBO_Query component with the following delete
statement:
> >
> > DELETE FROM ORDERITEMS
> > WHERE IDNUM = :IDNUM
> >
> > From my Delphi 7 program I call: the Delete method and I get the
> > message: "Invalid reference to delete".
> >
> > If I refresh the dataset, the record has actually been deleted.
> >
> > Below is the SQL monitor output, which all seems in order.
> >
> > Can someone point me in the right direction?
> >
> > Rick
> >
> >
> > /*---
> > EXECUTE STATEMENT
> > TR_HANDLE = 16486648
> > STMT_HANDLE = 16544160
> > PARAMS = [ Version 1 SQLd 1 SQLn 1
> > [IDNUM] = 48200 ]
> >
> > SELECT COUNT: 1
> > DELETE COUNT: 1
> > ----*/
> > /*---
> > COMMIT RETAINING
> > TR_HANDLE = 16486648
> >
> > SECONDS = 0.010
> > ----*/
> >