Skip to content

Commit 7ebe0db

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: Return integer field types as native integers instead of strings
2 parents 598bb2c + 847e1f9 commit 7ebe0db

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

ext/pdo_firebird/firebird_statement.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,23 @@ static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
217217
}
218218
memmove(cp, var->aliasname, var->aliasname_length);
219219
*(cp+var->aliasname_length) = '\0';
220-
col->param_type = PDO_PARAM_STR;
220+
221+
if (var->sqlscale < 0) {
222+
col->param_type = PDO_PARAM_STR;
223+
} else {
224+
switch (var->sqltype & ~1) {
225+
case SQL_SHORT:
226+
case SQL_LONG:
227+
#if SIZEOF_ZEND_LONG >= 8
228+
case SQL_INT64:
229+
#endif
230+
col->param_type = PDO_PARAM_INT;
231+
break;
232+
default:
233+
col->param_type = PDO_PARAM_STR;
234+
break;
235+
}
236+
}
221237

222238
return 1;
223239
}
@@ -373,16 +389,24 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{
373389
*len = var->sqllen;
374390
break;
375391
case SQL_SHORT:
376-
*ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL);
377-
*len = slprintf(*ptr, CHAR_BUF_LEN, "%d", *(short*)var->sqldata);
392+
*len = sizeof(zend_long);
393+
*ptr = FETCH_BUF(S->fetch_buf[colno], zend_long, 1, NULL);
394+
*(zend_long *)*ptr = *(short*)var->sqldata;
378395
break;
379396
case SQL_LONG:
380-
*ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL);
381-
*len = slprintf(*ptr, CHAR_BUF_LEN, "%d", *(ISC_LONG*)var->sqldata);
397+
*len = sizeof(zend_long);
398+
*ptr = FETCH_BUF(S->fetch_buf[colno], zend_long, 1, NULL);
399+
*(zend_long *)*ptr = *(ISC_LONG*)var->sqldata;
382400
break;
383401
case SQL_INT64:
402+
#if SIZEOF_ZEND_LONG >= 8
403+
*len = sizeof(zend_long);
404+
*ptr = FETCH_BUF(S->fetch_buf[colno], zend_long, 1, NULL);
405+
*(zend_long *)*ptr = *(ISC_INT64*)var->sqldata;
406+
#else
384407
*ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL);
385408
*len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d", *(ISC_INT64*)var->sqldata);
409+
#endif
386410
break;
387411
case SQL_FLOAT:
388412
*ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL);

ext/pdo_firebird/tests/bug_72583.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
PDO_Firebird: Feature 72583 Fetch integers as php integers not as strings
3+
--SKIPIF--
4+
<?php if (!extension_loaded('interbase') || !extension_loaded('pdo_firebird')) die('skip'); ?>
5+
--FILE--
6+
<?php
7+
require 'testdb.inc';
8+
$C = new PDO('firebird:dbname='.$test_base, $user, $password) or die;
9+
@$C->exec('drop table atable');
10+
$C->exec('create table atable (aint integer, asmi smallint)');
11+
$C->exec('insert into atable values (1, -1)');
12+
$S = $C->prepare('select aint, asmi from atable');
13+
$S->execute();
14+
$D = $S->fetch(PDO::FETCH_NUM);
15+
echo gettype($D[0])."\n".gettype($D[1]);
16+
unset($S);
17+
unset($C);
18+
?>
19+
--EXPECT--
20+
integer
21+
integer

ext/pdo_firebird/tests/execute.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ bool(true)
5050
int(1)
5151
array(6) {
5252
["ID"]=>
53-
string(1) "1"
53+
int(1)
5454
[0]=>
55-
string(1) "1"
55+
int(1)
5656
["TEXT"]=>
5757
string(3) "bla"
5858
[1]=>

0 commit comments

Comments
 (0)