mbeccati                Thu Apr 23 13:22:12 2009 UTC

  Added files:                 
    /php-src/ext/pdo_oci/tests  bug46274.phpt bug46274_2.phpt 

  Modified files:              
    /php-src/ext/pdo    pdo_stmt.c 
    /php-src/ext/pdo_pgsql      pgsql_statement.c 
    /php-src/ext/pdo_pgsql/tests        bug46274_2.phpt 
  Log:
  - Reverted previous fix for bug #46274 and properly fixed it
  - Fixed bug #48060
  # Also added tests for pdo_oci as it's the only other driver currently
  # using streams: no regression found
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo/pdo_stmt.c?r1=1.221&r2=1.222&diff_format=u
Index: php-src/ext/pdo/pdo_stmt.c
diff -u php-src/ext/pdo/pdo_stmt.c:1.221 php-src/ext/pdo/pdo_stmt.c:1.222
--- php-src/ext/pdo/pdo_stmt.c:1.221    Thu Apr  2 16:40:33 2009
+++ php-src/ext/pdo/pdo_stmt.c  Thu Apr 23 13:22:12 2009
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo_stmt.c,v 1.221 2009/04/02 16:40:33 mbeccati Exp $ */
+/* $Id: pdo_stmt.c,v 1.222 2009/04/23 13:22:12 mbeccati Exp $ */
 
 /* The PDO Statement Handle Class */
 
@@ -583,6 +583,7 @@
                        if (value == NULL) {
                                ZVAL_NULL(dest);
                        } else if (value_len == 0) {
+                               /* Warning, empty strings need to be passed as 
stream */
                                if (stmt->dbh->stringify || new_type == 
PDO_PARAM_STR) {
                                        char *buf = NULL;
                                        size_t len;
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/pgsql_statement.c?r1=1.52&r2=1.53&diff_format=u
Index: php-src/ext/pdo_pgsql/pgsql_statement.c
diff -u php-src/ext/pdo_pgsql/pgsql_statement.c:1.52 
php-src/ext/pdo_pgsql/pgsql_statement.c:1.53
--- php-src/ext/pdo_pgsql/pgsql_statement.c:1.52        Sat Mar 28 03:01:38 2009
+++ php-src/ext/pdo_pgsql/pgsql_statement.c     Thu Apr 23 13:22:12 2009
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pgsql_statement.c,v 1.52 2009/03/28 03:01:38 mbeccati Exp $ */
+/* $Id: pgsql_statement.c,v 1.53 2009/04/23 13:22:12 mbeccati Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -619,8 +619,14 @@
                                        return 0;
                                } else {
                                        *ptr = 
php_pdo_pgsql_unescape_bytea(*ptr, &tmp_len);
-                                       *len = tmp_len;
-                                       *caller_frees = 1;
+                                       if (!tmp_len) {
+                                               /* Empty string, return as 
empty stream */
+                                               *ptr = (char 
*)php_stream_memory_open(TEMP_STREAM_READONLY, "", 0);
+                                               *len = 0;
+                                       } else {
+                                               *len = tmp_len;
+                                               *caller_frees = 1;
+                                       }
                                }
                                break;
                        case PDO_PARAM_NULL:
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/tests/bug46274_2.phpt?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/pdo_pgsql/tests/bug46274_2.phpt
diff -u php-src/ext/pdo_pgsql/tests/bug46274_2.phpt:1.2 
php-src/ext/pdo_pgsql/tests/bug46274_2.phpt:1.3
--- php-src/ext/pdo_pgsql/tests/bug46274_2.phpt:1.2     Sat Mar 28 02:34:02 2009
+++ php-src/ext/pdo_pgsql/tests/bug46274_2.phpt Thu Apr 23 13:22:12 2009
@@ -47,11 +47,13 @@
 var_dump($x = $res->fetch());
 var_dump(fread($x['blob1'], 10));
 
-// Empty string
+// Resource
 var_dump($res->fetch());
