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