Commit 0ae1695e authored by Vincent Pelletier's avatar Vincent Pelletier

Some MySQL verions behave strangely when LAST_INSERT_ID is used twice in the...

Some MySQL verions behave strangely when LAST_INSERT_ID is used twice in the same request. As the query is in a BEGIN..COMMIT block, fetch the inserted value instead of using LAST_INSERT_ID trick. Patch proposed by Yoshinori & applied verbatim.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13789 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c5c22344
......@@ -109,14 +109,13 @@ default:int=1</string> </value>
\n
BEGIN\n
<dtml-var sql_delimiter>\n
INSERT INTO\n
portal_ids (`id_group`, `last_id`)\n
VALUES\n
(<dtml-sqlvar id_group type="string">, LAST_INSERT_ID(<dtml-sqlvar expr="default + id_count" type="int">))\n
ON DUPLICATE KEY UPDATE\n
`last_id` = LAST_INSERT_ID(`last_id` + <dtml-sqlvar id_count type="int">)\n
INSERT INTO portal_ids (`id_group`, `last_id`)\n
VALUES (<dtml-sqlvar id_group type="string">, <dtml-sqlvar expr="id_count + default" type="int">)\n
ON DUPLICATE KEY UPDATE `last_id` = `last_id` + <dtml-sqlvar id_count type="int">\n
<dtml-var sql_delimiter>\n
SELECT LAST_INSERT_ID()
SELECT `last_id` AS `LAST_INSERT_ID()` FROM portal_ids\n
WHERE `id_group` = <dtml-sqlvar id_group type="string">\n
]]></string> </value>
</item>
......@@ -159,14 +158,13 @@ SELECT LAST_INSERT_ID()
\n
BEGIN\n
<dtml-var sql_delimiter>\n
INSERT INTO\n
portal_ids (`id_group`, `last_id`)\n
VALUES\n
(<dtml-sqlvar id_group type="string">, LAST_INSERT_ID(<dtml-sqlvar expr="default + id_count" type="int">))\n
ON DUPLICATE KEY UPDATE\n
`last_id` = LAST_INSERT_ID(`last_id` + <dtml-sqlvar id_count type="int">)\n
INSERT INTO portal_ids (`id_group`, `last_id`)\n
VALUES (<dtml-sqlvar id_group type="string">, <dtml-sqlvar expr="id_count + default" type="int">)\n
ON DUPLICATE KEY UPDATE `last_id` = `last_id` + <dtml-sqlvar id_count type="int">\n
<dtml-var sql_delimiter>\n
SELECT LAST_INSERT_ID()
SELECT `last_id` AS `LAST_INSERT_ID()` FROM portal_ids\n
WHERE `id_group` = <dtml-sqlvar id_group type="string">\n
]]></string> </value>
</item>
......
38
\ No newline at end of file
40
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment