diff options
author | Simonov Denis <sim-mail@list.ru> | 2019-09-10 09:22:26 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2019-09-10 09:22:26 +0200 |
commit | 481f89551eab4f455cb72e421cd18a9f961311dd (patch) | |
tree | 5368e7b8a141ef1f550aa22c0462b33a3199f479 | |
parent | bcf9d1e9953aec84c25ae3da1d6f775cbc52e0bd (diff) | |
download | php-git-481f89551eab4f455cb72e421cd18a9f961311dd.tar.gz |
Request #77863: PDO firebird support type Boolean in input parameters
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/pdo_firebird/firebird_statement.c | 76 | ||||
-rw-r--r-- | ext/pdo_firebird/tests/bug_77863.phpt | 135 |
3 files changed, 204 insertions, 11 deletions
@@ -13,6 +13,10 @@ PHP NEWS - PCRE: . Fixed bug #78349 (Bundled pcre2 library missing LICENCE file). (Peter Kokot) +- PDO_Firebird: + . Implemented FR #77863 (PDO firebird support type Boolean in input + parameters). (Simonov Denis) + - PDO_MySQL: . Fixed bug #41997 (SP call yields additional empty result set). (cmb) diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index aee748d0e1..75d7221923 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -611,6 +611,60 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat } } +#ifdef SQL_BOOLEAN + /* keep native BOOLEAN type */ + if ((var->sqltype & ~1) == SQL_BOOLEAN) { + switch (Z_TYPE_P(parameter)) { + case IS_LONG: + case IS_DOUBLE: + case IS_TRUE: + case IS_FALSE: + *(FB_BOOLEAN*)var->sqldata = zend_is_true(parameter) ? FB_TRUE : FB_FALSE; + break; + case IS_STRING: + { + zend_long lval; + double dval; + + if ((Z_STRLEN_P(parameter) == 0)) { + *(FB_BOOLEAN*)var->sqldata = FB_FALSE; + break; + } + + switch (is_numeric_string(Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), &lval, &dval, 0)) { + case IS_LONG: + *(FB_BOOLEAN*)var->sqldata = (lval != 0) ? FB_TRUE : FB_FALSE; + break; + case IS_DOUBLE: + *(FB_BOOLEAN*)var->sqldata = (dval != 0) ? FB_TRUE : FB_FALSE; + break; + default: + if (!zend_binary_strncasecmp(Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), "true", 4, 4)) { + *(FB_BOOLEAN*)var->sqldata = FB_TRUE; + } else if (!zend_binary_strncasecmp(Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), "false", 5, 5)) { + *(FB_BOOLEAN*)var->sqldata = FB_FALSE; + } else { + strcpy(stmt->error_code, "HY105"); + S->H->last_app_error = "Cannot convert string to boolean"; + return 0; + } + + } + } + break; + case IS_NULL: + *var->sqlind = -1; + break; + default: + strcpy(stmt->error_code, "HY105"); + S->H->last_app_error = "Binding arrays/objects is not supported"; + return 0; + } + break; + } +#endif + + /* check if a NULL should be inserted */ switch (Z_TYPE_P(parameter)) { int force_null; @@ -646,7 +700,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat /* keep the allow-NULL flag */ var->sqltype = SQL_TEXT | (var->sqltype & 1); var->sqldata = Z_STRVAL_P(parameter); - var->sqllen = Z_STRLEN_P(parameter); + var->sqllen = Z_STRLEN_P(parameter); break; } case IS_NULL: @@ -666,9 +720,9 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat break; case PDO_PARAM_EVT_FETCH_POST: - if (param->paramno == -1) { - return 0; - } + if (param->paramno == -1) { + return 0; + } if (param->is_param) { break; } @@ -696,13 +750,13 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat break; } case PDO_PARAM_EVT_NORMALIZE: - if (!param->is_param) { - char *s = ZSTR_VAL(param->name); - while (*s != '\0') { - *s = toupper(*s); - s++; - } - } + if (!param->is_param) { + char *s = ZSTR_VAL(param->name); + while (*s != '\0') { + *s = toupper(*s); + s++; + } + } break; default: ZVAL_NULL(parameter); diff --git a/ext/pdo_firebird/tests/bug_77863.phpt b/ext/pdo_firebird/tests/bug_77863.phpt new file mode 100644 index 0000000000..a133de5ba8 --- /dev/null +++ b/ext/pdo_firebird/tests/bug_77863.phpt @@ -0,0 +1,135 @@ +--TEST-- +PDO_Firebird: Bug #76488 PDO Firebird does not support boolean datatype in input parameters +--SKIPIF-- +<?php require('skipif.inc'); ?> +--FILE-- +<?php + +require 'testdb.inc'; + +$sql = <<<SQL +with t(b, s) as ( + select true, 'true' from rdb\$database + union all + select false, 'false' from rdb\$database + union all + select unknown, 'unknown' from rdb\$database +) +select trim(s) as s from t where b is not distinct from :p +SQL; + +try { + $query = $dbh->prepare($sql); + + // PDO::PARAM_BOOL + $query->bindValue('p', 0, PDO::PARAM_BOOL); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 1, PDO::PARAM_BOOL); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', false, PDO::PARAM_BOOL); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', true, PDO::PARAM_BOOL); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 'false', PDO::PARAM_BOOL); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 'True', PDO::PARAM_BOOL); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', null, PDO::PARAM_BOOL); + $query->execute(); + var_dump($query->fetchColumn(0)); + + // PDO::PARAM_STR + $query->bindValue('p', false, PDO::PARAM_STR); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', true, PDO::PARAM_STR); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 0, PDO::PARAM_STR); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 1, PDO::PARAM_STR); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 'false', PDO::PARAM_STR); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 'true', PDO::PARAM_STR); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', null, PDO::PARAM_STR); + $query->execute(); + var_dump($query->fetchColumn(0)); + + // PDO::PARAM_INT + $query->bindValue('p', false, PDO::PARAM_INT); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', true, PDO::PARAM_INT); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 0, PDO::PARAM_INT); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 1, PDO::PARAM_INT); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 'false', PDO::PARAM_INT); + $query->execute(); + var_dump($query->fetchColumn(0)); + + $query->bindValue('p', 'true', PDO::PARAM_INT); + $query->execute(); + var_dump($query->fetchColumn(0)); + + echo "OK\n"; +} +catch(Exception $e) { + echo $e->getMessage() . '<br>'; + echo $e->getTraceAsString(); +} +?> +--EXPECT-- +string(5) "false" +string(4) "true" +string(5) "false" +string(4) "true" +string(5) "false" +string(4) "true" +string(7) "unknown" +string(5) "false" +string(4) "true" +string(5) "false" +string(4) "true" +string(5) "false" +string(4) "true" +string(7) "unknown" +string(5) "false" +string(4) "true" +string(5) "false" +string(4) "true" +string(5) "false" +string(4) "true" +OK |