dbs Wed Jan 25 15:19:15 2006 UTC
Added files:
/pecl/ibm_db2/tests test_6572.phpt
Modified files:
/pecl/ibm_db2 ibm_db2.c
Log:
Fix bug 6572 -- handle SQL strings containing \0 chars correctly.
http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/ibm_db2.c?r1=1.34&r2=1.35&diff_format=u
Index: pecl/ibm_db2/ibm_db2.c
diff -u pecl/ibm_db2/ibm_db2.c:1.34 pecl/ibm_db2/ibm_db2.c:1.35
--- pecl/ibm_db2/ibm_db2.c:1.34 Mon Jan 23 18:54:46 2006
+++ pecl/ibm_db2/ibm_db2.c Wed Jan 25 15:19:15 2006
@@ -18,7 +18,7 @@
| Dan Scott, Helmut Tessarek |
+----------------------------------------------------------------------+
- $Id: ibm_db2.c,v 1.34 2006/01/23 18:54:46 dbs Exp $
+ $Id: ibm_db2.c,v 1.35 2006/01/25 15:19:15 dbs Exp $
*/
#define MODULE_RELEASE "1.2.0"
@@ -1836,9 +1836,9 @@
}
/* }}} */
-/* {{{ static int _php_db2_do_prepare(SQLHANDLE hdbc, string stmt_string,
stmt_handle *stmt_res, zval *options TSRMLS_DC)
+/* {{{ static int _php_db2_do_prepare(SQLHANDLE hdbc, string stmt_string,
stmt_handle *stmt_res, int stmt_string_len, zval *options TSRMLS_DC)
*/
-static int _php_db2_do_prepare(SQLHANDLE hdbc, char* stmt_string, stmt_handle
*stmt_res, zval *options TSRMLS_DC)
+static int _php_db2_do_prepare(SQLHANDLE hdbc, char* stmt_string, stmt_handle
*stmt_res, int stmt_string_len, zval *options TSRMLS_DC)
{
int rc;
@@ -1857,7 +1857,7 @@
}
/* Prepare the stmt. The cursor type requested has already been set in
_php_db2_assign_options */
- rc = SQLPrepare((SQLHSTMT)stmt_res->hstmt, (SQLCHAR*)stmt_string,
SQL_NTS);
+ rc = SQLPrepare((SQLHSTMT)stmt_res->hstmt, (SQLCHAR*)stmt_string,
(SQLINTEGER)stmt_string_len);
if ( rc == SQL_ERROR ) {
_php_db2_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, rc,
1, NULL, -1, 1 TSRMLS_CC);
}
@@ -1914,7 +1914,7 @@
/* Allocates the stmt handle */
/* Prepares the statement */
/* returns the stat_handle back to the calling function */
- rc = _php_db2_do_prepare(conn_res->hdbc, stmt_string, stmt_res,
options TSRMLS_CC);
+ rc = _php_db2_do_prepare(conn_res->hdbc, stmt_string, stmt_res,
stmt_string_len, options TSRMLS_CC);
if ( rc < SQL_SUCCESS ) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement
Prepare Failed");
efree(stmt_res);
@@ -1992,7 +1992,7 @@
/* Allocates the stmt handle */
/* Prepares the statement */
/* returns the stat_handle back to the calling function */
- rc = _php_db2_do_prepare(conn_res->hdbc, stmt_string, stmt_res,
options TSRMLS_CC);
+ rc = _php_db2_do_prepare(conn_res->hdbc, stmt_string, stmt_res,
stmt_string_len, options TSRMLS_CC);
if ( rc < SQL_SUCCESS ) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement
Prepare Failed");
RETURN_FALSE;
@@ -2113,7 +2113,7 @@
case SQL_LONGVARBINARY:
case SQL_VARBINARY:
/* account for bin_mode settings as
well */
- curr->bind_indicator = SQL_NTS;
+ curr->bind_indicator =
(curr->value)->value.str.len;
valueType = SQL_C_BINARY;
paramValuePtr =
(SQLPOINTER)((curr->value)->value.str.val);
break;
@@ -2121,7 +2121,7 @@
/* This option should handle most other types
such as DATE, VARCHAR etc */
default:
valueType = SQL_C_CHAR;
- curr->bind_indicator = SQL_NTS;
+ curr->bind_indicator =
(curr->value)->value.str.len;
paramValuePtr =
(SQLPOINTER)((curr->value)->value.str.val);
}
http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/tests/test_6572.phpt?view=markup&rev=1.1
Index: pecl/ibm_db2/tests/test_6572.phpt
+++ pecl/ibm_db2/tests/test_6572.phpt
--TEST--
IBM-DB2: PECL bug 6572 -- SQL strings containing NULL characters
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require_once('connection.inc');
$conn = db2_connect($database, $user, $password);
if ($conn) {
$null_string = "scaly\0guy";
print "PHP value of null_string is {$null_string}.\n";
$stmt = db2_exec($conn, "INSERT INTO animals (breed, name) VALUES ('gecko',
'{$null_string}')");
$stmt = db2_prepare($conn, "SELECT breed, name FROM animals WHERE name =
?");
$result = db2_execute($stmt, array($null_string));
if (!$result) {
print("ERROR: " . db2_stmt_errormsg($stmt));
exit();
}
while ($row = db2_fetch_array($stmt)) {
var_dump($row);
}
db2_close($conn);
}
else {
echo "Connection failed.\n";
}
?>
--EXPECT--
PHP value of null_string is scaly
array(2) {
[0]=>
string(5) "gecko"
[1]=>
string(5) "scaly"
}
|