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