Skip to content

Commit 3a867b9

Browse files
committed
Fixed bug #80808
If the ZEROFILL flag is set for a field, do not convert it into an integer (text protocol) or convert it explicitly into a padded string (binary protocol).
1 parent c28751c commit 3a867b9

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

ext/mysqli/tests/003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ array(7) {
9292
[2]=>
9393
string(19) "2002-01-02 17:46:59"
9494
[3]=>
95-
int(2010)
95+
string(4) "2010"
9696
[4]=>
9797
string(19) "2010-07-10 00:00:00"
9898
[5]=>

ext/mysqli/tests/020.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ array(7) {
8787
[2]=>
8888
%s(19) "2002-01-02 17:46:59"
8989
[3]=>
90-
int(2010)
90+
string(4) "2010"
9191
[4]=>
9292
%s(19) "2010-07-10 00:00:00"
9393
[5]=>

ext/mysqlnd/mysqlnd_ps_codec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ ps_fetch_from_1_to_8_bytes(zval * zv, const MYSQLND_FIELD * const field, const u
7474
case 1:uval = (uint64_t) uint1korr(*row);break;
7575
}
7676

77+
if (field->flags & ZEROFILL_FLAG) {
78+
DBG_INF("stringify due to zerofill");
79+
tmp_len = sprintf((char *)&tmp, "%0*" PRIu64, (int) field->length, uval);
80+
DBG_INF_FMT("value=%s", tmp);
81+
} else
7782
#if SIZEOF_ZEND_LONG==4
7883
if (uval > INT_MAX) {
7984
DBG_INF("stringify");

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,8 @@ php_mysqlnd_rowp_read_text_protocol(MYSQLND_ROW_BUFFER * row_buffer, zval * fiel
16001600
} else if (Z_TYPE_P(current_field) == IS_STRING) {
16011601
/* nothing to do here, as we want a string and ps_fetch_from_1_to_8_bytes() has given us one */
16021602
}
1603-
} else if (as_int_or_float && perm_bind.php_type == IS_LONG) {
1603+
} else if (as_int_or_float && perm_bind.php_type == IS_LONG
1604+
&& !(fields_metadata[i].flags & ZEROFILL_FLAG)) {
16041605
zend_uchar save = *(p + len);
16051606
/* We have to make it ASCIIZ temporarily */
16061607
*(p + len) = '\0';

ext/pdo_mysql/tests/bug80808.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #80808: PDO returns ZEROFILL integers without leading zeros
3+
--SKIPIF--
4+
<?php
5+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13+
$pdo = MySQLPDOTest::factory();
14+
15+
$pdo->exec('DROP TABLE IF EXISTS test');
16+
$pdo->exec('CREATE TABLE test (postcode INT(4) UNSIGNED ZEROFILL)');
17+
$pdo->exec('INSERT INTO test (postcode) VALUES (\'0800\')');
18+
19+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
20+
var_dump($pdo->query('SELECT * FROM test')->fetchColumn(0));
21+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
22+
var_dump($pdo->query('SELECT * FROM test')->fetchColumn(0));
23+
24+
?>
25+
--EXPECT--
26+
string(4) "0800"
27+
string(4) "0800"

0 commit comments

Comments
 (0)