diff options
| author | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
|---|---|---|
| committer | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
| commit | cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (patch) | |
| tree | 1315c623bb7d9dfa8d366fa9cd2c6834ceeb5da5 /ext/pdo_pgsql | |
| parent | 9ea47aab740772adf0c69d8c94b208a464e599ea (diff) | |
| download | php-upstream/5.2.9.dfsg.1.tar.gz | |
Imported Upstream version 5.2.9.dfsg.1upstream/5.2.9.dfsg.1
Diffstat (limited to 'ext/pdo_pgsql')
| -rw-r--r-- | ext/pdo_pgsql/pdo_pgsql.c | 6 | ||||
| -rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 4 | ||||
| -rw-r--r-- | ext/pdo_pgsql/pgsql_statement.c | 18 | ||||
| -rw-r--r-- | ext/pdo_pgsql/php_pdo_pgsql.h | 4 | ||||
| -rw-r--r-- | ext/pdo_pgsql/php_pdo_pgsql_int.h | 4 | ||||
| -rw-r--r-- | ext/pdo_pgsql/tests/bug43925.phpt | 59 | ||||
| -rw-r--r-- | ext/pdo_pgsql/tests/bug46274.phpt | 85 | ||||
| -rw-r--r-- | ext/pdo_pgsql/tests/bug46274_2.phpt | 87 | ||||
| -rw-r--r-- | ext/pdo_pgsql/tests/large_objects.phpt | 36 |
9 files changed, 288 insertions, 15 deletions
diff --git a/ext/pdo_pgsql/pdo_pgsql.c b/ext/pdo_pgsql/pdo_pgsql.c index 000e4a859..f0f823b2f 100644 --- a/ext/pdo_pgsql/pdo_pgsql.c +++ b/ext/pdo_pgsql/pdo_pgsql.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdo_pgsql.c,v 1.7.2.11.2.2 2007/12/31 07:20:10 sebastian Exp $ */ +/* $Id: pdo_pgsql.c,v 1.7.2.11.2.3 2008/12/31 11:17:42 sebastian Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -123,7 +123,7 @@ PHP_MINFO_FUNCTION(pdo_pgsql) php_info_print_table_row(2, "PostgreSQL(libpq) Version", PG_VERSION); #endif php_info_print_table_row(2, "Module version", pdo_pgsql_module_entry.version); - php_info_print_table_row(2, "Revision", " $Id: pdo_pgsql.c,v 1.7.2.11.2.2 2007/12/31 07:20:10 sebastian Exp $ "); + php_info_print_table_row(2, "Revision", " $Id: pdo_pgsql.c,v 1.7.2.11.2.3 2008/12/31 11:17:42 sebastian Exp $ "); php_info_print_table_end(); } diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 82d141522..3bd07f5c2 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql_driver.c,v 1.53.2.14.2.11 2007/12/31 07:20:10 sebastian Exp $ */ +/* $Id: pgsql_driver.c,v 1.53.2.14.2.12 2008/12/31 11:17:42 sebastian Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 33aea2335..1842ad572 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql_statement.c,v 1.31.2.12.2.11 2008/02/26 00:14:04 iliaa Exp $ */ +/* $Id: pgsql_statement.c,v 1.31.2.12.2.14 2008/12/31 11:17:42 sebastian Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -246,6 +246,9 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data * break; case PDO_PARAM_EVT_ALLOC: + case PDO_PARAM_EVT_EXEC_POST: + case PDO_PARAM_EVT_FETCH_PRE: + case PDO_PARAM_EVT_FETCH_POST: /* work is handled by EVT_NORMALIZE */ return 1; @@ -293,10 +296,16 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data * S->param_types[param->paramno] = OIDOID; return 1; } else { + int len; + SEPARATE_ZVAL_IF_NOT_REF(¶m->parameter); Z_TYPE_P(param->parameter) = IS_STRING; - Z_STRLEN_P(param->parameter) = php_stream_copy_to_mem(stm, - &Z_STRVAL_P(param->parameter), PHP_STREAM_COPY_ALL, 0); + + if ((len = php_stream_copy_to_mem(stm, &Z_STRVAL_P(param->parameter), PHP_STREAM_COPY_ALL, 0)) > 0) { + Z_STRLEN_P(param->parameter) = len; + } else { + ZVAL_EMPTY_STRING(param->parameter); + } } } else { /* expected a stream resource */ @@ -598,6 +607,7 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned case PDO_PARAM_STR: case PDO_PARAM_STMT: case PDO_PARAM_INPUT_OUTPUT: + default: break; } } diff --git a/ext/pdo_pgsql/php_pdo_pgsql.h b/ext/pdo_pgsql/php_pdo_pgsql.h index 4a6e2d6cc..964f44dc4 100644 --- a/ext/pdo_pgsql/php_pdo_pgsql.h +++ b/ext/pdo_pgsql/php_pdo_pgsql.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pdo_pgsql.h,v 1.3.2.1.2.2 2007/12/31 07:20:10 sebastian Exp $ */ +/* $Id: php_pdo_pgsql.h,v 1.3.2.1.2.3 2008/12/31 11:17:42 sebastian Exp $ */ #ifndef PHP_PDO_PGSQL_H #define PHP_PDO_PGSQL_H diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h index 87b56dcb1..e8cfe3f3e 100644 --- a/ext/pdo_pgsql/php_pdo_pgsql_int.h +++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pdo_pgsql_int.h,v 1.13.2.4.2.2 2007/12/31 07:20:10 sebastian Exp $ */ +/* $Id: php_pdo_pgsql_int.h,v 1.13.2.4.2.3 2008/12/31 11:17:42 sebastian Exp $ */ #ifndef PHP_PDO_PGSQL_INT_H #define PHP_PDO_PGSQL_INT_H diff --git a/ext/pdo_pgsql/tests/bug43925.phpt b/ext/pdo_pgsql/tests/bug43925.phpt new file mode 100644 index 000000000..e22ffba04 --- /dev/null +++ b/ext/pdo_pgsql/tests/bug43925.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #43925 (Incorrect argument counter in prepared statements with pgsql) +--SKIPIF-- +<?php +if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); +require dirname(__FILE__) . '/config.inc'; +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +PDOTest::skip(); +?> +--FILE-- +<?php +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +$dbh = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); + +@$dbh->query('DROP TABLE nodes'); + +$dbh->query(' +CREATE TABLE nodes +( + id integer NOT NULL PRIMARY KEY + , root integer NOT NULL + , lft integer NOT NULL + , rgt integer NOT NULL +);'); + +$dbh->query('INSERT INTO nodes (id, root, lft, rgt) VALUES (1, 1, 1, 6);'); +$dbh->query('INSERT INTO nodes (id, root, lft, rgt) VALUES (2, 1, 2, 3);'); +$dbh->query('INSERT INTO nodes (id, root, lft, rgt) VALUES (3, 1, 4, 5);'); + + +$stmt = $dbh->prepare(' + SELECT * + FROM nodes + WHERE (:rootId > 0 OR lft > :left OR rgt > :left) + AND (root = :rootId OR root = :left) + AND (1 > :left OR 1 < :left OR 1 = :left) + AND (:x > 0 OR :x < 10 OR :x > 100) + OR :y = 1 OR :left = 1 +'); + +$stmt->bindValue('left', 1, PDO::PARAM_INT); +$stmt->bindValue('rootId', 3, PDO::PARAM_INT); +$stmt->bindValue('x', 5, PDO::PARAM_INT); +$stmt->bindValue('y', 50, PDO::PARAM_INT); + +$stmt->execute(); + +foreach ($stmt->fetchAll() as $row) { + print implode(' - ', $row); + print "\n"; +} + +$dbh->query('DROP TABLE nodes'); + +?> +--EXPECTF-- +1 - 1 - 1 - 1 - 1 - 1 - 6 - 6 +2 - 2 - 1 - 1 - 2 - 2 - 3 - 3 +3 - 3 - 1 - 1 - 4 - 4 - 5 - 5 diff --git a/ext/pdo_pgsql/tests/bug46274.phpt b/ext/pdo_pgsql/tests/bug46274.phpt new file mode 100644 index 000000000..c34839ad4 --- /dev/null +++ b/ext/pdo_pgsql/tests/bug46274.phpt @@ -0,0 +1,85 @@ +--TEST-- +Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob) +--SKIPIF-- +<?php +if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); +require dirname(__FILE__) . '/config.inc'; +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +PDOTest::skip(); +?> +--FILE-- +<?php +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); + +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + +$db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)'); + +$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)"); + +$data = 'foo'; +$blob = fopen('php://memory', 'a'); +fwrite($blob, $data); +rewind($blob); + +$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); +$stmt->execute(); + +$blob = ''; +$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); +$stmt->execute(); + +$data = ''; +$blob = fopen('php://memory', 'a'); +fwrite($blob, $data); +rewind($blob); + +$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); +$stmt->execute(); + +$blob = NULL; +$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()); + +// Empty string +var_dump($res->fetch()); + +// NULL +var_dump($res->fetch()); + +$db->query('DROP TABLE test_one_blob'); + +?> +--EXPECTF-- +array(2) { + ["blob1"]=> + string(3) "foo" + [0]=> + string(3) "foo" +} +array(2) { + ["blob1"]=> + string(0) "" + [0]=> + string(0) "" +} +array(2) { + ["blob1"]=> + string(0) "" + [0]=> + string(0) "" +} +array(2) { + ["blob1"]=> + NULL + [0]=> + NULL +} diff --git a/ext/pdo_pgsql/tests/bug46274_2.phpt b/ext/pdo_pgsql/tests/bug46274_2.phpt new file mode 100644 index 000000000..5e3555688 --- /dev/null +++ b/ext/pdo_pgsql/tests/bug46274_2.phpt @@ -0,0 +1,87 @@ +--TEST-- +Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob) +--SKIPIF-- +<?php +if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); +require dirname(__FILE__) . '/config.inc'; +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +PDOTest::skip(); +?> +--FILE-- +<?php +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); + +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + +$db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)'); + +$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)"); + +$data = 'foo'; +$blob = fopen('php://memory', 'a'); +fwrite($blob, $data); +rewind($blob); + +$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); +$stmt->execute(); + +$blob = ''; +$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); +$stmt->execute(); + +$data = ''; +$blob = fopen('php://memory', 'a'); +fwrite($blob, $data); +rewind($blob); + +$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); +$stmt->execute(); + +$blob = NULL; +$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); +$stmt->execute(); + +$res = $db->query("SELECT blob1 from test_one_blob"); +// Resource +var_dump($x = $res->fetch()); +var_dump(fread($x['blob1'], 10)); + +// Empty string +var_dump($res->fetch()); + +// Empty string +var_dump($res->fetch()); + +// NULL +var_dump($res->fetch()); + +$db->query('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"]=> + string(0) "" + [0]=> + string(0) "" +} +array(2) { + ["blob1"]=> + string(0) "" + [0]=> + string(0) "" +} +array(2) { + ["blob1"]=> + NULL + [0]=> + NULL +} diff --git a/ext/pdo_pgsql/tests/large_objects.phpt b/ext/pdo_pgsql/tests/large_objects.phpt index f6ee9e29c..316963a38 100644 --- a/ext/pdo_pgsql/tests/large_objects.phpt +++ b/ext/pdo_pgsql/tests/large_objects.phpt @@ -19,7 +19,7 @@ $db->exec('CREATE TABLE test (blobid integer not null primary key, bloboid OID)' $db->beginTransaction(); $oid = $db->pgsqlLOBCreate(); try { -$stm = $db->pgsqlLOBOpen($oid); +$stm = $db->pgsqlLOBOpen($oid, 'w+b'); fwrite($stm, "Hello dude\n"); $stmt = $db->prepare("INSERT INTO test (blobid, bloboid) values (?, ?)"); @@ -34,14 +34,37 @@ $stm = null; /* Pull it out */ $stmt = $db->prepare("SELECT * from test"); -$stmt->execute(); $stmt->bindColumn('bloboid', $lob, PDO::PARAM_LOB); +$stmt->execute(); echo "Fetching:\n"; while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) { var_dump($row['blobid']); var_dump(stream_get_contents($lob)); } echo "Fetched!\n"; + +/* Try again, with late bind */ +$stmt = $db->prepare("SELECT * from test"); +$stmt->execute(); +$stmt->bindColumn('bloboid', $lob, PDO::PARAM_LOB); +echo "Fetching late bind:\n"; +while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) { + var_dump($row['blobid']); + var_dump(is_int($row['bloboid'])); +} +echo "Fetched!\n"; + +/* Try again, with NO bind */ +$stmt = $db->prepare("SELECT * from test"); +$stmt->execute(); +$stmt->bindColumn('bloboid', $lob, PDO::PARAM_LOB); +echo "Fetching NO bind:\n"; +while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) { + var_dump($row['blobid']); + var_dump(is_int($row['bloboid'])); +} +echo "Fetched!\n"; + } catch (Exception $e) { /* catch exceptions so that we can guarantee to clean * up the LOB */ @@ -53,9 +76,18 @@ echo "Fetched!\n"; * linger and clutter up the storage */ $db->pgsqlLOBUnlink($oid); +?> --EXPECT-- Fetching: int(1) string(11) "Hello dude " Fetched! +Fetching late bind: +int(1) +bool(true) +Fetched! +Fetching NO bind: +int(1) +bool(true) +Fetched! |