+var_dump(fread($x['blob1'], 10));
 
-// Empty string
+// Resource
 var_dump($res->fetch());
+var_dump(fread($x['blob1'], 10));
 
 // NULL
 var_dump($res->fetch());
@@ -69,16 +71,18 @@
 string(3) "foo"
 array(2) {
   ["blob1"]=>
-  string(0) ""
+  resource(%d) of type (stream)
   [0]=>
-  string(0) ""
+  resource(%d) of type (stream)
 }
+string(0) ""
 array(2) {
   ["blob1"]=>
-  string(0) ""
+  resource(%d) of type (stream)
   [0]=>
-  string(0) ""
+  resource(%d) of type (stream)
 }
+string(0) ""
 array(2) {
   ["blob1"]=>
   NULL

http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/tests/bug46274.phpt?view=markup&rev=1.1
Index: php-src/ext/pdo_oci/tests/bug46274.phpt
+++ php-src/ext/pdo_oci/tests/bug46274.phpt
--TEST--
Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and 
blob)
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) 
die('skip not loaded');
require dirname(__FILE__).'/../../pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
require 'ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);

try {
        $db->exec("DROP TABLE test_one_blob");
} catch (Exception $e) {
}

$db->beginTransaction();

$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)');

$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, 
EMPTY_BLOB()) RETURNING blob1 INTO :foo");

$data = 'foo';
$blob = fopen('php://memory', 'a');
fwrite($blob, $data);
rewind($blob);

$id = 1;
$stmt->bindparam(':id', $id);
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
$stmt->execute();

$data = '';
$blob = fopen('php://memory', 'a');
fwrite($blob, $data);
rewind($blob);

$id = 1;
$stmt->bindparam(':id', $id);
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
$stmt->execute();

$res = $db->query("SELECT blob1 from test_one_blob");
// Resource
var_dump($res->fetch());

// Empty string
var_dump($res->fetch());

$db->exec("DROP TABLE test_one_blob");

?>
--EXPECTF--
array(2) {
  ["blob1"]=>
  string(3) "foo"
  [0]=>
  string(3) "foo"
}
array(2) {
  ["blob1"]=>
  string(0) ""
  [0]=>
  string(0) ""
}

http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/tests/bug46274_2.phpt?view=markup&rev=1.1
Index: php-src/ext/pdo_oci/tests/bug46274_2.phpt
+++ php-src/ext/pdo_oci/tests/bug46274_2.phpt
--TEST--
Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and 
blob)
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) 
die('skip not loaded');
require dirname(__FILE__).'/../../pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
require 'ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);

try {
        $db->exec("DROP TABLE test_one_blob");
} catch (Exception $e) {
}

$db->beginTransaction();

$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)');

$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, 
EMPTY_BLOB()) RETURNING blob1 INTO :foo");

$data = 'foo';
$blob = fopen('php://memory', 'a');
fwrite($blob, $data);
rewind($blob);

$id = 1;
$stmt->bindparam(':id', $id);
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
$stmt->execute();

$data = '';
$blob = fopen('php://memory', 'a');
fwrite($blob, $data);
rewind($blob);

$id = 1;
$stmt->bindparam(':id', $id);
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
$stmt->execute();

$res = $db->query("SELECT blob1 from test_one_blob");
// Resource
var_dump($row = $res->fetch());
var_dump(fread($row[0], 1024));
fclose($row[0]);

// Empty string
var_dump($row = $res->fetch());
var_dump(fread($row[0], 1024));
fclose($row[0]);

$db->exec("DROP TABLE test_one_blob");

?>
--EXPECTF--
array(2) {
  ["blob1"]=>
  resource(%d) of type (stream)
  [0]=>
  resource(%d) of type (stream)
}
string(3) "foo"
array(2) {
  ["blob1"]=>
  resource(%d) of type (stream)
  [0]=>
  resource(%d) of type (stream)
}
string(0) ""



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to