xref: /PHP-8.2/ext/oci8/tests/lob_001.phpt (revision b5a14e6c)
1--TEST--
2oci_lob_write() 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');
14
15// Initialization
16
17$stmtarray = array(
18    "drop table lob_001_tab",
19    "create table lob_001_tab (id number, b1 blob)",
20);
21
22oci8_test_sql_execute($c, $stmtarray);
23
24echo "Test 1 OCI_B_BLOB bind\n";
25
26$statement = oci_parse($c, "insert into lob_001_tab (id, b1) values (1, empty_blob()) returning b1 into :v_b1 ");
27$blob = oci_new_descriptor($c,OCI_D_LOB);
28var_dump(oci_bind_by_name($statement, ":v_b1", $blob, -1, OCI_B_BLOB));
29oci_execute($statement, OCI_DEFAULT);
30var_dump($blob);
31
32echo "Test 2\n";
33
34var_dump($blob->write("test"));
35var_dump($blob->tell());
36var_dump($blob->seek(10, OCI_SEEK_CUR));
37var_dump($blob->write("string"));
38var_dump($blob->flush());
39
40oci_commit($c);
41
42echo "Test 3\n";
43
44$s = oci_parse($c, "select b1 from lob_001_tab where id = 1");
45oci_execute($s);
46var_dump(oci_fetch_array($s, OCI_RETURN_LOBS));
47
48echo "Test 4 SQLT_BLOB (an alias for OCI_B_BLOB) bind\n";
49
50$statement = oci_parse($c, "insert into lob_001_tab (id, b1) values (2, empty_blob()) returning b1 into :v_b1 ");
51$blob = oci_new_descriptor($c,OCI_D_LOB);
52var_dump(oci_bind_by_name($statement, ":v_b1", $blob, -1, SQLT_BLOB));
53oci_execute($statement, OCI_DEFAULT);
54var_dump($blob->write("test row 2"));
55
56$s = oci_parse($c, "select b1 from lob_001_tab where id = 2");
57oci_execute($s);
58var_dump(oci_fetch_array($s, OCI_RETURN_LOBS));
59
60// Cleanup
61
62$stmtarray = array(
63    "drop table lob_001_tab"
64);
65
66oci8_test_sql_execute($c, $stmtarray);
67
68?>
69--EXPECTF--
70Test 1 OCI_B_BLOB bind
71bool(true)
72object(OCILob)#%d (1) {
73  ["descriptor"]=>
74  resource(%d) of type (oci8 descriptor)
75}
76Test 2
77int(4)
78int(4)
79bool(true)
80int(6)
81bool(false)
82Test 3
83array(2) {
84  [0]=>
85  string(20) "test%0%0%0%0%0%0%0%0%0%0string"
86  ["B1"]=>
87  string(20) "test%0%0%0%0%0%0%0%0%0%0string"
88}
89Test 4 SQLT_BLOB (an alias for OCI_B_BLOB) bind
90bool(true)
91int(10)
92array(2) {
93  [0]=>
94  string(10) "test row 2"
95  ["B1"]=>
96  string(10) "test row 2"
97}
98