lob_030.phpt 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --TEST--
  2. Test piecewise fetch of CLOBs equal to, and larger than PHP_OCI_LOB_BUFFER_SIZE
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  8. require(__DIR__.'/skipif.inc');
  9. ?>
  10. --FILE--
  11. <?php
  12. require __DIR__.'/connect.inc';
  13. require __DIR__.'/create_table.inc';
  14. function 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. $statement = oci_parse($c,$ora_sql);
  24. $clob = oci_new_descriptor($c,OCI_D_LOB);
  25. oci_bind_by_name($statement,":v_clob", $clob, -1, OCI_B_CLOB);
  26. oci_execute($statement, OCI_DEFAULT);
  27. $data = str_pad("x", $length, "x");
  28. $clob->write($data);
  29. // Verify the data
  30. $select_sql = "SELECT clob FROM ".$tn." where id = ".$id;
  31. $s = oci_parse($c, $select_sql);
  32. oci_execute($s);
  33. $row = oci_fetch_array($s, OCI_RETURN_LOBS);
  34. var_dump(strlen($row[0]));
  35. }
  36. echo "Test 1: A CLOB with an even number of bytes\n";
  37. insert_verify($c, $schema.$table_name, 1, 1050000);
  38. echo "Test 2: A CLOB with an odd number of bytes\n";
  39. insert_verify($c, $schema.$table_name, 2, 1050001);
  40. echo "Test 3: A CLOB of 1048576 bytes (== size of PHP_OCI_LOB_BUFFER_SIZE at time of test creation)\n";
  41. insert_verify($c, $schema.$table_name, 3, 1048576);
  42. echo "Test 4: A CLOB of 1049028 bytes (the value used for chunks in the code)\n";
  43. insert_verify($c, $schema.$table_name, 4, 1049028);
  44. echo "Test 5: A CLOB of 1049028-1 bytes\n";
  45. insert_verify($c, $schema.$table_name, 5, 1049028-1);
  46. echo "Test 6: A CLOB of 1049028+1 bytes\n";
  47. insert_verify($c, $schema.$table_name, 6, 1049028+1);
  48. require __DIR__.'/drop_table.inc';
  49. echo "Done\n";
  50. ?>
  51. --EXPECT--
  52. Test 1: A CLOB with an even number of bytes
  53. int(1050000)
  54. Test 2: A CLOB with an odd number of bytes
  55. int(1050001)
  56. Test 3: A CLOB of 1048576 bytes (== size of PHP_OCI_LOB_BUFFER_SIZE at time of test creation)
  57. int(1048576)
  58. Test 4: A CLOB of 1049028 bytes (the value used for chunks in the code)
  59. int(1049028)
  60. Test 5: A CLOB of 1049028-1 bytes
  61. int(1049027)
  62. Test 6: A CLOB of 1049028+1 bytes
  63. int(1049029)
  64. Done