/ Changes On Branch toTypeFuncs
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch toTypeFuncs Excluding Merge-Ins

This is equivalent to a diff from f0cf8c85 to a88b5be0

2013-10-14
19:35
Add implementations for the toInteger() and toReal() SQL functions. (check-in: a0f7cbc0 user: drh tags: trunk)
10:46
Add a new application_id for GeoPackage version 1.0. (check-in: 98ddfe45 user: drh tags: trunk)
2013-10-12
23:39
Merge updates from trunk. (Closed-Leaf check-in: a88b5be0 user: mistachkin tags: toTypeFuncs)
20:22
Restore the index_list pragma back to its former operation. Create a new PRAGMA stats used to access the table and index widths and heights. (check-in: f0cf8c85 user: drh tags: trunk)
15:12
Fix handling of "DROP TABLE" commands when "PRAGMA defer_foreign_keys=1" is set. (check-in: 27001356 user: dan tags: trunk)
2013-09-24
19:07
Merge updates from trunk. (check-in: 435ce3b3 user: mistachkin tags: toTypeFuncs)

Changes to Makefile.msc.

    27     27   !ENDIF
    28     28   
    29     29   # Set this non-0 to dynamically link to the MSVC runtime library.
    30     30   #
    31     31   !IFNDEF USE_CRT_DLL
    32     32   USE_CRT_DLL = 0
    33     33   !ENDIF
           34  +
           35  +# Set this non-0 to generate assembly code listings for the source code
           36  +# files.
           37  +#
           38  +!IFNDEF USE_LISTINGS
           39  +USE_LISTINGS = 0
           40  +!ENDIF
    34     41   
    35     42   # Set this non-0 to attempt setting the native compiler automatically
    36     43   # for cross-compiling the command line tools needed during the compilation
    37     44   # process.
    38     45   #
    39     46   !IFNDEF XCOMPILE
    40     47   XCOMPILE = 0
................................................................................
   183    190   
   184    191   NSDKLIBPATH = $(NSDKLIBPATH:\\=\)
   185    192   
   186    193   # C compiler and options for use in building executables that
   187    194   # will run on the platform that is doing the build.
   188    195   #
   189    196   BCC = $(NCC) -W3
          197  +
          198  +# Check if assembly code listings should be generated for the source
          199  +# code files to be compiled.
          200  +#
          201  +!IF $(USE_LISTINGS)!=0
          202  +BCC = $(BCC) -FAcs
          203  +!ENDIF
   190    204   
   191    205   # Check if the native library paths should be used when compiling
   192    206   # the command line tools used during the compilation process.  If
   193    207   # so, set the necessary macro now.
   194    208   #
   195    209   !IF $(USE_NATIVE_LIBPATHS)!=0
   196    210   NLTLIBPATHS = "/LIBPATH:$(NCRTLIBPATH)" "/LIBPATH:$(NSDKLIBPATH)"
................................................................................
   198    212   
   199    213   # C compiler and options for use in building executables that
   200    214   # will run on the target platform.  (BCC and TCC are usually the
   201    215   # same unless your are cross-compiling.)
   202    216   #
   203    217   TCC = $(CC) -W3 -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src -fp:precise
   204    218   RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src
          219  +
          220  +# Check if assembly code listings should be generated for the source
          221  +# code files to be compiled.
          222  +#
          223  +!IF $(USE_LISTINGS)!=0
          224  +TCC = $(TCC) -FAcs
          225  +!ENDIF
   205    226   
   206    227   # When compiling the library for use in the WinRT environment,
   207    228   # the following compile-time options must be used as well to
   208    229   # disable use of Win32 APIs that are not available and to enable
   209    230   # use of Win32 APIs that are specific to Windows 8 and/or WinRT.
   210    231   #
   211    232   !IF $(FOR_WINRT)!=0
................................................................................
  1308   1329   
  1309   1330   sqlite3_analyzer.exe:	sqlite3_analyzer.c $(LIBRESOBJS)
  1310   1331   	$(LTLINK) -DBUILD_sqlite -DTCLSH=2 -I$(TCLINCDIR) sqlite3_analyzer.c \
  1311   1332   		/link $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1312   1333   
  1313   1334   clean:
  1314   1335   	del /Q *.lo *.ilk *.lib *.obj *.pdb sqlite3.exe libsqlite3.lib
  1315         -	del /Q *.da *.bb *.bbg gmon.out
         1336  +	del /Q *.cod *.da *.bb *.bbg gmon.out
  1316   1337   	del /Q sqlite3.h opcodes.c opcodes.h
  1317   1338   	del /Q lemon.exe lempar.c parse.*
  1318   1339   	del /Q mkkeywordhash.exe keywordhash.h
  1319   1340   	-rmdir /Q/S .deps
  1320   1341   	-rmdir /Q/S .libs
  1321   1342   	-rmdir /Q/S quota2a
  1322   1343   	-rmdir /Q/S quota2b

Changes to src/func.c.

   961    961         assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
   962    962         sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC);
   963    963         break;
   964    964       }
   965    965     }
   966    966   }
   967    967   
          968  +/*
          969  +** tointeger(X):  If X is any value (integer, double, blob, or string) that
          970  +** can be losslessly converted into an integer, then make the conversion and
          971  +** return the result.  Otherwise, return NULL.
          972  +*/
          973  +static void tointegerFunc(
          974  +  sqlite3_context *context,
          975  +  int argc,
          976  +  sqlite3_value **argv
          977  +){
          978  +  assert( argc==1 );
          979  +  UNUSED_PARAMETER(argc);
          980  +  switch( sqlite3_value_type(argv[0]) ){
          981  +    case SQLITE_FLOAT: {
          982  +      double rVal = sqlite3_value_double(argv[0]);
          983  +      i64 iVal = (i64)rVal;
          984  +      if( rVal==(double)iVal ){
          985  +        sqlite3_result_int64(context, iVal);
          986  +      }
          987  +      break;
          988  +    }
          989  +    case SQLITE_INTEGER: {
          990  +      sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
          991  +      break;
          992  +    }
          993  +    case SQLITE_BLOB: {
          994  +      const unsigned char *zBlob = sqlite3_value_blob(argv[0]);
          995  +      if( zBlob ){
          996  +        int nBlob = sqlite3_value_bytes(argv[0]);
          997  +        if( nBlob==sizeof(i64) ){
          998  +          i64 iVal;
          999  +          if( SQLITE_BIGENDIAN ){
         1000  +            int i;
         1001  +            unsigned char *zBlobRev = contextMalloc(context, nBlob);
         1002  +            if( !zBlobRev ) break;
         1003  +            for(i=0; i<nBlob; i++) zBlobRev[i] = zBlob[nBlob-1-i];
         1004  +            memcpy(&iVal, zBlobRev, sizeof(i64));
         1005  +            sqlite3_free(zBlobRev);
         1006  +          }else{
         1007  +            memcpy(&iVal, zBlob, sizeof(i64));
         1008  +          }
         1009  +          sqlite3_result_int64(context, iVal);
         1010  +        }
         1011  +      }
         1012  +      break;
         1013  +    }
         1014  +    case SQLITE_TEXT: {
         1015  +      const unsigned char *zStr = sqlite3_value_text(argv[0]);
         1016  +      if( zStr ){
         1017  +        int nStr = sqlite3_value_bytes(argv[0]);
         1018  +        if( nStr && !sqlite3Isspace(zStr[0]) ){
         1019  +          i64 iVal;
         1020  +          if( !sqlite3Atoi64((const char*)zStr, &iVal, nStr, SQLITE_UTF8) ){
         1021  +            sqlite3_result_int64(context, iVal);
         1022  +          }
         1023  +        }
         1024  +      }
         1025  +      break;
         1026  +    }
         1027  +    default: {
         1028  +      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
         1029  +      break;
         1030  +    }
         1031  +  }
         1032  +}
         1033  +
         1034  +/*
         1035  +** toreal(X): If X is any value (integer, double, blob, or string) that can
         1036  +** be losslessly converted into a real number, then do so and return that
         1037  +** real number.  Otherwise return NULL.
         1038  +*/
         1039  +#if defined(_MSC_VER)
         1040  +#pragma optimize("", off)
         1041  +#endif
         1042  +static void torealFunc(
         1043  +  sqlite3_context *context,
         1044  +  int argc,
         1045  +  sqlite3_value **argv
         1046  +){
         1047  +  assert( argc==1 );
         1048  +  UNUSED_PARAMETER(argc);
         1049  +  switch( sqlite3_value_type(argv[0]) ){
         1050  +    case SQLITE_FLOAT: {
         1051  +      sqlite3_result_double(context, sqlite3_value_double(argv[0]));
         1052  +      break;
         1053  +    }
         1054  +    case SQLITE_INTEGER: {
         1055  +      i64 iVal = sqlite3_value_int64(argv[0]);
         1056  +      double rVal = (double)iVal;
         1057  +      if( iVal==(i64)rVal ){
         1058  +        sqlite3_result_double(context, rVal);
         1059  +      }
         1060  +      break;
         1061  +    }
         1062  +    case SQLITE_BLOB: {
         1063  +      const unsigned char *zBlob = sqlite3_value_blob(argv[0]);
         1064  +      if( zBlob ){
         1065  +        int nBlob = sqlite3_value_bytes(argv[0]);
         1066  +        if( nBlob==sizeof(double) ){
         1067  +          double rVal;
         1068  +          if( SQLITE_LITTLEENDIAN ){
         1069  +            int i;
         1070  +            unsigned char *zBlobRev = contextMalloc(context, nBlob);
         1071  +            if( !zBlobRev ) break;
         1072  +            for(i=0; i<nBlob; i++) zBlobRev[i] = zBlob[nBlob-1-i];
         1073  +            memcpy(&rVal, zBlobRev, sizeof(double));
         1074  +            sqlite3_free(zBlobRev);
         1075  +          }else{
         1076  +            memcpy(&rVal, zBlob, sizeof(double));
         1077  +          }
         1078  +          sqlite3_result_double(context, rVal);
         1079  +        }
         1080  +      }
         1081  +      break;
         1082  +    }
         1083  +    case SQLITE_TEXT: {
         1084  +      const unsigned char *zStr = sqlite3_value_text(argv[0]);
         1085  +      if( zStr ){
         1086  +        int nStr = sqlite3_value_bytes(argv[0]);
         1087  +        if( nStr && !sqlite3Isspace(zStr[0]) && !sqlite3Isspace(zStr[nStr-1]) ){
         1088  +          double rVal;
         1089  +          if( sqlite3AtoF((const char*)zStr, &rVal, nStr, SQLITE_UTF8) ){
         1090  +            sqlite3_result_double(context, rVal);
         1091  +            return;
         1092  +          }
         1093  +        }
         1094  +      }
         1095  +      break;
         1096  +    }
         1097  +    default: {
         1098  +      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
         1099  +      break;
         1100  +    }
         1101  +  }
         1102  +}
         1103  +#if defined(_MSC_VER)
         1104  +#pragma optimize("", on)
         1105  +#endif
         1106  +
   968   1107   /*
   969   1108   ** The unicode() function.  Return the integer unicode code-point value
   970   1109   ** for the first character of the input string. 
   971   1110   */
   972   1111   static void unicodeFunc(
   973   1112     sqlite3_context *context,
   974   1113     int argc,
................................................................................
  1671   1810       FUNCTION(sqlite_source_id,   0, 0, 0, sourceidFunc     ),
  1672   1811       FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
  1673   1812   #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  1674   1813       FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
  1675   1814       FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
  1676   1815   #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
  1677   1816       FUNCTION(quote,              1, 0, 0, quoteFunc        ),
         1817  +    FUNCTION(tointeger,          1, 0, 0, tointegerFunc    ),
         1818  +    FUNCTION(toreal,             1, 0, 0, torealFunc       ),
  1678   1819       FUNCTION(last_insert_rowid,  0, 0, 0, last_insert_rowid),
  1679   1820       FUNCTION(changes,            0, 0, 0, changes          ),
  1680   1821       FUNCTION(total_changes,      0, 0, 0, total_changes    ),
  1681   1822       FUNCTION(replace,            3, 0, 0, replaceFunc      ),
  1682   1823       FUNCTION(zeroblob,           1, 0, 0, zeroblobFunc     ),
  1683   1824     #ifdef SQLITE_SOUNDEX
  1684   1825       FUNCTION(soundex,            1, 0, 0, soundexFunc      ),

Added test/func4.test.

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