cursors.phpt 1.3 KB

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