> I'm not convinced this will work. > What about concurrent inserts? Won't the optimistic "get id > in > advance" return the same id twice when the actual inserts > will use > unique ids?
This is done with sequences or triggers, and such sequences are generated for specific isolated contet, so it is promissed to be correct. > What about inserting multiple rows? Won't the "get id in > advance" > method return the id of the first inserted row while the > "get id > after the fact" return the last inserted row's id? Aren't > both > wrong? > Shouldn't we get multiple ids? > What about failed inserts? What about triggers that > manipulate the > id during the insert? This situation is not the situation that should be handled by "last_insert_id()" in ant case. > > What problem are we solving by returning the id in any > case? Trivial example that you would find in lots of systems. sql << "INSERT INTO messages(text) VALUES(:text)" ,using(message); int inserted_id = sql.last_insert_id(); url = "http://www.some.site.com/message/" + to_string(id); redirect(url) > Couldn't this be better dealt with by providing the id in > the first > place instead of using identity fields? Yes, unless you have concurrent access form multiple sources and you want to keep id value low (so UUID is no-go), thus autogenerated ids are very good and robust solusion > Couldn't this be > dealt with > by using stored procedures? You are assuming that anybody uses Oracle, PostgreSQL or MS SQL. What if I develop for some small system with Sqlite3 that is perfect DB for huge amount of applications? Also, writing stored procedures require quite advances skills in SQL and can't be done in "cross-sql" way, while simple inserts and queries do. This is very popular and useful feature, from **my** point of view it was the desition to move to LibDBI+DbiXX from SOCI because of this small feature. (I use moslty Sqlite3, MySQL and PostgreSQL) Artyom ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ Soci-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/soci-users
