[egenix-users] how to insert new row, update in-memory object with same row from database?

Michael Rothwell rothwell at holly-springs.nc.us
Mon Dec 30 13:30:14 CET 2002


M.-A. Lemburg wrote:
> In that case you'll have to figure out a set of columns using
> .specialcolumns(). I still don't understand how you would
> identify a newly inserted row like this, though. If the database
> provides defaults and maybe uses a trigger to fill in an ID
> column, then the knowledge of such a column wouldn't get you
> any further. Maybe I'm missing something ?

Well, it would be a sub-optimal solution. I'd have to coax the last 
insert ID out of the database, somehow, and then select using that key. 
On SQL Server, I would run "select @@IDENTITY," for instance, right 
after the insert of a single row. Then, query for that row to get all of 
the default values.

There's really no clean way to do it, as far as I can tell. Seems like a 
hole in the RDBMS concept -- one has to know the key to get the key. The 
best option is the one you mentioned -- create the unique IDs myself and 
store them in the tables, rather than using identity fields or 
equivalents. Still not very clean, but workable with a new scheme, at least.

Thanks,

-M






More information about the egenix-users mailing list