From b759ba70f31e212d80cf926602c5e4f8a9fbecdc Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 7 Oct 2026 10:42:29 +0900 Subject: [PATCH] Add try / catch block for DB tests --- www/admin/class_test.db.php | 76 ++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/www/admin/class_test.db.php b/www/admin/class_test.db.php index 4a7676e7..c0521277 100644 --- a/www/admin/class_test.db.php +++ b/www/admin/class_test.db.php @@ -683,42 +683,48 @@ echo "
"; // 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] Warning 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] Warning in pgb_sel_test_foo prepare
"; -} else { - print "[PGB] [2] pgb_sel_test_foo prepare OK
"; -} -// same statment name, different query -if ( - $db->dbPrepare('pgb_sel_test_foo', <<"; -} else { - print "[PGB] [3] pgb_sel_test_foo prepare OK
"; -} -$stm_status = $db->dbPreparedCursorStatus(''); -print "[PGB] Empty statement name: " . $log->prAr($stm_status) . "
"; -$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foobar'); -print "[PGB] Prepared name not match status: $stm_status
"; -$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo'); -print "[PGB] Prepared name match status: $stm_status
"; -$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', $q_prep); -print "[PGB] prepared exists and query match status: $stm_status
"; -$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', "SELECT * FROM test_foo"); -print "[PGB] prepared exists and query not match status: $stm_status
"; +try { + $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] Warning 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] Warning in pgb_sel_test_foo prepare
"; + } else { + print "[PGB] [2] pgb_sel_test_foo prepare OK
"; + } + // same statment name, different query + if ( + $db->dbPrepare('pgb_sel_test_foo', <<"; + } else { + print "[PGB] [3] pgb_sel_test_foo prepare OK
"; + } + $stm_status = $db->dbPreparedCursorStatus(''); + print "[PGB] Empty statement name: " . $log->prAr($stm_status) . "
"; + $stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foobar'); + print "[PGB] Prepared name not match status: $stm_status
"; + $stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo'); + print "[PGB] Prepared name match status: $stm_status
"; + $stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', $q_prep); + print "[PGB] prepared exists and query match status: $stm_status
"; + $stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', "SELECT * FROM test_foo"); + print "[PGB] prepared exists and query not match status: $stm_status
"; -$db_pgb->dbClose(); + $db_pgb->dbClose(); +} catch (\Exception $e) { + print ""; + print "[PGB] Exception caught: " . $e->getMessage() . "
"; + print "
"; +} # db write class test $table = 'test_foo';