BASE . LOG, 'log_file_id' => $LOG_FILE_ID, 'log_per_date' => true, ]); $PAGE_NAME = 'TEST CLASS: DB CONVERT PLACEHOLDER'; print ""; print "" . $PAGE_NAME . ""; print ""; print '
Class Test Master
'; print '

' . $PAGE_NAME . '

'; print "LOGFILE NAME: " . $log->getLogFile() . "
"; print "LOGFILE ID: " . $log->getLogFileId() . "
"; print "Lookup Regex:
" . Html::htmlent(ConvertPlaceholder::REGEX_LOOKUP_PLACEHOLDERS) . "
"; print "Lookup Numbered Regex:
" . Html::htmlent(ConvertPlaceholder::REGEX_LOOKUP_NUMBERED) . "
"; print "Replace Named Regex:
" . Html::htmlent(ConvertPlaceholder::REGEX_REPLACE_NAMED) . "
"; print "Replace Question Mark Regex:
"
	. Html::htmlent(ConvertPlaceholder::REGEX_REPLACE_QUESTION_MARK) . "
"; print "Replace Numbered Regex:
" . Html::htmlent(ConvertPlaceholder::REGEX_REPLACE_NUMBERED) . "
"; $uniqid = \CoreLibs\Create\Uids::uniqIdShort(); // $binary_data = $db->dbEscapeBytea(file_get_contents('class_test.db.php') ?: ''); // $binary_data = file_get_contents('class_test.db.php') ?: ''; $binary_data = ''; $params = [ $uniqid, true, 'STRING A', 2, 2.5, 1, date('H:m:s'), date('Y-m-d H:i: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 = <<[ALL] Convert: " . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params)) . "
"; echo "
"; $query = "SELECT foo FROM bar WHERE baz = :baz AND buz = :baz AND biz = :biz AND boz = :bez"; $params = [':baz' => 'SETBAZ', ':bez' => 'SETBEZ', ':biz' => 'SETBIZ']; print "[NO PARAMS] Convert: " . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params)) . "
"; echo "
"; $query = "SELECT foo FROM bar WHERE baz = :baz AND buz = :baz AND biz = :biz AND boz = :bez"; $params = null; print "[NO PARAMS] Convert: " . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params)) . "
"; echo "
"; $query = "SELECT row_varchar FROM table_with_primary_key WHERE row_varchar <> :row_varchar"; $params = null; print "[NO PARAMS] Convert: " . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params)) . "
"; echo "
"; $query = "SELECT row_varchar, row_varchar_literal, row_int, row_date FROM table_with_primary_key"; $params = null; print "[NO PARAMS] TEST: " . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params)) . "
"; echo "
"; $query = <<[All the same params] TEST: " . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params)) . "
"; echo "
"; $query = << 1]; print "[: param] TEST: " . Support::printAr(ConvertPlaceholder::convertPlaceholderInQuery($query, $params)) . "
"; echo "
"; print "[P-CONV]: " . Support::printAr( ConvertPlaceholder::updateParamList([ 'original' => [ 'query' => 'SELECT foo FROM bar WHERE baz = :baz AND buz = :biz AND biz = :biz AND boz = :bez', 'params' => [':baz' => 'SETBAZ', ':bez' => 'SETBEZ', ':biz' => 'SETBIZ'], 'empty_params' => false, ], 'type' => 'named', 'found' => 3, // 'matches' => [ // ':baz' // ], // 'params_lookup' => [ // ':baz' => '$1' // ], // 'query' => "SELECT foo FROM bar WHERE baz = $1", // 'parms' => [ // 'SETBAZ' // ], ]) ); echo "
"; // test connectors: = , <> () for query detection // convert placeholder tests // ? -> $n // :name -> $n // other way around (just visual) $test_queries = [ 'skip' => [ 'query' => << [], 'direction' => 'pg', ], 'numbers' => [ 'query' => << [\CoreLibs\Create\Uids::uniqIdShort(), 'string A-1', 1234], 'direction' => 'pdo', ], 'a?' => [ 'query' => << [\CoreLibs\Create\Uids::uniqIdShort(), 'string A-1', 1234], 'direction' => 'pg', ], 'b?' => [ 'query' => << [1234], 'direction' => 'pg', ], 'b:' => [ 'query' => << [ ':test' => \CoreLibs\Create\Uids::uniqIdShort(), ':string_a' => 'string B-1', ':number_a' => 5678 ], 'direction' => 'pg', ], 'select, compare $' => [ 'query' => <<= $1 OR row_int <= $2 OR row_int > $3 OR row_int < $4 OR row_int = $5 OR row_int <> $6 SQL, 'params' => null, 'direction' => 'pg' ] ]; 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)) . "
"; echo "
"; } print ""; $log->debug('DEBUGEND', '==================================== [END]'); // __END__