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

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Mark Morgan Lloyd
brian wrote 11 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?

Embedded in what way? I use Firebird on occasion as an alternative to PostgreSQL (i.e. in a client-server scenario), but I'd have thought for a single-system application SQLite would have been worth a look.

Having said that, apart from Firebird's poor documentation I've had no significant problem querying and updating tables. What exactly are you trying to do?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

brian
to Mark Morgan Lloyd
you wrote 17 lines
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? Embedded in what way? I use Firebird on occasion as an alternative to PostgreSQL (i.e. in a client-server scenario), but I'd have thought for a single-system application SQLite would have been worth a look.

Embedded as in there is no requirement for the user to do anything except unpack a zip file and run the executable. No installation of any kind of server on the host system.

Having said that, apart from Firebird's poor documentation I've had no significant problem querying and updating tables. What exactly are you trying to do?

Retrieve a value generated by a Firebird generator (in other words, an autoincremented value stored within the database) and get that incremented value into a Pascal variable. The SQL code to increment the value in the Firebird database is

SELECT (<generator>,<increment>) FROM RDB$DATABASE;

but I'm struggling to find a way to retrieve that incremented value. Simply attaching a data source to the query returns zero rows when the SQL is executed. I'm wondering whether I need to use a dummy table and then use the generator to update a field, then retrieve the data with a separate query.

Brian.

Reply by email

Gabor Boros

2015.04.25. 16:52 keltez?ssel, brian ?rta:

Show quoted text 13 lines
Retrieve a value generated by a Firebird generator (in other words, an autoincremented value stored within the database) and get that incremented value into a Pascal variable. The SQL code to increment the value in the Firebird database is SELECT (<generator>,<increment>) FROM RDB$DATABASE; but I'm struggling to find a way to retrieve that incremented value. Simply attaching a data source to the query returns zero rows when the SQL is executed. I'm wondering whether I need to use a dummy table and then use the generator to update a field, then retrieve the data with a separate query.

Hi,

Use RETURNING clause with INSERT or UPDATE is a better solution.

Gabor

Reply by email

Michael Van Canneyt
to Gabor Boros
Gabor Boros wrote 18 lines
2015.04.25. 16:52 keltez?ssel, brian ?rta: > > Retrieve a value generated by a Firebird generator (in other words, an > autoincremented value stored within the database) and get that > incremented value into a Pascal variable. The SQL code to increment > the value in the Firebird database is > > SELECT (<generator>,<increment>) FROM RDB$DATABASE; > > but I'm struggling to find a way to retrieve that incremented value. > Simply attaching a data source to the query returns zero rows when the > SQL is executed. I'm wondering whether I need to use a dummy table and > then use the generator to update a field, then retrieve the data with > a separate query. Hi, Use RETURNING clause with INSERT or UPDATE is a better solution.

Correct but this is not a solution if you just need the value, without INSERT or UPDATE statement.

Michael.

Reply by email