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