define6.phpt 2.8 KB

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