From b4b33d68734d550652098f799d5dd02a0c158810 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 3 Apr 2023 15:02:39 +0900 Subject: [PATCH] Bug fix for DB\IO returning detection it was still coded with old one line and not taking in possible line breaks in the returning code part --- www/admin/class_test.db.php | 26 ++++++++++++++++++++++++-- www/lib/CoreLibs/DB/IO.php | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/www/admin/class_test.db.php b/www/admin/class_test.db.php index 5ca62573..afaefc92 100644 --- a/www/admin/class_test.db.php +++ b/www/admin/class_test.db.php @@ -413,13 +413,35 @@ if (is_array($s_res = $db->dbReturnRow($q)) && !empty($s_res['test'])) { } // UPDATE WITH RETURNING -$status = $db->dbExec("UPDATE test_foo SET test = 'SOMETHING DIFFERENT' " - . "WHERE test_foo_id = " . (int)$last_insert_pk . " RETURNING test"); +$status = $db->dbExec("UPDATE test_foo SET test = 'SOMETHING DIFFERENT', string_a = '" . (string)rand(1, 100) . "' " + . "WHERE test_foo_id = " . (int)$last_insert_pk . " RETURNING test_foo.test, string_a"); print "UPDATE WITH PK " . Support::printToString($last_insert_pk) . " RETURN STATUS: " . Support::printToString($status) . " |
" . "QUERY: " . $db->dbGetQuery() . " |
" . "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | " . "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "
"; +// UPDATE BUT EOM STYLE +$status = $db->dbExecParams( + <<" + . "QUERY: " . $db->dbGetQuery() . " |
" + . "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | " + . "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "
"; + +// a stand alone insert? $db->dbExec("INSERT INTO test_foo (test) VALUES ('STAND ALONE')"); // INSERT WITH NO RETURNING diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index f54cc823..6e2b8814 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -280,7 +280,7 @@ class IO /** @var string default hash type */ public const ERROR_HASH_TYPE = 'adler32'; /** @var string regex to get returning with matches at position 1 */ - public const REGEX_RETURNING = '/\s+returning\s+(.+?);?$/i'; + public const REGEX_RETURNING = '/\s+returning\s+(.+\s*(?:.+\s*)+);?$/i'; // recommend to set private/protected and only allow setting via method // can bet set from outside