From ff94efee8dd880c30efd8b969e4d3df6e660da65 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 2 Nov 2017 17:04:43 +0900 Subject: [PATCH] Fix in class db io returning on insert Skip add RETURNING on auto set if 'NULL' is set as a primary key. On return, also run if count of returned ids is > 0 (so it actually runs the extended return flow) --- www/libs/Class.DB.IO.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/libs/Class.DB.IO.inc b/www/libs/Class.DB.IO.inc index 4833e09a..b7383048 100644 --- a/www/libs/Class.DB.IO.inc +++ b/www/libs/Class.DB.IO.inc @@ -663,12 +663,12 @@ } $this->pk_name = $this->pk_name_table[$table] ? $this->pk_name_table[$table] : 'NULL'; } - if (!preg_match("/ returning /i", $this->query) && $this->pk_name) + if (!preg_match("/ returning /i", $this->query) && $this->pk_name && $this->pk_name != 'NULL') { $this->query .= " RETURNING ".$this->pk_name; $this->returning_id = true; } - elseif (preg_match("/ returning (.*)/i", $this->query, $matches) && $this->pk_name) + elseif (preg_match("/ returning (.*)/i", $this->query, $matches) && $this->pk_name && $this->pk_name != 'NULL') { // add the primary key if it is not in the returning set if (!preg_match("/$this->pk_name/", $matches[1])) @@ -763,7 +763,7 @@ $this->insert_id[] = $_insert_id; } // if we have only one, revert from array to single - if (count($this->insert_id) == 1) + if (count($this->insert_id) >= 1) { // echo "* SINGLE DATA CONVERT: ".count($this->insert_id[0])." => ".array_key_exists($this->pk_name, $this->insert_id[0])."
"; // echo "* PK DIRECT: ".$this->insert_id[0][$this->pk_name]."
";