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