cursors.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --TEST--
  2. fetching cursor from a statement
  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. $insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)";
  15. if (!($s = oci_parse($c, $insert_sql))) {
  16. die("oci_parse(insert) failed!\n");
  17. }
  18. for ($i = 0; $i<3; $i++) {
  19. if (!oci_execute($s)) {
  20. die("oci_execute(insert) failed!\n");
  21. }
  22. }
  23. if (!oci_commit($c)) {
  24. die("oci_commit() failed!\n");
  25. }
  26. $sql = "select CURSOR(select * from ".$schema.$table_name.") as curs FROM dual";
  27. $stmt = oci_parse($c, $sql);
  28. oci_execute($stmt);
  29. while ($data = oci_fetch_assoc($stmt)) {
  30. oci_execute($data["CURS"]);
  31. $subdata = oci_fetch_assoc($data["CURS"]);
  32. var_dump($subdata);
  33. var_dump(oci_cancel($data["CURS"]));
  34. $subdata = oci_fetch_assoc($data["CURS"]);
  35. var_dump($subdata);
  36. var_dump(oci_cancel($data["CURS"]));
  37. }
  38. require __DIR__."/drop_table.inc";
  39. echo "Done\n";
  40. ?>
  41. --EXPECTF--
  42. array(5) {
  43. ["ID"]=>
  44. string(1) "1"
  45. ["VALUE"]=>
  46. string(1) "1"
  47. ["BLOB"]=>
  48. NULL
  49. ["CLOB"]=>
  50. NULL
  51. ["STRING"]=>
  52. NULL
  53. }
  54. bool(true)
  55. Warning: oci_fetch_assoc(): ORA-01002: fetch out of sequence in %s on line %d
  56. bool(false)
  57. bool(true)
  58. Done