xref: /PHP-7.1/ext/oci8/tests/lob_027.phpt (revision 37652336)
1--TEST--
2oci_lob_truncate()
3--SKIPIF--
4<?php
5$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
6require(dirname(__FILE__).'/skipif.inc');
7?>
8--FILE--
9<?php
10
11require dirname(__FILE__).'/connect.inc';
12require dirname(__FILE__).'/create_table.inc';
13
14$ora_sql = "INSERT INTO
15                       ".$schema.$table_name." (blob)
16                      VALUES (empty_blob())
17                      RETURNING
18                               blob
19                      INTO :v_blob ";
20
21$statement = oci_parse($c,$ora_sql);
22$blob = oci_new_descriptor($c,OCI_D_LOB);
23oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
24oci_execute($statement, OCI_DEFAULT);
25
26var_dump($blob);
27
28$str = "this is a biiiig faaat test string. why are you reading it, I wonder? =)";
29var_dump($blob->write($str));
30
31oci_commit($c);
32
33$select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
34$s = oci_parse($c, $select_sql);
35oci_execute($s, OCI_DEFAULT);
36
37var_dump($row = oci_fetch_array($s));
38oci_commit($c);
39
40for ($i = 5; $i >= 0; $i--) {
41
42	$select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
43	$s = oci_parse($c, $select_sql);
44	oci_execute($s, OCI_DEFAULT);
45
46	$row = oci_fetch_array($s);
47	var_dump($row['BLOB']->load());
48	var_dump($row['BLOB']->truncate(($i-1)*10));
49
50	oci_commit($c);
51}
52
53$select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
54$s = oci_parse($c, $select_sql);
55oci_execute($s, OCI_DEFAULT);
56
57$row = oci_fetch_array($s);
58var_dump($row['BLOB']->load());
59var_dump($row['BLOB']->truncate(-1));
60var_dump($row['BLOB']->truncate(0));
61
62oci_commit($c);
63
64require dirname(__FILE__).'/drop_table.inc';
65
66echo "Done\n";
67
68?>
69--EXPECTF--
70object(OCI-Lob)#%d (1) {
71  ["descriptor"]=>
72  resource(%d) of type (oci8 descriptor)
73}
74int(72)
75array(2) {
76  [0]=>
77  object(OCI-Lob)#%d (1) {
78    ["descriptor"]=>
79    resource(%d) of type (oci8 descriptor)
80  }
81  ["BLOB"]=>
82  object(OCI-Lob)#%d (1) {
83    ["descriptor"]=>
84    resource(%d) of type (oci8 descriptor)
85  }
86}
87string(72) "this is a biiiig faaat test string. why are you reading it, I wonder? =)"
88bool(true)
89string(40) "this is a biiiig faaat test string. why "
90bool(true)
91string(30) "this is a biiiig faaat test st"
92bool(true)
93string(20) "this is a biiiig faa"
94bool(true)
95string(10) "this is a "
96bool(true)
97string(0) ""
98
99Warning: OCI-Lob::truncate(): Length must be greater than or equal to zero in %s on line %d
100bool(false)
101string(0) ""
102
103Warning: OCI-Lob::truncate(): Length must be greater than or equal to zero in %s on line %d
104bool(false)
105bool(true)
106Done
107