Can't declare variable in Firebird 2.5, why?
Asked Answered
S

2

7

I have a one line query:

DECLARE VARIABLE var_SecondsOfTime INTEGER;

But after running the query I am getting this message:

Engine Error (code = 335544569): Dynamic SQL Error. SQL error code = -104. Token unknown - line 1, column 9. VARIABLE.

SQL Error (code = -104): Invalid token.

I've looked everywhere on the Internet and all examples showing the same declaration style which I am using.

What is wrong?

Shalon answered 2/2, 2011 at 22:42 Comment(2)
Where are you declaring your variable?? stored procedure, or where? from where are you executing your code, isql? other?Zischke
@jachguate: I am declaring it in a plain query, which is executed by FirebirdMaestro application. I guess it connects to the DB via isql. As I said it is one line query, nothing more. No stored procedure, nothing. Just this line of code.Shalon
Z
5

Firebird 2.5 supports execution of code blocks surrounded by a execute block statement, try this:

set term ^ ;

EXECUTE BLOCK 
AS
   DECLARE VARIABLE var_SecondsOfTime INTEGER;

BEGIN
  SELECT 1 from RDB$DATABASE into var_SecondsOfTime ;
END
^

set term ; ^

I issued the select because I'm pretty sure it is not possible to execute an empty block, try this by yourself removing the select.

isql running the block

Edit My original select was invalid for a block, I added the into clause to collect the result. I never used firebird maestro, but it now works perfectly on isql, as shown.

Zischke answered 3/2, 2011 at 0:26 Comment(4)
Thank you for your interest, the error which I have after executing your code is this: Engine Error (code = 335544569): Dynamic SQL Error. SQL error code = -104. Token unknown - line 1, column 1. END. SQL Error (code = -104): Invalid token. Maybe there is something wrong with Firebird Maestro..?Shalon
@Shalon the block was missing a into clause. I personally never used firebird maestro, so I don't know if it requires a different terminator, I surrounded the block on a couple of set term clauses just in case.Zischke
Thanks for your intereest, I'll check your updated answer shortly and will let you know if it worked.Shalon
The second set term needs the semi colon before the carat.. set term ;^ .Music
C
5

Try this:

set term ^ ;

EXECUTE BLOCK 
AS
   DECLARE VARIABLE var_SecondsOfTime INTEGER;

BEGIN
  SELECT  1 from RDB$DATABASE  into :var_SecondsOfTime ;
END^

set term  ;^

The second set term needs the semi colon before the carat.

Connection answered 26/2, 2011 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.