summaryrefslogtreecommitdiff
path: root/ext/sqlite3/sqlite3.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2016-04-12 19:15:08 +0200
committerAnatol Belski <ab@php.net>2016-04-12 19:15:08 +0200
commit8b8b44145b3d526b69ed4dd563a8b591d48c34f0 (patch)
tree1b72730ea895c5c07fbc1683db49dd19a1b36693 /ext/sqlite3/sqlite3.c
parenteaf489ac2b86430822db785a713ae02c8bbad910 (diff)
parente49580c96e189b3574a3cbf65d96a7173feb07f0 (diff)
downloadphp-git-8b8b44145b3d526b69ed4dd563a8b591d48c34f0.tar.gz
Merge branch 'PHP-7.0'
* PHP-7.0: Fixed bug #68849 bindValue is not using the right data type
Diffstat (limited to 'ext/sqlite3/sqlite3.c')
-rw-r--r--ext/sqlite3/sqlite3.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 3c7239021f..64b05d7e05 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -1392,6 +1392,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)
@@ -1416,6 +1436,10 @@ PHP_METHOD(sqlite3stmt, bindParam)
ZVAL_COPY(&param.parameter, parameter);
+ if (ZEND_NUM_ARGS() < 3) {
+ PHP_SQLITE3_SET_TYPE(parameter, param);
+ }
+
if (!register_bound_parameter_to_sqlite(&param, stmt_obj)) {
if (!Z_ISUNDEF(param.parameter)) {
zval_ptr_dtor(&(param.parameter));
@@ -1451,6 +1475,10 @@ PHP_METHOD(sqlite3stmt, bindValue)
ZVAL_COPY(&param.parameter, parameter);
+ if (ZEND_NUM_ARGS() < 3) {
+ PHP_SQLITE3_SET_TYPE(parameter, param);
+ }
+
if (!register_bound_parameter_to_sqlite(&param, stmt_obj)) {
if (!Z_ISUNDEF(param.parameter)) {
zval_ptr_dtor(&(param.parameter));
@@ -1462,6 +1490,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)