From: drh Date: Fri, 21 Jun 2013 19:29:33 +0000 (+0000) Subject: Merge in the latest changes from trunk. Simplify the implementation of the X-Git-Tag: version-3.8.1~11^2~18^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0057a74675bea6cf863ea498e5e5c9e1428b41cb;p=thirdparty%2Fsqlite.git Merge in the latest changes from trunk. Simplify the implementation of the tointeger() and toreal() functions. Fix test cases and put unambiguous labels on all testcase names. FossilOrigin-Name: 9b837b0508fbfb395f0a0d8e4bd127730c80ffc5 --- 0057a74675bea6cf863ea498e5e5c9e1428b41cb diff --cc manifest index 45330aae4a,cb36277b86..0c437e55e8 --- a/manifest +++ b/manifest @@@ -1,5 -1,5 +1,5 @@@ - C Merge\supdates\sfrom\strunk. - D 2013-06-21T18:32:11.955 -C Remove\san\sunused\sfunction\sdeclaration\sfrom\sthe\sFTS3\ssource\scode. -D 2013-06-21T18:36:44.416 ++C Merge\sin\sthe\slatest\schanges\sfrom\strunk.\s\sSimplify\sthe\simplementation\sof\sthe\ntointeger()\sand\storeal()\sfunctions.\s\sFix\stest\scases\sand\sput\sunambiguous\nlabels\son\sall\stestcase\snames. ++D 2013-06-21T19:29:33.743 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@@ -174,7 -174,7 +174,7 @@@ F src/delete.c aeabdabeeeaa0584127f291b F src/expr.c ac9d259eea3123faa05fabe6dd8717696aca72b1 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e16942bd5c8a868ac53287886464a5ed0e72b179 - F src/func.c 771ceaa9b3e8e3a4ee55839b03e5f99ddf300c1d -F src/func.c 5c50c1ea31fd864b0fe921fe1a8d4c55acd609ef ++F src/func.c 835168be942c8c18a6c6b3b78462bc378d25c7b4 F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759 F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4 F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22 @@@ -555,7 -556,6 +556,7 @@@ F test/full.test 6b3c8fb43c6beab6b95438 F test/func.test b0fc34fdc36897769651975a2b0a606312753643 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 001021e5b88bd02a3b365a5c5fd8f6f49d39744a - F test/func4.test cf09a622b456d3e2f33a3fb1a2be8eec7a8e35e2 ++F test/func4.test 0e2d0e295bc9093676c6e34ff6e33e2541417985 F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74 F test/fuzz.test 77fd50afc12847af50fcf1941679d90adebadde6 F test/fuzz2.test 207d0f9d06db3eaf47a6b7bfc835b8e2fc397167 @@@ -1094,7 -1094,7 +1095,7 @@@ F tool/vdbe-compress.tcl f12c884766bd14 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac - P 6fbad957259eb8c15eaf7e5657240ae24aaf343e b674462243138fcee192ef05d434665e30c681c4 - R 612ff5a12d31b338ed757ecbce2de7e8 - U mistachkin - Z d50d5563e695cb5fa48c05a0f64143b0 -P 361084e1eb281e985568d19fe217263be92be31d -R 0d6c636b8cfd628682ea33e027cb07be ++P fa2a91e6c631864846484d13cffdc51856953cd1 096ae1d8f9a08f92daedece6b0615f4d22b05023 ++R 6ba2737cc75280e9c7b2e803134db342 + U drh -Z 55b5720fc386809651d148c0a8415781 ++Z 3e127bc98d3edb650de7203bad06de46 diff --cc manifest.uuid index 5520fa8444,773d5a6db0..d51919ca22 --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - fa2a91e6c631864846484d13cffdc51856953cd1 -096ae1d8f9a08f92daedece6b0615f4d22b05023 ++9b837b0508fbfb395f0a0d8e4bd127730c80ffc5 diff --cc src/func.c index 9bee8576b1,49f6c892be..995f104260 --- a/src/func.c +++ b/src/func.c @@@ -968,134 -965,6 +965,98 @@@ static void quoteFunc(sqlite3_context * } } +/* - ** EXPERIMENTAL - This is not an official function. The interface may - ** change. This function may disappear. Do not write code that depends - ** on this function. - ** - ** Implementation of the tointeger() function. This function takes a - ** single argument. If the argument is an integer or is a double that - ** can be losslessly converted to an integer, the return value is the - ** same as the argument. If the argument is a double that cannot be - ** losslessly represented as an integer, the return value is NULL. - ** If the argument is NULL, the return value is NULL. Otherwise, an - ** attempt is made to convert the argument to an integer. If the - ** conversion is successful, the integer value is returned; otherwise, - ** NULL is returned. ++** tointeger(X): If X is any value (integer, double, or string) that can ++** be losslessly converted into an integer, then make the conversion and ++** return the result. Otherwise, return NULL. +*/ +static void tointegerFunc( + sqlite3_context *context, + 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 - { ++ case SQLITE_FLOAT: { + 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; ++ i64 iVal = (i64)rVal; ++ if( !sqlite3IsNaN(rVal) && rVal==(double)iVal ){ ++ sqlite3_result_int64(context, iVal); + } - 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]); + if( zStr ){ + int nStr = sqlite3_value_bytes(argv[0]); + if( nStr ){ + i64 iVal; + if( !sqlite3Atoi64(zStr, &iVal, nStr, SQLITE_UTF8) ){ + sqlite3_result_int64(context, iVal); - return; + } + } + } - sqlite3_result_null(context); + break; + } + default: { + assert( sqlite3_value_type(argv[0])==SQLITE_NULL ); - sqlite3_result_null(context); + break; + } + } +} + +/* - ** EXPERIMENTAL - This is not an official function. The interface may - ** change. This function may disappear. Do not write code that depends - ** on this function. - ** - ** Implementation of the toreal() function. This function takes a - ** single argument. If the argument is a double or is an integer that - ** can be losslessly converted to a double, the return value is the - ** same as the argument. If the argument is an integer that cannot be - ** losslessly represented as a double, the return value is NULL. - ** If the argument is NULL, the return value is NULL. Otherwise, an - ** attempt is made to convert the argument to a double. If the - ** conversion is successful, the double value is returned; otherwise, - ** NULL is returned. ++** toreal(X): If X can be losslessly converted into a real number, then ++** do so and return that real number. Otherwise return NULL. +*/ - #ifndef SQLITE_OMIT_FLOATING_POINT +static void torealFunc( + 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 ){ + double rVal; + if( sqlite3AtoF(zStr, &rVal, nStr, SQLITE_UTF8) ){ + sqlite3_result_double(context, rVal); + return; + } + } + } - sqlite3_result_null(context); + break; + } + default: { + assert( sqlite3_value_type(argv[0])==SQLITE_NULL ); - sqlite3_result_null(context); + break; + } + } +} - #endif + /* ** The unicode() function. Return the integer unicode code-point value ** for the first character of the input string. @@@ -1804,10 -1673,6 +1765,8 @@@ void sqlite3RegisterGlobalFunctions(voi FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ FUNCTION(quote, 1, 0, 0, quoteFunc ), + FUNCTION(tointeger, 1, 0, 0, tointegerFunc ), - #ifndef SQLITE_OMIT_FLOATING_POINT + FUNCTION(toreal, 1, 0, 0, torealFunc ), - #endif FUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid), FUNCTION(changes, 0, 0, 0, changes ), FUNCTION(total_changes, 0, 0, 0, total_changes ), diff --cc test/func4.test index 44a275a486,0000000000..b40cca448e mode 100644,000000..100644 --- a/test/func4.test +++ b/test/func4.test @@@ -1,482 -1,0 +1,481 @@@ +# 2013 March 10 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the tointeger() and toreal() +# functions. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + - set i 0 - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.1 { + SELECT tointeger(NULL); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.2 { + SELECT tointeger(''); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.3 { + SELECT tointeger(' '); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.4 { + SELECT tointeger('1234'); +} {1234} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.5 { + SELECT tointeger(' 1234'); +} {1234} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.6 { + SELECT tointeger('bad'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.7 { + SELECT tointeger('0xBAD'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.8 { + SELECT tointeger('123BAD'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.9 { + SELECT tointeger('0x123BAD'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.10 { + SELECT tointeger('123NO'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.11 { + SELECT tointeger('0x123NO'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.12 { + SELECT tointeger('-0x1'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.13 { + SELECT tointeger('-0x0'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.14 { + SELECT tointeger('0x0'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.15 { + SELECT tointeger('0x1'); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.16 { + SELECT tointeger(-1); +} {-1} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.17 { + SELECT tointeger(-0); +} {0} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.18 { + SELECT tointeger(0); +} {0} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.19 { + SELECT tointeger(1); +} {1} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.20 { + SELECT tointeger(-1.79769313486232e308 - 1); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.21 { + SELECT tointeger(-1.79769313486232e308); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.22 { + SELECT tointeger(-1.79769313486232e308 + 1); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.23 { + SELECT tointeger(-9223372036854775808 - 1); +} {-9223372036854775808} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.24 { + SELECT tointeger(-9223372036854775808); +} {-9223372036854775808} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.25 { + SELECT tointeger(-9223372036854775808 + 1); +} {-9223372036854775807} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.26 { + SELECT tointeger(-2147483648 - 1); +} {-2147483649} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.27 { + SELECT tointeger(-2147483648); +} {-2147483648} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.28 { + SELECT tointeger(-2147483648 + 1); +} {-2147483647} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.29 { + SELECT tointeger(2147483647 - 1); +} {2147483646} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.30 { + SELECT tointeger(2147483647); +} {2147483647} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.31 { + SELECT tointeger(2147483647 + 1); +} {2147483648} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.32 { + SELECT tointeger(9223372036854775807 - 1); +} {9223372036854775806} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.33 { + SELECT tointeger(9223372036854775807); +} {9223372036854775807} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.34 { + SELECT tointeger(9223372036854775807 + 1); - } {-9223372036854775808} - do_execsql_test func4-1.[incr i] { ++} {{}} ++do_execsql_test func4-1.35 { + SELECT tointeger(1.79769313486232e308 - 1); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.36 { + SELECT tointeger(1.79769313486232e308); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.37 { + SELECT tointeger(1.79769313486232e308 + 1); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.38 { + SELECT tointeger(4503599627370496 - 1); +} {4503599627370495} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.39 { + SELECT tointeger(4503599627370496); +} {4503599627370496} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.40 { + SELECT tointeger(4503599627370496 + 1); +} {4503599627370497} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.41 { + SELECT tointeger(9007199254740992 - 1); +} {9007199254740991} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.42 { + SELECT tointeger(9007199254740992); +} {9007199254740992} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.43 { + SELECT tointeger(9007199254740992 + 1); +} {9007199254740993} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.44 { + SELECT tointeger(9223372036854775808 - 1); - } {-9223372036854775808} - do_execsql_test func4-1.[incr i] { ++} {{}} ++do_execsql_test func4-1.45 { + SELECT tointeger(9223372036854775808); - } {-9223372036854775808} - do_execsql_test func4-1.[incr i] { ++} {{}} ++do_execsql_test func4-1.46 { + SELECT tointeger(9223372036854775808 + 1); - } {-9223372036854775808} - do_execsql_test func4-1.[incr i] { ++} {{}} ++do_execsql_test func4-1.47 { + SELECT tointeger(18446744073709551616 - 1); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.48 { + SELECT tointeger(18446744073709551616); +} {{}} - do_execsql_test func4-1.[incr i] { ++do_execsql_test func4-1.49 { + SELECT tointeger(18446744073709551616 + 1); +} {{}} + +ifcapable floatingpoint { + set i 0 - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.1 { + SELECT toreal(NULL); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.2 { + SELECT toreal(''); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.3 { + SELECT toreal(' '); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.4 { + SELECT toreal('1234'); + } {1234.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.5 { + SELECT toreal(' 1234'); + } {1234.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.6 { + SELECT toreal('bad'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.7 { + SELECT toreal('0xBAD'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.8 { + SELECT toreal('123BAD'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.9 { + SELECT toreal('0x123BAD'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.10 { + SELECT toreal('123NO'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.11 { + SELECT toreal('0x123NO'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.12 { + SELECT toreal('-0x1'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.13 { + SELECT toreal('-0x0'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.14 { + SELECT toreal('0x0'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.15 { + SELECT toreal('0x1'); + } {{}} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.16 { + SELECT toreal(-1); + } {-1.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.17 { + SELECT toreal(-0); + } {0.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.18 { + SELECT toreal(0); + } {0.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.19 { + SELECT toreal(1); + } {1.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.20 { + SELECT toreal(-1.79769313486232e308 - 1); + } {-Inf} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.21 { + SELECT toreal(-1.79769313486232e308); + } {-Inf} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.22 { + SELECT toreal(-1.79769313486232e308 + 1); + } {-Inf} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.23 { + SELECT toreal(-9223372036854775808 - 1); + } {-9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.24 { + SELECT toreal(-9223372036854775808); + } {-9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.25 { + SELECT toreal(-9223372036854775808 + 1); + } {-9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.26 { + SELECT toreal(-2147483648 - 1); + } {-2147483649.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.27 { + SELECT toreal(-2147483648); + } {-2147483648.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.28 { + SELECT toreal(-2147483648 + 1); + } {-2147483647.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.29 { + SELECT toreal(2147483647 - 1); + } {2147483646.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.30 { + SELECT toreal(2147483647); + } {2147483647.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.31 { + SELECT toreal(2147483647 + 1); + } {2147483648.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.32 { + SELECT toreal(9223372036854775807 - 1); + } {9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.33 { + SELECT toreal(9223372036854775807); + } {9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.34 { + SELECT toreal(9223372036854775807 + 1); + } {9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.35 { + SELECT toreal(1.79769313486232e308 - 1); + } {Inf} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.36 { + SELECT toreal(1.79769313486232e308); + } {Inf} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.37 { + SELECT toreal(1.79769313486232e308 + 1); + } {Inf} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.38 { + SELECT toreal(4503599627370496 - 1); + } {4503599627370500.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.39 { + SELECT toreal(4503599627370496); + } {4503599627370500.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.40 { + SELECT toreal(4503599627370496 + 1); + } {4503599627370500.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.41 { + SELECT toreal(9007199254740992 - 1); + } {9007199254740990.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.42 { + SELECT toreal(9007199254740992); + } {9007199254740990.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.43 { + SELECT toreal(9007199254740992 + 1); + } {9007199254740990.0} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.44 { + SELECT toreal(9223372036854775808 - 1); + } {9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.45 { + SELECT toreal(9223372036854775808); + } {9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.46 { + SELECT toreal(9223372036854775808 + 1); + } {9.22337203685478e+18} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.47 { + SELECT toreal(18446744073709551616 - 1); + } {1.84467440737096e+19} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.48 { + SELECT toreal(18446744073709551616); + } {1.84467440737096e+19} - do_execsql_test func4-2.[incr i] { ++ do_execsql_test func4-2.49 { + SELECT toreal(18446744073709551616 + 1); + } {1.84467440737096e+19} +} + +ifcapable check { + set i 0 - do_execsql_test func4-3.[incr i] { ++ do_execsql_test func4-3.1 { + CREATE TABLE t1( + x INTEGER CHECK(tointeger(x) IS NOT NULL AND x = CAST(x AS INTEGER)) + ); + } {} - do_test func4-3.[incr i] { ++ do_test func4-3.2 { + catchsql { + INSERT INTO t1 (x) VALUES (NULL); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.3 { + catchsql { + INSERT INTO t1 (x) VALUES (NULL); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.4 { + catchsql { + INSERT INTO t1 (x) VALUES (''); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.5 { + catchsql { + INSERT INTO t1 (x) VALUES ('bad'); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.6 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234bad'); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.7 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.56bad'); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.8 { + catchsql { + INSERT INTO t1 (x) VALUES (1234); + } + } {0 {}} - do_test func4-3.[incr i] { ++ do_test func4-3.9 { + catchsql { + INSERT INTO t1 (x) VALUES (1234.56); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.10 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234'); + } + } {0 {}} - do_test func4-3.[incr i] { ++ do_test func4-3.11 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.56'); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.12 { + catchsql { + INSERT INTO t1 (x) VALUES (ZEROBLOB(4)); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.13 { + catchsql { + INSERT INTO t1 (x) VALUES (X''); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.14 { + catchsql { + INSERT INTO t1 (x) VALUES (X'1234'); + } + } {1 {constraint failed}} - do_test func4-3.[incr i] { ++ do_test func4-3.15 { + catchsql { + INSERT INTO t1 (x) VALUES (X'12345678'); + } + } {1 {constraint failed}} - do_execsql_test func4-3.[incr i] { ++ do_execsql_test func4-3.16 { + SELECT x FROM t1 ORDER BY x; + } {1234 1234} + + ifcapable floatingpoint { + set i 0 - do_execsql_test func4-4.[incr i] { ++ do_execsql_test func4-4.1 { + CREATE TABLE t2( + x REAL CHECK(toreal(x) IS NOT NULL) + ); + } {} - do_test func4-4.[incr i] { ++ do_test func4-4.2 { + catchsql { + INSERT INTO t2 (x) VALUES (NULL); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.3 { + catchsql { + INSERT INTO t2 (x) VALUES (NULL); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.4 { + catchsql { + INSERT INTO t2 (x) VALUES (''); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.5 { + catchsql { + INSERT INTO t2 (x) VALUES ('bad'); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.6 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234bad'); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.7 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234.56bad'); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.8 { + catchsql { + INSERT INTO t2 (x) VALUES (1234); + } + } {0 {}} - do_test func4-4.[incr i] { ++ do_test func4-4.9 { + catchsql { + INSERT INTO t2 (x) VALUES (1234.56); + } + } {0 {}} - do_test func4-4.[incr i] { ++ do_test func4-4.10 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234'); + } + } {0 {}} - do_test func4-4.[incr i] { ++ do_test func4-4.11 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234.56'); + } + } {0 {}} - do_test func4-4.[incr i] { ++ do_test func4-4.12 { + catchsql { + INSERT INTO t2 (x) VALUES (ZEROBLOB(4)); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.13 { + catchsql { + INSERT INTO t2 (x) VALUES (X''); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.14 { + catchsql { + INSERT INTO t2 (x) VALUES (X'1234'); + } + } {1 {constraint failed}} - do_test func4-4.[incr i] { ++ do_test func4-4.15 { + catchsql { + INSERT INTO t2 (x) VALUES (X'12345678'); + } + } {1 {constraint failed}} - do_execsql_test func4-4.[incr i] { ++ do_execsql_test func4-4.16 { + SELECT x FROM t2 ORDER BY x; + } {1234.0 1234.0 1234.56 1234.56} + } +} + +finish_test