Add implementations for the toInteger() and toReal() SQL functions.

FossilOrigin-Name: a0f7cbc068416cf55b86056f2ce7ee505c6cc3ea
This commit is contained in:
drh 2013-10-14 19:35:33 +00:00
commit 4398c9524f
5 changed files with 931 additions and 10 deletions

View File

@ -32,6 +32,13 @@ USE_ICU = 0
USE_CRT_DLL = 0
!ENDIF
# Set this non-0 to generate assembly code listings for the source code
# files.
#
!IFNDEF USE_LISTINGS
USE_LISTINGS = 0
!ENDIF
# Set this non-0 to attempt setting the native compiler automatically
# for cross-compiling the command line tools needed during the compilation
# process.
@ -188,6 +195,13 @@ NSDKLIBPATH = $(NSDKLIBPATH:\\=\)
#
BCC = $(NCC) -W3
# Check if assembly code listings should be generated for the source
# code files to be compiled.
#
!IF $(USE_LISTINGS)!=0
BCC = $(BCC) -FAcs
!ENDIF
# Check if the native library paths should be used when compiling
# the command line tools used during the compilation process. If
# so, set the necessary macro now.
@ -203,6 +217,13 @@ NLTLIBPATHS = "/LIBPATH:$(NCRTLIBPATH)" "/LIBPATH:$(NSDKLIBPATH)"
TCC = $(CC) -W3 -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src -fp:precise
RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src
# Check if assembly code listings should be generated for the source
# code files to be compiled.
#
!IF $(USE_LISTINGS)!=0
TCC = $(TCC) -FAcs
!ENDIF
# When compiling the library for use in the WinRT environment,
# the following compile-time options must be used as well to
# disable use of Win32 APIs that are not available and to enable
@ -1312,7 +1333,7 @@ sqlite3_analyzer.exe: sqlite3_analyzer.c $(LIBRESOBJS)
clean:
del /Q *.lo *.ilk *.lib *.obj *.pdb sqlite3.exe libsqlite3.lib
del /Q *.da *.bb *.bbg gmon.out
del /Q *.cod *.da *.bb *.bbg gmon.out
del /Q sqlite3.h opcodes.c opcodes.h
del /Q lemon.exe lempar.c parse.*
del /Q mkkeywordhash.exe keywordhash.h

View File

@ -1,9 +1,9 @@
C Fix\sfor\sbuilding\swith\sSQLITE_OMIT_FOREIGN_KEY.
D 2013-10-14T15:41:39.130
C Add\simplementations\sfor\sthe\stoInteger()\sand\stoReal()\sSQL\sfunctions.
D 2013-10-14T19:35:33.432
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in e2d28ec95bd17ab4f3b6ee40b7102e9d7a0857b9
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F Makefile.msc a08b5f4ed4f760bae4eae4e723371487c5378983
F Makefile.msc d72be28ba13ec3986ac5791a6549036a84dc5903
F Makefile.vxworks db21ed42a01d5740e656b16f92cb5d8d5e5dd315
F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6
F VERSION a8d1f6839521130dc73c5408cdd24bcfd791df34
@ -176,7 +176,7 @@ F src/delete.c 45788c5e48734f2af4acd75a876466e5b9838e34
F src/expr.c e7338ccffdc391c53ba2d51c5eb6a2f5299e040e
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 5dc10cbaa355753903cd2a64da040f948997ebf8
F src/func.c 2c47b65e6e00e3e9374942f28254faf8adafe398
F src/func.c 5fb4103cc5fd2920696e0a263e6a56a2844ab35d
F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759
F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
@ -569,6 +569,7 @@ F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
F test/func.test c7e80a44eebac8604397eb2ad83d0d5d9d541237
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
F test/func3.test dbccee9133cfef1473c59ec07b5f0262b9d72f9a
F test/func4.test 142490571f2e7ee6c3c5a65f24cad3f8342c02a2
F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74
F test/fuzz.test 77fd50afc12847af50fcf1941679d90adebadde6
F test/fuzz2.test 207d0f9d06db3eaf47a6b7bfc835b8e2fc397167
@ -1123,7 +1124,8 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P 208b259ad73b51e7df163fee3d7ed2bd79767597
R d404755b57382c433b54a7ffeebb1595
U dan
Z 9d63388bf55fa4140187d4341a01752c
P b8b5f6c8f646989bc62bb59416de9bca003a5896 a88b5be01e68b26267ff6eb05e931ef2e7fc9f99
R fc9823e555e748e8dd749e50020ff907
T +closed a88b5be01e68b26267ff6eb05e931ef2e7fc9f99
U drh
Z f917a0a33a0846e0a4d8398bd8607f59

