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