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