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