Add try / catch block for DB tests
This commit is contained in:
1 parent
68ea44964f
commit
b759ba70f3
1 file changed
+31
-25
+31
-25
@@ -683,42 +683,48 @@ echo "<hr>";
|
|||||||
|
|
||||||
// NOTE: try to replacate connection still exists if script is run a second time
|
// NOTE: try to replacate connection still exists if script is run a second time
|
||||||
// open pg bouncer connection
|
// open pg bouncer connection
|
||||||
$db_pgb = new CoreLibs\DB\IO($DB_CONFIG['test_pgbouncer'] ?? [], $log);
|
try {
|
||||||
print "[PGB] DBINFO: " . $db_pgb->dbInfo() . "<br>";
|
$db_pgb = new CoreLibs\DB\IO($DB_CONFIG['test_pgbouncer'] ?? [], $log);
|
||||||
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
print "[PGB] DBINFO: " . $db_pgb->dbInfo() . "<br>";
|
||||||
|
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
||||||
print "[PGB] [1] Warning in pgb_sel_test_foo prepare<br>";
|
print "[PGB] [1] Warning in pgb_sel_test_foo prepare<br>";
|
||||||
} else {
|
} else {
|
||||||
print "[PGB] [1] pgb_sel_test_foo prepare OK<br>";
|
print "[PGB] [1] pgb_sel_test_foo prepare OK<br>";
|
||||||
}
|
}
|
||||||
// second prepare
|
// second prepare
|
||||||
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
|
||||||
print "[PGB] [2] Warning in pgb_sel_test_foo prepare<br>";
|
print "[PGB] [2] Warning in pgb_sel_test_foo prepare<br>";
|
||||||
} else {
|
} else {
|
||||||
print "[PGB] [2] pgb_sel_test_foo prepare OK<br>";
|
print "[PGB] [2] pgb_sel_test_foo prepare OK<br>";
|
||||||
}
|
}
|
||||||
// same statment name, different query
|
// same statment name, different query
|
||||||
if (
|
if (
|
||||||
$db->dbPrepare('pgb_sel_test_foo', <<<SQL
|
$db->dbPrepare('pgb_sel_test_foo', <<<SQL
|
||||||
SELECT * FROM test_foo WHERE test = $1
|
SELECT * FROM test_foo WHERE test = $1
|
||||||
ORDER BY test_foo_id DESC LIMIT 5
|
ORDER BY test_foo_id DESC LIMIT 5
|
||||||
SQL) === false
|
SQL) === false
|
||||||
) {
|
) {
|
||||||
print "[PGB] [3] Error in pgb_sel_test_foo prepare<br>";
|
print "[PGB] [3] Error in pgb_sel_test_foo prepare<br>";
|
||||||
} else {
|
} else {
|
||||||
print "[PGB] [3] pgb_sel_test_foo prepare OK<br>";
|
print "[PGB] [3] pgb_sel_test_foo prepare OK<br>";
|
||||||
}
|
}
|
||||||
$stm_status = $db->dbPreparedCursorStatus('');
|
$stm_status = $db->dbPreparedCursorStatus('');
|
||||||
print "[PGB] Empty statement name: " . $log->prAr($stm_status) . "<br>";
|
print "[PGB] Empty statement name: " . $log->prAr($stm_status) . "<br>";
|
||||||
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foobar');
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foobar');
|
||||||
print "[PGB] Prepared name not match status: $stm_status<br>";
|
print "[PGB] Prepared name not match status: $stm_status<br>";
|
||||||
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo');
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo');
|
||||||
print "[PGB] Prepared name match status: $stm_status<br>";
|
print "[PGB] Prepared name match status: $stm_status<br>";
|
||||||
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', $q_prep);
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', $q_prep);
|
||||||
print "[PGB] prepared exists and query match status: $stm_status<br>";
|
print "[PGB] prepared exists and query match status: $stm_status<br>";
|
||||||
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', "SELECT * FROM test_foo");
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', "SELECT * FROM test_foo");
|
||||||
print "[PGB] prepared exists and query not match status: $stm_status<br>";
|
print "[PGB] prepared exists and query not match status: $stm_status<br>";
|
||||||
|
|
||||||
$db_pgb->dbClose();
|
$db_pgb->dbClose();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
print "<font color='red'>";
|
||||||
|
print "[PGB] Exception caught: " . $e->getMessage() . "<br>";
|
||||||
|
print "</font>";
|
||||||
|
}
|
||||||
|
|
||||||
# db write class test
|
# db write class test
|
||||||
$table = 'test_foo';
|
$table = 'test_foo';
|
||||||
|
|||||||
Reference in new issue
Block a user