lob_020.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. --TEST--
  2. oci_lob_write()/erase()/read() with CLOBs
  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." (Clob)
  16. VALUES (empty_Clob())
  17. RETURNING
  18. clob
  19. INTO :v_clob ";
  20. $statement = oci_parse($c,$ora_sql);
  21. $clob = oci_new_descriptor($c,OCI_D_LOB);
  22. oci_bind_by_name($statement,":v_clob", $clob,-1,OCI_B_CLOB);
  23. oci_execute($statement, OCI_DEFAULT);
  24. var_dump($clob);
  25. $str = "%0%0%0%0%0this is a biiiig faaat test string. why are you reading it, I wonder? =)";
  26. var_dump($clob->write($str));
  27. var_dump($clob->erase(10,20));
  28. oci_commit($c);
  29. $select_sql = "SELECT clob FROM ".$schema.$table_name." FOR UPDATE";
  30. $s = oci_parse($c, $select_sql);
  31. oci_execute($s, OCI_DEFAULT);
  32. var_dump($row = oci_fetch_array($s));
  33. var_dump($row[0]->read(2));
  34. var_dump($row[0]->read(5));
  35. var_dump($row[0]->read(50));
  36. var_dump($clob->erase());
  37. echo "\nInvalid values\n";
  38. echo "\nTest 1\n";
  39. try {
  40. var_dump($clob->erase(-10));
  41. } catch (ValueError $e) {
  42. echo $e->getMessage(), "\n";
  43. }
  44. echo "\nTest 2\n";
  45. try {
  46. var_dump($clob->erase(10,-20));
  47. } catch (ValueError $e) {
  48. echo $e->getMessage(), "\n";
  49. }
  50. echo "\nTest 3\n";
  51. try {
  52. var_dump($clob->erase(-10,-20));
  53. } catch (ValueError $e) {
  54. echo $e->getMessage(), "\n";
  55. }
  56. echo "\nTest 4\n";
  57. try {
  58. // ORA-22990: LOB locators cannot span transactions
  59. var_dump(oci_lob_erase($clob));
  60. } catch (ValueError $e) {
  61. echo $e->getMessage(), "\n";
  62. }
  63. echo "\nTest 5\n";
  64. try {
  65. var_dump(oci_lob_erase($clob,-10));
  66. } catch (ValueError $e) {
  67. echo $e->getMessage(), "\n";
  68. }
  69. echo "\nTest 6\n";
  70. try {
  71. var_dump(oci_lob_erase($clob,10,-20));
  72. } catch (ValueError $e) {
  73. echo $e->getMessage(), "\n";
  74. }
  75. echo "\nTest 7\n";
  76. try {
  77. var_dump(oci_lob_erase($clob,-10,-20));
  78. } catch (ValueError $e) {
  79. echo $e->getMessage(), "\n";
  80. }
  81. echo "\nTest 8\n";
  82. unset($clob->descriptor);
  83. var_dump(oci_lob_erase($clob,10,20));
  84. require __DIR__.'/drop_table.inc';
  85. echo "Done\n";
  86. ?>
  87. --EXPECTF--
  88. object(OCILob)#%d (1) {
  89. ["descriptor"]=>
  90. resource(%d) of type (oci8 descriptor)
  91. }
  92. int(82)
  93. int(20)
  94. array(2) {
  95. [0]=>
  96. object(OCILob)#%d (1) {
  97. ["descriptor"]=>
  98. resource(%d) of type (oci8 descriptor)
  99. }
  100. ["CLOB"]=>
  101. object(OCILob)#%d (1) {
  102. ["descriptor"]=>
  103. resource(%d) of type (oci8 descriptor)
  104. }
  105. }
  106. string(2) "%s"
  107. string(5) "%s"
  108. string(50) "%s at test string. why are you"
  109. Warning: OCILob::erase(): ORA-22990: %s in %s on line %d
  110. bool(false)
  111. Invalid values
  112. Test 1
  113. OCILob::erase(): Argument #1 ($offset) must be greater than or equal to 0
  114. Test 2
  115. OCILob::erase(): Argument #2 ($length) must be greater than or equal to 0
  116. Test 3
  117. OCILob::erase(): Argument #1 ($offset) must be greater than or equal to 0
  118. Test 4
  119. Warning: oci_lob_erase(): ORA-22990: %s in %s on line %d
  120. bool(false)
  121. Test 5
  122. oci_lob_erase(): Argument #2 ($offset) must be greater than or equal to 0
  123. Test 6
  124. oci_lob_erase(): Argument #3 ($length) must be greater than or equal to 0
  125. Test 7
  126. oci_lob_erase(): Argument #2 ($offset) must be greater than or equal to 0
  127. Test 8
  128. Warning: oci_lob_erase(): Unable to find descriptor property in %s on line %d
  129. bool(false)
  130. Done