xref: /PHP-8.2/ext/oci8/tests/lob_003.phpt (revision b5a14e6c)
1--TEST--
2oci_lob_read() and friends
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." (blob)
18                      VALUES (empty_blob())
19                      RETURNING
20                               blob
21                      INTO :v_blob ";
22
23$statement = oci_parse($c,$ora_sql);
24$blob = oci_new_descriptor($c,OCI_D_LOB);
25oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
26oci_execute($statement, OCI_DEFAULT);
27
28var_dump($blob);
29
30var_dump($blob->write("test"));
31var_dump($blob->tell());
32var_dump($blob->seek(10, OCI_SEEK_CUR));
33var_dump($blob->write("string"));
34var_dump($blob->flush());
35
36oci_commit($c);
37
38$select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
39$s = oci_parse($c, $select_sql);
40oci_execute($s, OCI_DEFAULT);
41
42var_dump($row = oci_fetch_array($s));
43
44try {
45    var_dump($row[0]->read(-1));
46} catch (ValueError $e) {
47    echo $e->getMessage(), "\n";
48}
49var_dump($row[0]->read(10000));
50
51require __DIR__.'/drop_table.inc';
52
53echo "Done\n";
54
55?>
56--EXPECTF--
57object(OCILob)#%d (1) {
58  ["descriptor"]=>
59  resource(%d) of type (oci8 descriptor)
60}
61int(4)
62int(4)
63bool(true)
64int(6)
65bool(false)
66array(2) {
67  [0]=>
68  object(OCILob)#%d (1) {
69    ["descriptor"]=>
70    resource(%d) of type (oci8 descriptor)
71  }
72  ["BLOB"]=>
73  object(OCILob)#%d (1) {
74    ["descriptor"]=>
75    resource(%d) of type (oci8 descriptor)
76  }
77}
78OCILob::read(): Argument #1 ($length) must be greater than 0
79string(20) "test%0%0%0%0%0%0%0%0%0%0string"
80Done
81