V . I . C . O . D . I . N snow
Howdy everyone! LAST_INSERT_ID() in MySQL returns the number of the last automatically generated autoincrement value on a per-connection basis. Now, as far as I understand, when using ZMySQLDA all queries share one connection which saves a lot of time, because it is not necessary to open a new connection for each and every statement. But what happens when the server load is increasing and there are many insert statements? Wouldn't it be possible that another insert would be executed by another Zope thread in between an insert and a corresponding select LAST_INSERT_ID() so that LAST_INSERT_ID() would not return the expected value? Cheers, Ragnar
On Thu, 2 Sep 2004 18:48:27 +0200, Ragnar Beer <rbeer1@uni-goettingen.de> wrote:
LAST_INSERT_ID() in MySQL returns the number of the last automatically generated autoincrement value on a per-connection basis. Now, as far as I understand, when using ZMySQLDA all queries share one connection which saves a lot of time, because it is not necessary to open a new connection for each and every statement.
No, the DA mechanisms create one connection per thread, so LAST_INSERT_ID() should be safe. I do recommend incorporating this into the same Z SQL Method as your INSERT. Note that you must separate SQL statements in a Z SQL Method with <dtml-var sql_delimiter>. http://www.zope.org/Documentation/Guides/ZSQL-HTML/ZSQL.1.4.4.html In other words: INSERT .... into blah <dtml-var sql_delimiter> SELECT LAST_INSERT_ID() sql_delimiter is actually a null character (\0) as I recall used by the DA to split up statements. -- Computer interfaces should never be made of meat.
That's good news. Thank you, Andy! On Thu, 2 Sep 2004 13:45:45 -0400 Andy Dustman <farcepest@gmail.com> wrote:
On Thu, 2 Sep 2004 18:48:27 +0200, Ragnar Beer <rbeer1@uni-goettingen.de> wrote:
LAST_INSERT_ID() in MySQL returns the number of the last automatically generated autoincrement value on a per-connection basis. Now, as far as I understand, when using ZMySQLDA all queries share one connection which saves a lot of time, because it is not necessary to open a new connection for each and every statement.
No, the DA mechanisms create one connection per thread, so LAST_INSERT_ID() should be safe. I do recommend incorporating this into the same Z SQL Method as your INSERT. Note that you must separate SQL statements in a Z SQL Method with <dtml-var sql_delimiter>.
http://www.zope.org/Documentation/Guides/ZSQL-HTML/ZSQL.1.4.4.html
In other words:
INSERT .... into blah <dtml-var sql_delimiter> SELECT LAST_INSERT_ID()
sql_delimiter is actually a null character (\0) as I recall used by the DA to split up statements. -- Computer interfaces should never be made of meat. _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Andy Dustman -
delcie Dressler -
Ragnar Beer