From 1a6c65df0ecd9c51609701649d931bf76cb7760b Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 5 Aug 2022 12:43:57 +0900 Subject: [PATCH] Minor test updates, comment typo updates, DB_CONFIG_SET for default $DB_CONFIG_SET is now default current selcted db config instead of $DB_CONFIG so to not overwrite the array itself --- www/admin/class_test.db.php | 36 ++++++++++++++++++++++++++++------- www/configs/config.db.php | 15 ++++++++++++++- www/configs/config.master.php | 2 +- www/lib/CoreLibs/DB/IO.php | 4 ++-- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/www/admin/class_test.db.php b/www/admin/class_test.db.php index a6cd2662..ee19d98a 100644 --- a/www/admin/class_test.db.php +++ b/www/admin/class_test.db.php @@ -209,13 +209,12 @@ print "INSERT WITH NO PRIMARY KEY WITH RETURNING STATUS: " . Support::printToStr print ""; // READ PREPARE -if ( - $db->dbPrepare( - 'sel_test_foo', - "SELECT test_foo_id, test, some_bool, string_a, number_a, number_a_numeric, some_time " - . "FROM test_foo ORDER BY test_foo_id DESC LIMIT 5" - ) === false -) { +$q_prep = "SELECT test_foo_id, test, some_bool, string_a, number_a, " + . "number_a_numeric, some_time " + . "FROM test_foo " + . "WHERE test = $1 " + . "ORDER BY test_foo_id DESC LIMIT 5"; +if ($db->dbPrepare('sel_test_foo', $q_prep) === false) { print "Error in sel_test_foo prepare
"; } else { $max_rows = 6; @@ -229,6 +228,29 @@ if ( $i++; } } +// prepre a second time on normal connection +if ($db->dbPrepare('sel_test_foo', $q_prep) === false) { + print "Error prepareing
"; + print "ERROR (dbPrepare on same query): " + . $db->dbGetLastError() . "/" . $db->dbGetLastWarning() . "/" + . "
" . print_r($db->dbGetCombinedErrorHistory(), true) . "

"; +} +// NOTE: try to replacate connection still exists if script is run a second time +// open pg bouncer connection +$db_pgb = new CoreLibs\DB\IO($DB_CONFIG['test_pgbouncer'], $log); +print "[PGB] DBINFO: " . $db_pgb->dbInfo() . "
"; +if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) { + print "[PGB] [1] Error in pgb_sel_test_foo prepare
"; +} else { + print "[PGB] [1] pgb_sel_test_foo prepare OK
"; +} +// second prepare +if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) { + print "[PGB] [2] Error in pgb_sel_test_foo prepare
"; +} else { + print "[PGB] [2] pgb_sel_test_foo prepare OK
"; +} +$db_pgb->dbClose(); # db write class test $table = 'test_foo'; diff --git a/www/configs/config.db.php b/www/configs/config.db.php index 3c4c06e4..23bf44d3 100644 --- a/www/configs/config.db.php +++ b/www/configs/config.db.php @@ -17,7 +17,20 @@ $DB_CONFIG = [ 'db_user' => $_ENV['DB_USER.TEST'] ?? '', 'db_pass' => $_ENV['DB_PASS.TEST'] ?? '', 'db_host' => $_ENV['DB_HOST.TEST'] ?? '', - 'db_port' => 5432, + 'db_port' => $_ENV['DB_PORT.PG'] ?? 5432, + 'db_schema' => 'public', + 'db_type' => 'pgsql', + 'db_encoding' => '', + 'db_ssl' => 'allow', // allow, disable, require, prefer + 'db_debug' => true, // turn on logging or not + ], + // same as above, but uses pg bouncer + 'test_pgbouncer' => [ + 'db_name' => $_ENV['DB_NAME.TEST'] ?? '', + 'db_user' => $_ENV['DB_USER.TEST'] ?? '', + 'db_pass' => $_ENV['DB_PASS.TEST'] ?? '', + 'db_host' => $_ENV['DB_HOST.TEST'] ?? '', + 'db_port' => $_ENV['DB_PORT.PG_BOUNCER'] ?? 5432, 'db_schema' => 'public', 'db_type' => 'pgsql', 'db_encoding' => '', diff --git a/www/configs/config.master.php b/www/configs/config.master.php index 82abd0c9..163f957b 100644 --- a/www/configs/config.master.php +++ b/www/configs/config.master.php @@ -252,7 +252,7 @@ if ($is_secure) { define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host']); define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []); // because we can't change constant, but we want to for db debug flag -$GLOBALS['DB_CONFIG'] = DB_CONFIG; +$GLOBALS['DB_CONFIG_SET'] = DB_CONFIG; // define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']); // define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']); // override for login and global schemas diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index df9c9d10..83bc6b61 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -2963,7 +2963,7 @@ class IO * Either as single array level for single insert * Or nested array for multiple insert values * - * If key was set only returns tghose values directly or as array + * If key was set only returns those values directly or as array * * On multiple insert return the position for which to return can be set too * @@ -2978,7 +2978,7 @@ class IO // return as is if key is null if ($key === null) { if (count($this->insert_id_arr) == 1) { - // return as nul if not found + // return as null if not found return $this->insert_id_arr[0] ?? null; } else { return $this->insert_id_arr;