summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Baratz <adambaratz@php.net>2017-06-29 11:40:56 +0200
committerAdam Baratz <adambaratz@php.net>2017-06-29 11:40:56 +0200
commitf15790ec73decf5a8495494a069ba6c83806ef92 (patch)
tree001e6d667af44b99f4a82d1ab75c0b2cc4357baa
parenta99c5f28c5354f0696cecc9155c1023aac1596f2 (diff)
parent08089f014cee7a43fac9ee75d677fcb93c0a5297 (diff)
downloadphp-git-f15790ec73decf5a8495494a069ba6c83806ef92.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fixed #69356: PDOStatement::debugDumpParams() truncates query
-rw-r--r--ext/pdo/pdo_stmt.c7
-rw-r--r--ext/pdo/tests/bug_69356.phpt40
2 files changed, 44 insertions, 3 deletions
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 6aaec93657..b953739a6a 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -2104,9 +2104,10 @@ static PHP_METHOD(PDOStatement, debugDumpParams)
RETURN_FALSE;
}
- php_stream_printf(out, "SQL: [%zd] %.*s\n",
- stmt->query_stringlen,
- (int) stmt->query_stringlen, stmt->query_string);
+ /* break into multiple operations so query string won't be truncated at FORMAT_CONV_MAX_PRECISION */
+ php_stream_printf(out, "SQL: [%zd] ", stmt->query_stringlen);
+ php_stream_write(out, stmt->query_string, stmt->query_stringlen);
+ php_stream_write(out, "\n", 1);
php_stream_printf(out, "Params: %d\n",
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0);
diff --git a/ext/pdo/tests/bug_69356.phpt b/ext/pdo/tests/bug_69356.phpt
new file mode 100644
index 0000000000..6c9b14c8a4
--- /dev/null
+++ b/ext/pdo/tests/bug_69356.phpt
@@ -0,0 +1,40 @@
+--TEST--
+PDO Common: Bug #69356 (PDOStatement::debugDumpParams() truncates query)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+
+$db = PDOTest::factory();
+$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+$stmt = $db->query("
+ SELECT '
+ Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
+ This is a debug function, which dump directly the data on the normal output.
+ Tip:
+ As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example).
+ This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed.
+ '
+");
+var_dump($stmt->debugDumpParams());
+?>
+--EXPECT--
+SQL: [835]
+ SELECT '
+ Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
+ This is a debug function, which dump directly the data on the normal output.
+ Tip:
+ As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example).
+ This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed.
+ '
+
+Params: 0
+NULL