Skip to content

Commit 90ad6e3

Browse files
committed
add test for bug #47803
1 parent ff115e2 commit 90ad6e3

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed

ext/odbc/tests/bug47803.phpt

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
--TEST--
2+
Bug #47803 Executing prepared statements is succesfull only for the first two statements
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
8+
include dirname(__FILE__) . "/config.inc";
9+
10+
$create_table = "CREATE TABLE FOO(
11+
[PAR_ID] [int] NOT NULL,
12+
[PAR_INT] [int] NULL,
13+
[PAR_CHR] [varchar](500) NULL
14+
)";
15+
16+
$inserts = "INSERT INTO FOO
17+
([PAR_ID]
18+
,[PAR_INT]
19+
,[PAR_CHR])
20+
VALUES
21+
(1,14,''),
22+
(2,30,''),
23+
(3,7,''),
24+
(4,7,''),
25+
(5,0,''),
26+
(6,0,''),
27+
(7,20130901,''),
28+
(8,20140201,''),
29+
(9,20140201,''),
30+
(10,20140620,''),
31+
(11,221,'')";
32+
33+
34+
date_default_timezone_set('Europe/Warsaw');
35+
36+
$link = odbc_connect($dsn, $user, $pass);
37+
38+
odbc_exec($link, 'CREATE DATABASE odbcTEST');
39+
odbc_exec($link, $create_table);
40+
odbc_exec($link, $inserts);
41+
42+
$upd_params = array(
43+
array('id'=>1, 'name'=>'test 1'),
44+
array('id'=>2, 'name'=>'test 2'),
45+
array('id'=>3, 'name'=>'test 3'),
46+
array('id'=>4, 'name'=>'test 4'),
47+
array('id'=>5, 'name'=>'test 5'),
48+
array('id'=>10, 'name'=>'test 10'),
49+
array('id'=>9, 'name'=>'test 9'),
50+
array('id'=>8, 'name'=>'test 8'),
51+
array('id'=>7, 'name'=>'test 7'),
52+
array('id'=>6, 'name'=>'test 6'),
53+
);
54+
$sql = "UPDATE FOO
55+
SET [PAR_CHR] = ?
56+
WHERE [PAR_ID] = ?";
57+
$result = odbc_prepare($link, $sql);
58+
if (!$result) {
59+
print ('[sql] prep: '.$sql);
60+
goto out;
61+
}
62+
foreach ($upd_params as &$k) {
63+
if(!odbc_execute($result, array($k['name'], $k['id']))) {
64+
print ('[sql] exec: '."array({$k['name']}, {$k['id']})");
65+
goto out;
66+
}
67+
}
68+
odbc_free_result($result);
69+
70+
$sql = "SELECT * FROM FOO WHERE [PAR_ID] = ?";
71+
$result = odbc_prepare($link, $sql);
72+
if (!$result) {
73+
print ('[sql] prep: '.$sql);
74+
goto out;
75+
}
76+
foreach ($upd_params as $k) {
77+
if(!odbc_execute($result, array($k['id']))) {
78+
print ('[sql] exec: '."array({$k['id']})");
79+
goto out;
80+
}
81+
while (($r = odbc_fetch_array($result)) !== false) {
82+
var_dump($r);
83+
}
84+
}
85+
86+
out:
87+
if ($result) odbc_free_result($result);
88+
odbc_close($link);
89+
90+
?>
91+
==DONE==
92+
--EXPECT--
93+
array(3) {
94+
["PAR_ID"]=>
95+
string(1) "1"
96+
["PAR_INT"]=>
97+
string(2) "14"
98+
["PAR_CHR"]=>
99+
string(6) "test 1"
100+
}
101+
array(3) {
102+
["PAR_ID"]=>
103+
string(1) "2"
104+
["PAR_INT"]=>
105+
string(2) "30"
106+
["PAR_CHR"]=>
107+
string(6) "test 2"
108+
}
109+
array(3) {
110+
["PAR_ID"]=>
111+
string(1) "3"
112+
["PAR_INT"]=>
113+
string(1) "7"
114+
["PAR_CHR"]=>
115+
string(6) "test 3"
116+
}
117+
array(3) {
118+
["PAR_ID"]=>
119+
string(1) "4"
120+
["PAR_INT"]=>
121+
string(1) "7"
122+
["PAR_CHR"]=>
123+
string(6) "test 4"
124+
}
125+
array(3) {
126+
["PAR_ID"]=>
127+
string(1) "5"
128+
["PAR_INT"]=>
129+
string(1) "0"
130+
["PAR_CHR"]=>
131+
string(6) "test 5"
132+
}
133+
array(3) {
134+
["PAR_ID"]=>
135+
string(2) "10"
136+
["PAR_INT"]=>
137+
string(8) "20140620"
138+
["PAR_CHR"]=>
139+
string(7) "test 10"
140+
}
141+
array(3) {
142+
["PAR_ID"]=>
143+
string(1) "9"
144+
["PAR_INT"]=>
145+
string(8) "20140201"
146+
["PAR_CHR"]=>
147+
string(6) "test 9"
148+
}
149+
array(3) {
150+
["PAR_ID"]=>
151+
string(1) "8"
152+
["PAR_INT"]=>
153+
string(8) "20140201"
154+
["PAR_CHR"]=>
155+
string(6) "test 8"
156+
}
157+
array(3) {
158+
["PAR_ID"]=>
159+
string(1) "7"
160+
["PAR_INT"]=>
161+
string(8) "20130901"
162+
["PAR_CHR"]=>
163+
string(6) "test 7"
164+
}
165+
array(3) {
166+
["PAR_ID"]=>
167+
string(1) "7"
168+
["PAR_INT"]=>
169+
string(8) "20130901"
170+
["PAR_CHR"]=>
171+
string(6) "test 7"
172+
}
173+
==DONE==
174+
--CLEAN--
175+
<?php
176+
include 'config.inc';
177+
178+
$conn = odbc_connect($dsn, $user, $pass);
179+
180+
odbc_exec($conn, 'DROP TABLE FOO');
181+
odbc_exec($conn, 'DROP DATABASE odbcTEST');
182+
183+
odbc_close($conn);
184+
185+
?>

0 commit comments

Comments
 (0)