From 40c24a65c474d3a87500bf338b96bcb8b6185ee1 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 31 Oct 2005 02:07:38 +0000 Subject: [PATCH] improve test portability. improve infrastructure for LOB support. --- ext/pdo/pdo_stmt.c | 24 +++++++++++++++--- ext/pdo/php_pdo_driver.h | 6 ++++- ext/pdo/tests/bug_34630.phpt | 43 ++++++++++++++++++++++---------- ext/pdo/tests/pecl_bug_5772.phpt | 2 +- ext/pdo/tests/pecl_bug_5809.phpt | 2 +- 5 files changed, 58 insertions(+), 19 deletions(-) diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index bc498f59cd..f251db919f 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -474,8 +474,16 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ if (value == NULL) { ZVAL_NULL(dest); } else if (value_len == 0) { - php_stream_to_zval((php_stream*)value, dest); - } else { + if (stmt->dbh->stringify) { + char *buf = NULL; + size_t len; + len = php_stream_copy_to_mem((php_stream*)value, &buf, PHP_STREAM_COPY_ALL, 0); + ZVAL_STRINGL(dest, buf, len, 0); + php_stream_close((php_stream*)value); + } else { + php_stream_to_zval((php_stream*)value, dest); + } + } else if (!stmt->dbh->stringify) { /* they gave us a string, but LOBs are represented as streams in PDO */ php_stream *stm; #ifdef TEMP_STREAM_TAKE_BUFFER @@ -2075,13 +2083,23 @@ static void free_statement(pdo_stmt_t *stmt TSRMLS_DC) efree(stmt); } -void pdo_dbstmt_free_storage(pdo_stmt_t *stmt TSRMLS_DC) +PDO_API void php_pdo_stmt_addref(pdo_stmt_t *stmt TSRMLS_DC) +{ + stmt->refcount++; +} + +PDO_API void php_pdo_stmt_delref(pdo_stmt_t *stmt TSRMLS_DC) { if (--stmt->refcount == 0) { free_statement(stmt TSRMLS_CC); } } +void pdo_dbstmt_free_storage(pdo_stmt_t *stmt TSRMLS_DC) +{ + php_pdo_stmt_delref(stmt TSRMLS_CC); +} + zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC) { zend_object_value retval; diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 146d4c297c..ad754e7736 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -44,7 +44,7 @@ PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC); # define FALSE 0 #endif -#define PDO_DRIVER_API 20051002 +#define PDO_DRIVER_API 20051031 enum pdo_param_type { PDO_PARAM_NULL, @@ -645,6 +645,10 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, PDO_API void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate, const char *supp TSRMLS_DC); +PDO_API void php_pdo_stmt_addref(pdo_stmt_t *stmt TSRMLS_DC); +PDO_API void php_pdo_stmt_delref(pdo_stmt_t *stmt TSRMLS_DC); + + #endif /* PHP_PDO_DRIVER_H */ /* * Local variables: diff --git a/ext/pdo/tests/bug_34630.phpt b/ext/pdo/tests/bug_34630.phpt index f308f230e4..d61732724c 100644 --- a/ext/pdo/tests/bug_34630.phpt +++ b/ext/pdo/tests/bug_34630.phpt @@ -13,27 +13,44 @@ PDOTest::skip(); 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->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val VARCHAR(256))'); + +$is_oci = $db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci'; + +if ($is_oci) { + $db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val BLOB)'); +} else { + $db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val VARCHAR(256))'); +} $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $fp = tmpfile(); fwrite($fp, "I am the LOB data"); rewind($fp); -$insert = $db->prepare("insert into test (id, val) values (1, ?)"); -$insert->bindValue(1, $fp, PDO::PARAM_LOB); +if ($is_oci) { + /* oracle is a bit different; you need to initiate a transaction otherwise + * the empty blob will be committed implicitly when the statement is + * executed */ + $db->beginTransaction(); + $insert = $db->prepare("insert into test (id, val) values (1, EMPTY_BLOB()) RETURNING val INTO :blob"); +} else { + $insert = $db->prepare("insert into test (id, val) values (1, :blob)"); +} +$insert->bindValue(':blob', $fp, PDO::PARAM_LOB); $insert->execute(); +$insert = null; -print_r($db->query("SELECT * from test")->fetchAll(PDO::FETCH_ASSOC)); +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); +var_dump($db->query("SELECT * from test")->fetchAll(PDO::FETCH_ASSOC)); ?> --EXPECT-- -Array -( - [0] => Array - ( - [id] => 1 - [val] => I am the LOB data - ) - -) +array(1) { + [0]=> + array(2) { + ["id"]=> + string(1) "1" + ["val"]=> + string(17) "I am the LOB data" + } +} diff --git a/ext/pdo/tests/pecl_bug_5772.phpt b/ext/pdo/tests/pecl_bug_5772.phpt index d037609e2a..af380ff285 100644 --- a/ext/pdo/tests/pecl_bug_5772.phpt +++ b/ext/pdo/tests/pecl_bug_5772.phpt @@ -14,7 +14,7 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; $db = PDOTest::factory(); -$db->exec("CREATE TABLE test (id int(10) NOT NULL, PRIMARY KEY (id))"); +$db->exec("CREATE TABLE test (id int NOT NULL, PRIMARY KEY (id))"); $db->exec("INSERT INTO test (id) VALUES (1)"); function heLLO($row) { diff --git a/ext/pdo/tests/pecl_bug_5809.phpt b/ext/pdo/tests/pecl_bug_5809.phpt index 66f8c21e99..fa36233e19 100644 --- a/ext/pdo/tests/pecl_bug_5809.phpt +++ b/ext/pdo/tests/pecl_bug_5809.phpt @@ -14,7 +14,7 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; $db = PDOTest::factory(); -$db->exec("CREATE TABLE test (id int(10) NOT NULL, PRIMARY KEY (id))"); +$db->exec("CREATE TABLE test (id int NOT NULL, PRIMARY KEY (id))"); $db->exec("INSERT INTO test (id) VALUES (1)"); $values = array(1); -- 2.40.0