From 23d4b4f4033e97dea7fca85dddcf878f6d03f99c Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Sat, 15 Oct 2016 11:51:05 +0200 Subject: [PATCH 1/4] Fixed pgsql lastInserteId --- src/Database/Table/Selection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 7ca6d7e2c..87651141c 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -821,7 +821,7 @@ public function insert($data) ? implode('.', array_map([$this->context->getConnection()->getSupplementalDriver(), 'delimite'], explode('.', $tmp))) : NULL ); - if ($primaryKey === FALSE) { + if ($primaryKey === FALSE || $primaryKey === "0") { unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]); return $return->getRowCount(); } From e96689929ed1163f62aa3dfda96059855b519bf1 Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Sun, 16 Oct 2016 11:00:31 +0200 Subject: [PATCH 2/4] Fixed quotes --- src/Database/Table/Selection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 87651141c..490dc6b0b 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -821,7 +821,7 @@ public function insert($data) ? implode('.', array_map([$this->context->getConnection()->getSupplementalDriver(), 'delimite'], explode('.', $tmp))) : NULL ); - if ($primaryKey === FALSE || $primaryKey === "0") { + if ($primaryKey === FALSE || $primaryKey === '0') { unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]); return $return->getRowCount(); } From c497ccde69070301a92a70f11ecb926d51cdd276 Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Tue, 18 Oct 2016 07:08:22 +0200 Subject: [PATCH 3/4] Return $data or ActiveRow also when primary key is not autoincrement --- src/Database/Table/Selection.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 490dc6b0b..06ccab416 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -821,12 +821,12 @@ public function insert($data) ? implode('.', array_map([$this->context->getConnection()->getSupplementalDriver(), 'delimite'], explode('.', $tmp))) : NULL ); - if ($primaryKey === FALSE || $primaryKey === '0') { + if ($primaryKey === FALSE) { unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]); return $return->getRowCount(); } - if (is_array($this->getPrimary())) { + if (!$primaryKey && is_array($this->getPrimary())) { $primaryKey = []; foreach ((array) $this->getPrimary() as $key) { @@ -839,7 +839,13 @@ public function insert($data) if (count($primaryKey) === 1) { $primaryKey = reset($primaryKey); } - } + } elseif (!$primaryKey && is_string($this->getPrimary())) { + $key = $this->getPrimary(); + if (!isset($data[$key])) { + return $data; + } + $primaryKey = $data[$key]; + } $row = $this->createSelectionInstance() ->select('*') From 6301f2b7730b242ad50f9418732c2192973225e7 Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Tue, 18 Oct 2016 07:12:44 +0200 Subject: [PATCH 4/4] Revert commit --- src/Database/Table/Selection.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 06ccab416..490dc6b0b 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -821,12 +821,12 @@ public function insert($data) ? implode('.', array_map([$this->context->getConnection()->getSupplementalDriver(), 'delimite'], explode('.', $tmp))) : NULL ); - if ($primaryKey === FALSE) { + if ($primaryKey === FALSE || $primaryKey === '0') { unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]); return $return->getRowCount(); } - if (!$primaryKey && is_array($this->getPrimary())) { + if (is_array($this->getPrimary())) { $primaryKey = []; foreach ((array) $this->getPrimary() as $key) { @@ -839,13 +839,7 @@ public function insert($data) if (count($primaryKey) === 1) { $primaryKey = reset($primaryKey); } - } elseif (!$primaryKey && is_string($this->getPrimary())) { - $key = $this->getPrimary(); - if (!isset($data[$key])) { - return $data; - } - $primaryKey = $data[$key]; - } + } $row = $this->createSelectionInstance() ->select('*')