]> granicus.if.org Git - php/commitdiff
improve test portability.
authorWez Furlong <wez@php.net>
Mon, 31 Oct 2005 02:07:38 +0000 (02:07 +0000)
committerWez Furlong <wez@php.net>
Mon, 31 Oct 2005 02:07:38 +0000 (02:07 +0000)
improve infrastructure for LOB support.

ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h
ext/pdo/tests/bug_34630.phpt
ext/pdo/tests/pecl_bug_5772.phpt
ext/pdo/tests/pecl_bug_5809.phpt

index bc498f59cd70b4ec9214315c4316dbc529f29d80..f251db919f80ba4de38d4e5306e14ea50de4dd34 100755 (executable)
@@ -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;
index 146d4c297c2740b428c1b00757b62088d3352df1..ad754e77368f66145b2bb43562fe2357db604d48 100755 (executable)
@@ -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:
index f308f230e45e5b70f99697ee6e3a2f82824bdf19..d61732724c6444dcfadc1546ccd9b2c630bdc183 100644 (file)
@@ -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"
+  }
+}
index d037609e2ae2a55f38b72f51ff2861c3bcc933a8..af380ff28569ff418c214c024eef327d837980df 100644 (file)
@@ -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) {
index 66f8c21e9908ee9676d53331fac92af92fe52852..fa36233e198b20d282688fc532f70216863bf49e 100644 (file)
@@ -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);