mirror of
https://github.com/php/php-src.git
synced 2025-08-16 22:18:50 +02:00
Fixed bug #68849 bindValue is not using the right data type
This commit is contained in:
parent
4e585eb429
commit
e49580c96e
2 changed files with 101 additions and 0 deletions
|
@ -1406,6 +1406,26 @@ static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *pa
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Best try to map between PHP and SQLite. Default is still text. */
|
||||
#define PHP_SQLITE3_SET_TYPE(z, p) \
|
||||
switch (Z_TYPE_P(z)) { \
|
||||
default: \
|
||||
(p).type = SQLITE_TEXT; \
|
||||
break; \
|
||||
case IS_LONG: \
|
||||
case IS_TRUE: \
|
||||
case IS_FALSE: \
|
||||
(p).type = SQLITE_INTEGER; \
|
||||
break; \
|
||||
case IS_DOUBLE: \
|
||||
(p).type = SQLITE_FLOAT; \
|
||||
break; \
|
||||
case IS_NULL: \
|
||||
(p).type = SQLITE_NULL; \
|
||||
break; \
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type])
|
||||
Bind Parameter to a stmt variable. */
|
||||
PHP_METHOD(sqlite3stmt, bindParam)
|
||||
|
@ -1430,6 +1450,10 @@ PHP_METHOD(sqlite3stmt, bindParam)
|
|||
|
||||
ZVAL_COPY(¶m.parameter, parameter);
|
||||
|
||||
if (ZEND_NUM_ARGS() < 3) {
|
||||
PHP_SQLITE3_SET_TYPE(parameter, param);
|
||||
}
|
||||
|
||||
if (!register_bound_parameter_to_sqlite(¶m, stmt_obj)) {
|
||||
if (!Z_ISUNDEF(param.parameter)) {
|
||||
zval_ptr_dtor(&(param.parameter));
|
||||
|
@ -1465,6 +1489,10 @@ PHP_METHOD(sqlite3stmt, bindValue)
|
|||
|
||||
ZVAL_COPY(¶m.parameter, parameter);
|
||||
|
||||
if (ZEND_NUM_ARGS() < 3) {
|
||||
PHP_SQLITE3_SET_TYPE(parameter, param);
|
||||
}
|
||||
|
||||
if (!register_bound_parameter_to_sqlite(¶m, stmt_obj)) {
|
||||
if (!Z_ISUNDEF(param.parameter)) {
|
||||
zval_ptr_dtor(&(param.parameter));
|
||||
|
@ -1476,6 +1504,8 @@ PHP_METHOD(sqlite3stmt, bindValue)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
#undef PHP_SQLITE3_SET_TYPE
|
||||
|
||||
/* {{{ proto SQLite3Result SQLite3Stmt::execute()
|
||||
Executes a prepared statement and returns a result set object. */
|
||||
PHP_METHOD(sqlite3stmt, execute)
|
||||
|
|
71
ext/sqlite3/tests/sqlite3_bind_bug68849.phpt
Normal file
71
ext/sqlite3/tests/sqlite3_bind_bug68849.phpt
Normal file
|
@ -0,0 +1,71 @@
|
|||
--TEST--
|
||||
Bug #68849 bindValue is not using the right data type
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$db = new SQLite3(':memory:');
|
||||
|
||||
$db->exec("CREATE TABLE test (a INTEGER, b TEXT, c REAL);" .
|
||||
"INSERT INTO test VALUES (1, 'hello', 3.14);" .
|
||||
"INSERT INTO test VALUES (3, 'world', 3.15);" .
|
||||
"INSERT INTO test VALUES (0, '42', 0.42);"
|
||||
);
|
||||
|
||||
$s = $db->prepare('SELECT * FROM test WHERE (a+2) = ?;');
|
||||
$s->bindValue(1, 3);
|
||||
$r = $s->execute();
|
||||
var_dump($r->fetchArray(SQLITE3_ASSOC));
|
||||
|
||||
$s = $db->prepare('SELECT * FROM test WHERE a = ?;');
|
||||
$s->bindValue(1, true);
|
||||
$r = $s->execute();
|
||||
var_dump($r->fetchArray(SQLITE3_ASSOC));
|
||||
|
||||
$s = $db->prepare('SELECT * FROM test WHERE a = ?;');
|
||||
$s->bindValue(1, false);
|
||||
$r = $s->execute();
|
||||
var_dump($r->fetchArray(SQLITE3_ASSOC));
|
||||
|
||||
$s = $db->prepare('SELECT * FROM test WHERE c = ?;');
|
||||
$s->bindValue(1, 3.15);
|
||||
$r = $s->execute();
|
||||
var_dump($r->fetchArray(SQLITE3_ASSOC));
|
||||
|
||||
?>
|
||||
==DONE==
|
||||
--EXPECTF--
|
||||
array(3) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
["b"]=>
|
||||
string(5) "hello"
|
||||
["c"]=>
|
||||
float(3.14)
|
||||
}
|
||||
array(3) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
["b"]=>
|
||||
string(5) "hello"
|
||||
["c"]=>
|
||||
float(3.14)
|
||||
}
|
||||
array(3) {
|
||||
["a"]=>
|
||||
int(0)
|
||||
["b"]=>
|
||||
string(2) "42"
|
||||
["c"]=>
|
||||
float(0.42)
|
||||
}
|
||||
array(3) {
|
||||
["a"]=>
|
||||
int(3)
|
||||
["b"]=>
|
||||
string(5) "world"
|
||||
["c"]=>
|
||||
float(3.15)
|
||||
}
|
||||
==DONE==
|
Loading…
Add table
Add a link
Reference in a new issue