xref: /PHP-8.3/ext/oci8/tests/lob_027.phpt (revision a53e5617)
1--TEST--
2oci_lob_truncate()
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';
15require __DIR__.'/create_table.inc';
16
17$ora_sql = "INSERT INTO
18                       ".$schema.$table_name." (blob)
19                      VALUES (empty_blob())
20                      RETURNING
21                               blob
22                      INTO :v_blob ";
23
24$statement = oci_parse($c,$ora_sql);
25$blob = oci_new_descriptor($c,OCI_D_LOB);
26oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
27oci_execute($statement, OCI_DEFAULT);
28
29var_dump($blob);
30
31$str = "this is a biiiig faaat test string. why are you reading it, I wonder? =)";
32var_dump($blob->write($str));
33
34oci_commit($c);
35
36$select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
37$s = oci_parse($c, $select_sql);
38oci_execute($s, OCI_DEFAULT);
39
40var_dump($row = oci_fetch_array($s));
41oci_commit($c);
42
43for ($i = 5; $i >= 0; $i--) {
44
45    $select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
46    $s = oci_parse($c, $select_sql);
47    oci_execute($s, OCI_DEFAULT);
48
49    $row = oci_fetch_array($s);
50    var_dump($row['BLOB']->load());
51    try {
52        var_dump($row['BLOB']->truncate(($i-1)*10));
53    } catch (ValueError $e) {
54        echo $e->getMessage(), "\n";
55    }
56
57    oci_commit($c);
58}
59
60$select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
61$s = oci_parse($c, $select_sql);
62oci_execute($s, OCI_DEFAULT);
63
64$row = oci_fetch_array($s);
65var_dump($row['BLOB']->load());
66var_dump($row['BLOB']->truncate(0));
67
68try {
69    var_dump($row['BLOB']->truncate(-1));
70} catch (ValueError $e) {
71    echo $e->getMessage(), "\n";
72}
73
74oci_commit($c);
75
76require __DIR__.'/drop_table.inc';
77
78echo "Done\n";
79
80?>
81--EXPECTF--
82object(OCILob)#%d (1) {
83  ["descriptor"]=>
84  resource(%d) of type (oci8 descriptor)
85}
86int(72)
87array(2) {
88  [0]=>
89  object(OCILob)#%d (1) {
90    ["descriptor"]=>
91    resource(%d) of type (oci8 descriptor)
92  }
93  ["BLOB"]=>
94  object(OCILob)#%d (1) {
95    ["descriptor"]=>
96    resource(%d) of type (oci8 descriptor)
97  }
98}
99string(72) "this is a biiiig faaat test string. why are you reading it, I wonder? =)"
100bool(true)
101string(40) "this is a biiiig faaat test string. why "
102bool(true)
103string(30) "this is a biiiig faaat test st"
104bool(true)
105string(20) "this is a biiiig faa"
106bool(true)
107string(10) "this is a "
108bool(true)
109string(0) ""
110OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
111string(0) ""
112bool(true)
113OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
114Done
115