xref: /PHP-8.3/ext/oci8/tests/lob_020.phpt (revision a53e5617)
1--TEST--
2oci_lob_write()/erase()/read() with CLOBs
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." (Clob)
19                      VALUES (empty_Clob())
20                      RETURNING
21                               clob
22                      INTO :v_clob ";
23
24$statement = oci_parse($c,$ora_sql);
25$clob = oci_new_descriptor($c,OCI_D_LOB);
26oci_bind_by_name($statement,":v_clob", $clob,-1,OCI_B_CLOB);
27oci_execute($statement, OCI_DEFAULT);
28
29var_dump($clob);
30
31$str = "%0%0%0%0%0this is a biiiig faaat test string. why are you reading it, I wonder? =)";
32var_dump($clob->write($str));
33var_dump($clob->erase(10,20));
34
35oci_commit($c);
36
37$select_sql = "SELECT clob FROM ".$schema.$table_name." FOR UPDATE";
38$s = oci_parse($c, $select_sql);
39oci_execute($s, OCI_DEFAULT);
40
41var_dump($row = oci_fetch_array($s));
42
43var_dump($row[0]->read(2));
44var_dump($row[0]->read(5));
45var_dump($row[0]->read(50));
46
47var_dump($clob->erase());
48
49echo "\nInvalid values\n";
50
51echo "\nTest 1\n";
52try {
53    var_dump($clob->erase(-10));
54} catch (ValueError $e) {
55    echo $e->getMessage(), "\n";
56}
57
58echo "\nTest 2\n";
59try {
60    var_dump($clob->erase(10,-20));
61} catch (ValueError $e) {
62    echo $e->getMessage(), "\n";
63}
64
65echo "\nTest 3\n";
66try {
67    var_dump($clob->erase(-10,-20));
68} catch (ValueError $e) {
69    echo $e->getMessage(), "\n";
70}
71
72echo "\nTest 4\n";
73try {
74    // ORA-22990: LOB locators cannot span transactions
75    var_dump(oci_lob_erase($clob));
76} catch (ValueError $e) {
77    echo $e->getMessage(), "\n";
78}
79
80echo "\nTest 5\n";
81try {
82    var_dump(oci_lob_erase($clob,-10));
83} catch (ValueError $e) {
84    echo $e->getMessage(), "\n";
85}
86
87echo "\nTest 6\n";
88try {
89    var_dump(oci_lob_erase($clob,10,-20));
90} catch (ValueError $e) {
91    echo $e->getMessage(), "\n";
92}
93
94echo "\nTest 7\n";
95try {
96    var_dump(oci_lob_erase($clob,-10,-20));
97} catch (ValueError $e) {
98    echo $e->getMessage(), "\n";
99}
100
101echo "\nTest 8\n";
102unset($clob->descriptor);
103var_dump(oci_lob_erase($clob,10,20));
104
105require __DIR__.'/drop_table.inc';
106
107echo "Done\n";
108
109?>
110--EXPECTF--
111object(OCILob)#%d (1) {
112  ["descriptor"]=>
113  resource(%d) of type (oci8 descriptor)
114}
115int(82)
116int(20)
117array(2) {
118  [0]=>
119  object(OCILob)#%d (1) {
120    ["descriptor"]=>
121    resource(%d) of type (oci8 descriptor)
122  }
123  ["CLOB"]=>
124  object(OCILob)#%d (1) {
125    ["descriptor"]=>
126    resource(%d) of type (oci8 descriptor)
127  }
128}
129string(2) "%s"
130string(5) "%s"
131string(50) "%s                    at test string. why are you"
132
133Warning: OCILob::erase(): ORA-22990: %s in %s on line %d
134bool(false)
135
136Invalid values
137
138Test 1
139OCILob::erase(): Argument #1 ($offset) must be greater than or equal to 0
140
141Test 2
142OCILob::erase(): Argument #2 ($length) must be greater than or equal to 0
143
144Test 3
145OCILob::erase(): Argument #1 ($offset) must be greater than or equal to 0
146
147Test 4
148
149Warning: oci_lob_erase(): ORA-22990: %s in %s on line %d
150bool(false)
151
152Test 5
153oci_lob_erase(): Argument #2 ($offset) must be greater than or equal to 0
154
155Test 6
156oci_lob_erase(): Argument #3 ($length) must be greater than or equal to 0
157
158Test 7
159oci_lob_erase(): Argument #2 ($offset) must be greater than or equal to 0
160
161Test 8
162
163Warning: oci_lob_erase(): Unable to find descriptor property in %s on line %d
164bool(false)
165Done
166