Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-04

Returning value from a Firebird (embedded) generator into Lazarus code

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
brian wrote 12 lines
Hi folks, Can someone please give me a hint with this problem. I'm new to Firebird, but I needed a database which could be used in embedded fashion, and seemed to have a choice of one under Linux. What I need to do is to return a value generated by a Firebird generator into my Pascal code. Doing it what seemed to me to be the obvious way returns zero rows, do I need to update an interim table and then query that table? Or is there some other method which I've missed?

Do a

SELECT GEN_ID(YOUR_GENERATOR,1) AS THEVALUE FROM RDB$DATABASE

in a TSQLQuery instance. Then call "Open" and you can get the value.

Something like:

With TSQLQuery.Create(Nil) do
   try
     Database:=MyDatabase;
     SQL.Text:='SELECT GEN_ID(YOUR_GENERATOR,1) AS THEVALUE FROM RDB$DATABASE';
     Open;
     MyGenValue:=Fields[0].AsLargeInt;
   Finally
     Free;
   end;

Michael.

Reply by email

brian
to Michael Van Canneyt
you wrote 36 lines
On Sat, 25 Apr 2015, brian wrote: > > Hi folks, > > Can someone please give me a hint with this problem. I'm new to > Firebird, but I needed a database which could be used in embedded > fashion, and seemed to have a choice of one under Linux. > > What I need to do is to return a value generated by a Firebird > generator into my Pascal code. Doing it what seemed to me to be the > obvious way returns zero rows, do I need to update an interim table > and then query that table? Or is there some other method which I've > missed? Do a SELECT GEN_ID(YOUR_GENERATOR,1) AS THEVALUE FROM RDB$DATABASE in a TSQLQuery instance. Then call "Open" and you can get the value. Something like: With TSQLQuery.Create(Nil) do try Database:=MyDatabase; SQL.Text:='SELECT GEN_ID(YOUR_GENERATOR,1) AS THEVALUE FROM RDB$DATABASE'; Open; MyGenValue:=Fields[0].AsLargeInt; Finally Free; end; Michael.

Ahh.. OK, I knew it was something obvious. Thanks, Michael. I guess I've forgotten more of my (Oracle) SQL than I thought. I see what I've been doing wrong.

Brian.

Reply by email