zeos and auto increment

Forum related to all other 6.x versions of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
vinicius_vdb
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 12.01.2006, 18:40

zeos and auto increment

Post by vinicius_vdb »

Hi,,,

I've used zeos with postgre, but i don't know how to use it with auto-increment, when i trie to append a new record by a TZquery the auto increment cod is not inserted, but when i execute a query (e.g. insert into...) all works ok..

thanks...
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

When inserting a row use the NULL value, example:

Insert Into CUSTOMER Values (NULL, "Customer name")
benp
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 26.01.2006, 12:15

Post by benp »

Is it possible to get the value of the autoinc-field of the inserted recordset?
I've seen JDBC-database-connectors that offer this feature, and it's really nice!

Best regards, Benedikt
ssamayoa
Junior Boarder
Junior Boarder
Posts: 29
Joined: 14.01.2006, 19:06

Post by ssamayoa »

This is the normal behaviour of C/S applications.
The application must SELECT the new insrted record to known wich fielsd where changed by pre-insert triggers and / or identity or auto inc fields.

Normally JDBC drivers can do this because them do the trick changing the SQL text adding RETURNING clause for those databases which supports it.

Better use sequence and get the value from database then put it on the field of your table before post.

Regards.
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

To get the last inserted key: Select LAST_INSERT_ID()
benp
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 26.01.2006, 12:15

Post by benp »

Zippo, thanks a lot for this hint!

I just made a little test and it seems to me that you get even then to correct autoinc-number if there are 2 concurrent inserts running.
Does someone know whether the 'select LAST_INSERT_ID()' works with all databases?

cheers
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

Think no, but you shoul consult some manuals (at leas PosGRe, Interbase and MsSQL
bravecobra
Junior Boarder
Junior Boarder
Posts: 29
Joined: 31.10.2005, 00:09
Location: Antwerp
Contact:

Post by bravecobra »

That's discussed here.
Post Reply