sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | # 2023-03-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 focus of |
| 12 | # this file is testing the tointeger() and toreal() functions that are |
| 13 | # part of the "totype.c" extension. This file does not test the core |
| 14 | # SQLite library. Failures of tests in this file are related to the |
| 15 | # ext/misc/totype.c extension. |
| 16 | # |
| 17 | # Several of the toreal() tests are disabled on platforms where floating |
| 18 | # point precision is not high enough to represent their constant integer |
| 19 | # expression arguments as double precision floating point values. |
| 20 | # |
| 21 | set testdir [file dirname $argv0] |
| 22 | source $testdir/tester.tcl |
| 23 | set saved_tcl_precision $tcl_precision |
| 24 | set tcl_precision 0 |
| 25 | load_static_extension db totype |
| 26 | |
| 27 | set highPrecision(1) [expr \ |
| 28 | {[db eval {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}] |
| 29 | set highPrecision(2) [expr \ |
| 30 | {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}] |
| 31 | |
| 32 | # highPrecision(3) is only known to be false on i586 with gcc-13 and -O2. |
| 33 | # It is true on the exact same platform with -O0. Both results seem |
| 34 | # reasonable, so we'll just very the expectation accordingly. |
| 35 | # |
| 36 | set highPrecision(3) [expr \ |
| 37 | {[db eval {SELECT toreal(9007199254740992 + 1);}] eq {{}}}] |
| 38 | |
| 39 | if {!$highPrecision(1) || !$highPrecision(2) || !$highPrecision(3)} { |
| 40 | puts "NOTICE:\ |
| 41 | highPrecision: $highPrecision(1) $highPrecision(2) $highPrecision(3)" |
| 42 | } |
| 43 | |
| 44 | do_execsql_test func4-1.1 { |
| 45 | SELECT tointeger(NULL); |
| 46 | } {{}} |
| 47 | do_execsql_test func4-1.2 { |
| 48 | SELECT tointeger(''); |
| 49 | } {{}} |
| 50 | do_execsql_test func4-1.3 { |
| 51 | SELECT tointeger(' '); |
| 52 | } {{}} |
| 53 | do_execsql_test func4-1.4 { |
| 54 | SELECT tointeger('1234'); |
| 55 | } {1234} |
| 56 | do_execsql_test func4-1.5 { |
| 57 | SELECT tointeger(' 1234'); |
| 58 | } {{}} |
| 59 | do_execsql_test func4-1.6 { |
| 60 | SELECT tointeger('bad'); |
| 61 | } {{}} |
| 62 | do_execsql_test func4-1.7 { |
| 63 | SELECT tointeger('0xBAD'); |
| 64 | } {{}} |
| 65 | do_execsql_test func4-1.8 { |
| 66 | SELECT tointeger('123BAD'); |
| 67 | } {{}} |
| 68 | do_execsql_test func4-1.9 { |
| 69 | SELECT tointeger('0x123BAD'); |
| 70 | } {{}} |
| 71 | do_execsql_test func4-1.10 { |
| 72 | SELECT tointeger('123NO'); |
| 73 | } {{}} |
| 74 | do_execsql_test func4-1.11 { |
| 75 | SELECT tointeger('0x123NO'); |
| 76 | } {{}} |
| 77 | do_execsql_test func4-1.12 { |
| 78 | SELECT tointeger('-0x1'); |
| 79 | } {{}} |
| 80 | do_execsql_test func4-1.13 { |
| 81 | SELECT tointeger('-0x0'); |
| 82 | } {{}} |
| 83 | do_execsql_test func4-1.14 { |
| 84 | SELECT tointeger('0x0'); |
| 85 | } {{}} |
| 86 | do_execsql_test func4-1.15 { |
| 87 | SELECT tointeger('0x1'); |
| 88 | } {{}} |
| 89 | do_execsql_test func4-1.16 { |
| 90 | SELECT tointeger(-1); |
| 91 | } {-1} |
| 92 | do_execsql_test func4-1.17 { |
| 93 | SELECT tointeger(-0); |
| 94 | } {0} |
| 95 | do_execsql_test func4-1.18 { |
| 96 | SELECT tointeger(0); |
| 97 | } {0} |
| 98 | do_execsql_test func4-1.19 { |
| 99 | SELECT tointeger(1); |
| 100 | } {1} |
| 101 | do_execsql_test func4-1.20 { |
| 102 | SELECT tointeger(-1.79769313486232e308 - 1); |
| 103 | } {{}} |
| 104 | do_execsql_test func4-1.21 { |
| 105 | SELECT tointeger(-1.79769313486232e308); |
| 106 | } {{}} |
| 107 | do_execsql_test func4-1.22 { |
| 108 | SELECT tointeger(-1.79769313486232e308 + 1); |
| 109 | } {{}} |
| 110 | do_execsql_test func4-1.23 { |
| 111 | SELECT tointeger(-9223372036854775808 - 1); |
| 112 | } {{}} |
| 113 | do_execsql_test func4-1.24 { |
| 114 | SELECT tointeger(-9223372036854775808); |
| 115 | } {-9223372036854775808} |
| 116 | do_execsql_test func4-1.25 { |
| 117 | SELECT tointeger(-9223372036854775808 + 1); |
| 118 | } {-9223372036854775807} |
| 119 | do_execsql_test func4-1.26 { |
| 120 | SELECT tointeger(-9223372036854775807 - 1); |
| 121 | } {-9223372036854775808} |
| 122 | do_execsql_test func4-1.27 { |
| 123 | SELECT tointeger(-9223372036854775807); |
| 124 | } {-9223372036854775807} |
| 125 | do_execsql_test func4-1.28 { |
| 126 | SELECT tointeger(-9223372036854775807 + 1); |
| 127 | } {-9223372036854775806} |
| 128 | do_execsql_test func4-1.29 { |
| 129 | SELECT tointeger(-2147483648 - 1); |
| 130 | } {-2147483649} |
| 131 | do_execsql_test func4-1.30 { |
| 132 | SELECT tointeger(-2147483648); |
| 133 | } {-2147483648} |
| 134 | do_execsql_test func4-1.31 { |
| 135 | SELECT tointeger(-2147483648 + 1); |
| 136 | } {-2147483647} |
| 137 | do_execsql_test func4-1.32 { |
| 138 | SELECT tointeger(2147483647 - 1); |
| 139 | } {2147483646} |
| 140 | do_execsql_test func4-1.33 { |
| 141 | SELECT tointeger(2147483647); |
| 142 | } {2147483647} |
| 143 | do_execsql_test func4-1.34 { |
| 144 | SELECT tointeger(2147483647 + 1); |
| 145 | } {2147483648} |
| 146 | do_execsql_test func4-1.35 { |
| 147 | SELECT tointeger(9223372036854775807 - 1); |
| 148 | } {9223372036854775806} |
| 149 | do_execsql_test func4-1.36 { |
| 150 | SELECT tointeger(9223372036854775807); |
| 151 | } {9223372036854775807} |
| 152 | if {$highPrecision(1)} { |
| 153 | do_execsql_test func4-1.37 { |
| 154 | SELECT tointeger(9223372036854775807 + 1); |
| 155 | } {{}} |
| 156 | } |
| 157 | do_execsql_test func4-1.38 { |
| 158 | SELECT tointeger(1.79769313486232e308 - 1); |
| 159 | } {{}} |
| 160 | do_execsql_test func4-1.39 { |
| 161 | SELECT tointeger(1.79769313486232e308); |
| 162 | } {{}} |
| 163 | do_execsql_test func4-1.40 { |
| 164 | SELECT tointeger(1.79769313486232e308 + 1); |
| 165 | } {{}} |
| 166 | do_execsql_test func4-1.41 { |
| 167 | SELECT tointeger(4503599627370496 - 1); |
| 168 | } {4503599627370495} |
| 169 | do_execsql_test func4-1.42 { |
| 170 | SELECT tointeger(4503599627370496); |
| 171 | } {4503599627370496} |
| 172 | do_execsql_test func4-1.43 { |
| 173 | SELECT tointeger(4503599627370496 + 1); |
| 174 | } {4503599627370497} |
| 175 | do_execsql_test func4-1.44 { |
| 176 | SELECT tointeger(9007199254740992 - 1); |
| 177 | } {9007199254740991} |
| 178 | do_execsql_test func4-1.45 { |
| 179 | SELECT tointeger(9007199254740992); |
| 180 | } {9007199254740992} |
| 181 | do_execsql_test func4-1.46 { |
| 182 | SELECT tointeger(9007199254740992 + 1); |
| 183 | } {9007199254740993} |
| 184 | do_execsql_test func4-1.47 { |
| 185 | SELECT tointeger(9223372036854775807 - 1); |
| 186 | } {9223372036854775806} |
| 187 | do_execsql_test func4-1.48 { |
| 188 | SELECT tointeger(9223372036854775807); |
| 189 | } {9223372036854775807} |
| 190 | if {$highPrecision(1)} { |
| 191 | do_execsql_test func4-1.49 { |
| 192 | SELECT tointeger(9223372036854775807 + 1); |
| 193 | } {{}} |
| 194 | do_execsql_test func4-1.50 { |
| 195 | SELECT tointeger(9223372036854775808 - 1); |
| 196 | } {{}} |
| 197 | do_execsql_test func4-1.51 { |
| 198 | SELECT tointeger(9223372036854775808); |
| 199 | } {{}} |
| 200 | do_execsql_test func4-1.52 { |
| 201 | SELECT tointeger(9223372036854775808 + 1); |
| 202 | } {{}} |
| 203 | } |
| 204 | do_execsql_test func4-1.53 { |
| 205 | SELECT tointeger(18446744073709551616 - 1); |
| 206 | } {{}} |
| 207 | do_execsql_test func4-1.54 { |
| 208 | SELECT tointeger(18446744073709551616); |
| 209 | } {{}} |
| 210 | do_execsql_test func4-1.55 { |
| 211 | SELECT tointeger(18446744073709551616 + 1); |
| 212 | } {{}} |
| 213 | |
| 214 | ifcapable floatingpoint { |
| 215 | |
| 216 | do_execsql_test func4-2.1 { |
| 217 | SELECT toreal(NULL); |
| 218 | } {{}} |
| 219 | do_execsql_test func4-2.2 { |
| 220 | SELECT toreal(''); |
| 221 | } {{}} |
| 222 | do_execsql_test func4-2.3 { |
| 223 | SELECT toreal(' '); |
| 224 | } {{}} |
| 225 | do_execsql_test func4-2.4 { |
| 226 | SELECT toreal('1234'); |
| 227 | } {1234.0} |
| 228 | do_execsql_test func4-2.5 { |
| 229 | SELECT toreal(' 1234'); |
| 230 | } {{}} |
| 231 | do_execsql_test func4-2.6 { |
| 232 | SELECT toreal('bad'); |
| 233 | } {{}} |
| 234 | do_execsql_test func4-2.7 { |
| 235 | SELECT toreal('0xBAD'); |
| 236 | } {{}} |
| 237 | do_execsql_test func4-2.8 { |
| 238 | SELECT toreal('123BAD'); |
| 239 | } {{}} |
| 240 | do_execsql_test func4-2.9 { |
| 241 | SELECT toreal('0x123BAD'); |
| 242 | } {{}} |
| 243 | do_execsql_test func4-2.10 { |
| 244 | SELECT toreal('123NO'); |
| 245 | } {{}} |
| 246 | do_execsql_test func4-2.11 { |
| 247 | SELECT toreal('0x123NO'); |
| 248 | } {{}} |
| 249 | do_execsql_test func4-2.12 { |
| 250 | SELECT toreal('-0x1'); |
| 251 | } {{}} |
| 252 | do_execsql_test func4-2.13 { |
| 253 | SELECT toreal('-0x0'); |
| 254 | } {{}} |
| 255 | do_execsql_test func4-2.14 { |
| 256 | SELECT toreal('0x0'); |
| 257 | } {{}} |
| 258 | do_execsql_test func4-2.15 { |
| 259 | SELECT toreal('0x1'); |
| 260 | } {{}} |
| 261 | do_execsql_test func4-2.16 { |
| 262 | SELECT toreal(-1); |
| 263 | } {-1.0} |
| 264 | do_execsql_test func4-2.17 { |
| 265 | SELECT toreal(-0); |
| 266 | } {0.0} |
| 267 | do_execsql_test func4-2.18 { |
| 268 | SELECT toreal(0); |
| 269 | } {0.0} |
| 270 | do_execsql_test func4-2.19 { |
| 271 | SELECT toreal(1); |
| 272 | } {1.0} |
| 273 | do_execsql_test func4-2.20 { |
| 274 | SELECT toreal(-1.79769313486232e308 - 1); |
| 275 | } {-Inf} |
| 276 | do_execsql_test func4-2.21 { |
| 277 | SELECT toreal(-1.79769313486232e308); |
| 278 | } {-Inf} |
| 279 | do_execsql_test func4-2.22 { |
| 280 | SELECT toreal(-1.79769313486232e308 + 1); |
| 281 | } {-Inf} |
| 282 | do_execsql_test func4-2.23 { |
| 283 | SELECT toreal(-9223372036854775808 - 1); |
| 284 | } {-9.223372036854776e+18} |
| 285 | do_execsql_test func4-2.24 { |
| 286 | SELECT toreal(-9223372036854775808); |
| 287 | } {{}} |
| 288 | if {$highPrecision(2)} { |
| 289 | do_execsql_test func4-2.25 { |
| 290 | SELECT toreal(-9223372036854775808 + 1); |
| 291 | } {{}} |
| 292 | } |
| 293 | do_execsql_test func4-2.26 { |
| 294 | SELECT toreal(-9223372036854775807 - 1); |
| 295 | } {{}} |
| 296 | if {$highPrecision(2)} { |
| 297 | do_execsql_test func4-2.27 { |
| 298 | SELECT toreal(-9223372036854775807); |
| 299 | } {{}} |
| 300 | do_execsql_test func4-2.28 { |
| 301 | SELECT toreal(-9223372036854775807 + 1); |
| 302 | } {{}} |
| 303 | } |
| 304 | do_execsql_test func4-2.29 { |
| 305 | SELECT toreal(-2147483648 - 1); |
| 306 | } {-2147483649.0} |
| 307 | do_execsql_test func4-2.30 { |
| 308 | SELECT toreal(-2147483648); |
| 309 | } {-2147483648.0} |
| 310 | do_execsql_test func4-2.31 { |
| 311 | SELECT toreal(-2147483648 + 1); |
| 312 | } {-2147483647.0} |
| 313 | do_execsql_test func4-2.32 { |
| 314 | SELECT toreal(2147483647 - 1); |
| 315 | } {2147483646.0} |
| 316 | do_execsql_test func4-2.33 { |
| 317 | SELECT toreal(2147483647); |
| 318 | } {2147483647.0} |
| 319 | do_execsql_test func4-2.34 { |
| 320 | SELECT toreal(2147483647 + 1); |
| 321 | } {2147483648.0} |
| 322 | if {$highPrecision(2)} { |
| 323 | do_execsql_test func4-2.35 { |
| 324 | SELECT toreal(9223372036854775807 - 1); |
| 325 | } {{}} |
| 326 | if {$highPrecision(1)} { |
| 327 | do_execsql_test func4-2.36 { |
| 328 | SELECT toreal(9223372036854775807); |
| 329 | } {{}} |
| 330 | } |
| 331 | } |
| 332 | do_execsql_test func4-2.37 { |
| 333 | SELECT toreal(9223372036854775807 + 1); |
| 334 | } {9.223372036854776e+18} |
| 335 | do_execsql_test func4-2.38 { |
| 336 | SELECT toreal(1.79769313486232e308 - 1); |
| 337 | } {Inf} |
| 338 | do_execsql_test func4-2.39 { |
| 339 | SELECT toreal(1.79769313486232e308); |
| 340 | } {Inf} |
| 341 | do_execsql_test func4-2.40 { |
| 342 | SELECT toreal(1.79769313486232e308 + 1); |
| 343 | } {Inf} |
| 344 | do_execsql_test func4-2.41 { |
| 345 | SELECT toreal(4503599627370496 - 1); |
| 346 | } {4503599627370495.0} |
| 347 | do_execsql_test func4-2.42 { |
| 348 | SELECT toreal(4503599627370496); |
| 349 | } {4503599627370496.0} |
| 350 | do_execsql_test func4-2.43 { |
| 351 | SELECT toreal(4503599627370496 + 1); |
| 352 | } {4503599627370497.0} |
| 353 | do_execsql_test func4-2.44 { |
| 354 | SELECT toreal(9007199254740992 - 1); |
| 355 | } {9007199254740991.0} |
| 356 | do_execsql_test func4-2.45 { |
| 357 | SELECT toreal(9007199254740992); |
| 358 | } {9007199254740992.0} |
| 359 | if {$highPrecision(3)} { |
| 360 | do_execsql_test func4-2.46 { |
| 361 | SELECT toreal(9007199254740992 + 1); |
| 362 | } {{}} |
| 363 | } else { |
| 364 | do_execsql_test func4-2.46 { |
| 365 | SELECT toreal(9007199254740992 + 1); |
| 366 | } {9007199254740992.0} |
| 367 | } |
| 368 | do_execsql_test func4-2.47 { |
| 369 | SELECT toreal(9007199254740992 + 2); |
| 370 | } {9007199254740994.0} |
| 371 | do_execsql_test func4-2.48 { |
| 372 | SELECT toreal(tointeger(9223372036854775808) - 1); |
| 373 | } {{}} |
| 374 | if {$highPrecision(1)} { |
| 375 | do_execsql_test func4-2.49 { |
| 376 | SELECT toreal(tointeger(9223372036854775808)); |
| 377 | } {{}} |
| 378 | do_execsql_test func4-2.50 { |
| 379 | SELECT toreal(tointeger(9223372036854775808) + 1); |
| 380 | } {{}} |
| 381 | } |
| 382 | do_execsql_test func4-2.51 { |
| 383 | SELECT toreal(tointeger(18446744073709551616) - 1); |
| 384 | } {{}} |
| 385 | do_execsql_test func4-2.52 { |
| 386 | SELECT toreal(tointeger(18446744073709551616)); |
| 387 | } {{}} |
| 388 | do_execsql_test func4-2.53 { |
| 389 | SELECT toreal(tointeger(18446744073709551616) + 1); |
| 390 | } {{}} |
| 391 | } |
| 392 | |
| 393 | ifcapable check { |
| 394 | do_execsql_test func4-3.1 { |
| 395 | CREATE TABLE t1( |
| 396 | x INTEGER CHECK(tointeger(x) IS NOT NULL) |
| 397 | ); |
| 398 | } {} |
| 399 | do_test func4-3.2 { |
| 400 | catchsql { |
| 401 | INSERT INTO t1 (x) VALUES (NULL); |
| 402 | } |
| 403 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 404 | do_test func4-3.3 { |
| 405 | catchsql { |
| 406 | INSERT INTO t1 (x) VALUES (NULL); |
| 407 | } |
| 408 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 409 | do_test func4-3.4 { |
| 410 | catchsql { |
| 411 | INSERT INTO t1 (x) VALUES (''); |
| 412 | } |
| 413 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 414 | do_test func4-3.5 { |
| 415 | catchsql { |
| 416 | INSERT INTO t1 (x) VALUES ('bad'); |
| 417 | } |
| 418 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 419 | do_test func4-3.6 { |
| 420 | catchsql { |
| 421 | INSERT INTO t1 (x) VALUES ('1234bad'); |
| 422 | } |
| 423 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 424 | do_test func4-3.7 { |
| 425 | catchsql { |
| 426 | INSERT INTO t1 (x) VALUES ('1234.56bad'); |
| 427 | } |
| 428 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 429 | do_test func4-3.8 { |
| 430 | catchsql { |
| 431 | INSERT INTO t1 (x) VALUES (1234); |
| 432 | } |
| 433 | } {0 {}} |
| 434 | do_test func4-3.9 { |
| 435 | catchsql { |
| 436 | INSERT INTO t1 (x) VALUES (1234.56); |
| 437 | } |
| 438 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 439 | do_test func4-3.10 { |
| 440 | catchsql { |
| 441 | INSERT INTO t1 (x) VALUES ('1234'); |
| 442 | } |
| 443 | } {0 {}} |
| 444 | do_test func4-3.11 { |
| 445 | catchsql { |
| 446 | INSERT INTO t1 (x) VALUES ('1234.56'); |
| 447 | } |
| 448 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 449 | do_test func4-3.12 { |
| 450 | catchsql { |
| 451 | INSERT INTO t1 (x) VALUES (ZEROBLOB(4)); |
| 452 | } |
| 453 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 454 | do_test func4-3.13 { |
| 455 | catchsql { |
| 456 | INSERT INTO t1 (x) VALUES (X''); |
| 457 | } |
| 458 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 459 | do_test func4-3.14 { |
| 460 | catchsql { |
| 461 | INSERT INTO t1 (x) VALUES (X'1234'); |
| 462 | } |
| 463 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 464 | do_test func4-3.15 { |
| 465 | catchsql { |
| 466 | INSERT INTO t1 (x) VALUES (X'12345678'); |
| 467 | } |
| 468 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 469 | do_test func4-3.16 { |
| 470 | catchsql { |
| 471 | INSERT INTO t1 (x) VALUES ('1234.00'); |
| 472 | } |
| 473 | } {0 {}} |
| 474 | do_test func4-3.17 { |
| 475 | catchsql { |
| 476 | INSERT INTO t1 (x) VALUES (1234.00); |
| 477 | } |
| 478 | } {0 {}} |
| 479 | do_test func4-3.18 { |
| 480 | catchsql { |
| 481 | INSERT INTO t1 (x) VALUES ('-9223372036854775809'); |
| 482 | } |
| 483 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 484 | if {$highPrecision(1)} { |
| 485 | do_test func4-3.19 { |
| 486 | catchsql { |
| 487 | INSERT INTO t1 (x) VALUES (9223372036854775808); |
| 488 | } |
| 489 | } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} |
| 490 | } |
| 491 | do_execsql_test func4-3.20 { |
| 492 | SELECT x FROM t1 WHERE x>0 ORDER BY x; |
| 493 | } {1234 1234 1234 1234} |
| 494 | |
| 495 | ifcapable floatingpoint { |
| 496 | do_execsql_test func4-4.1 { |
| 497 | CREATE TABLE t2( |
| 498 | x REAL CHECK(toreal(x) IS NOT NULL) |
| 499 | ); |
| 500 | } {} |
| 501 | do_test func4-4.2 { |
| 502 | catchsql { |
| 503 | INSERT INTO t2 (x) VALUES (NULL); |
| 504 | } |
| 505 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 506 | do_test func4-4.3 { |
| 507 | catchsql { |
| 508 | INSERT INTO t2 (x) VALUES (NULL); |
| 509 | } |
| 510 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 511 | do_test func4-4.4 { |
| 512 | catchsql { |
| 513 | INSERT INTO t2 (x) VALUES (''); |
| 514 | } |
| 515 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 516 | do_test func4-4.5 { |
| 517 | catchsql { |
| 518 | INSERT INTO t2 (x) VALUES ('bad'); |
| 519 | } |
| 520 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 521 | do_test func4-4.6 { |
| 522 | catchsql { |
| 523 | INSERT INTO t2 (x) VALUES ('1234bad'); |
| 524 | } |
| 525 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 526 | do_test func4-4.7 { |
| 527 | catchsql { |
| 528 | INSERT INTO t2 (x) VALUES ('1234.56bad'); |
| 529 | } |
| 530 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 531 | do_test func4-4.8 { |
| 532 | catchsql { |
| 533 | INSERT INTO t2 (x) VALUES (1234); |
| 534 | } |
| 535 | } {0 {}} |
| 536 | do_test func4-4.9 { |
| 537 | catchsql { |
| 538 | INSERT INTO t2 (x) VALUES (1234.56); |
| 539 | } |
| 540 | } {0 {}} |
| 541 | do_test func4-4.10 { |
| 542 | catchsql { |
| 543 | INSERT INTO t2 (x) VALUES ('1234'); |
| 544 | } |
| 545 | } {0 {}} |
| 546 | do_test func4-4.11 { |
| 547 | catchsql { |
| 548 | INSERT INTO t2 (x) VALUES ('1234.56'); |
| 549 | } |
| 550 | } {0 {}} |
| 551 | do_test func4-4.12 { |
| 552 | catchsql { |
| 553 | INSERT INTO t2 (x) VALUES (ZEROBLOB(4)); |
| 554 | } |
| 555 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 556 | do_test func4-4.13 { |
| 557 | catchsql { |
| 558 | INSERT INTO t2 (x) VALUES (X''); |
| 559 | } |
| 560 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 561 | do_test func4-4.14 { |
| 562 | catchsql { |
| 563 | INSERT INTO t2 (x) VALUES (X'1234'); |
| 564 | } |
| 565 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 566 | do_test func4-4.15 { |
| 567 | catchsql { |
| 568 | INSERT INTO t2 (x) VALUES (X'12345678'); |
| 569 | } |
| 570 | } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} |
| 571 | do_execsql_test func4-4.16 { |
| 572 | SELECT x FROM t2 ORDER BY x; |
| 573 | } {1234.0 1234.0 1234.56 1234.56} |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | ifcapable floatingpoint { |
| 578 | do_execsql_test func4-5.1 { |
| 579 | SELECT tointeger(toreal('1234')); |
| 580 | } {1234} |
| 581 | do_execsql_test func4-5.2 { |
| 582 | SELECT tointeger(toreal(-1)); |
| 583 | } {-1} |
| 584 | do_execsql_test func4-5.3 { |
| 585 | SELECT tointeger(toreal(-0)); |
| 586 | } {0} |
| 587 | do_execsql_test func4-5.4 { |
| 588 | SELECT tointeger(toreal(0)); |
| 589 | } {0} |
| 590 | do_execsql_test func4-5.5 { |
| 591 | SELECT tointeger(toreal(1)); |
| 592 | } {1} |
| 593 | do_execsql_test func4-5.6 { |
| 594 | SELECT tointeger(toreal(-9223372036854775808 - 1)); |
| 595 | } {{}} |
| 596 | do_execsql_test func4-5.7 { |
| 597 | SELECT tointeger(toreal(-9223372036854775808)); |
| 598 | } {{}} |
| 599 | if {$highPrecision(2)} { |
| 600 | do_execsql_test func4-5.8 { |
| 601 | SELECT tointeger(toreal(-9223372036854775808 + 1)); |
| 602 | } {{}} |
| 603 | } |
| 604 | do_execsql_test func4-5.9 { |
| 605 | SELECT tointeger(toreal(-2147483648 - 1)); |
| 606 | } {-2147483649} |
| 607 | do_execsql_test func4-5.10 { |
| 608 | SELECT tointeger(toreal(-2147483648)); |
| 609 | } {-2147483648} |
| 610 | do_execsql_test func4-5.11 { |
| 611 | SELECT tointeger(toreal(-2147483648 + 1)); |
| 612 | } {-2147483647} |
| 613 | do_execsql_test func4-5.12 { |
| 614 | SELECT tointeger(toreal(2147483647 - 1)); |
| 615 | } {2147483646} |
| 616 | do_execsql_test func4-5.13 { |
| 617 | SELECT tointeger(toreal(2147483647)); |
| 618 | } {2147483647} |
| 619 | do_execsql_test func4-5.14 { |
| 620 | SELECT tointeger(toreal(2147483647 + 1)); |
| 621 | } {2147483648} |
| 622 | do_execsql_test func4-5.15 { |
| 623 | SELECT tointeger(toreal(9223372036854775807 - 1)); |
| 624 | } {{}} |
| 625 | if {$highPrecision(1)} { |
| 626 | do_execsql_test func4-5.16 { |
| 627 | SELECT tointeger(toreal(9223372036854775807)); |
| 628 | } {{}} |
| 629 | do_execsql_test func4-5.17 { |
| 630 | SELECT tointeger(toreal(9223372036854775807 + 1)); |
| 631 | } {{}} |
| 632 | } |
| 633 | do_execsql_test func4-5.18 { |
| 634 | SELECT tointeger(toreal(4503599627370496 - 1)); |
| 635 | } {4503599627370495} |
| 636 | do_execsql_test func4-5.19 { |
| 637 | SELECT tointeger(toreal(4503599627370496)); |
| 638 | } {4503599627370496} |
| 639 | do_execsql_test func4-5.20 { |
| 640 | SELECT tointeger(toreal(4503599627370496 + 1)); |
| 641 | } {4503599627370497} |
| 642 | do_execsql_test func4-5.21 { |
| 643 | SELECT tointeger(toreal(9007199254740992 - 1)); |
| 644 | } {9007199254740991} |
| 645 | do_execsql_test func4-5.22 { |
| 646 | SELECT tointeger(toreal(9007199254740992)); |
| 647 | } {9007199254740992} |
| 648 | if {$highPrecision(3)} { |
| 649 | do_execsql_test func4-5.23 { |
| 650 | SELECT tointeger(toreal(9007199254740992 + 1)); |
| 651 | } {{}} |
| 652 | } else { |
| 653 | do_execsql_test func4-5.23 { |
| 654 | SELECT tointeger(toreal(9007199254740992 + 1)); |
| 655 | } {9007199254740992} |
| 656 | } |
| 657 | do_execsql_test func4-5.24 { |
| 658 | SELECT tointeger(toreal(9007199254740992 + 2)); |
| 659 | } {9007199254740994} |
| 660 | if {$highPrecision(1)} { |
| 661 | do_execsql_test func4-5.25 { |
| 662 | SELECT tointeger(toreal(9223372036854775808 - 1)); |
| 663 | } {{}} |
| 664 | do_execsql_test func4-5.26 { |
| 665 | SELECT tointeger(toreal(9223372036854775808)); |
| 666 | } {{}} |
| 667 | do_execsql_test func4-5.27 { |
| 668 | SELECT tointeger(toreal(9223372036854775808 + 1)); |
| 669 | } {{}} |
| 670 | } |
| 671 | do_execsql_test func4-5.28 { |
| 672 | SELECT tointeger(toreal(18446744073709551616 - 1)); |
| 673 | } {{}} |
| 674 | do_execsql_test func4-5.29 { |
| 675 | SELECT tointeger(toreal(18446744073709551616)); |
| 676 | } {{}} |
| 677 | do_execsql_test func4-5.30 { |
| 678 | SELECT tointeger(toreal(18446744073709551616 + 1)); |
| 679 | } {{}} |
| 680 | } |
| 681 | |
| 682 | for {set i 0} {$i < 10} {incr i} { |
| 683 | if {$i == 8} continue |
| 684 | do_execsql_test func4-6.1.$i.1 [subst { |
| 685 | SELECT tointeger(x'[string repeat 01 $i]'); |
| 686 | }] {{}} |
| 687 | ifcapable floatingpoint { |
| 688 | do_execsql_test func4-6.1.$i.2 [subst { |
| 689 | SELECT toreal(x'[string repeat 01 $i]'); |
| 690 | }] {{}} |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | do_execsql_test func4-6.2.1 { |
| 695 | SELECT tointeger(x'0102030405060708'); |
| 696 | } {578437695752307201} |
| 697 | do_execsql_test func4-6.2.2 { |
| 698 | SELECT tointeger(x'0807060504030201'); |
| 699 | } {72623859790382856} |
| 700 | |
| 701 | ifcapable floatingpoint { |
| 702 | do_execsql_test func4-6.3.1 { |
| 703 | SELECT toreal(x'ffefffffffffffff'); |
| 704 | } {-1.7976931348623157e+308} |
| 705 | do_execsql_test func4-6.3.2 { |
| 706 | SELECT toreal(x'8010000000000000'); |
| 707 | } {-2.2250738585072014e-308} |
| 708 | do_execsql_test func4-6.3.3 { |
| 709 | SELECT toreal(x'c000000000000000'); |
| 710 | } {-2.0} |
| 711 | do_execsql_test func4-6.3.4 { |
| 712 | SELECT toreal(x'bff0000000000000'); |
| 713 | } {-1.0} |
| 714 | do_execsql_test func4-6.3.5 { |
| 715 | SELECT toreal(x'8000000000000000'); |
| 716 | } {-0.0} |
| 717 | do_execsql_test func4-6.3.6 { |
| 718 | SELECT toreal(x'0000000000000000'); |
| 719 | } {0.0} |
| 720 | do_execsql_test func4-6.3.7 { |
| 721 | SELECT toreal(x'3ff0000000000000'); |
| 722 | } {1.0} |
| 723 | do_execsql_test func4-6.3.8 { |
| 724 | SELECT toreal(x'4000000000000000'); |
| 725 | } {2.0} |
| 726 | do_execsql_test func4-6.3.9 { |
| 727 | SELECT toreal(x'0010000000000000'); |
| 728 | } {2.2250738585072014e-308} |
| 729 | do_execsql_test func4-6.3.10 { |
| 730 | SELECT toreal(x'7fefffffffffffff'); |
| 731 | } {1.7976931348623157e+308} |
| 732 | do_execsql_test func4-6.3.11 { |
| 733 | SELECT toreal(x'8000000000000001'); |
| 734 | } {-5e-324} |
| 735 | do_execsql_test func4-6.3.12 { |
| 736 | SELECT toreal(x'800fffffffffffff'); |
| 737 | } {-2.225073858507201e-308} |
| 738 | do_execsql_test func4-6.3.13 { |
| 739 | SELECT toreal(x'0000000000000001'); |
| 740 | } {5e-324} |
| 741 | do_execsql_test func4-6.3.14 { |
| 742 | SELECT toreal(x'000fffffffffffff'); |
| 743 | } {2.225073858507201e-308} |
| 744 | do_execsql_test func4-6.3.15 { |
| 745 | SELECT toreal(x'fff0000000000000'); |
| 746 | } {-Inf} |
| 747 | do_execsql_test func4-6.3.16 { |
| 748 | SELECT toreal(x'7ff0000000000000'); |
| 749 | } {Inf} |
| 750 | do_execsql_test func4-6.3.17 { |
| 751 | SELECT toreal(x'fff8000000000000'); |
| 752 | } {{}} |
| 753 | do_execsql_test func4-6.3.18 { |
| 754 | SELECT toreal(x'fff0000000000001'); |
| 755 | } {{}} |
| 756 | do_execsql_test func4-6.3.19 { |
| 757 | SELECT toreal(x'fff7ffffffffffff'); |
| 758 | } {{}} |
| 759 | do_execsql_test func4-6.3.20 { |
| 760 | SELECT toreal(x'7ff0000000000001'); |
| 761 | } {{}} |
| 762 | do_execsql_test func4-6.3.21 { |
| 763 | SELECT toreal(x'7ff7ffffffffffff'); |
| 764 | } {{}} |
| 765 | do_execsql_test func4-6.3.22 { |
| 766 | SELECT toreal(x'fff8000000000001'); |
| 767 | } {{}} |
| 768 | do_execsql_test func4-6.3.23 { |
| 769 | SELECT toreal(x'ffffffffffffffff'); |
| 770 | } {{}} |
| 771 | do_execsql_test func4-6.3.24 { |
| 772 | SELECT toreal(x'7ff8000000000000'); |
| 773 | } {{}} |
| 774 | do_execsql_test func4-6.3.25 { |
| 775 | SELECT toreal(x'7fffffffffffffff'); |
| 776 | } {{}} |
| 777 | } |
| 778 | |
| 779 | set tcl_precision $saved_tcl_precision |
| 780 | unset saved_tcl_precision |
| 781 | finish_test |