com php-src: Return integer field types as native integers instead of strings: ext/pdo_firebird/firebird_statement.c ext/pdo
_firebird/tests/bug_72583.phpt ext/pdo_fire bird/tests/execute.phpt

From: Date: Fri, 06 Jan 2017 16:43:46 +0000
Subject: com php-src: Return integer field types as native integers instead of strings: ext/pdo_firebird/firebird_statement.c ext/pdo
_firebird/tests/bug_72583.phpt ext/pdo_fire bird/tests/execute.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-96575@lists.php.net to get a copy of this message
Commit: 826122fa8e1db4a0deee3830660ae3b8b5626534 Author: Dorin Marcoci <dorin.marcoci@marcodor.com> Mon, 2 Jan 2017 16:46:09 +0200 Committer: Anatol Belski <ab@php.net> Fri, 6 Jan 2017 17:43:46 +0100 Parents: e55e93a1e335bec39b7edb28f0b8470fa974f4e3 Branches: PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=826122fa8e1db4a0deee3830660ae3b8b5626534 Log: Return integer field types as native integers instead of strings Use another define for better compatibility Test case for #72583 Feature. Small optimisations. Adjust conditional directives according to coding standards Add more compatibility for "end of line" on multiple environements Updated execute.phpt test after switching to integer mapping Bugs: https://bugs.php.net/72583 Changed paths: M ext/pdo_firebird/firebird_statement.c A ext/pdo_firebird/tests/bug_72583.phpt M ext/pdo_firebird/tests/execute.phpt Diff: diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index c83ba38..3feeedf 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -217,7 +217,23 @@ static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */ } memmove(cp, var->aliasname, var->aliasname_length); *(cp+var->aliasname_length) = '\0'; - col->param_type = PDO_PARAM_STR; + + if (var->sqlscale < 0) { + col->param_type = PDO_PARAM_STR; + } else { + switch (var->sqltype & ~1) { + case SQL_SHORT: + case SQL_LONG: +#if SIZEOF_ZEND_LONG >= 8 + case SQL_INT64: +#endif + col->param_type = PDO_PARAM_INT; + break; + default: + col->param_type = PDO_PARAM_STR; + break; + } + } return 1; } @@ -373,16 +389,24 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ *len = var->sqllen; break; case SQL_SHORT: - *ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL); - *len = slprintf(*ptr, CHAR_BUF_LEN, "%d", *(short*)var->sqldata); + *len = sizeof(zend_long); + *ptr = FETCH_BUF(S->fetch_buf[colno], zend_long, 1, NULL); + *(zend_long *)*ptr = *(short*)var->sqldata; break; case SQL_LONG: - *ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL); - *len = slprintf(*ptr, CHAR_BUF_LEN, "%d", *(ISC_LONG*)var->sqldata); + *len = sizeof(zend_long); + *ptr = FETCH_BUF(S->fetch_buf[colno], zend_long, 1, NULL); + *(zend_long *)*ptr = *(ISC_LONG*)var->sqldata; break; case SQL_INT64: +#if SIZEOF_ZEND_LONG >= 8 + *len = sizeof(zend_long); + *ptr = FETCH_BUF(S->fetch_buf[colno], zend_long, 1, NULL); + *(zend_long *)*ptr = *(ISC_INT64*)var->sqldata; +#else *ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL); *len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d", *(ISC_INT64*)var->sqldata); +#endif break; case SQL_FLOAT: *ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL); diff --git a/ext/pdo_firebird/tests/bug_72583.phpt b/ext/pdo_firebird/tests/bug_72583.phpt new file mode 100644 index 0000000..6aa94a7 --- /dev/null +++ b/ext/pdo_firebird/tests/bug_72583.phpt @@ -0,0 +1,21 @@ +--TEST-- +PDO_Firebird: Feature 72583 Fetch integers as php integers not as strings +--SKIPIF-- +<?php if (!extension_loaded('interbase') || !extension_loaded('pdo_firebird')) die('skip'); ?> +--FILE-- +<?php +require 'testdb.inc'; +$C = new PDO('firebird:dbname='.$test_base, $user, $password) or die; +@$C->exec('drop table atable'); +$C->exec('create table atable (aint integer, asmi smallint)'); +$C->exec('insert into atable values (1, -1)'); +$S = $C->prepare('select aint, asmi from atable'); +$S->execute(); +$D = $S->fetch(PDO::FETCH_NUM); +echo gettype($D[0])."\n".gettype($D[1]); +unset($S); +unset($C); +?> +--EXPECT-- +integer +integer diff --git a/ext/pdo_firebird/tests/execute.phpt b/ext/pdo_firebird/tests/execute.phpt index 896347e..3cec9e3 100644 --- a/ext/pdo_firebird/tests/execute.phpt +++ b/ext/pdo_firebird/tests/execute.phpt @@ -50,9 +50,9 @@ bool(true) int(1) array(6) { ["ID"]=> - string(1) "1" + int(1) [0]=> - string(1) "1" + int(1) ["TEXT"]=> string(3) "bla" [1]=>

« previous php.cvs (#96575) next »