diff --git a/www/admin/class_test.db.php b/www/admin/class_test.db.php index c791d8a9..848d0f13 100644 --- a/www/admin/class_test.db.php +++ b/www/admin/class_test.db.php @@ -38,9 +38,10 @@ print ""; print "
" . print_r(pg_version($dbh), true) . "
" . print_r($db->dbGetReturningExt(), true) . "|
" . print_r($db->dbGetReturningArray(), true) . "|
" + . "ERROR: " . $db->dbGetLastError(true) . "
"; +echo "
"; + +// convert placeholder tests +// ? -> $n +// :name -> $n + +// other way around (just visual) +$test_queries = [ + 'skip' => [ + 'query' => <<[], + 'direction' => 'pg', + ], + 'a?' => [ + 'query' => << [\CoreLibs\Create\Uids::uniqIdShort(), 'string A-1', 1234], + 'direction' => 'pg', + ], + 'b:' => [ + 'query' => << [ + ':test' => \CoreLibs\Create\Uids::uniqIdShort(), + ':string_a' => 'string B-1', + ':number_a' => 5678 + ], + 'direction' => 'pg', + ], +]; + +$db->dbSetConvertPlaceholder(true); +foreach ($test_queries as $info => $data) { + $query = $data['query']; + $params = $data['params']; + $direction = $data['direction']; + // print "[$info] Convert: " + // . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params, $direction)) + // . "
"; + if ($db->dbCheckQueryForSelect($query)) { + $row = $db->dbReturnRowParams($query, $params); + print "[$info] SELECT: " . Support::prAr($row) . "
"; + } else { + $db->dbExecParams($query, $params); + } + print "[$info] " . Support::printAr($db->dbGetPlaceholderConverted()) . "
"; + echo "
"; +} + +echo "dbReturn read:
"; +while ( + is_array($res = $db->dbReturnParams( + <<"; +} + +print "CursorExt: " . Support::prAr($db->dbGetCursorExt(<< dbReturnRowParams(<< dbGetPlaceholderConverted()) . "
"; + +print ""; +$db->log->debug('DEBUGEND', '==================================== [END]'); + +// __END__ diff --git a/www/admin/class_test.db.single.php b/www/admin/class_test.db.single.php index 256dc902..ea196ff0 100644 --- a/www/admin/class_test.db.single.php +++ b/www/admin/class_test.db.single.php @@ -16,7 +16,7 @@ define('USE_DATABASE', true); // sample config require 'config.php'; // define log file id -$LOG_FILE_ID = 'classTest-db-single'; +$LOG_FILE_ID = 'classTest-db-query-placeholders'; ob_end_flush(); use CoreLibs\Debug\Support; @@ -30,7 +30,7 @@ $log = new CoreLibs\Logging\Logging([ $db = new CoreLibs\DB\IO(DB_CONFIG, $log); $db->log->debug('START', '=============================>'); -$PAGE_NAME = 'TEST CLASS: DB SINGLE'; +$PAGE_NAME = 'TEST CLASS: DB QUERY PLACEHOLDERS'; print ""; print "" . $PAGE_NAME . " "; print ""; @@ -65,63 +65,6 @@ function testDBS(\CoreLibs\DB\IO $dbc): void $dbc->dbReturnRow("SELECT test FROM test_foo LIMIT 1"); } -$uniqid = \CoreLibs\Create\Uids::uniqIdShort(); -$binary_data = $db->dbEscapeBytea(file_get_contents('class_test.db.php') ?: ''); -$query_params = [ - $uniqid, - true, - 'STRING A', - 2, - 2.5, - 1, - date('H:m:s'), - date('Y-m-d H:m:s'), - json_encode(['a' => 'string', 'b' => 1, 'c' => 1.5, 'f' => true, 'g' => ['a', 1, 1.5]]), - null, - '{"a", "b"}', - '{1,2}', - '{"(array Text A, 5, 8.8)","(array Text B, 10, 15.2)"}', - '("Text", 4, 6.3)', - $binary_data -]; - -$query_insert = <<dbExecParams($query_insert, $query_params); -$query_select = << dbReturnRowParams($query_select, [$uniqid]); -if (is_array($res)) { - var_dump($res); -} - testDBS($db); print ""; diff --git a/www/admin/class_test.php b/www/admin/class_test.php index c8f528f3..75c9e516 100644 --- a/www/admin/class_test.php +++ b/www/admin/class_test.php @@ -69,9 +69,10 @@ print ""; // key: file name, value; name $test_files = [ 'class_test.db.php' => 'Class Test: DB', - 'class_test.db.types.php' => 'Class Test: DB COLUMN TYPES', - 'class_test.db.single.php' => 'Class Test: DB SINGLE', + 'class_test.db.types.php' => 'Class Test: DB column type convert', + 'class_test.db.query-placeholder.php' => 'Class Test: DB query placeholder convert', 'class_test.db.dbReturn.php' => 'Class Test: DB dbReturn', + 'class_test.db.single.php' => 'Class Test: DB single query tests', 'class_test.convert.colors.php' => 'Class Test: CONVERT COLORS', 'class_test.check.colors.php' => 'Class Test: CHECK COLORS', 'class_test.mime.php' => 'Class Test: MIME',