[Lazarus] newbie question: tsqlquery; primarykey; insert.

Kovács László info at kovacsoltvideo.hu
Tue Nov 26 22:22:57 CET 2013


First let me say thank you very much Antonio and Reinier!

------ Az eredeti üzenet ------
Feladó: "Reinier Olislagers" <reinierolislagers at gmail.com>
Címzett: "Lazarus mailing list" <lazarus at lists.lazarus.freepascal.org>
Elküldött elemek: 2013.11.26. 17:05:23
Tárgy Re: [Lazarus] newbie question: tsqlquery; primarykey; insert.
>
>FYI:
>1. IBExprt is a good tool, but FlameRobin is also nice (and open
>source). Multiplatform as well.
>2. There's a Lazarus data desktop application included in (IIRC) the
>tools directory of your Lazarus install.
Thanks for the hint on FlameRobin, I'll check it.
IBExpert was really a big help for me.
After you mentioned, looked for but didn't find that data desktop in the 
tools dir.
I'm running on Windows, and just installed the latest Lazarus I could 
download.
Should it really be there?

------ Az eredeti üzenet ------
Feladó: "Antonio Fortuny" <a.fortuny at sitasoftware.lu>
Címzett: lazarus at lists.lazarus.freepascal.org
Elküldött elemek: 2013.11.26. 16:52:06
Tárgy Re: [Lazarus] newbie question: tsqlquery; primarykey; insert.

In the application when you need a new value for a sequence (an insert 
for instance) I execute the next query just before:
select next value for my_generator_name as column_name_i_want from 
rdb$database
and I get the value with the query which executed the query (some TQuery 
component, using FieldByName('column_name_i_want).AsInteger or better 
AsLargeInt)
The unique ID has been definitely reserved and the I can use it into any 
other update or insert with other tables.
This is my way but it not the only one but because I want to control 
everything which reports to database, i'm used to this method

Antonio.
-------------------

Antonio, thanks!
That rocks!
I dropped my triggers,because they are useless now.
I added another query with the sql you mentioned (adapted the fields 
names of course :))
This is GenQuery.
My original query  is already open, and bound to a dbgrid, and is now 
just a select * from a table, I'm just testing the basics.
So, this is TestQuery.
I have put in TestQuery afterinsert event handler
Genquery.Open; TestQuery.FieldbyName ('ID').asLargeint := 
GenQuery.Fields[0].asLargeint; GenQuery.Close;
So if the dbgrid adds a row, I can see the newly generated ID in the 
column.
So far, so good, one basic thing is working, the new ID is under my 
control, cause I can have it in a variable, if I want to, and that's 
vital for further processing.
I think TestQuery.Post is called automatically by the DBGrid, but seems, 
that I have to call upplyupdates and commit.

Thank you very much!


Best regards
Laszlo Kovacs






More information about the Lazarus mailing list