xref: /PHP-8.2/ext/oci8/tests/lob_035.phpt (revision b5a14e6c)
1--TEST--
2oci_lob_copy() - 2
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." (id, blob)
18                      VALUES (1, 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
28echo "Writing blob\n";
29var_dump($blob->write("some string here. string, I said"));
30oci_commit($c);
31
32$ora_sql = "INSERT INTO
33                       ".$schema.$table_name." (id, blob)
34                      VALUES (2, empty_blob())
35                      RETURNING
36                               blob
37                      INTO :v_blob ";
38
39$statement = oci_parse($c,$ora_sql);
40$blob = oci_new_descriptor($c,OCI_D_LOB);
41oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
42oci_execute($statement, OCI_DEFAULT);
43
44oci_commit($c);
45
46$select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 1";
47$s = oci_parse($c, $select_sql);
48oci_execute($s);
49
50$row1 = oci_fetch_array($s);
51
52$select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 2 FOR UPDATE";
53$s = oci_parse($c, $select_sql);
54oci_execute($s, OCI_DEFAULT);
55
56$row2 = oci_fetch_array($s);
57
58$dummy = oci_new_descriptor($c, OCI_D_LOB);
59
60//--------------------------------------------------
61
62echo "\noci_lob_copy invalid args\n";
63
64var_dump(oci_lob_copy($dummy, $row1[0]));
65var_dump(oci_lob_copy($row2[0], $dummy));
66var_dump(oci_lob_copy($row2[0], $row1[0], 0));
67var_dump(oci_lob_copy($row2[0], $row1[0], 100000));
68
69try {
70    var_dump(oci_lob_copy($row2[0], $row1[0], -1));
71} catch (ValueError $e) {
72    echo $e->getMessage(), "\n";
73}
74
75//--------------------------------------------------
76
77echo "\noci_lob_size tests\n";
78
79var_dump(oci_lob_size($row2[0]));
80unset($dummy->descriptor);
81var_dump(oci_lob_size($dummy));
82
83oci_rollback($c);
84
85//--------------------------------------------------
86
87echo "\nQuery test\n";
88
89$select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 2 FOR UPDATE";
90$s = oci_parse($c, $select_sql);
91oci_execute($s, OCI_DEFAULT);
92
93var_dump($row2 = oci_fetch_array($s, OCI_RETURN_LOBS));
94
95require __DIR__.'/drop_table.inc';
96
97echo "Done\n";
98
99?>
100--EXPECTF--
101Writing blob
102int(32)
103
104oci_lob_copy invalid args
105
106Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d
107bool(false)
108
109Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d
110bool(false)
111bool(false)
112bool(true)
113oci_lob_copy(): Argument #3 ($length) must be greater than or equal to 0
114
115oci_lob_size tests
116int(0)
117
118Warning: oci_lob_size(): Unable to find descriptor property in %s on line %d
119bool(false)
120
121Query test
122array(2) {
123  [0]=>
124  string(0) ""
125  ["BLOB"]=>
126  string(0) ""
127}
128Done
129