@@ -4,28 +4,29 @@ use warnings;
4
4
use DBI;
5
5
use DBI::Const::GetInfoType;
6
6
use Test::More;
7
+ select (($| =1,select (STDERR ),$| =1)[1]);
7
8
use lib ' t' , ' .' ;
8
9
require ' lib.pl' ;
9
10
10
11
use vars qw( $test_dsn $test_user $test_password) ;
11
12
12
- my $dbh ;
13
+ my ( $dbh , $t ) ;
13
14
eval {$dbh = DBI-> connect ($test_dsn , $test_user , $test_password ,
14
- { RaiseError => 1, PrintError => 1, AutoCommit => 0 });};
15
+ { RaiseError => 1, PrintError => 1, AutoCommit => 1 });};
15
16
if ($@ ) {
16
17
plan skip_all => " no database connection" ;
17
18
}
18
- plan tests => 26;
19
+ plan tests => 98;
19
20
20
- ok $dbh -> do(" DROP TABLE IF EXISTS dbd_mysql_t51bind_type_guessing" ), " drop table if exists dbd_mysql_t51bind_type_guessing" ;
21
+ ok $dbh -> do(" DROP TABLE IF EXISTS dbd_mysql_t51bind_type_guessing" ),
22
+ " drop table if exists dbd_mysql_t51bind_type_guessing" ;
21
23
22
24
my $create = <<"EOTABLE" ;
23
25
create table dbd_mysql_t51bind_type_guessing (
24
26
id bigint unsigned not null default 0
25
27
)
26
28
EOTABLE
27
29
28
-
29
30
ok $dbh -> do($create ), " creating table" ;
30
31
31
32
my $statement = " insert into dbd_mysql_t51bind_type_guessing (id) values (?)" ;
@@ -54,29 +55,152 @@ ok $sth2= $dbh->prepare($statement);
54
55
ok $rows = $sth2 -> execute(' 9999999999999996' , ' 9999999999999997' );
55
56
56
57
my $retref ;
57
- ok $retref = $dbh -> selectall_arrayref(" select * from dbd_mysql_t51bind_type_guessing" );
58
+ ok $retref = $dbh -> selectall_arrayref(
59
+ " select * from dbd_mysql_t51bind_type_guessing" );
58
60
59
61
cmp_ok $retref -> [0][0], ' ==' , 9999999999999998;
60
62
cmp_ok $retref -> [1][0], ' ==' , 9999999999999996;
61
63
62
64
# checking varchars/empty strings/misidentification:
63
65
$create = <<"EOTABLE" ;
64
66
create table dbd_mysql_t51bind_type_guessing (
67
+ id bigint default 0 not null,
68
+ nn bigint default 0,
69
+ dd double(12,4),
65
70
str varchar(80),
66
- num bigint
67
- )
71
+ primary key (id)
72
+ ) engine=innodb
68
73
EOTABLE
74
+
69
75
ok $dbh -> do(" DROP TABLE IF EXISTS dbd_mysql_t51bind_type_guessing" ), " drop table if exists dbd_mysql_t51bind_type_guessing" ;
70
- ok $dbh -> do($create ), " creating table w/ varchar" ;
76
+
77
+ ok $dbh -> do($create ), " creating table with int, double, and varchar" ;
78
+
79
+ my @sts ;
80
+ $t = " prepare insert integer col nn into dbd_mysql_t51bind_type_guessing" ;
81
+ ok $sts [0] = $dbh -> prepare(" insert into dbd_mysql_t51bind_type_guessing (id,nn) values (?,?)" ), $t ;
82
+ $t = " prepare update double col dd dbd_mysql_t51bind_type_guessing" ;
83
+ ok $sts [1] = $dbh -> prepare(" update dbd_mysql_t51bind_type_guessing set dd = ? where id = ?" ), $t ;
84
+ $t = " prepare update string col str dbd_mysql_t51bind_type_guessing" ;
85
+ ok $sts [2] = $dbh -> prepare(" update dbd_mysql_t51bind_type_guessing set str = ? where id = ?" ), $t ;
86
+
87
+ # various values to try including issue 251
88
+ my @vals = ( 52.3,
89
+ ' 77.7777' ,
90
+ ' .1' ,
91
+ ' 5e3' ,
92
+ +1,
93
+ -1,
94
+ undef ,
95
+ ' 5e' ,
96
+ ' 1+' ,
97
+ ' +' ,
98
+ ' .' ,
99
+ ' e5' ,
100
+ );
101
+
102
+ my $val ;
103
+ # the tests for 'like' are when values fail to be inserted/updated
104
+ for my $i (0 .. 11) {
105
+ $val = $vals [$i ];
106
+ if (defined $val ) {
107
+ $t = " insert int val $val id $i "
108
+ }
109
+ else {
110
+ $t = " insert undef into int id $i " ;
111
+ }
112
+ if ($i >= 8) {
113
+ eval {
114
+ $rows = $sts [0]-> execute($i , $val );
115
+ };
116
+ if ($i == 8) {
117
+ like ($@ , qr { Data truncated for column} , $t );
118
+ }
119
+ else {
120
+ like ($@ , qr { Incorrect integer value} , $t );
121
+ }
122
+ $rows = $sts [0]-> execute($i , 0);
123
+ }
124
+ else {
125
+ ok $rows = $sts [0]-> execute($i , $val ),$t ;
126
+ }
127
+
128
+ if (defined $val ) {
129
+ $t = " update double val $val id $i " ;
130
+ }
131
+ else {
132
+ $t = " update double val undefined id $i " ;
133
+ }
134
+ if ($i >= 7) {
135
+ eval {
136
+ $rows = $sts [1]-> execute($val , $i );
137
+ };
138
+ like ($@ , qr { Data truncated for column} , $t );
139
+ $rows = $sts [1]-> execute(0, $i );
140
+ }
141
+ else {
142
+ ok $rows = $sts [1]-> execute($val ,$i ),$t ;
143
+ }
144
+
145
+ if (defined $val ) {
146
+ $t = " update string val $val id $i " ;
147
+ }
148
+ else {
149
+ $t = " update string val undef id $i " ;
150
+ }
151
+ ok $rows = $sts [2]-> execute($val ,$i ),$t ;
152
+ }
153
+
154
+ for my $i (0 .. 2) {
155
+ $sts [$i ]-> finish();
156
+ }
157
+
158
+ # expected results
159
+ my $res = [
160
+ [ 0, 52, ' 52.3' , ' 52.3' ],
161
+ [ 1, 78, ' 77.7777' , ' 77.7777' ],
162
+ [ 2, 0, ' 0.1' , ' 0.1' ],
163
+ [ 3, 5000, ' 5000' , ' 5e3' ],
164
+ [ 4, 1, ' 1' , ' 1' ],
165
+ [ 5, -1, ' -1' , ' -1' ],
166
+ [ 6, undef , undef , undef ],
167
+ [ 7, 5, ' 0' , ' 5e' ],
168
+ [ 8, 0, ' 0' , ' 1+' ],
169
+ [ 9, 0, ' 0' , ' +' ],
170
+ [ 10, 0, ' 0' , ' .' ],
171
+ [ 11, 0, ' 0' , ' e5' ]
172
+ ];
173
+
174
+ $t = " Select all values" ;
175
+ my $query = " select * from dbd_mysql_t51bind_type_guessing" ;
176
+
177
+ ok $retref = $dbh -> selectall_arrayref($query ), $t ;
178
+
179
+ for my $i (0 .. $# $res ) {
180
+ if ($i == 6) {
181
+ is($retref -> [$i ][1], undef , " $i : nn undefined as expected" );
182
+ is($retref -> [$i ][2], undef , " $i : dd undefined as expected" );
183
+ is($retref -> [$i ][3], undef , " $i : str undefined as expected" );
184
+ }
185
+ else {
186
+ cmp_ok $retref -> [$i ][1], ' ==' , $res -> [$i ][1],
187
+ " test: " . " $retref ->[$i ][1], '==', $res ->[$i ][1]" ;
188
+ cmp_ok $retref -> [$i ][2], ' eq' , $res -> [$i ][2],
189
+ " test: " . " $retref ->[$i ][2], '==', $res ->[$i ][2]" ;
190
+ cmp_ok $retref -> [$i ][3], ' eq' , $res -> [$i ][3],
191
+ " test: " . " $retref ->[$i ][2], '==', $res ->[$i ][2]" ;
192
+ }
193
+ }
194
+
71
195
my $sth3 ;
72
- ok $sth3 = $dbh -> prepare( " insert into dbd_mysql_t51bind_type_guessing (str, num) values (?, ?) " ) ;
73
- ok $rows = $sth3 -> execute(52.3, 44) ;
74
- ok $rows = $sth3 -> execute( ' ' , ' 77 ' ) ;
75
- ok $rows = $sth3 -> execute( undef , undef ) ;
76
-
77
- ok $sth3 = $dbh -> prepare( " select * from dbd_mysql_t51bind_type_guessing limit ? " ) ;
78
- ok $rows = $sth3 -> execute(1) ;
79
- ok $rows = $sth3 -> execute(' 1 ' ) ;
196
+ $t = " Prepare limit statement " ;
197
+ ok $sth3 = $dbh -> prepare( " select * from dbd_mysql_t51bind_type_guessing limit ? " ), $t ;
198
+ $val = 1 ;
199
+ $t = " select with limit $val statement " ;
200
+ ok $rows = $sth3 -> execute( $val ), $t ;
201
+ $val = ' 1 ' ;
202
+ $t = " select with limit $val statement " ;
203
+ ok $rows = $sth3 -> execute($val ), $t ;
80
204
$sth3 -> finish();
81
205
82
206
ok $dbh -> do(" DROP TABLE dbd_mysql_t51bind_type_guessing" );
0 commit comments