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