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