summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Richter <georg@php.net>2005-12-29 09:49:19 +0000
committerGeorg Richter <georg@php.net>2005-12-29 09:49:19 +0000
commita5acdfc5f22c753b7699abd45c98bd870b400efb (patch)
treef510a5ca3e1ad543e3f35261400ecf709e83c5fb
parent3795f9d8bb6b0fac5ca48d98afe84941c7661b98 (diff)
downloadphp-git-a5acdfc5f22c753b7699abd45c98bd870b400efb.tar.gz
Fix for bug #35517:
added missing unsigned flag for result buffer fixed returncode in mysql_stmt_fetch for data truncation
-rw-r--r--NEWS1
-rw-r--r--ext/mysqli/mysqli_api.c9
-rw-r--r--ext/mysqli/tests/bug35517.phpt29
3 files changed, 39 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 29d1e1ac33..ef73c34c30 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ PHP NEWS
- Fixed bug #35781 (stream_filter_append() can cause segfault). (Tony)
- Fixed bug #35759 (mysqli_stmt_bind_result() makes huge allocation when
column empty). (Andrey)
+- Fixed bug #35517 (mysql_stmt_fetch returns NULL on data truncation). (Georg)
- Fixed bug #29955 (mb_strtoupper() / lower() broken with Turkish encoding).
(Rui)
- Fixed bug #28899 (mb_substr() and substr() behave differently when
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index b4cb8911b9..cbb1b486ed 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -299,6 +299,7 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
bind[ofs].buffer_type = MYSQL_TYPE_LONG;
bind[ofs].buffer = stmt->result.buf[ofs].val;
bind[ofs].is_null = &stmt->result.is_null[ofs];
+ bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
break;
case MYSQL_TYPE_LONGLONG:
@@ -309,6 +310,7 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
bind[ofs].buffer = stmt->result.buf[ofs].val;
bind[ofs].is_null = &stmt->result.is_null[ofs];
bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
+ bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
break;
case MYSQL_TYPE_DATE:
@@ -721,6 +723,13 @@ PHP_FUNCTION(mysqli_stmt_fetch)
switch (ret) {
case 0:
+#ifdef MYSQL_DATA_TRUNCATED
+ /* according to SQL standard truncation (e.g. loss of precision is
+ not an error) - for detecting possible truncation you have to
+ check mysqli_stmt_warning
+ */
+ case MYSQL_DATA_TRUNCATED:
+#endif
RETURN_TRUE;
break;
case 1:
diff --git a/ext/mysqli/tests/bug35517.phpt b/ext/mysqli/tests/bug35517.phpt
new file mode 100644
index 0000000000..eb1b543463
--- /dev/null
+++ b/ext/mysqli/tests/bug35517.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Bug #35517 mysqli_stmt_fetch returns NULL
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+ include "connect.inc";
+
+ $mysql = new mysqli($host, $user, $passwd, "test");
+
+ $mysql->query("CREATE TABLE temp (id INT UNSIGNED NOT NULL)");
+ $mysql->query("INSERT INTO temp (id) VALUES (3000000897),(3800001532),(3900002281),(3100059612)");
+
+ $stmt = $mysql->prepare("SELECT id FROM temp");
+ $stmt->execute();
+ $stmt->bind_result($id);
+ while ($stmt->fetch()) {
+ var_dump($id);
+ }
+ $stmt->close();
+
+ $mysql->query("DROP TABLE temp");
+ $mysql->close();
+?>
+--EXPECTF--
+string(10) "3000000897"
+string(10) "3800001532"
+string(10) "3900002281"
+string(10) "3100059612"