[TASK] Do not use sequence table when uid field is auto-incremented 79/39079/2
authorXavier Perseguers <xavier@typo3.org>
Thu, 30 Apr 2015 10:43:42 +0000 (12:43 +0200)
committerXavier Perseguers <xavier@typo3.org>
Thu, 30 Apr 2015 13:33:44 +0000 (15:33 +0200)
A sequence table should not be used when the underlying ADOdb driver
is capable of properly using and retrieving auto-incremented fields.

Change-Id: I8d474e253c927d2dcb4d6ebc9ad6eb5bb4d06f2d
Releases: master, 6.2
Resolves: #66680
Reviewed-on: http://review.typo3.org/39079
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Tested-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/sysext/dbal/Classes/Database/DatabaseConnection.php

index b14aa32..ddee5ea 100644 (file)
@@ -509,7 +509,9 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection {
                                                if ($table != 'tx_dbal_debuglog') {
                                                        $this->handlerInstance[$this->lastHandlerKey]->last_insert_id = $new_id;
                                                }
-                                       } else {
+                                       } elseif (!$this->handlerInstance[$this->lastHandlerKey]->hasInsertID) {
+                                               // The table does not support auto-incremented fields, fall back to
+                                               // using a sequence table to simulate the auto-increment
                                                $new_id = $this->handlerInstance[$this->lastHandlerKey]->GenID($table . '_' . $this->cache_autoIncFields[$table], $this->handlerInstance[$this->lastHandlerKey]->sequenceStart);
                                                $fields_values[$this->cache_autoIncFields[$table]] = $new_id;
                                                if ($table != 'tx_dbal_debuglog') {
@@ -524,6 +526,10 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection {
                                        $this->handlerInstance[$this->lastHandlerKey]->StartTrans();
                                        if ($this->lastQuery[0] !== '') {
                                                $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery[0], FALSE);
+                                               if ($this->handlerInstance[$this->lastHandlerKey]->hasInsertID) {
+                                                       // The table is able to retrieve the ID of the last insert, use it to update the blob below
+                                                       $new_id = $this->handlerInstance[$this->lastHandlerKey]->Insert_ID($table, $this->cache_autoIncFields[$table]);
+                                               }
                                        }
                                        if (is_array($this->lastQuery[1])) {
                                                foreach ($this->lastQuery[1] as $field => $content) {