[Gambas-user] Gambas2 components?
Rob
sourceforge-raindog2 at ...94...
Wed Jan 14 20:42:27 CET 2009
On Wednesday 14 January 2009 10:29, Gareth Bult wrote:
> This function would be required regardless of the underlying DB .. so
> what't the PG equivalent ?
By looking at the sqlite docs, I'm guessing last_insert_rowid() is their
equivalent, but I only have MySQL installed so I can't test it.
But some DB engines don't even have auto-incrementing fields, let alone a
function to return the last inserted ID. Google tells me
CURRVAL(pg_get_serial_sequence('my_tbl_name','id_col_name'))
is the Postgres equivalent, but if it uses sequences, I think that's
different than what we know as autoincrement fields. With Firebird, you
can approximate the functionality with generators, like this:
-- before inserting any rows into table
CREATE GENERATOR generator_id;
-- then, as part of each insert statement
INSERT INTO tablename (keycolumn, ...) VALUES
(gen_id(generator_id, 1), ...);
-- after all that, here's the LAST_INSERT_ID() equivalent
SELECT gen_id(generator_id, 0);
I have no idea whether this is safe to use with multiple connections (like
MySQL's is) or anything like that. I also don't think there's any
standard ODBC mechanism to do this.
Rob
More information about the User
mailing list