Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Increase strictness of the new experimental functions and add more tests. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | toTypeFuncs |
Files: | files | file ages | folders |
SHA1: |
05c4463ec5f36dde50f6eb116624dc40 |
User & Date: | mistachkin 2013-03-12 09:07:25.371 |
Context
2013-03-13
| ||
06:48 | Rename the experimental todouble() function to toreal(), update comments. (check-in: 12c318ef1b user: mistachkin tags: toTypeFuncs) | |
2013-03-12
| ||
09:07 | Increase strictness of the new experimental functions and add more tests. (check-in: 05c4463ec5 user: mistachkin tags: toTypeFuncs) | |
2013-03-11
| ||
06:24 | Add more tests. (check-in: f9468e334d user: mistachkin tags: toTypeFuncs) | |
Changes
Changes to src/func.c.
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. */ #include "sqliteInt.h" #include <stdlib.h> #include <assert.h> #include "vdbeInt.h" /* ** Return the collating function associated with a function. */ static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){ return context->pColl; | > > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. */ #include "sqliteInt.h" #include <stdlib.h> #include <assert.h> #ifndef SQLITE_OMIT_FLOATING_POINT # include <math.h> #endif #include "vdbeInt.h" /* ** Return the collating function associated with a function. */ static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){ return context->pColl; |
︙ | ︙ | |||
982 983 984 985 986 987 988 989 990 991 992 993 994 995 | int argc, sqlite3_value **argv ){ assert( argc==1 ); UNUSED_PARAMETER(argc); switch( sqlite3_value_type(argv[0]) ){ case SQLITE_FLOAT: case SQLITE_INTEGER: { sqlite3_result_int64(context, sqlite3_value_int64(argv[0])); break; } case SQLITE_BLOB: case SQLITE_TEXT: { const unsigned char *zStr = sqlite3_value_text(argv[0]); | > > > > > > > > > > > > > | 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | int argc, sqlite3_value **argv ){ assert( argc==1 ); UNUSED_PARAMETER(argc); switch( sqlite3_value_type(argv[0]) ){ case SQLITE_FLOAT: #ifndef SQLITE_OMIT_FLOATING_POINT { double rVal = sqlite3_value_double(argv[0]); double rIntVal = 0.0; if( !sqlite3IsNaN(rVal) && modf(rVal, &rIntVal)==0.0 && rIntVal>=SMALLEST_INT64 && rIntVal<=LARGEST_INT64 ){ sqlite3_result_int64(context, (i64)rIntVal); return; } sqlite3_result_null(context); break; } #endif case SQLITE_INTEGER: { sqlite3_result_int64(context, sqlite3_value_int64(argv[0])); break; } case SQLITE_BLOB: case SQLITE_TEXT: { const unsigned char *zStr = sqlite3_value_text(argv[0]); |
︙ | ︙ | |||
1034 1035 1036 1037 1038 1039 1040 | sqlite3_context *context, int argc, sqlite3_value **argv ){ assert( argc==1 ); UNUSED_PARAMETER(argc); switch( sqlite3_value_type(argv[0]) ){ | | > > > > > > | > > > | 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 | sqlite3_context *context, int argc, sqlite3_value **argv ){ assert( argc==1 ); UNUSED_PARAMETER(argc); switch( sqlite3_value_type(argv[0]) ){ case SQLITE_FLOAT: { sqlite3_result_double(context, sqlite3_value_double(argv[0])); break; } case SQLITE_INTEGER: { i64 iVal = sqlite3_value_int64(argv[0]); double rVal = (double)iVal; if( iVal==rVal ){ sqlite3_result_double(context, rVal); return; } sqlite3_result_null(context); break; } case SQLITE_BLOB: case SQLITE_TEXT: { const unsigned char *zStr = sqlite3_value_text(argv[0]); if( zStr ){ int nStr = sqlite3_value_bytes(argv[0]); if( nStr ){ |
︙ | ︙ |
Changes to src/sqliteInt.h.
︙ | ︙ | |||
343 344 345 346 347 348 349 350 351 352 353 354 355 356 | # ifndef SQLITE_BIG_DBL # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) # endif # define SQLITE_OMIT_DATETIME_FUNCS 1 # define SQLITE_OMIT_TRACE 1 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT # undef SQLITE_HAVE_ISNAN #endif #ifndef SQLITE_BIG_DBL # define SQLITE_BIG_DBL (1e99) #endif /* ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 | > > | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | # ifndef SQLITE_BIG_DBL # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) # endif # define SQLITE_OMIT_DATETIME_FUNCS 1 # define SQLITE_OMIT_TRACE 1 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT # undef SQLITE_HAVE_ISNAN #else # include <math.h> #endif #ifndef SQLITE_BIG_DBL # define SQLITE_BIG_DBL (1e99) #endif /* ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 |
︙ | ︙ |
Changes to test/func4.test.
︙ | ︙ | |||
71 72 73 74 75 76 77 | SELECT tointeger(0); } {0} do_execsql_test func4-1.[incr i] { SELECT tointeger(1); } {1} do_execsql_test func4-1.[incr i] { SELECT tointeger(-1.79769313486232e308 - 1); | | | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | SELECT tointeger(0); } {0} do_execsql_test func4-1.[incr i] { SELECT tointeger(1); } {1} do_execsql_test func4-1.[incr i] { SELECT tointeger(-1.79769313486232e308 - 1); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(-1.79769313486232e308); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(-1.79769313486232e308 + 1); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(-9223372036854775808 - 1); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { SELECT tointeger(-9223372036854775808); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { |
︙ | ︙ | |||
116 117 118 119 120 121 122 | SELECT tointeger(9223372036854775807); } {9223372036854775807} do_execsql_test func4-1.[incr i] { SELECT tointeger(9223372036854775807 + 1); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { SELECT tointeger(1.79769313486232e308 - 1); | | | | | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | SELECT tointeger(9223372036854775807); } {9223372036854775807} do_execsql_test func4-1.[incr i] { SELECT tointeger(9223372036854775807 + 1); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { SELECT tointeger(1.79769313486232e308 - 1); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(1.79769313486232e308); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(1.79769313486232e308 + 1); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(4503599627370496 - 1); } {4503599627370495} do_execsql_test func4-1.[incr i] { SELECT tointeger(4503599627370496); } {4503599627370496} do_execsql_test func4-1.[incr i] { |
︙ | ︙ | |||
152 153 154 155 156 157 158 | SELECT tointeger(9223372036854775808); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { SELECT tointeger(9223372036854775808 + 1); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { SELECT tointeger(18446744073709551616 - 1); | | | | | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | SELECT tointeger(9223372036854775808); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { SELECT tointeger(9223372036854775808 + 1); } {-9223372036854775808} do_execsql_test func4-1.[incr i] { SELECT tointeger(18446744073709551616 - 1); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(18446744073709551616); } {{}} do_execsql_test func4-1.[incr i] { SELECT tointeger(18446744073709551616 + 1); } {{}} ifcapable floatingpoint { set i 0 do_execsql_test func4-2.[incr i] { SELECT todouble(NULL); } {{}} do_execsql_test func4-2.[incr i] { |
︙ | ︙ | |||
344 345 346 347 348 349 350 351 352 353 354 355 356 357 | } {1 {constraint failed}} do_test func4-3.[incr i] { catchsql { INSERT INTO t1 (x) VALUES ('1234bad'); } } {1 {constraint failed}} do_test func4-3.[incr i] { catchsql { INSERT INTO t1 (x) VALUES (1234); } } {0 {}} do_test func4-3.[incr i] { catchsql { INSERT INTO t1 (x) VALUES (1234.56); | > > > > > | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | } {1 {constraint failed}} do_test func4-3.[incr i] { catchsql { INSERT INTO t1 (x) VALUES ('1234bad'); } } {1 {constraint failed}} do_test func4-3.[incr i] { catchsql { INSERT INTO t1 (x) VALUES ('1234.56bad'); } } {1 {constraint failed}} do_test func4-3.[incr i] { catchsql { INSERT INTO t1 (x) VALUES (1234); } } {0 {}} do_test func4-3.[incr i] { catchsql { INSERT INTO t1 (x) VALUES (1234.56); |
︙ | ︙ | |||
386 387 388 389 390 391 392 | catchsql { INSERT INTO t1 (x) VALUES (X'12345678'); } } {1 {constraint failed}} do_execsql_test func4-3.[incr i] { SELECT x FROM t1 ORDER BY x; } {1234 1234} | | > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | catchsql { INSERT INTO t1 (x) VALUES (X'12345678'); } } {1 {constraint failed}} do_execsql_test func4-3.[incr i] { SELECT x FROM t1 ORDER BY x; } {1234 1234} ifcapable floatingpoint { set i 0 do_execsql_test func4-4.[incr i] { CREATE TABLE t2( x REAL CHECK(todouble(x) IS NOT NULL) ); } {} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (NULL); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (NULL); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (''); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES ('bad'); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES ('1234bad'); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES ('1234.56bad'); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (1234); } } {0 {}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (1234.56); } } {0 {}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES ('1234'); } } {0 {}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES ('1234.56'); } } {0 {}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (ZEROBLOB(4)); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (X''); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (X'1234'); } } {1 {constraint failed}} do_test func4-4.[incr i] { catchsql { INSERT INTO t2 (x) VALUES (X'12345678'); } } {1 {constraint failed}} do_execsql_test func4-4.[incr i] { SELECT x FROM t2 ORDER BY x; } {1234.0 1234.0 1234.56 1234.56} } } finish_test |