xref: /PHP-8.2/ext/oci8/tests/lob_031.phpt (revision b5a14e6c)
1--TEST--
2Test LOB->read(), LOB->seek() and LOB->tell() with nul bytes in data
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9?>
10--FILE--
11<?php
12
13require __DIR__.'/connect.inc';
14require __DIR__.'/create_table.inc';
15
16$ora_sql = "INSERT INTO
17                       ".$schema.$table_name." (blob)
18                      VALUES (empty_blob())
19                      RETURNING
20                               blob
21                      INTO :v_blob ";
22
23$statement = oci_parse($c,$ora_sql);
24$blob = oci_new_descriptor($c,OCI_D_LOB);
25oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
26oci_execute($statement, OCI_DEFAULT);
27
28$blob->write("test");
29$blob->tell();
30$blob->seek(10, OCI_SEEK_CUR);
31$blob->write("string");
32$blob->flush();
33
34$select_sql = "SELECT blob FROM ".$schema.$table_name;
35$s = oci_parse($c, $select_sql);
36oci_execute($s);
37$row = oci_fetch_array($s);
38
39$row[0]->read(3);
40echo " 1. ".$row[0]->tell(). "\n";
41
42$row[0]->read(3);
43echo " 2. ".$row[0]->tell(). "\n";
44
45$row[0]->read(3);
46echo " 3. ".$row[0]->tell(). "\n";
47
48$row[0]->read(6);
49echo " 4. ".$row[0]->tell(). "\n";
50
51$row[0]->read(4);
52echo " 5. ".$row[0]->tell(). "\n";
53
54// Read past end
55$row[0]->read(5);
56echo " 6. ".$row[0]->tell(). "\n";
57
58$row[0]->read(1);
59echo " 8. ".$row[0]->tell(). "\n";
60
61// Now seek
62$row[0]->seek(1);
63echo " 9. ".$row[0]->tell(). "\n";
64
65$row[0]->seek(8);
66echo "10. ".$row[0]->tell(). "\n";
67
68$row[0]->seek(20);
69echo "11. ".$row[0]->tell(). "\n";
70
71// Seek past end
72$row[0]->seek(25);
73echo "12. ".$row[0]->tell(). "\n";
74
75// Seek past end
76$row[0]->seek(2, OCI_SEEK_SET);
77echo "13. ".$row[0]->tell(). "\n";
78
79// Move on 2 more
80$row[0]->seek(2, OCI_SEEK_CUR);
81echo "14. ".$row[0]->tell(). "\n";
82
83// Move 3 past the end
84$row[0]->seek(3, OCI_SEEK_END);
85echo "15. ".$row[0]->tell(). "\n";
86
87// Move 4 before the end
88$row[0]->seek(-4, OCI_SEEK_END);
89echo "16. ".$row[0]->tell(). "\n";
90
91require __DIR__.'/drop_table.inc';
92
93echo "Done\n";
94
95?>
96--EXPECT--
97 1. 3
98 2. 6
99 3. 9
100 4. 15
101 5. 19
102 6. 20
103 8. 20
104 9. 1
10510. 8
10611. 20
10712. 25
10813. 2
10914. 4
11015. 23
11116. 16
112Done
113