[PECL-CVS] [pecl-database-pdo_oci] pdo_oci_blob_fetchall_fix: Add the tests and required images for blob

[email protected] (Sharad Chandran R)
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Sharad Chandran R (sharadraju)
Date: 2026-01-07T09:42:49+05:30

Commit: https://github.com/php/pecl-database-pdo_oci/commit/1038ec72b4cfe222affeecf436b5d5a8d8321d0d
Raw diff: https://github.com/php/pecl-database-pdo_oci/commit/1038ec72b4cfe222affeecf436b5d5a8d8321d0d.diff

Add the tests and required images for blob

Changed paths:
  A  tests/pdo_oci_blob.phpt
  A  tests/test1.gif
  A  tests/test2.gif


Diff:

diff --git a/tests/pdo_oci_blob.phpt b/tests/pdo_oci_blob.phpt
new file mode 100644
index 0000000..ca843c0
--- /dev/null
+++ b/tests/pdo_oci_blob.phpt
@@ -0,0 +1,96 @@
+--TEST--
+PDO_OCI: BLOB insert and fetch test
+--EXTENSIONS--
+pdo
+pdo_oci
+--SKIPIF--
+<?php
+require(getenv('PDO_TEST_DIR').'/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require_once(getenv('PDO_TEST_DIR').'/pdo_test.inc');
+
+$db = PDOTest::factory();
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
+
+try {
+    $db->exec("DROP TABLE test_blob");
+} catch (PDOException $e) {
+    // Table may not exist, ignore
+}
+// Create table
+$db->exec("CREATE TABLE test_blob (id NUMBER, picture BLOB)");
+
+for ($id = 1; $id < 3; $id++) {
+    $db->beginTransaction();
+
+    // Sample image data (replace with actual paths or data)
+    // For testing, we'll use dummy data
+    $imageData = file_get_contents(dirname(__FILE__) .'/test' . $id . '.gif');
+
+    // Insert and bind output LOB
+    $lob = null;
+    $stmt = $db->prepare("INSERT INTO test_blob (id, picture) VALUES (:id, EMPTY_BLOB()) RETURNING picture INTO :picture");
+    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
+    $stmt->bindParam(':picture', $lob, PDO::PARAM_LOB);
+    $stmt->execute();
+
+    if (is_resource($lob)) {
+        fwrite($lob, $imageData);
+        fclose($lob);
+    }
+
+    $db->commit();
+}
+
+// Select and fetch BLOB using fetchAll
+echo "Using fetchAll:\n";
+$stm = $db->query("SELECT picture FROM test_blob");
+foreach ($stm->fetchAll(PDO::FETCH_NUM) as $row) {
+    if (is_resource($row[0])) {
+        rewind($row[0]);
+        $blob = stream_get_contents($row[0]);
+    } else {
+        $blob = $row[0];
+    }
+    echo "Blob length: " . strlen($blob) . "\n";
+}
+
+echo "-----------------------------------\n";
+
+// Select and fetch BLOB using fetch in loop
+echo "Using fetch in loop:\n";
+$stmt = $db->query("SELECT picture FROM test_blob");
+while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
+    if (is_resource($row[0])) {
+        rewind($row[0]);
+        $blob = stream_get_contents($row[0]);
+    } else {
+        $blob = $row[0];
+    }
+    echo "Blob length: " . strlen($blob) . "\n";
+}
+?>
+--CLEAN--
+<?php
+require_once(getenv('PDO_TEST_DIR').'/pdo_test.inc');
+$db = PDOTest::test_factory(getenv('PDO_OCI_TEST_DIR').'/common.phpt');
+$db->exec("begin
+             execute immediate 'drop table test_blob';
+             exception when others then
+               if sqlcode <> -942 then
+                 raise;
+               end if;
+           end;");
+?>
+--EXPECT--
+Using fetchAll:
+Blob length: 2523
+Blob length: 35
+-----------------------------------
+Using fetch in loop:
+Blob length: 2523
+Blob length: 35
diff --git a/tests/test1.gif b/tests/test1.gif
new file mode 100644
index 0000000..f352c73
Binary files /dev/null and b/tests/test1.gif differ
diff --git a/tests/test2.gif b/tests/test2.gif
new file mode 100644
index 0000000..c4d4483
Binary files /dev/null and b/tests/test2.gif differ
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.