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