lob_027.phpt 2.6 KB

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