batch_stmt_try.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --TEST--
  2. PDO_DBLIB: driver supports exceptions
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded('pdo_dblib')) die('skip not loaded');
  6. require dirname(__FILE__) . '/config.inc';
  7. if (!driver_supports_batch_statements_without_select($db)) die('xfail test will fail with this version of FreeTDS');
  8. ?>
  9. --FILE--
  10. <?php
  11. require dirname(__FILE__) . '/config.inc';
  12. $stmt = $db->query(
  13. "create table #php_pdo(id int);" .
  14. "insert into #php_pdo values(1), (2), (3);" .
  15. "select * from #php_pdo;" .
  16. "begin try " .
  17. " update #php_pdo set id = 'f';" .
  18. "end try " .
  19. "begin catch " .
  20. " throw;" .
  21. "end catch " .
  22. "select * from #php_pdo;" .
  23. "delete from #php_pdo;" .
  24. "drop table #php_pdo;"
  25. );
  26. // check results from the create table
  27. var_dump($stmt->rowCount());
  28. var_dump($stmt->nextRowset());
  29. // check results from the first insert
  30. var_dump($stmt->rowCount());
  31. var_dump($stmt->nextRowset());
  32. // check results from the select
  33. var_dump($stmt->rowCount());
  34. var_dump($stmt->nextRowset());
  35. // check results from try
  36. var_dump($stmt->rowCount());
  37. var_dump($stmt->nextRowset());
  38. // check results from the update
  39. var_dump($stmt->rowCount());
  40. var_dump($stmt->nextRowset());
  41. // check that the update statement throws an error
  42. try {
  43. var_dump($stmt->rowCount());
  44. var_dump($stmt->nextRowset());
  45. } catch (PDOException $e) {
  46. var_dump($e->getMessage());
  47. }
  48. // once an error is thrown, the batch is terminated.
  49. // there should no results from here on
  50. // check results from the select
  51. var_dump($stmt->fetchAll());
  52. var_dump($stmt->rowCount());
  53. var_dump($stmt->nextRowset());
  54. // check results from the delete
  55. var_dump($stmt->rowCount());
  56. var_dump($stmt->nextRowset());
  57. // check results from the drop
  58. var_dump($stmt->rowCount());
  59. var_dump($stmt->nextRowset());
  60. // check that there are no more results
  61. var_dump($stmt->rowCount());
  62. var_dump($stmt->nextRowset());
  63. ?>
  64. --EXPECT--
  65. int(-1)
  66. bool(true)
  67. int(3)
  68. bool(true)
  69. int(-1)
  70. bool(true)
  71. int(-1)
  72. bool(true)
  73. int(0)
  74. bool(true)
  75. int(-1)
  76. string(68) "SQLSTATE[HY000]: General error: PDO_DBLIB: dbresults() returned FAIL"
  77. array(0) {
  78. }
  79. int(-1)
  80. bool(false)
  81. int(-1)
  82. bool(false)
  83. int(-1)
  84. bool(false)
  85. int(-1)
  86. bool(false)