1# 2013 March 10 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# This file implements regression tests for SQLite library. The 12# focus of this file is testing the TOINTEGER() and TODOUBLE() 13# functions. 14# 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17 18set i 0 19do_execsql_test func4-1.[incr i] { 20 SELECT tointeger(NULL); 21} {{}} 22do_execsql_test func4-1.[incr i] { 23 SELECT tointeger(''); 24} {{}} 25do_execsql_test func4-1.[incr i] { 26 SELECT tointeger(' '); 27} {{}} 28do_execsql_test func4-1.[incr i] { 29 SELECT tointeger('1234'); 30} {1234} 31do_execsql_test func4-1.[incr i] { 32 SELECT tointeger(' 1234'); 33} {1234} 34do_execsql_test func4-1.[incr i] { 35 SELECT tointeger('bad'); 36} {{}} 37do_execsql_test func4-1.[incr i] { 38 SELECT tointeger('0xBAD'); 39} {{}} 40do_execsql_test func4-1.[incr i] { 41 SELECT tointeger('123BAD'); 42} {{}} 43do_execsql_test func4-1.[incr i] { 44 SELECT tointeger('0x123BAD'); 45} {{}} 46do_execsql_test func4-1.[incr i] { 47 SELECT tointeger('123NO'); 48} {{}} 49do_execsql_test func4-1.[incr i] { 50 SELECT tointeger('0x123NO'); 51} {{}} 52do_execsql_test func4-1.[incr i] { 53 SELECT tointeger('-0x1'); 54} {{}} 55do_execsql_test func4-1.[incr i] { 56 SELECT tointeger('-0x0'); 57} {{}} 58do_execsql_test func4-1.[incr i] { 59 SELECT tointeger('0x0'); 60} {{}} 61do_execsql_test func4-1.[incr i] { 62 SELECT tointeger('0x1'); 63} {{}} 64do_execsql_test func4-1.[incr i] { 65 SELECT tointeger(-1); 66} {-1} 67do_execsql_test func4-1.[incr i] { 68 SELECT tointeger(-0); 69} {0} 70do_execsql_test func4-1.[incr i] { 71 SELECT tointeger(0); 72} {0} 73do_execsql_test func4-1.[incr i] { 74 SELECT tointeger(1); 75} {1} 76do_execsql_test func4-1.[incr i] { 77 SELECT tointeger(-1.79769313486232e308 - 1); 78} {-9223372036854775808} 79do_execsql_test func4-1.[incr i] { 80 SELECT tointeger(-1.79769313486232e308); 81} {-9223372036854775808} 82do_execsql_test func4-1.[incr i] { 83 SELECT tointeger(-1.79769313486232e308 + 1); 84} {-9223372036854775808} 85do_execsql_test func4-1.[incr i] { 86 SELECT tointeger(-9223372036854775808 - 1); 87} {-9223372036854775808} 88do_execsql_test func4-1.[incr i] { 89 SELECT tointeger(-9223372036854775808); 90} {-9223372036854775808} 91do_execsql_test func4-1.[incr i] { 92 SELECT tointeger(-9223372036854775808 + 1); 93} {-9223372036854775807} 94do_execsql_test func4-1.[incr i] { 95 SELECT tointeger(-2147483648 - 1); 96} {-2147483649} 97do_execsql_test func4-1.[incr i] { 98 SELECT tointeger(-2147483648); 99} {-2147483648} 100do_execsql_test func4-1.[incr i] { 101 SELECT tointeger(-2147483648 + 1); 102} {-2147483647} 103do_execsql_test func4-1.[incr i] { 104 SELECT tointeger(2147483647 - 1); 105} {2147483646} 106do_execsql_test func4-1.[incr i] { 107 SELECT tointeger(2147483647); 108} {2147483647} 109do_execsql_test func4-1.[incr i] { 110 SELECT tointeger(2147483647 + 1); 111} {2147483648} 112do_execsql_test func4-1.[incr i] { 113 SELECT tointeger(9223372036854775807 - 1); 114} {9223372036854775806} 115do_execsql_test func4-1.[incr i] { 116 SELECT tointeger(9223372036854775807); 117} {9223372036854775807} 118do_execsql_test func4-1.[incr i] { 119 SELECT tointeger(9223372036854775807 + 1); 120} {-9223372036854775808} 121do_execsql_test func4-1.[incr i] { 122 SELECT tointeger(1.79769313486232e308 - 1); 123} {-9223372036854775808} 124do_execsql_test func4-1.[incr i] { 125 SELECT tointeger(1.79769313486232e308); 126} {-9223372036854775808} 127do_execsql_test func4-1.[incr i] { 128 SELECT tointeger(1.79769313486232e308 + 1); 129} {-9223372036854775808} 130do_execsql_test func4-1.[incr i] { 131 SELECT tointeger(4503599627370496 - 1); 132} {4503599627370495} 133do_execsql_test func4-1.[incr i] { 134 SELECT tointeger(4503599627370496); 135} {4503599627370496} 136do_execsql_test func4-1.[incr i] { 137 SELECT tointeger(4503599627370496 + 1); 138} {4503599627370497} 139do_execsql_test func4-1.[incr i] { 140 SELECT tointeger(9007199254740992 - 1); 141} {9007199254740991} 142do_execsql_test func4-1.[incr i] { 143 SELECT tointeger(9007199254740992); 144} {9007199254740992} 145do_execsql_test func4-1.[incr i] { 146 SELECT tointeger(9007199254740992 + 1); 147} {9007199254740993} 148do_execsql_test func4-1.[incr i] { 149 SELECT tointeger(9223372036854775808 - 1); 150} {-9223372036854775808} 151do_execsql_test func4-1.[incr i] { 152 SELECT tointeger(9223372036854775808); 153} {-9223372036854775808} 154do_execsql_test func4-1.[incr i] { 155 SELECT tointeger(9223372036854775808 + 1); 156} {-9223372036854775808} 157do_execsql_test func4-1.[incr i] { 158 SELECT tointeger(18446744073709551616 - 1); 159} {-9223372036854775808} 160do_execsql_test func4-1.[incr i] { 161 SELECT tointeger(18446744073709551616); 162} {-9223372036854775808} 163do_execsql_test func4-1.[incr i] { 164 SELECT tointeger(18446744073709551616 + 1); 165} {-9223372036854775808} 166 167ifcapable floatingpoint { 168 set i 0 169 do_execsql_test func4-2.[incr i] { 170 SELECT todouble(NULL); 171 } {{}} 172 do_execsql_test func4-2.[incr i] { 173 SELECT todouble(''); 174 } {{}} 175 do_execsql_test func4-2.[incr i] { 176 SELECT todouble(' '); 177 } {{}} 178 do_execsql_test func4-2.[incr i] { 179 SELECT todouble('1234'); 180 } {1234.0} 181 do_execsql_test func4-2.[incr i] { 182 SELECT todouble(' 1234'); 183 } {1234.0} 184 do_execsql_test func4-2.[incr i] { 185 SELECT todouble('bad'); 186 } {{}} 187 do_execsql_test func4-2.[incr i] { 188 SELECT todouble('0xBAD'); 189 } {{}} 190 do_execsql_test func4-2.[incr i] { 191 SELECT todouble('123BAD'); 192 } {{}} 193 do_execsql_test func4-2.[incr i] { 194 SELECT todouble('0x123BAD'); 195 } {{}} 196 do_execsql_test func4-2.[incr i] { 197 SELECT todouble('123NO'); 198 } {{}} 199 do_execsql_test func4-2.[incr i] { 200 SELECT todouble('0x123NO'); 201 } {{}} 202 do_execsql_test func4-2.[incr i] { 203 SELECT todouble('-0x1'); 204 } {{}} 205 do_execsql_test func4-2.[incr i] { 206 SELECT todouble('-0x0'); 207 } {{}} 208 do_execsql_test func4-2.[incr i] { 209 SELECT todouble('0x0'); 210 } {{}} 211 do_execsql_test func4-2.[incr i] { 212 SELECT todouble('0x1'); 213 } {{}} 214 do_execsql_test func4-2.[incr i] { 215 SELECT todouble(-1); 216 } {-1.0} 217 do_execsql_test func4-2.[incr i] { 218 SELECT todouble(-0); 219 } {0.0} 220 do_execsql_test func4-2.[incr i] { 221 SELECT todouble(0); 222 } {0.0} 223 do_execsql_test func4-2.[incr i] { 224 SELECT todouble(1); 225 } {1.0} 226 do_execsql_test func4-2.[incr i] { 227 SELECT todouble(-1.79769313486232e308 - 1); 228 } {-Inf} 229 do_execsql_test func4-2.[incr i] { 230 SELECT todouble(-1.79769313486232e308); 231 } {-Inf} 232 do_execsql_test func4-2.[incr i] { 233 SELECT todouble(-1.79769313486232e308 + 1); 234 } {-Inf} 235 do_execsql_test func4-2.[incr i] { 236 SELECT todouble(-9223372036854775808 - 1); 237 } {-9.22337203685478e+18} 238 do_execsql_test func4-2.[incr i] { 239 SELECT todouble(-9223372036854775808); 240 } {-9.22337203685478e+18} 241 do_execsql_test func4-2.[incr i] { 242 SELECT todouble(-9223372036854775808 + 1); 243 } {-9.22337203685478e+18} 244 do_execsql_test func4-2.[incr i] { 245 SELECT todouble(-2147483648 - 1); 246 } {-2147483649.0} 247 do_execsql_test func4-2.[incr i] { 248 SELECT todouble(-2147483648); 249 } {-2147483648.0} 250 do_execsql_test func4-2.[incr i] { 251 SELECT todouble(-2147483648 + 1); 252 } {-2147483647.0} 253 do_execsql_test func4-2.[incr i] { 254 SELECT todouble(2147483647 - 1); 255 } {2147483646.0} 256 do_execsql_test func4-2.[incr i] { 257 SELECT todouble(2147483647); 258 } {2147483647.0} 259 do_execsql_test func4-2.[incr i] { 260 SELECT todouble(2147483647 + 1); 261 } {2147483648.0} 262 do_execsql_test func4-2.[incr i] { 263 SELECT todouble(9223372036854775807 - 1); 264 } {9.22337203685478e+18} 265 do_execsql_test func4-2.[incr i] { 266 SELECT todouble(9223372036854775807); 267 } {9.22337203685478e+18} 268 do_execsql_test func4-2.[incr i] { 269 SELECT todouble(9223372036854775807 + 1); 270 } {9.22337203685478e+18} 271 do_execsql_test func4-2.[incr i] { 272 SELECT todouble(1.79769313486232e308 - 1); 273 } {Inf} 274 do_execsql_test func4-2.[incr i] { 275 SELECT todouble(1.79769313486232e308); 276 } {Inf} 277 do_execsql_test func4-2.[incr i] { 278 SELECT todouble(1.79769313486232e308 + 1); 279 } {Inf} 280 do_execsql_test func4-2.[incr i] { 281 SELECT todouble(4503599627370496 - 1); 282 } {4503599627370500.0} 283 do_execsql_test func4-2.[incr i] { 284 SELECT todouble(4503599627370496); 285 } {4503599627370500.0} 286 do_execsql_test func4-2.[incr i] { 287 SELECT todouble(4503599627370496 + 1); 288 } {4503599627370500.0} 289 do_execsql_test func4-2.[incr i] { 290 SELECT todouble(9007199254740992 - 1); 291 } {9007199254740990.0} 292 do_execsql_test func4-2.[incr i] { 293 SELECT todouble(9007199254740992); 294 } {9007199254740990.0} 295 do_execsql_test func4-2.[incr i] { 296 SELECT todouble(9007199254740992 + 1); 297 } {9007199254740990.0} 298 do_execsql_test func4-2.[incr i] { 299 SELECT todouble(9223372036854775808 - 1); 300 } {9.22337203685478e+18} 301 do_execsql_test func4-2.[incr i] { 302 SELECT todouble(9223372036854775808); 303 } {9.22337203685478e+18} 304 do_execsql_test func4-2.[incr i] { 305 SELECT todouble(9223372036854775808 + 1); 306 } {9.22337203685478e+18} 307 do_execsql_test func4-2.[incr i] { 308 SELECT todouble(18446744073709551616 - 1); 309 } {1.84467440737096e+19} 310 do_execsql_test func4-2.[incr i] { 311 SELECT todouble(18446744073709551616); 312 } {1.84467440737096e+19} 313 do_execsql_test func4-2.[incr i] { 314 SELECT todouble(18446744073709551616 + 1); 315 } {1.84467440737096e+19} 316} 317 318ifcapable check { 319 set i 0 320 do_execsql_test func4-3.[incr i] { 321 CREATE TABLE t1( 322 x INTEGER CHECK(tointeger(x) IS NOT NULL AND x = CAST(x AS INTEGER)) 323 ); 324 } {} 325 do_test func4-3.[incr i] { 326 catchsql { 327 INSERT INTO t1 (x) VALUES (NULL); 328 } 329 } {1 {constraint failed}} 330 do_test func4-3.[incr i] { 331 catchsql { 332 INSERT INTO t1 (x) VALUES (NULL); 333 } 334 } {1 {constraint failed}} 335 do_test func4-3.[incr i] { 336 catchsql { 337 INSERT INTO t1 (x) VALUES (''); 338 } 339 } {1 {constraint failed}} 340 do_test func4-3.[incr i] { 341 catchsql { 342 INSERT INTO t1 (x) VALUES ('bad'); 343 } 344 } {1 {constraint failed}} 345 do_test func4-3.[incr i] { 346 catchsql { 347 INSERT INTO t1 (x) VALUES ('1234bad'); 348 } 349 } {1 {constraint failed}} 350 do_test func4-3.[incr i] { 351 catchsql { 352 INSERT INTO t1 (x) VALUES (1234); 353 } 354 } {0 {}} 355 do_test func4-3.[incr i] { 356 catchsql { 357 INSERT INTO t1 (x) VALUES (1234.56); 358 } 359 } {1 {constraint failed}} 360 do_test func4-3.[incr i] { 361 catchsql { 362 INSERT INTO t1 (x) VALUES ('1234'); 363 } 364 } {0 {}} 365 do_test func4-3.[incr i] { 366 catchsql { 367 INSERT INTO t1 (x) VALUES ('1234.56'); 368 } 369 } {1 {constraint failed}} 370 do_test func4-3.[incr i] { 371 catchsql { 372 INSERT INTO t1 (x) VALUES (ZEROBLOB(4)); 373 } 374 } {1 {constraint failed}} 375 do_test func4-3.[incr i] { 376 catchsql { 377 INSERT INTO t1 (x) VALUES (X''); 378 } 379 } {1 {constraint failed}} 380 do_test func4-3.[incr i] { 381 catchsql { 382 INSERT INTO t1 (x) VALUES (X'1234'); 383 } 384 } {1 {constraint failed}} 385 do_test func4-3.[incr i] { 386 catchsql { 387 INSERT INTO t1 (x) VALUES (X'12345678'); 388 } 389 } {1 {constraint failed}} 390 do_execsql_test func4-3.[incr i] { 391 SELECT x FROM t1 ORDER BY x; 392 } {1234 1234} 393} 394 395finish_test 396