Add auto type convert for DB\IO
set via db options "db_convert_type" as array with "on", "json", "numeric", "bytea" "on" only converts know good types: "bool", "int" "json" will convert json/jsonb to array "bytea" will decode escaped bytea to string (note: this might change to resource) "numeric" will convert to float. NOTE: if a numeric number is too large a covnersion might drop data. Use with care. Convert flags can be chagned with dbSetConvertFlag and dbUnsetConvertFlag All convert flags are in "DB\Options\Convert" as enum.
This commit is contained in:
@@ -35,7 +35,6 @@ print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><a href="class_test.db.dbReturn.php">Class Test DB dbReturn</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "LOGFILE NAME: " . $db->log->getLogFile() . "<br>";
|
||||
@@ -54,38 +53,62 @@ if (($dbh = $db->dbGetDbh()) instanceof \PgSql\Connection) {
|
||||
print "NO DB HANDLER<br>";
|
||||
}
|
||||
|
||||
// params > 10 for debug
|
||||
// error catcher
|
||||
$query_insert = <<<SQL
|
||||
INSERT INTO many_columns (
|
||||
col_01_int,
|
||||
col_01, col_02, col_03, col_04, col_05, col_06, col_07, col_08, col_09,
|
||||
col_10, col_11, col_12, col_02_int
|
||||
) VALUES (
|
||||
1,
|
||||
$1, $2, $3, $4, $5, $6, $7, $8, $9,
|
||||
$10, $11, $12, $13
|
||||
)
|
||||
RETURNING
|
||||
many_columns_id,
|
||||
col_01_int,
|
||||
col_01, col_02, col_03, col_04, col_05, col_06, col_07, col_08, col_09,
|
||||
col_10, col_11, col_12, col_02_int
|
||||
SQL;
|
||||
$uniqid = \CoreLibs\Create\Uids::uniqIdShort();
|
||||
$binary_data = $db->dbEscapeBytea(file_get_contents('class_test.db.php') ?: '');
|
||||
$query_params = [
|
||||
'col 1', 'col 2', 'col 3', 'col 4', 'col 5', 'col 6', 'col 7', 'col 8',
|
||||
'col 9', 'col 10', 'col 11', 'col 12', null
|
||||
$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 = <<<SQL
|
||||
INSERT INTO test_foo (
|
||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
||||
some_time, some_timestamp, json_string, null_var,
|
||||
array_char_1, array_int_1,
|
||||
array_composite,
|
||||
composite_item,
|
||||
some_binary
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6,
|
||||
$7, $8, $9, $10,
|
||||
$11, $12,
|
||||
$13,
|
||||
$14,
|
||||
$15
|
||||
)
|
||||
SQL;
|
||||
$status = $db->dbExecParams($query_insert, $query_params);
|
||||
echo "<b>*</b><br>";
|
||||
echo "EOM STRING WITH MORE THAN 10 PARAMETERS: "
|
||||
. Support::printToString($query_params) . " |<br>"
|
||||
. " |<br>"
|
||||
. "PRIMARY KEY: " . Support::printToString($db->dbGetInsertPK()) . " | "
|
||||
// . "RETURNING EXT: " . Support::printToString($db->dbGetReturningExt()) . " | "
|
||||
. "RETURNING RETURN: " . Support::printToString($db->dbGetReturningArray())
|
||||
. "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||
echo "<hr>";
|
||||
$query_select = <<<SQL
|
||||
SELECT
|
||||
test_foo_id,
|
||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
||||
number_real, number_double, number_serial,
|
||||
some_time, some_timestamp, json_string, null_var,
|
||||
array_char_1, array_char_2, array_int_1, array_int_2, array_composite,
|
||||
composite_item, (composite_item).*
|
||||
some_binary
|
||||
FROM
|
||||
test_foo
|
||||
WHERE
|
||||
test = $1;
|
||||
SQL;
|
||||
$res = $db->dbReturnRowParams($query_select, [$uniqid]);
|
||||
if (is_array($res)) {
|
||||
var_dump($res);
|
||||
}
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user