|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-10-05 07:45 UTC] nexisentertainment at gmail dot com
Description: ------------ pg_query_params somehow converts (boolean)false (as a parameter) to a blank string before sending it to postgres. Note, behavior has not been documented, but has been mentioned by a user comment: http://php.net/manual/en/function.pg-query-params.php#115063 I therefore conclude I am not crazy and imagining things. May be related to #19575. Test script: --------------- <?php // NOTE: General layout unabashedly stolen from [FILE] of https://github.com/php/php-src/blob/master/ext/pgsql/tests/bug64609.phpt $conn_str='user=test password=test host=localhost dbname=test'; error_reporting(E_ALL); $db = pg_connect($conn_str); foreach(array(TRUE,FALSE) as $bool) { echo "Inserting ".($bool?'true':'false'); pg_query("BEGIN"); pg_query("CREATE TABLE test_bool_table (a boolean)"); $values = array($bool); pg_query_params($db,'INSERT INTO test_bool_table (a) VALUES ($1)',$values); pg_query("ROLLBACK"); } Expected result: ---------------- No errors, output of: Inserting true Inserting false Actual result: -------------- Inserting true Inserting false Warning: pg_query_params(): Query failed: ERROR: invalid input syntax for type boolean: "" in /host/[NOPE]/htdocs/testpgbug.php on line 13 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 15:00:01 2025 UTC |
With prepared query type query, NULL must be handled special way. Therefore, NULL is treated specially. Implicit type conversion for database is evil, since database fields could have much higher precisions. Except NULL, any values are simply converted to string including bool. ('1' or ''). Bool could be treated specially like NULL, but it's BC. Thus, it's a feature request. for(i = 0; i < num_params; i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); _php_pgsql_free_params(params, num_params); RETURN_FALSE; } if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; } else { zval tmp_val = **tmp; zval_copy_ctor(&tmp_val); convert_to_cstring(&tmp_val); if (Z_TYPE(tmp_val) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); zval_dtor(&tmp_val); _php_pgsql_free_params(params, num_params); RETURN_FALSE; } params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr)); }