Subject Re: [ib-support] help
Author Helen Borrie
At 04:47 PM 30/01/2003 +0700, you wrote:
>i am beginner,
>
>i try to create procedure with my Delphi Program.This is my part of my code
>:

Advice: As a beginner, don't try to do this. A stored procedure
declaration is a complex DDL statement that can't be executed via a
single-statement dynamic SQL component such as TIBSQL.

> IBSQL.SQL.Clear;
> IBSQL.SQL.Add('CREATE PROCEDURE ITEMLIST '+
> 'RETURNS(ITEMNO VARCHAR(60),ITEMDESCRIPTION VARCHAR(100),QUANTITY
>NUMERIC(15,2)) '+
> 'AS '+
> ' Declare Variable QuantityPurchase Numeric(15,2); '+
> ' Declare Variable QuantitySales Numeric(15,2); ' +
> 'BEGIN '+
> ' for Select ItemNo,ItemDescription from Item into :ItemNo,
>:ItemDescription do '+
> ' begin '+
> ' Select Quantity from ItemHist where ItemNo = :ItemNo '+
> ' and JenisTransaksi = ''P'' <--- here's a syntax error (double
> quotes are invalid for strings..)

>into :QuantityPurchase; '+
> ' Select Quantity from ItemHist where ItemNo = :ItemNo '+
> ' JenisTransaksi = ''S'' <--- same error as above

>into :QuantitySales; '+
> ' Quantity = QuantityPurchase - QuantitySales; '+
> ' Suspend; '+
> ' end '+
> 'END'); <-- here's your terminaotr error

Your create procedure statement has to preceded by a SET TERM statement
that sets the line terminator to something other than a semicolon, since
the programming language (PSQL) subset needs the semicolon as the statement
terminator *within* the procedure body.

Create procedure begins the declaration, the last END statement ends it.

So, in a script, you might have set the terminator to be "cat-ears" - two
caret symbols ^^ using

SET TERM ^^ ;

then the last END statement in the procedure declaration would be

...
END ^^

...not doable in a single DSQL statement. Needs to be done in a script, or
in an an admin tool that can run scripts or otherwise simulate batched
statements.


> IBSQL.ExecQuery;
>
>when that SQL Statement Execute, my Delphi Program Raise an Excepction:
>"Dynamic SQL Error SQL error code = -104 Token unknown -line 1,char 266 ?"

That's just Delphi delivering the exception message returned by the server.

heLen