xref: /PHP-8.3/ext/oci8/tests/lob_022.phpt (revision a53e5617)
1--TEST--
2fetching the same lob several times
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';
15
16$drop = "DROP table lob_test";
17$statement = oci_parse($c, $drop);
18@oci_execute($statement);
19
20$create = "CREATE table lob_test(mykey NUMBER, lob_1 CLOB)";
21$statement = oci_parse($c, $create);
22oci_execute($statement);
23
24$init = "INSERT INTO lob_test (mykey, lob_1) VALUES(1, EMPTY_CLOB()) RETURNING lob_1 INTO :mylob";
25$statement = oci_parse($c, $init);
26$clob = oci_new_descriptor($c, OCI_D_LOB);
27oci_bind_by_name($statement, ":mylob", $clob, -1, OCI_B_CLOB);
28oci_execute($statement, OCI_DEFAULT);
29oci_lob_save($clob, "data");
30unset($clob->descriptor);
31
32oci_commit($c);
33
34$init = "INSERT INTO lob_test (mykey, lob_1) VALUES(2, EMPTY_CLOB()) RETURNING lob_1 INTO :mylob";
35$statement = oci_parse($c, $init);
36$clob = oci_new_descriptor($c, OCI_D_LOB);
37oci_bind_by_name($statement, ":mylob", $clob, -1, OCI_B_CLOB);
38oci_execute($statement, OCI_DEFAULT);
39$clob->save("long data");
40$clob->save("long data", 0);
41
42try {
43    $clob->save("long data", -1);
44} catch (ValueError $e) {
45    echo $e->getMessage(), "\n";
46}
47
48oci_commit($c);
49
50$query = 'SELECT * FROM lob_test ORDER BY mykey ASC';
51$statement = oci_parse ($c, $query);
52oci_execute($statement, OCI_DEFAULT);
53
54while ($row = oci_fetch_array($statement, OCI_ASSOC)) {
55    $result = $row['LOB_1']->load();
56    var_dump($result);
57}
58
59$query = 'SELECT * FROM lob_test ORDER BY mykey DESC';
60$statement = oci_parse ($c, $query);
61oci_execute($statement, OCI_DEFAULT);
62
63while ($row = oci_fetch_array($statement, OCI_ASSOC)) {
64    $result = $row['LOB_1']->load();
65    var_dump($result);
66}
67
68$drop = "DROP table lob_test";
69$statement = oci_parse($c, $drop);
70@oci_execute($statement);
71
72echo "Done\n";
73
74?>
75--EXPECT--
76
77OCILob::save(): Argument #2 ($offset) must be greater than or equal to 0
78string(4) "data"
79string(9) "long data"
80string(9) "long data"
81string(4) "data"
82Done
83