View File

@ -1 +1 @@
b8b5f6c8f646989bc62bb59416de9bca003a5896
a0f7cbc068416cf55b86056f2ce7ee505c6cc3ea

View File

@ -965,6 +965,145 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
}
}
/*
** tointeger(X): If X is any value (integer, double, blob, 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: {
double rVal = sqlite3_value_double(argv[0]);
i64 iVal = (i64)rVal;
if( rVal==(double)iVal ){
sqlite3_result_int64(context, iVal);
}
break;
}
case SQLITE_INTEGER: {
sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
break;
}
case SQLITE_BLOB: {
const unsigned char *zBlob = sqlite3_value_blob(argv[0]);
if( zBlob ){
int nBlob = sqlite3_value_bytes(argv[0]);
if( nBlob==sizeof(i64) ){
i64 iVal;
if( SQLITE_BIGENDIAN ){
int i;
unsigned char *zBlobRev = contextMalloc(context, nBlob);
if( !zBlobRev ) break;
for(i=0; i<nBlob; i++) zBlobRev[i] = zBlob[nBlob-1-i];
memcpy(&iVal, zBlobRev, sizeof(i64));
sqlite3_free(zBlobRev);
}else{
memcpy(&iVal, zBlob, sizeof(i64));
}
sqlite3_result_int64(context, iVal);
}
}
break;
}
case SQLITE_TEXT: {
const unsigned char *zStr = sqlite3_value_text(argv[0]);
if( zStr ){
int nStr = sqlite3_value_bytes(argv[0]);
if( nStr && !sqlite3Isspace(zStr[0]) ){
i64 iVal;
if( !sqlite3Atoi64((const char*)zStr, &iVal, nStr, SQLITE_UTF8) ){
sqlite3_result_int64(context, iVal);
}
}
}
break;
}
default: {
assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
break;
}
}
}
/*
** toreal(X): If X is any value (integer, double, blob, or string) that can
** be losslessly converted into a real number, then do so and return that
** real number. Otherwise return NULL.
*/
#if defined(_MSC_VER)
#pragma optimize("", off)
#endif
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==(i64)rVal ){
sqlite3_result_double(context, rVal);
}
break;
}
case SQLITE_BLOB: {
const unsigned char *zBlob = sqlite3_value_blob(argv[0]);
if( zBlob ){
int nBlob = sqlite3_value_bytes(argv[0]);
if( nBlob==sizeof(double) ){
double rVal;
if( SQLITE_LITTLEENDIAN ){
int i;
unsigned char *zBlobRev = contextMalloc(context, nBlob);
if( !zBlobRev ) break;
for(i=0; i<nBlob; i++) zBlobRev[i] = zBlob[nBlob-1-i];
memcpy(&rVal, zBlobRev, sizeof(double));
sqlite3_free(zBlobRev);
}else{
memcpy(&rVal, zBlob, sizeof(double));
}
sqlite3_result_double(context, rVal);
}
}
break;
}
case SQLITE_TEXT: {
const unsigned char *zStr = sqlite3_value_text(argv[0]);
if( zStr ){
int nStr = sqlite3_value_bytes(argv[0]);
if( nStr && !sqlite3Isspace(zStr[0]) && !sqlite3Isspace(zStr[nStr-1]) ){
double rVal;
if( sqlite3AtoF((const char*)zStr, &rVal, nStr, SQLITE_UTF8) ){
sqlite3_result_double(context, rVal);
return;
}
}
}
break;
}
default: {
assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
break;
}
}
}
#if defined(_MSC_VER)
#pragma optimize("", on)
#endif
/*
** The unicode() function. Return the integer unicode code-point value
** for the first character of the input string.
@ -1675,6 +1814,8 @@ void sqlite3RegisterGlobalFunctions(void){
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 ),
FUNCTION(toreal, 1, 0, 0, torealFunc ),
FUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
FUNCTION(changes, 0, 0, 0, changes ),
FUNCTION(total_changes, 0, 0, 0, total_changes ),

757
test/func4.test Normal file
View File

@ -0,0 +1,757 @@
# 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.
#
# Several of the toreal() tests are disabled on platforms where floating
# point precision is not high enough to represent their constant integer
# expression arguments as double precision floating point values.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set saved_tcl_precision $tcl_precision
set tcl_precision 0
set highPrecision(1) [expr \
{[memdbsql {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}]
do_execsql_test func4-1.1 {
SELECT tointeger(NULL);
} {{}}
do_execsql_test func4-1.2 {
SELECT tointeger('');
} {{}}
do_execsql_test func4-1.3 {
SELECT tointeger(' ');
} {{}}
do_execsql_test func4-1.4 {
SELECT tointeger('1234');
} {1234}
do_execsql_test func4-1.5 {
SELECT tointeger(' 1234');
} {{}}
do_execsql_test func4-1.6 {
SELECT tointeger('bad');
} {{}}
do_execsql_test func4-1.7 {
SELECT tointeger('0xBAD');
} {{}}
do_execsql_test func4-1.8 {
SELECT tointeger('123BAD');
} {{}}
do_execsql_test func4-1.9 {
SELECT tointeger('0x123BAD');
} {{}}
do_execsql_test func4-1.10 {
SELECT tointeger('123NO');
} {{}}
do_execsql_test func4-1.11 {
SELECT tointeger('0x123NO');
} {{}}
do_execsql_test func4-1.12 {
SELECT tointeger('-0x1');
} {{}}
do_execsql_test func4-1.13 {
SELECT tointeger('-0x0');
} {{}}
do_execsql_test func4-1.14 {
SELECT tointeger('0x0');
} {{}}
do_execsql_test func4-1.15 {
SELECT tointeger('0x1');
} {{}}
do_execsql_test func4-1.16 {
SELECT tointeger(-1);
} {-1}
do_execsql_test func4-1.17 {
SELECT tointeger(-0);
} {0}
do_execsql_test func4-1.18 {
SELECT tointeger(0);
} {0}
do_execsql_test func4-1.19 {
SELECT tointeger(1);
} {1}
do_execsql_test func4-1.20 {
SELECT tointeger(-1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.21 {
SELECT tointeger(-1.79769313486232e308);
} {{}}
do_execsql_test func4-1.22 {
SELECT tointeger(-1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.23 {
SELECT tointeger(-9223372036854775808 - 1);
} {-9223372036854775808}
do_execsql_test func4-1.24 {
SELECT tointeger(-9223372036854775808);
} {-9223372036854775808}
do_execsql_test func4-1.25 {
SELECT tointeger(-9223372036854775808 + 1);
} {-9223372036854775807}
do_execsql_test func4-1.26 {
SELECT tointeger(-9223372036854775807 - 1);
} {-9223372036854775808}
do_execsql_test func4-1.27 {
SELECT tointeger(-9223372036854775807);
} {-9223372036854775807}
do_execsql_test func4-1.28 {
SELECT tointeger(-9223372036854775807 + 1);
} {-9223372036854775806}
do_execsql_test func4-1.29 {
SELECT tointeger(-2147483648 - 1);
} {-2147483649}
do_execsql_test func4-1.30 {
SELECT tointeger(-2147483648);
} {-2147483648}
do_execsql_test func4-1.31 {
SELECT tointeger(-2147483648 + 1);
} {-2147483647}
do_execsql_test func4-1.32 {
SELECT tointeger(2147483647 - 1);
} {2147483646}
do_execsql_test func4-1.33 {
SELECT tointeger(2147483647);
} {2147483647}
do_execsql_test func4-1.34 {
SELECT tointeger(2147483647 + 1);
} {2147483648}
do_execsql_test func4-1.35 {
SELECT tointeger(9223372036854775807 - 1);
} {9223372036854775806}
do_execsql_test func4-1.36 {
SELECT tointeger(9223372036854775807);
} {9223372036854775807}
if {$highPrecision(1)} {
do_execsql_test func4-1.37 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
}
do_execsql_test func4-1.38 {
SELECT tointeger(1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.39 {
SELECT tointeger(1.79769313486232e308);
} {{}}
do_execsql_test func4-1.40 {
SELECT tointeger(1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.41 {
SELECT tointeger(4503599627370496 - 1);
} {4503599627370495}
do_execsql_test func4-1.42 {
SELECT tointeger(4503599627370496);
} {4503599627370496}
do_execsql_test func4-1.43 {
SELECT tointeger(4503599627370496 + 1);
} {4503599627370497}
do_execsql_test func4-1.44 {
SELECT tointeger(9007199254740992 - 1);
} {9007199254740991}
do_execsql_test func4-1.45 {
SELECT tointeger(9007199254740992);
} {9007199254740992}
do_execsql_test func4-1.46 {
SELECT tointeger(9007199254740992 + 1);
} {9007199254740993}
do_execsql_test func4-1.47 {
SELECT tointeger(9223372036854775807 - 1);
} {9223372036854775806}
do_execsql_test func4-1.48 {
SELECT tointeger(9223372036854775807);
} {9223372036854775807}
if {$highPrecision(1)} {
do_execsql_test func4-1.49 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
do_execsql_test func4-1.50 {
SELECT tointeger(9223372036854775808 - 1);
} {{}}
do_execsql_test func4-1.51 {
SELECT tointeger(9223372036854775808);
} {{}}
do_execsql_test func4-1.52 {
SELECT tointeger(9223372036854775808 + 1);
} {{}}
}
do_execsql_test func4-1.53 {
SELECT tointeger(18446744073709551616 - 1);
} {{}}
do_execsql_test func4-1.54 {
SELECT tointeger(18446744073709551616);
} {{}}
do_execsql_test func4-1.55 {
SELECT tointeger(18446744073709551616 + 1);
} {{}}
ifcapable floatingpoint {
set highPrecision(2) [expr \
{[memdbsql {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
do_execsql_test func4-2.1 {
SELECT toreal(NULL);
} {{}}
do_execsql_test func4-2.2 {
SELECT toreal('');
} {{}}
do_execsql_test func4-2.3 {
SELECT toreal(' ');
} {{}}
do_execsql_test func4-2.4 {
SELECT toreal('1234');
} {1234.0}
do_execsql_test func4-2.5 {
SELECT toreal(' 1234');
} {{}}
do_execsql_test func4-2.6 {
SELECT toreal('bad');
} {{}}
do_execsql_test func4-2.7 {
SELECT toreal('0xBAD');
} {{}}
do_execsql_test func4-2.8 {
SELECT toreal('123BAD');
} {{}}
do_execsql_test func4-2.9 {
SELECT toreal('0x123BAD');
} {{}}
do_execsql_test func4-2.10 {
SELECT toreal('123NO');
} {{}}
do_execsql_test func4-2.11 {
SELECT toreal('0x123NO');
} {{}}
do_execsql_test func4-2.12 {
SELECT toreal('-0x1');
} {{}}
do_execsql_test func4-2.13 {
SELECT toreal('-0x0');
} {{}}
do_execsql_test func4-2.14 {
SELECT toreal('0x0');
} {{}}
do_execsql_test func4-2.15 {
SELECT toreal('0x1');
} {{}}
do_execsql_test func4-2.16 {
SELECT toreal(-1);
} {-1.0}
do_execsql_test func4-2.17 {
SELECT toreal(-0);
} {0.0}
do_execsql_test func4-2.18 {
SELECT toreal(0);
} {0.0}
do_execsql_test func4-2.19 {
SELECT toreal(1);
} {1.0}
do_execsql_test func4-2.20 {
SELECT toreal(-1.79769313486232e308 - 1);
} {-Inf}
do_execsql_test func4-2.21 {
SELECT toreal(-1.79769313486232e308);
} {-Inf}
do_execsql_test func4-2.22 {
SELECT toreal(-1.79769313486232e308 + 1);
} {-Inf}
do_execsql_test func4-2.23 {
SELECT toreal(-9223372036854775808 - 1);
} {-9.223372036854776e+18}
do_execsql_test func4-2.24 {
SELECT toreal(-9223372036854775808);
} {-9.223372036854776e+18}
if {$highPrecision(2)} {
do_execsql_test func4-2.25 {
SELECT toreal(-9223372036854775808 + 1);
} {{}}
}
do_execsql_test func4-2.26 {
SELECT toreal(-9223372036854775807 - 1);
} {-9.223372036854776e+18}
if {$highPrecision(2)} {
do_execsql_test func4-2.27 {
SELECT toreal(-9223372036854775807);
} {{}}
do_execsql_test func4-2.28 {
SELECT toreal(-9223372036854775807 + 1);
} {{}}
}
do_execsql_test func4-2.29 {
SELECT toreal(-2147483648 - 1);
} {-2147483649.0}
do_execsql_test func4-2.30 {
SELECT toreal(-2147483648);
} {-2147483648.0}
do_execsql_test func4-2.31 {
SELECT toreal(-2147483648 + 1);
} {-2147483647.0}
do_execsql_test func4-2.32 {
SELECT toreal(2147483647 - 1);
} {2147483646.0}
do_execsql_test func4-2.33 {
SELECT toreal(2147483647);
} {2147483647.0}
do_execsql_test func4-2.34 {
SELECT toreal(2147483647 + 1);
} {2147483648.0}
if {$highPrecision(2)} {
do_execsql_test func4-2.35 {
SELECT toreal(9223372036854775807 - 1);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-2.36 {
SELECT toreal(9223372036854775807);
} {{}}
}
}
do_execsql_test func4-2.37 {
SELECT toreal(9223372036854775807 + 1);
} {9.223372036854776e+18}
do_execsql_test func4-2.38 {
SELECT toreal(1.79769313486232e308 - 1);
} {Inf}
do_execsql_test func4-2.39 {
SELECT toreal(1.79769313486232e308);
} {Inf}
do_execsql_test func4-2.40 {
SELECT toreal(1.79769313486232e308 + 1);
} {Inf}
do_execsql_test func4-2.41 {
SELECT toreal(4503599627370496 - 1);
} {4503599627370495.0}
do_execsql_test func4-2.42 {
SELECT toreal(4503599627370496);
} {4503599627370496.0}
do_execsql_test func4-2.43 {
SELECT toreal(4503599627370496 + 1);
} {4503599627370497.0}
do_execsql_test func4-2.44 {
SELECT toreal(9007199254740992 - 1);
} {9007199254740991.0}
do_execsql_test func4-2.45 {
SELECT toreal(9007199254740992);
} {9007199254740992.0}
if {$highPrecision(2)} {
do_execsql_test func4-2.46 {
SELECT toreal(9007199254740992 + 1);
} {{}}
}
do_execsql_test func4-2.47 {
SELECT toreal(9007199254740992 + 2);
} {9007199254740994.0}
do_execsql_test func4-2.48 {
SELECT toreal(tointeger(9223372036854775808) - 1);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-2.49 {
SELECT toreal(tointeger(9223372036854775808));
} {{}}
do_execsql_test func4-2.50 {
SELECT toreal(tointeger(9223372036854775808) + 1);
} {{}}
}
do_execsql_test func4-2.51 {
SELECT toreal(tointeger(18446744073709551616) - 1);
} {{}}
do_execsql_test func4-2.52 {
SELECT toreal(tointeger(18446744073709551616));
} {{}}
do_execsql_test func4-2.53 {
SELECT toreal(tointeger(18446744073709551616) + 1);
} {{}}
}
ifcapable check {
do_execsql_test func4-3.1 {
CREATE TABLE t1(
x INTEGER CHECK(tointeger(x) IS NOT NULL)
);
} {}
do_test func4-3.2 {
catchsql {
INSERT INTO t1 (x) VALUES (NULL);
}
} {1 {constraint failed}}
do_test func4-3.3 {
catchsql {
INSERT INTO t1 (x) VALUES (NULL);
}
} {1 {constraint failed}}
do_test func4-3.4 {
catchsql {
INSERT INTO t1 (x) VALUES ('');
}
} {1 {constraint failed}}
do_test func4-3.5 {
catchsql {
INSERT INTO t1 (x) VALUES ('bad');
}
} {1 {constraint failed}}
do_test func4-3.6 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234bad');
}
} {1 {constraint failed}}
do_test func4-3.7 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234.56bad');
}
} {1 {constraint failed}}
do_test func4-3.8 {
catchsql {
INSERT INTO t1 (x) VALUES (1234);
}
} {0 {}}
do_test func4-3.9 {
catchsql {
INSERT INTO t1 (x) VALUES (1234.56);
}
} {1 {constraint failed}}
do_test func4-3.10 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234');
}
} {0 {}}
do_test func4-3.11 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234.56');
}
} {1 {constraint failed}}
do_test func4-3.12 {
catchsql {
INSERT INTO t1 (x) VALUES (ZEROBLOB(4));
}
} {1 {constraint failed}}
do_test func4-3.13 {
catchsql {
INSERT INTO t1 (x) VALUES (X'');
}
} {1 {constraint failed}}
do_test func4-3.14 {
catchsql {
INSERT INTO t1 (x) VALUES (X'1234');
}
} {1 {constraint failed}}
do_test func4-3.15 {
catchsql {
INSERT INTO t1 (x) VALUES (X'12345678');
}
} {1 {constraint failed}}
do_test func4-3.16 {
catchsql {
INSERT INTO t1 (x) VALUES ('1234.00');
}
} {1 {constraint failed}}
do_test func4-3.17 {
catchsql {
INSERT INTO t1 (x) VALUES (1234.00);
}
} {0 {}}
do_test func4-3.18 {
catchsql {
INSERT INTO t1 (x) VALUES ('-9223372036854775809');
}
} {1 {constraint failed}}
if {$highPrecision(1)} {
do_test func4-3.19 {
catchsql {
INSERT INTO t1 (x) VALUES (9223372036854775808);
}
} {1 {constraint failed}}
}
do_execsql_test func4-3.20 {
SELECT x FROM t1 ORDER BY x;
} {1234 1234 1234}
ifcapable floatingpoint {
do_execsql_test func4-4.1 {
CREATE TABLE t2(
x REAL CHECK(toreal(x) IS NOT NULL)
);
} {}
do_test func4-4.2 {
catchsql {
INSERT INTO t2 (x) VALUES (NULL);
}
} {1 {constraint failed}}
do_test func4-4.3 {
catchsql {
INSERT INTO t2 (x) VALUES (NULL);
}
} {1 {constraint failed}}
do_test func4-4.4 {
catchsql {
INSERT INTO t2 (x) VALUES ('');
}
} {1 {constraint failed}}
do_test func4-4.5 {
catchsql {
INSERT INTO t2 (x) VALUES ('bad');
}
} {1 {constraint failed}}
do_test func4-4.6 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234bad');
}
} {1 {constraint failed}}
do_test func4-4.7 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234.56bad');
}
} {1 {constraint failed}}
do_test func4-4.8 {
catchsql {
INSERT INTO t2 (x) VALUES (1234);
}
} {0 {}}
do_test func4-4.9 {
catchsql {
INSERT INTO t2 (x) VALUES (1234.56);
}
} {0 {}}
do_test func4-4.10 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234');
}
} {0 {}}
do_test func4-4.11 {
catchsql {
INSERT INTO t2 (x) VALUES ('1234.56');
}
} {0 {}}
do_test func4-4.12 {
catchsql {
INSERT INTO t2 (x) VALUES (ZEROBLOB(4));
}
} {1 {constraint failed}}
do_test func4-4.13 {
catchsql {
INSERT INTO t2 (x) VALUES (X'');
}
} {1 {constraint failed}}
do_test func4-4.14 {
catchsql {
INSERT INTO t2 (x) VALUES (X'1234');
}
} {1 {constraint failed}}
do_test func4-4.15 {
catchsql {
INSERT INTO t2 (x) VALUES (X'12345678');
}
} {1 {constraint failed}}
do_execsql_test func4-4.16 {
SELECT x FROM t2 ORDER BY x;
} {1234.0 1234.0 1234.56 1234.56}
}
}
ifcapable floatingpoint {
do_execsql_test func4-5.1 {
SELECT tointeger(toreal('1234'));
} {1234}
do_execsql_test func4-5.2 {
SELECT tointeger(toreal(-1));
} {-1}
do_execsql_test func4-5.3 {
SELECT tointeger(toreal(-0));
} {0}
do_execsql_test func4-5.4 {
SELECT tointeger(toreal(0));
} {0}
do_execsql_test func4-5.5 {
SELECT tointeger(toreal(1));
} {1}
do_execsql_test func4-5.6 {
SELECT tointeger(toreal(-9223372036854775808 - 1));
} {-9223372036854775808}
do_execsql_test func4-5.7 {
SELECT tointeger(toreal(-9223372036854775808));
} {-9223372036854775808}
if {$highPrecision(2)} {
do_execsql_test func4-5.8 {
SELECT tointeger(toreal(-9223372036854775808 + 1));
} {{}}
}
do_execsql_test func4-5.9 {
SELECT tointeger(toreal(-2147483648 - 1));
} {-2147483649}
do_execsql_test func4-5.10 {
SELECT tointeger(toreal(-2147483648));
} {-2147483648}
do_execsql_test func4-5.11 {
SELECT tointeger(toreal(-2147483648 + 1));
} {-2147483647}
do_execsql_test func4-5.12 {
SELECT tointeger(toreal(2147483647 - 1));
} {2147483646}
do_execsql_test func4-5.13 {
SELECT tointeger(toreal(2147483647));
} {2147483647}
do_execsql_test func4-5.14 {
SELECT tointeger(toreal(2147483647 + 1));
} {2147483648}
do_execsql_test func4-5.15 {
SELECT tointeger(toreal(9223372036854775807 - 1));
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-5.16 {
SELECT tointeger(toreal(9223372036854775807));
} {{}}
do_execsql_test func4-5.17 {
SELECT tointeger(toreal(9223372036854775807 + 1));
} {{}}
}
do_execsql_test func4-5.18 {
SELECT tointeger(toreal(4503599627370496 - 1));
} {4503599627370495}
do_execsql_test func4-5.19 {
SELECT tointeger(toreal(4503599627370496));
} {4503599627370496}
do_execsql_test func4-5.20 {
SELECT tointeger(toreal(4503599627370496 + 1));
} {4503599627370497}
do_execsql_test func4-5.21 {
SELECT tointeger(toreal(9007199254740992 - 1));
} {9007199254740991}
do_execsql_test func4-5.22 {
SELECT tointeger(toreal(9007199254740992));
} {9007199254740992}
if {$highPrecision(2)} {
do_execsql_test func4-5.23 {
SELECT tointeger(toreal(9007199254740992 + 1));
} {{}}
}
do_execsql_test func4-5.24 {
SELECT tointeger(toreal(9007199254740992 + 2));
} {9007199254740994}
if {$highPrecision(1)} {
do_execsql_test func4-5.25 {
SELECT tointeger(toreal(9223372036854775808 - 1));
} {{}}
do_execsql_test func4-5.26 {
SELECT tointeger(toreal(9223372036854775808));
} {{}}
do_execsql_test func4-5.27 {
SELECT tointeger(toreal(9223372036854775808 + 1));
} {{}}
}
do_execsql_test func4-5.28 {
SELECT tointeger(toreal(18446744073709551616 - 1));
} {{}}
do_execsql_test func4-5.29 {
SELECT tointeger(toreal(18446744073709551616));
} {{}}
do_execsql_test func4-5.30 {
SELECT tointeger(toreal(18446744073709551616 + 1));
} {{}}
}
for {set i 0} {$i < 10} {incr i} {
if {$i == 8} continue
do_execsql_test func4-6.1.$i.1 [subst {
SELECT tointeger(x'[string repeat 01 $i]');
}] {{}}
ifcapable floatingpoint {
do_execsql_test func4-6.1.$i.2 [subst {
SELECT toreal(x'[string repeat 01 $i]');
}] {{}}
}
}
do_execsql_test func4-6.2.1 {
SELECT tointeger(x'0102030405060708');
} {578437695752307201}
do_execsql_test func4-6.2.2 {
SELECT tointeger(x'0807060504030201');
} {72623859790382856}
ifcapable floatingpoint {
do_execsql_test func4-6.3.1 {
SELECT toreal(x'ffefffffffffffff');
} {-1.7976931348623157e+308}
do_execsql_test func4-6.3.2 {
SELECT toreal(x'8010000000000000');
} {-2.2250738585072014e-308}
do_execsql_test func4-6.3.3 {
SELECT toreal(x'c000000000000000');
} {-2.0}
do_execsql_test func4-6.3.4 {
SELECT toreal(x'bff0000000000000');
} {-1.0}
do_execsql_test func4-6.3.5 {
SELECT toreal(x'8000000000000000');
} {-0.0}
do_execsql_test func4-6.3.6 {
SELECT toreal(x'0000000000000000');
} {0.0}
do_execsql_test func4-6.3.7 {
SELECT toreal(x'3ff0000000000000');
} {1.0}
do_execsql_test func4-6.3.8 {
SELECT toreal(x'4000000000000000');
} {2.0}
do_execsql_test func4-6.3.9 {
SELECT toreal(x'0010000000000000');
} {2.2250738585072014e-308}
do_execsql_test func4-6.3.10 {
SELECT toreal(x'7fefffffffffffff');
} {1.7976931348623157e+308}
do_execsql_test func4-6.3.11 {
SELECT toreal(x'8000000000000001');
} {-5e-324}
do_execsql_test func4-6.3.12 {
SELECT toreal(x'800fffffffffffff');
} {-2.225073858507201e-308}
do_execsql_test func4-6.3.13 {
SELECT toreal(x'0000000000000001');
} {5e-324}
do_execsql_test func4-6.3.14 {
SELECT toreal(x'000fffffffffffff');
} {2.225073858507201e-308}
do_execsql_test func4-6.3.15 {
SELECT toreal(x'fff0000000000000');
} {-Inf}
do_execsql_test func4-6.3.16 {
SELECT toreal(x'7ff0000000000000');
} {Inf}
do_execsql_test func4-6.3.17 {
SELECT toreal(x'fff8000000000000');
} {{}}
do_execsql_test func4-6.3.18 {
SELECT toreal(x'fff0000000000001');
} {{}}
do_execsql_test func4-6.3.19 {
SELECT toreal(x'fff7ffffffffffff');
} {{}}
do_execsql_test func4-6.3.20 {
SELECT toreal(x'7ff0000000000001');
} {{}}
do_execsql_test func4-6.3.21 {
SELECT toreal(x'7ff7ffffffffffff');
} {{}}
do_execsql_test func4-6.3.22 {
SELECT toreal(x'fff8000000000001');
} {{}}
do_execsql_test func4-6.3.23 {
SELECT toreal(x'ffffffffffffffff');
} {{}}
do_execsql_test func4-6.3.24 {
SELECT toreal(x'7ff8000000000000');
} {{}}
do_execsql_test func4-6.3.25 {
SELECT toreal(x'7fffffffffffffff');
} {{}}
}
set tcl_precision $saved_tcl_precision
unset saved_tcl_precision
finish_test