define6.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --TEST--
  2. oci_define_by_name tests with REF CURSORs
  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. // Initialization
  12. $stmtarray = array(
  13. "drop table define6_tab",
  14. "create table define6_tab (id number)",
  15. "insert into define6_tab values (1)"
  16. );
  17. oci8_test_sql_execute($c, $stmtarray);
  18. // Run Test
  19. $sql =
  20. "DECLARE
  21. TYPE curtype IS REF CURSOR;
  22. cursor_var curtype;
  23. BEGIN
  24. OPEN cursor_var FOR SELECT id FROM define6_tab;
  25. :curs := cursor_var;
  26. END;";
  27. echo "Test 1 - define last\n";
  28. $s1 = oci_parse($c, $sql);
  29. $cursor1 = oci_new_cursor($c);
  30. oci_bind_by_name($s1, ":curs", $cursor1, -1, OCI_B_CURSOR);
  31. oci_execute($s1);
  32. oci_execute($cursor1);
  33. oci_define_by_name($cursor1, 'ID', $id1);
  34. while (oci_fetch_row($cursor1)) {
  35. var_dump($id1);
  36. }
  37. echo "Test 2 - define last with preset var\n";
  38. $s2 = oci_parse($c, $sql);
  39. $cursor2 = oci_new_cursor($c);
  40. oci_bind_by_name($s2, ":curs", $cursor2, -1, OCI_B_CURSOR);
  41. oci_execute($s2);
  42. oci_execute($cursor2);
  43. $id2 = '';
  44. oci_define_by_name($cursor2, 'ID', $id2);
  45. while (oci_fetch_row($cursor2)) {
  46. var_dump($id2);
  47. }
  48. echo "Test 3 - define before cursor execute\n";
  49. $s3 = oci_parse($c, $sql);
  50. $cursor3 = oci_new_cursor($c);
  51. oci_bind_by_name($s3, ":curs", $cursor3, -1, OCI_B_CURSOR);
  52. oci_execute($s3);
  53. oci_define_by_name($cursor3, 'ID', $id3);
  54. oci_execute($cursor3);
  55. while (oci_fetch_row($cursor3)) {
  56. var_dump($id3);
  57. }
  58. echo "Test 4 - define before top level execute\n";
  59. $s4 = oci_parse($c, $sql);
  60. $cursor4 = oci_new_cursor($c);
  61. oci_bind_by_name($s4, ":curs", $cursor4, -1, OCI_B_CURSOR);
  62. oci_define_by_name($cursor4, 'ID', $id4);
  63. oci_execute($s4);
  64. oci_execute($cursor4);
  65. while (oci_fetch_row($cursor4)) {
  66. var_dump($id4);
  67. }
  68. echo "Test 5 - define before bind\n";
  69. $s5 = oci_parse($c, $sql);
  70. $cursor5 = oci_new_cursor($c);
  71. oci_define_by_name($cursor5, 'ID', $id5);
  72. oci_bind_by_name($s5, ":curs", $cursor5, -1, OCI_B_CURSOR);
  73. oci_execute($s5);
  74. oci_execute($cursor5);
  75. while (oci_fetch_row($cursor5)) {
  76. var_dump($id5);
  77. }
  78. echo "Test 6 - fetch on wrong handle\n";
  79. $s6 = oci_parse($c, $sql);
  80. $cursor6 = oci_new_cursor($c);
  81. oci_define_by_name($cursor6, 'ID', $id6);
  82. oci_bind_by_name($s6, ":curs", $cursor6, -1, OCI_B_CURSOR);
  83. oci_execute($s6);
  84. oci_execute($cursor6);
  85. while (oci_fetch_row($s6)) {
  86. var_dump($id6);
  87. }
  88. // Clean up
  89. $stmtarray = array(
  90. "drop table define6_tab"
  91. );
  92. oci8_test_sql_execute($c, $stmtarray);
  93. ?>
  94. ===DONE===
  95. <?php exit(0); ?>
  96. --EXPECTF--
  97. Test 1 - define last
  98. NULL
  99. Test 2 - define last with preset var
  100. string(0) ""
  101. Test 3 - define before cursor execute
  102. string(1) "1"
  103. Test 4 - define before top level execute
  104. string(1) "1"
  105. Test 5 - define before bind
  106. string(1) "1"
  107. Test 6 - fetch on wrong handle
  108. Warning: oci_fetch_row(): ORA-24374: %s in %sdefine6.php on line %d
  109. ===DONE===