[Fdo_dev] About RDBI's get_gen_id() function
mateusz at loskot.net
Wed Jan 10 09:51:25 EST 2007
Hello after holidays and Happy New Year!
I'm struggling with small problem - implementation of get_gen_id()
function in RDBI driver for PostGIS.
The problem is that the higher level - GDBI - calling get_gen_id() does
not provide me with enough details.
The prototype looks as follows:
get_gen_id(postgis_context [in], table_name [in], id [out])
For MySQL it works because LAST_INSERT_ID returns session-wide value for
In PostgreSQL the situation is slightly different, to access particular
sequence, table name and column name are required.
Unfortunately, I don't get column name from the GDBI layer.
Unfortunately, I can't drop the GDBI usage here and nowhere in my
provider, so I have to deal with this issue in some way.
I see two solutions:
1) Change a bit the GDBI layer to provide me with column name too.
All tables and sequences for FDO meta schema are hard coded, so column
names also could be.
Then GdbiCommands::NextRDBMSAutoincrementNumber(sequence) function could
look as follows (pseudo-code):
if (sequence == HARDCODED_SEQ)
table = HARDCODED_TABLE_NAME
column = HARDCODED_COLUMN_NAME
get_gen_id(context, table, column, &id [out]);
Certainly, for MySQL and others, column param can be unused,
as table for MySQL is now.
I believe this change doesn't break any code on higher level, because
it's internal for GDBI and RDBI.
However, it would breat the MySQL code - additional parameter for
2) No GDBI changes, but I will resolve table name to column name inside
my RDBI driver. But here I'd need confirmation that there is
constant/unchangeable relation between table name and column name.
So, if I will get 'f_classdefinition' table, I can safely
assume the column name is 'classid'.
What do you think?
May be you'd suggest a better one?
BTW, I think the MySQL solution is logically unsafe.
For MySQL get_gen_id() returns session-wide version, without any
verification of table or table + column.
So, it is possible to occur, the sequence of operations will be as follows:
1. auto-increment field X in table A
2. auto-increment field Y in table B
3. Try to fetch value of auto-increment field for X in A
and because of nature of LAST_INSERT_ID(), incorrect value will be returned.
More information about the Fdo-internals