num.phpt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. --TEST--
  2. oci_num_*() family
  3. --SKIPIF--
  4. <?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
  5. --FILE--
  6. <?php
  7. require(dirname(__FILE__)."/connect.inc");
  8. // Initialize
  9. $stmtarray = array(
  10. "drop table num_tab",
  11. "create table num_tab (id number, value number)",
  12. );
  13. oci8_test_sql_execute($c, $stmtarray);
  14. // Run Test
  15. echo "Test 1\n";
  16. var_dump(ocirowcount());
  17. var_dump(oci_num_rows());
  18. var_dump(ocinumcols());
  19. var_dump(oci_num_fields());
  20. echo "Test 2\n";
  21. $insert_sql = "insert into num_tab (id, value) values (1,1)";
  22. if (!($s = oci_parse($c, $insert_sql))) {
  23. die("oci_parse(insert) failed!\n");
  24. }
  25. var_dump(ocirowcount($s));
  26. var_dump(oci_num_rows($s));
  27. var_dump(ocinumcols($s));
  28. var_dump(oci_num_fields($s));
  29. for ($i = 0; $i<3; $i++) {
  30. if (!oci_execute($s)) {
  31. die("oci_execute(insert) failed!\n");
  32. }
  33. }
  34. echo "Test 3\n";
  35. var_dump(ocirowcount($s));
  36. var_dump(oci_num_rows($s));
  37. var_dump(ocinumcols($s));
  38. var_dump(oci_num_fields($s));
  39. if (!oci_commit($c)) {
  40. die("oci_commit() failed!\n");
  41. }
  42. echo "Test 4\n";
  43. var_dump(ocirowcount($s));
  44. var_dump(oci_num_rows($s));
  45. var_dump(ocinumcols($s));
  46. var_dump(oci_num_fields($s));
  47. // All rows
  48. $select_sql = "select * from num_tab";
  49. if (!($s = oci_parse($c, $select_sql))) {
  50. die("oci_parse(select) failed!\n");
  51. }
  52. echo "Test 5a\n";
  53. var_dump(ocirowcount($s));
  54. var_dump(oci_num_rows($s));
  55. var_dump(ocinumcols($s));
  56. var_dump(oci_num_fields($s));
  57. if (!oci_execute($s)) {
  58. die("oci_execute(select) failed!\n");
  59. }
  60. echo "Test 5b\n";
  61. var_dump(ocirowcount($s));
  62. var_dump(oci_num_rows($s));
  63. var_dump(ocinumcols($s));
  64. var_dump(oci_num_fields($s));
  65. if (oci_fetch_all($s,$r) === false) {
  66. die("oci_fetch_all(select) failed!\n");
  67. }
  68. echo "Test 5c\n";
  69. var_dump(ocirowcount($s));
  70. var_dump(oci_num_rows($s));
  71. var_dump(ocinumcols($s));
  72. var_dump(oci_num_fields($s));
  73. // One row
  74. $select_sql = "SELECT id, value FROM num_tab WHERE ROWNUM < 2";
  75. if (!($s = oci_parse($c, $select_sql))) {
  76. die("oci_parse(select) failed!\n");
  77. }
  78. if (!oci_execute($s)) {
  79. die("oci_execute(select) failed!\n");
  80. }
  81. if (oci_fetch_all($s,$r) === false) {
  82. die("oci_fetch_all(select) failed!\n");
  83. }
  84. echo "Test 6\n";
  85. var_dump(ocirowcount($s));
  86. var_dump(oci_num_rows($s));
  87. var_dump(ocinumcols($s));
  88. var_dump(oci_num_fields($s));
  89. // No rows
  90. $select_sql = "select id from num_tab where 1=0";
  91. if (!($s = oci_parse($c, $select_sql))) {
  92. die("oci_parse(select) failed!\n");
  93. }
  94. if (!oci_execute($s)) {
  95. die("oci_execute(select) failed!\n");
  96. }
  97. if (oci_fetch_all($s,$r) === false) {
  98. die("oci_fetch_all(select) failed!\n");
  99. }
  100. echo "Test 7\n";
  101. var_dump(ocirowcount($s));
  102. var_dump(oci_num_rows($s));
  103. var_dump(ocinumcols($s));
  104. var_dump(oci_num_fields($s));
  105. $delete_sql = "delete from num_tab";
  106. if (!($s = oci_parse($c, $delete_sql))) {
  107. die("oci_parse(delete) failed!\n");
  108. }
  109. if (!oci_execute($s)) {
  110. die("oci_execute(delete) failed!\n");
  111. }
  112. echo "Test 8a\n";
  113. var_dump(ocirowcount($s));
  114. var_dump(oci_num_rows($s));
  115. var_dump(ocinumcols($s));
  116. var_dump(oci_num_fields($s));
  117. oci_commit($c);
  118. echo "Test 8b\n";
  119. var_dump(ocirowcount($s));
  120. var_dump(oci_num_rows($s));
  121. var_dump(ocinumcols($s));
  122. var_dump(oci_num_fields($s));
  123. // Cleanup
  124. $stmtarray = array(
  125. "drop table num_tab"
  126. );
  127. oci8_test_sql_execute($c, $stmtarray);
  128. echo "Done\n";
  129. ?>
  130. --EXPECTF--
  131. Test 1
  132. Warning: ocirowcount() expects exactly 1 parameter, 0 given in %s on line %d
  133. NULL
  134. Warning: oci_num_rows() expects exactly 1 parameter, 0 given in %s on line %d
  135. NULL
  136. Warning: ocinumcols() expects exactly 1 parameter, 0 given in %s on line %d
  137. NULL
  138. Warning: oci_num_fields() expects exactly 1 parameter, 0 given in %s on line %d
  139. NULL
  140. Test 2
  141. int(0)
  142. int(0)
  143. int(0)
  144. int(0)
  145. Test 3
  146. int(1)
  147. int(1)
  148. int(0)
  149. int(0)
  150. Test 4
  151. int(1)
  152. int(1)
  153. int(0)
  154. int(0)
  155. Test 5a
  156. int(0)
  157. int(0)
  158. int(0)
  159. int(0)
  160. Test 5b
  161. int(0)
  162. int(0)
  163. int(2)
  164. int(2)
  165. Test 5c
  166. int(3)
  167. int(3)
  168. int(2)
  169. int(2)
  170. Test 6
  171. int(1)
  172. int(1)
  173. int(2)
  174. int(2)
  175. Test 7
  176. int(0)
  177. int(0)
  178. int(1)
  179. int(1)
  180. Test 8a
  181. int(3)
  182. int(3)
  183. int(0)
  184. int(0)
  185. Test 8b
  186. int(3)
  187. int(3)
  188. int(0)
  189. int(0)
  190. Done