1--TEST--
2PDO_DBLIB: driver supports SET ROWCOUNT and SELECT @@ROWCOUNT in batch statements
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo_dblib')) die('skip not loaded');
6require __DIR__ . '/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 __DIR__ . '/config.inc';
13
14$stmt = $db->query(
15"create table #php_pdo(id int); " .
16"set rowcount 2; " .
17"insert into #php_pdo values(1), (2), (3); " .
18"insert into #php_pdo values(4), (5), (6); " .
19"update #php_pdo set id = 4; " .
20"select @@rowcount; "
21);
22
23// check results from the create table
24var_dump($stmt->rowCount());
25var_dump($stmt->nextRowset());
26
27// check results from the set rowcount
28var_dump($stmt->rowCount());
29var_dump($stmt->nextRowset());
30
31// check results from the first insert
32var_dump($stmt->rowCount());
33var_dump($stmt->nextRowset());
34
35// check results from the second insert
36var_dump($stmt->rowCount());
37var_dump($stmt->nextRowset());
38
39// check results from the update
40var_dump($stmt->rowCount());
41var_dump($stmt->nextRowset());
42
43// check results from the select rowcount
44var_dump($stmt->fetchAll());
45var_dump($stmt->rowCount());
46var_dump($stmt->nextRowset());
47
48// check that there are no more results
49var_dump($stmt->rowCount());
50var_dump($stmt->nextRowset());
51
52// now cleanup and check that the results are expected
53$stmt = $db->query("set rowcount 0;" .
54"select * from #php_pdo;" .
55"delete from #php_pdo;" .
56"drop table #php_pdo;"
57);
58
59// check results from set rowcount
60var_dump($stmt->rowCount());
61var_dump($stmt->nextRowset());
62
63// check results from the select
64var_dump($stmt->fetchAll());
65var_dump($stmt->rowCount());
66var_dump($stmt->nextRowset());
67
68// check results from the delete
69var_dump($stmt->rowCount());
70var_dump($stmt->nextRowset());
71
72// check results from the drop
73var_dump($stmt->rowCount());
74var_dump($stmt->nextRowset());
75
76// check that there are no more results
77var_dump($stmt->rowCount());
78var_dump($stmt->nextRowset());
79
80?>
81--EXPECT--
82int(-1)
83bool(true)
84int(-1)
85bool(true)
86int(2)
87bool(true)
88int(2)
89bool(true)
90int(2)
91bool(true)
92array(1) {
93  [0]=>
94  array(2) {
95    ["computed"]=>
96    int(2)
97    [0]=>
98    int(2)
99  }
100}
101int(-1)
102bool(false)
103int(-1)
104bool(false)
105int(-1)
106bool(true)
107array(4) {
108  [0]=>
109  array(2) {
110    ["id"]=>
111    int(4)
112    [0]=>
113    int(4)
114  }
115  [1]=>
116  array(2) {
117    ["id"]=>
118    int(4)
119    [0]=>
120    int(4)
121  }
122  [2]=>
123  array(2) {
124    ["id"]=>
125    int(4)
126    [0]=>
127    int(4)
128  }
129  [3]=>
130  array(2) {
131    ["id"]=>
132    int(5)
133    [0]=>
134    int(5)
135  }
136}
137int(-1)
138bool(true)
139int(4)
140bool(true)
141int(-1)
142bool(false)
143int(-1)
144bool(false)
145