Know the autoincremental ID before insert

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ben
Posts: 119
Joined: Wed 17 Nov 2004 19:48

Know the autoincremental ID before insert

Post by ben » Wed 02 Mar 2005 00:51

Hello, is it possible to know the auto incremental ID before doing the insert? Just to display in the user interface what is the next ID.

Thanks

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 02 Mar 2005 09:03

Not, MySQL doesn't provide such functionality.

ben
Posts: 119
Joined: Wed 17 Nov 2004 19:48

Post by ben » Wed 02 Mar 2005 23:39

Well, it supports:

show table status like 'tablename' and read the "Auto_increment" field.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Thu 03 Mar 2005 12:34

In the interval between this query and Post execution it might be an insertion of records from another client

ben
Posts: 119
Joined: Wed 17 Nov 2004 19:48

Post by ben » Thu 03 Mar 2005 19:25

yes thats why you are doing a LOCK TABLE before. Anyway my application is single user.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Fri 04 Mar 2005 10:58

Your solution most likely will work.

Post Reply