xref: /PHP-8.0/ext/oci8/tests/lob_030.phpt (revision 26dfce7f)
1--TEST--
2Test piecewise fetch of CLOBs equal to, and larger than PHP_OCI_LOB_BUFFER_SIZE
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
14function insert_verify($c, $tn, $id, $length)
15{
16    // Insert the data
17    $ora_sql = "INSERT INTO
18                       ".$tn." (id, clob)
19                      VALUES (".$id.", empty_clob())
20                      RETURNING
21                               clob
22                      INTO :v_clob ";
23
24    $statement = oci_parse($c,$ora_sql);
25    $clob = oci_new_descriptor($c,OCI_D_LOB);
26    oci_bind_by_name($statement,":v_clob", $clob, -1, OCI_B_CLOB);
27    oci_execute($statement, OCI_DEFAULT);
28
29    $data = str_pad("x", $length, "x");
30    $clob->write($data);
31
32    // Verify the data
33    $select_sql = "SELECT clob FROM ".$tn." where id = ".$id;
34    $s = oci_parse($c, $select_sql);
35    oci_execute($s);
36
37    $row = oci_fetch_array($s, OCI_RETURN_LOBS);
38
39    var_dump(strlen($row[0]));
40}
41
42echo "Test 1: A CLOB with an even number of bytes\n";
43insert_verify($c, $schema.$table_name, 1, 1050000);
44
45echo "Test 2: A CLOB with an odd number of bytes\n";
46insert_verify($c, $schema.$table_name, 2, 1050001);
47
48echo "Test 3: A CLOB of 1048576 bytes (== size of PHP_OCI_LOB_BUFFER_SIZE at time of test creation)\n";
49insert_verify($c, $schema.$table_name, 3, 1048576);
50
51echo "Test 4: A CLOB of 1049028 bytes (the value used for chunks in the code)\n";
52insert_verify($c, $schema.$table_name, 4, 1049028);
53
54echo "Test 5: A CLOB of 1049028-1 bytes\n";
55insert_verify($c, $schema.$table_name, 5, 1049028-1);
56
57echo "Test 6: A CLOB of 1049028+1 bytes\n";
58insert_verify($c, $schema.$table_name, 6, 1049028+1);
59
60require __DIR__.'/drop_table.inc';
61
62echo "Done\n";
63
64?>
65--EXPECT--
66Test 1: A CLOB with an even number of bytes
67int(1050000)
68Test 2: A CLOB with an odd number of bytes
69int(1050001)
70Test 3: A CLOB of 1048576 bytes (== size of PHP_OCI_LOB_BUFFER_SIZE at time of test creation)
71int(1048576)
72Test 4: A CLOB of 1049028 bytes (the value used for chunks in the code)
73int(1049028)
74Test 5: A CLOB of 1049028-1 bytes
75int(1049027)
76Test 6: A CLOB of 1049028+1 bytes
77int(1049029)
78Done
79