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