From 40774e7dbe6ca0d4f9e7aba3d3bc479f9c858301 Mon Sep 17 00:00:00 2001 From: Lewis Dimmick Date: Thu, 19 Jul 2018 15:10:43 +0100 Subject: [PATCH 1/5] Updated insertMulti Complete with fix for k warning. --- MysqliDb.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index 6a55bddf..baa5737c 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -780,6 +780,13 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys $autoCommit = (isset($this->_transaction_in_progress) ? !$this->_transaction_in_progress : true); $ids = array(); + $options = [ + '_queryOptions' => $this->_queryOptions, + '_nestJoin' => $this->_nestJoin, + '_forUpdate' => $this->_forUpdate, + '_lockInShareMode' => $this->_lockInShareMode + ]; + if($autoCommit) { $this->startTransaction(); } @@ -789,6 +796,10 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys // apply column-names if given, else assume they're already given in the data $insertData = array_combine($dataKeys, $insertData); } + + foreach ($options as $k => $v) { + $this->${'k'} = $v; + } $id = $this->insert($tableName, $insertData); if(!$id) { @@ -799,14 +810,12 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys } $ids[] = $id; } - if($autoCommit) { $this->commit(); } - return $ids; } - + /** * Replace method to add new row * From 597b1341a26194661d7436bc1ff0d5a8d97a268f Mon Sep 17 00:00:00 2001 From: Lewis Dimmick Date: Thu, 19 Jul 2018 15:34:04 +0100 Subject: [PATCH 2/5] Updated to acomodate insert ignore with multi White spaces removed too ? --- MysqliDb.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index baa5737c..4e1bef90 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -779,40 +779,39 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys // only auto-commit our inserts, if no transaction is currently running $autoCommit = (isset($this->_transaction_in_progress) ? !$this->_transaction_in_progress : true); $ids = array(); - $options = [ '_queryOptions' => $this->_queryOptions, '_nestJoin' => $this->_nestJoin, '_forUpdate' => $this->_forUpdate, - '_lockInShareMode' => $this->_lockInShareMode + '_lockInShareMode' => $this->_lockInShareMode ]; - if($autoCommit) { $this->startTransaction(); } - foreach ($multiInsertData as $insertData) { + $this->_queryOptions = $options['_queryOptions']; + $this->_nestJoin = $options['_nestJoin']; + $this->_forUpdate = $options['_forUpdate']; + $this->_lockInShareMode = $options['_lockInShareMode']; if($dataKeys !== null) { // apply column-names if given, else assume they're already given in the data $insertData = array_combine($dataKeys, $insertData); } - foreach ($options as $k => $v) { $this->${'k'} = $v; } - $id = $this->insert($tableName, $insertData); - if(!$id) { - if($autoCommit) { + if(!$id ) { + if($autoCommit && !in_array('IGNORE', $options['_queryOptions'])) { $this->rollback(); } - return false; + $id = false; } $ids[] = $id; - } + } if($autoCommit) { $this->commit(); - } + } return $ids; } From a955cf7775b7a4231b7f909a4665e33f1d3a00dd Mon Sep 17 00:00:00 2001 From: Lewis Dimmick Date: Thu, 19 Jul 2018 15:36:43 +0100 Subject: [PATCH 3/5] Woops, removed some redundant lines. --- MysqliDb.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index 4e1bef90..87b446fc 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -789,10 +789,6 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys $this->startTransaction(); } foreach ($multiInsertData as $insertData) { - $this->_queryOptions = $options['_queryOptions']; - $this->_nestJoin = $options['_nestJoin']; - $this->_forUpdate = $options['_forUpdate']; - $this->_lockInShareMode = $options['_lockInShareMode']; if($dataKeys !== null) { // apply column-names if given, else assume they're already given in the data $insertData = array_combine($dataKeys, $insertData); From f608e43bdb6e5887c1ffa32a2e0c31ffec682bb5 Mon Sep 17 00:00:00 2001 From: Lewis Dimmick Date: Fri, 20 Jul 2018 08:14:30 +0100 Subject: [PATCH 4/5] Sorted return type --- MysqliDb.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index 87b446fc..eb1572bd 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -793,15 +793,15 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys // apply column-names if given, else assume they're already given in the data $insertData = array_combine($dataKeys, $insertData); } - foreach ($options as $k => $v) { - $this->${'k'} = $v; - } + foreach ($options as $k => $v) { + $this->{$k} = $v; + } $id = $this->insert($tableName, $insertData); if(!$id ) { if($autoCommit && !in_array('IGNORE', $options['_queryOptions'])) { $this->rollback(); } - $id = false; + return $id; } $ids[] = $id; } From ababc3afc66495843bf726f110fb6444a087146b Mon Sep 17 00:00:00 2001 From: Lewis Dimmick Date: Fri, 20 Jul 2018 09:34:17 +0100 Subject: [PATCH 5/5] Is that one right.. ? --- MysqliDb.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MysqliDb.php b/MysqliDb.php index eb1572bd..aa05e187 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -774,7 +774,7 @@ public function insert($tableName, $insertData) * * @return bool|array Boolean indicating the insertion failed (false), else return id-array ([int]) */ - public function insertMulti($tableName, array $multiInsertData, array $dataKeys = null) + public function insertMulti($tableName, $multiInsertData, $dataKeys = null) { // only auto-commit our inserts, if no transaction is currently running $autoCommit = (isset($this->_transaction_in_progress) ? !$this->_transaction_in_progress : true); @@ -785,9 +785,11 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys '_forUpdate' => $this->_forUpdate, '_lockInShareMode' => $this->_lockInShareMode ]; + if($autoCommit) { $this->startTransaction(); } + foreach ($multiInsertData as $insertData) { if($dataKeys !== null) { // apply column-names if given, else assume they're already given in the data @@ -805,9 +807,11 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys } $ids[] = $id; } + if($autoCommit) { $this->commit(); } + return $ids; }