Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Changes to completely remove all floating point ops if SQLITE_OMIT_FLOATING_POINT defined. Note that w/o fp, date/time, round, nan, etc. are all gone or limited in functionality. Updated some of the test scripts to support missing fp and 64-bit functionality. Ticket #3029. (CVS 6250) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
5cef400023205b55152b91441acc78f9 |
User & Date: | shane 2009-02-04 03:59:25.000 |
Context
2009-02-04
| ||
08:17 | Fix a bug in malloc.test causing the exclusive permutation to fail. Changes to test code only. (CVS 6251) (check-in: 72745bde90 user: danielk1977 tags: trunk) | |
03:59 | Changes to completely remove all floating point ops if SQLITE_OMIT_FLOATING_POINT defined. Note that w/o fp, date/time, round, nan, etc. are all gone or limited in functionality. Updated some of the test scripts to support missing fp and 64-bit functionality. Ticket #3029. (CVS 6250) (check-in: 5cef400023 user: shane tags: trunk) | |
01:49 | Remove compiler warnings under MSVC. (CVS 6249) (check-in: 6301f08a2b user: shane tags: trunk) | |
Changes
Changes to src/date.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This file contains the C functions that implement date and time ** functions for SQLite. ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This file contains the C functions that implement date and time ** functions for SQLite. ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** ** $Id: date.c,v 1.103 2009/02/04 03:59:25 shane Exp $ ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon ** in Greenwich on November 24, 4714 B.C. according to the Gregorian ** calendar system. ** ** 1970-01-01 00:00:00 is JD 2440587.5 |
︙ | ︙ | |||
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | sqlite3_value **argv ){ time_t t; char *zFormat = (char *)sqlite3_user_data(context); sqlite3 *db; double rT; char zBuf[20]; db = sqlite3_context_db_handle(context); sqlite3OsCurrentTime(db->pVfs, &rT); t = 86400.0*(rT - 2440587.5) + 0.5; #ifdef HAVE_GMTIME_R { struct tm sNow; gmtime_r(&t, &sNow); strftime(zBuf, 20, zFormat, &sNow); } #else | > > > > > > > > > > | 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 | sqlite3_value **argv ){ time_t t; char *zFormat = (char *)sqlite3_user_data(context); sqlite3 *db; double rT; char zBuf[20]; UNUSED_PARAMETER(argc); UNUSED_PARAMETER(argv); db = sqlite3_context_db_handle(context); sqlite3OsCurrentTime(db->pVfs, &rT); #ifndef SQLITE_OMIT_FLOATING_POINT t = 86400.0*(rT - 2440587.5) + 0.5; #else /* without floating point support, rT will have ** already lost fractional day precision. */ t = 86400 * (rT - 2440587) - 43200; #endif #ifdef HAVE_GMTIME_R { struct tm sNow; gmtime_r(&t, &sNow); strftime(zBuf, 20, zFormat, &sNow); } #else |
︙ | ︙ |
Changes to src/expr.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** ** $Id: expr.c,v 1.411 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" /* ** Return the 'affinity' of the expression pExpr if any. ** ** If pExpr is a column, a reference to a column via an 'AS' alias, |
︙ | ︙ | |||
1928 1929 1930 1931 1932 1933 1934 | testcase( regFree1==0 ); testcase( regFree2==0 ); break; } case TK_UMINUS: { Expr *pLeft = pExpr->pLeft; assert( pLeft ); | < | | | | < | 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 | testcase( regFree1==0 ); testcase( regFree2==0 ); break; } case TK_UMINUS: { Expr *pLeft = pExpr->pLeft; assert( pLeft ); if( pLeft->op==TK_FLOAT ){ codeReal(v, (char*)pLeft->token.z, pLeft->token.n, 1, target); }else if( pLeft->op==TK_INTEGER ){ codeInteger(v, pLeft, 1, target); }else{ regFree1 = r1 = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp2(v, OP_Integer, 0, r1); r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free2); sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target); testcase( regFree2==0 ); } |
︙ | ︙ |
Changes to src/func.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This file contains the C functions that implement various SQL ** functions of SQLite. ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This file contains the C functions that implement various SQL ** functions of SQLite. ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** ** $Id: func.c,v 1.222 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" #include <stdlib.h> #include <assert.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | sqlite3_result_blob(context, (char*)&z[p1], (int)p2, SQLITE_TRANSIENT); } } /* ** Implementation of the round() function */ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; char zBuf[500]; /* larger than the %f representation of the largest double */ assert( argc==1 || argc==2 ); if( argc==2 ){ if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return; n = sqlite3_value_int(argv[1]); if( n>30 ) n = 30; if( n<0 ) n = 0; } if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; r = sqlite3_value_double(argv[0]); sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r); sqlite3AtoF(zBuf, &r); sqlite3_result_double(context, r); } /* ** Allocate nByte bytes of space using sqlite3_malloc(). If the ** allocation fails, call sqlite3_result_error_nomem() to notify ** the database handle that malloc() has failed. */ static void *contextMalloc(sqlite3_context *context, i64 nByte){ | > > | 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | sqlite3_result_blob(context, (char*)&z[p1], (int)p2, SQLITE_TRANSIENT); } } /* ** Implementation of the round() function */ #ifndef SQLITE_OMIT_FLOATING_POINT static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; char zBuf[500]; /* larger than the %f representation of the largest double */ assert( argc==1 || argc==2 ); if( argc==2 ){ if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return; n = sqlite3_value_int(argv[1]); if( n>30 ) n = 30; if( n<0 ) n = 0; } if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; r = sqlite3_value_double(argv[0]); sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r); sqlite3AtoF(zBuf, &r); sqlite3_result_double(context, r); } #endif /* ** Allocate nByte bytes of space using sqlite3_malloc(). If the ** allocation fails, call sqlite3_result_error_nomem() to notify ** the database handle that malloc() has failed. */ static void *contextMalloc(sqlite3_context *context, i64 nByte){ |
︙ | ︙ | |||
1127 1128 1129 1130 1131 1132 1133 | if( p && p->cnt>0 ){ sqlite3_result_double(context, p->rSum/(double)p->cnt); } } static void totalFinalize(sqlite3_context *context){ SumCtx *p; p = sqlite3_aggregate_context(context, 0); | > | | 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 | if( p && p->cnt>0 ){ sqlite3_result_double(context, p->rSum/(double)p->cnt); } } static void totalFinalize(sqlite3_context *context){ SumCtx *p; p = sqlite3_aggregate_context(context, 0); /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ sqlite3_result_double(context, p ? p->rSum : (double)0); } /* ** The following structure keeps track of state information for the ** count() aggregate function. */ typedef struct CountCtx CountCtx; |
︙ | ︙ | |||
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 | FUNCTION(max, 0, 1, 1, 0 ), AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), FUNCTION(typeof, 1, 0, 0, typeofFunc ), FUNCTION(length, 1, 0, 0, lengthFunc ), FUNCTION(substr, 2, 0, 0, substrFunc ), FUNCTION(substr, 3, 0, 0, substrFunc ), FUNCTION(abs, 1, 0, 0, absFunc ), FUNCTION(round, 1, 0, 0, roundFunc ), FUNCTION(round, 2, 0, 0, roundFunc ), FUNCTION(upper, 1, 0, 0, upperFunc ), FUNCTION(lower, 1, 0, 0, lowerFunc ), FUNCTION(coalesce, 1, 0, 0, 0 ), FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), FUNCTION(coalesce, 0, 0, 0, 0 ), FUNCTION(hex, 1, 0, 0, hexFunc ), FUNCTION(ifnull, 2, 0, 1, ifnullFunc ), | > > | 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 | FUNCTION(max, 0, 1, 1, 0 ), AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), FUNCTION(typeof, 1, 0, 0, typeofFunc ), FUNCTION(length, 1, 0, 0, lengthFunc ), FUNCTION(substr, 2, 0, 0, substrFunc ), FUNCTION(substr, 3, 0, 0, substrFunc ), FUNCTION(abs, 1, 0, 0, absFunc ), #ifndef SQLITE_OMIT_FLOATING_POINT FUNCTION(round, 1, 0, 0, roundFunc ), FUNCTION(round, 2, 0, 0, roundFunc ), #endif FUNCTION(upper, 1, 0, 0, upperFunc ), FUNCTION(lower, 1, 0, 0, lowerFunc ), FUNCTION(coalesce, 1, 0, 0, 0 ), FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), FUNCTION(coalesce, 0, 0, 0, 0 ), FUNCTION(hex, 1, 0, 0, hexFunc ), FUNCTION(ifnull, 2, 0, 1, ifnullFunc ), |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** ** $Id: main.c,v 1.526 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" #ifdef SQLITE_ENABLE_FTS3 # include "fts3.h" #endif #ifdef SQLITE_ENABLE_RTREE |
︙ | ︙ | |||
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | /* The following is just a sanity check to make sure SQLite has ** been compiled correctly. It is important to run this code, but ** we don't want to run it too often and soak up CPU cycles for no ** reason. So we run it once during initialization. */ #ifndef NDEBUG /* This section of code's only "output" is via assert() statements. */ if ( rc==SQLITE_OK ){ u64 x = (((u64)1)<<63)-1; double y; assert(sizeof(x)==8); assert(sizeof(x)==sizeof(y)); memcpy(&y, &x, 8); assert( sqlite3IsNaN(y) ); } #endif return rc; } /* ** Undo the effects of sqlite3_initialize(). Must not be called while | > > | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | /* The following is just a sanity check to make sure SQLite has ** been compiled correctly. It is important to run this code, but ** we don't want to run it too often and soak up CPU cycles for no ** reason. So we run it once during initialization. */ #ifndef NDEBUG #ifndef SQLITE_OMIT_FLOATING_POINT /* This section of code's only "output" is via assert() statements. */ if ( rc==SQLITE_OK ){ u64 x = (((u64)1)<<63)-1; double y; assert(sizeof(x)==8); assert(sizeof(x)==sizeof(y)); memcpy(&y, &x, 8); assert( sqlite3IsNaN(y) ); } #endif #endif return rc; } /* ** Undo the effects of sqlite3_initialize(). Must not be called while |
︙ | ︙ |
Changes to src/os_win.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** ** This file contains code that is specific to windows. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** ** This file contains code that is specific to windows. ** ** $Id: os_win.c,v 1.147 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" #if SQLITE_OS_WIN /* This file is used for windows only */ /* ** A Note About Memory Allocation: |
︙ | ︙ | |||
751 752 753 754 755 756 757 758 759 760 | /* ** Make sure all writes to a particular file are committed to disk. */ static int winSync(sqlite3_file *id, int flags){ #ifndef SQLITE_NO_SYNC winFile *pFile = (winFile*)id; #else UNUSED_PARAMETER(id); #endif | > < | 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | /* ** Make sure all writes to a particular file are committed to disk. */ static int winSync(sqlite3_file *id, int flags){ #ifndef SQLITE_NO_SYNC winFile *pFile = (winFile*)id; OSTRACE3("SYNC %d lock=%d\n", pFile->h, pFile->locktype); #else UNUSED_PARAMETER(id); #endif #ifndef SQLITE_TEST UNUSED_PARAMETER(flags); #else if( flags & SQLITE_SYNC_FULL ){ sqlite3_fullsync_count++; } sqlite3_sync_count++; |
︙ | ︙ | |||
1668 1669 1670 1671 1672 1673 1674 | ** return 0. Return 1 if the time and date cannot be found. */ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){ FILETIME ft; /* FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5). */ | | > | > > > > > > > > | > > > > > > > > | | 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 | ** return 0. Return 1 if the time and date cannot be found. */ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){ FILETIME ft; /* FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5). */ sqlite3_int64 timeW, timeF; #if SQLITE_OS_WINCE SYSTEMTIME time; GetSystemTime(&time); /* if SystemTimeToFileTime() fails, it returns zero. */ if (!SystemTimeToFileTime(&time,&ft)){ return 1; } #else GetSystemTimeAsFileTime( &ft ); #endif UNUSED_PARAMETER(pVfs); #if defined(_MSC_VER) timeW = (((sqlite3_int64)ft.dwHighDateTime)*4294967296) + ft.dwLowDateTime; timeF = timeW % 864000000000; /* fractional days (100-nanoseconds) */ timeW = timeW / 864000000000; /* whole days */ timeW = timeW + 2305813; /* add whole days (from 2305813.5) */ timeF = timeF + 432000000000; /* add half a day (from 2305813.5) */ timeW = timeW + (timeF / 864000000000); /* add whole day if half day made one */ timeF = timeF % 864000000000; /* compute new fractional days */ *prNow = (double)timeW + ((double)timeF / (double)864000000000); #else timeW = (((sqlite3_int64)ft.dwHighDateTime)*4294967296LL) + ft.dwLowDateTime; timeF = timeW % 864000000000LL; /* fractional days (100-nanoseconds) */ timeW = timeW / 864000000000LL; /* whole days */ timeW = timeW + 2305813; /* add whole days (from 2305813.5) */ timeF = timeF + 432000000000LL; /* add half a day (from 2305813.5) */ timeW = timeW + (timeF / 864000000000LL); /* add whole day if half day made one */ timeF = timeF % 864000000000LL; /* compute new fractional days */ *prNow = (double)timeW + ((double)timeF / (double)864000000000LL); #endif #ifdef SQLITE_TEST if( sqlite3_current_time ){ *prNow = ((double)sqlite3_current_time + (double)43200) / (double)86400 + (double)2440587; } #endif return 0; } /* ** The idea is that this function works like a combination of |
︙ | ︙ |
Changes to src/util.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** | | < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** ** $Id: util.c,v 1.248 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" #include <stdarg.h> /* ** Routine needed to support the testcase() macro. */ #ifdef SQLITE_COVERAGE_TEST void sqlite3Coverage(int x){ static int dummy = 0; |
︙ | ︙ |
Changes to src/vdbe.c.
︙ | ︙ | |||
39 40 41 42 43 44 45 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** ** $Id: vdbe.c,v 1.814 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" /* ** The following global variable is incremented every time a cursor ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test |
︙ | ︙ | |||
1224 1225 1226 1227 1228 1229 1230 | a = sqlite3VdbeRealValue(pIn1); b = sqlite3VdbeRealValue(pIn2); switch( pOp->opcode ){ case OP_Add: b += a; break; case OP_Subtract: b -= a; break; case OP_Multiply: b *= a; break; case OP_Divide: { | > | | 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 | a = sqlite3VdbeRealValue(pIn1); b = sqlite3VdbeRealValue(pIn2); switch( pOp->opcode ){ case OP_Add: b += a; break; case OP_Subtract: b -= a; break; case OP_Multiply: b *= a; break; case OP_Divide: { /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ if( a==(double)0 ) goto arithmetic_result_is_null; b /= a; break; } default: { i64 ia = (i64)a; i64 ib = (i64)b; if( ia==0 ) goto arithmetic_result_is_null; |
︙ | ︙ | |||
1869 1870 1871 1872 1873 1874 1875 | case OP_If: /* jump, in1 */ case OP_IfNot: { /* jump, in1 */ int c; if( pIn1->flags & MEM_Null ){ c = pOp->p3; }else{ #ifdef SQLITE_OMIT_FLOATING_POINT | | | 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 | case OP_If: /* jump, in1 */ case OP_IfNot: { /* jump, in1 */ int c; if( pIn1->flags & MEM_Null ){ c = pOp->p3; }else{ #ifdef SQLITE_OMIT_FLOATING_POINT c = sqlite3VdbeIntValue(pIn1)!=0; #else c = sqlite3VdbeRealValue(pIn1)!=0.0; #endif if( pOp->opcode==OP_IfNot ) c = !c; } if( c ){ pc = pOp->p2-1; |
︙ | ︙ |
Changes to src/vdbeapi.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** This file contains code use to implement APIs that are part of the ** VDBE. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** This file contains code use to implement APIs that are part of the ** VDBE. ** ** $Id: vdbeapi.c,v 1.151 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" #if 0 && defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) /* ** The following structure contains pointers to the end points of a |
︙ | ︙ | |||
748 749 750 751 752 753 754 | pVm = (Vdbe *)pStmt; if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){ sqlite3_mutex_enter(pVm->db->mutex); vals = sqlite3_data_count(pStmt); pOut = &pVm->pResultSet[i]; }else{ | > | | 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 | pVm = (Vdbe *)pStmt; if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){ sqlite3_mutex_enter(pVm->db->mutex); vals = sqlite3_data_count(pStmt); pOut = &pVm->pResultSet[i]; }else{ /* ((double)0) In case of SQLITE_OMIT_FLOATING_POINT... */ static const Mem nullMem = {{0}, (double)0, 0, "", 0, MEM_Null, SQLITE_NULL, 0, 0, 0 }; if( pVm->db ){ sqlite3_mutex_enter(pVm->db->mutex); sqlite3Error(pVm->db, SQLITE_RANGE, 0); } pOut = (Mem*)&nullMem; } return pOut; |
︙ | ︙ |
Changes to src/vdbemem.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** ** This file contains code use to manipulate "Mem" structure. A "Mem" ** stores a single value in the VDBE. Mem is an opaque structure visible ** only within the VDBE. Interface routines refer to a Mem using the ** name sqlite_value ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** ** This file contains code use to manipulate "Mem" structure. A "Mem" ** stores a single value in the VDBE. Mem is an opaque structure visible ** only within the VDBE. Interface routines refer to a Mem using the ** name sqlite_value ** ** $Id: vdbemem.c,v 1.137 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" /* ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*) ** P if required. |
︙ | ︙ | |||
369 370 371 372 373 374 375 | double sqlite3VdbeRealValue(Mem *pMem){ assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); if( pMem->flags & MEM_Real ){ return pMem->r; }else if( pMem->flags & MEM_Int ){ return (double)pMem->u.i; }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ | > | > | > | | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | double sqlite3VdbeRealValue(Mem *pMem){ assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); if( pMem->flags & MEM_Real ){ return pMem->r; }else if( pMem->flags & MEM_Int ){ return (double)pMem->u.i; }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ double val = (double)0; pMem->flags |= MEM_Str; if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8) || sqlite3VdbeMemNulTerminate(pMem) ){ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ return (double)0; } assert( pMem->z ); sqlite3AtoF(pMem->z, &val); return val; }else{ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ return (double)0; } } /* ** The MEM structure is already a MEM_Real. Try to also make it a ** MEM_Int if we can. */ |
︙ | ︙ | |||
965 966 967 968 969 970 971 | sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc); }else{ sqlite3ValueApplyAffinity(pVal, affinity, enc); } }else if( op==TK_UMINUS ) { if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){ pVal->u.i = -1 * pVal->u.i; | > | | 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc); }else{ sqlite3ValueApplyAffinity(pVal, affinity, enc); } }else if( op==TK_UMINUS ) { if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){ pVal->u.i = -1 * pVal->u.i; /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */ pVal->r = (double)-1 * pVal->r; } } #ifndef SQLITE_OMIT_BLOB_LITERAL else if( op==TK_BLOB ){ int nVal; assert( pExpr->token.n>=3 ); assert( pExpr->token.z[0]=='x' || pExpr->token.z[0]=='X' ); |
︙ | ︙ |
Changes to src/where.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is responsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is responsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** ** $Id: where.c,v 1.368 2009/02/04 03:59:25 shane Exp $ */ #include "sqliteInt.h" /* ** Trace output macros */ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
︙ | ︙ | |||
1543 1544 1545 1546 1547 1548 1549 | /* Allocate the sqlite3_index_info structure */ pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo) + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm + sizeof(*pIdxOrderBy)*nOrderBy ); if( pIdxInfo==0 ){ sqlite3ErrorMsg(pParse, "out of memory"); | > | | 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 | /* Allocate the sqlite3_index_info structure */ pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo) + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm + sizeof(*pIdxOrderBy)*nOrderBy ); if( pIdxInfo==0 ){ sqlite3ErrorMsg(pParse, "out of memory"); /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ return (double)0; } *ppIdxInfo = pIdxInfo; /* Initialize the structure. The sqlite3_index_info structure contains ** many fields that are declared "const" to prevent xBestIndex from ** changing them. We have to do some funky casting in order to ** initialize those fields. |
︙ | ︙ | |||
1646 1647 1648 1649 1650 1651 1652 | if( pIdxInfo->needToFreeIdxStr ){ sqlite3_free(pIdxInfo->idxStr); } pIdxInfo->idxStr = 0; pIdxInfo->idxNum = 0; pIdxInfo->needToFreeIdxStr = 0; pIdxInfo->orderByConsumed = 0; | > | | 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 | if( pIdxInfo->needToFreeIdxStr ){ sqlite3_free(pIdxInfo->idxStr); } pIdxInfo->idxStr = 0; pIdxInfo->idxNum = 0; pIdxInfo->needToFreeIdxStr = 0; pIdxInfo->orderByConsumed = 0; /* ((double)2) In case of SQLITE_OMIT_FLOATING_POINT... */ pIdxInfo->estimatedCost = SQLITE_BIG_DBL / ((double)2); nOrderBy = pIdxInfo->nOrderBy; if( pIdxInfo->nOrderBy && !orderByUsable ){ *(int*)&pIdxInfo->nOrderBy = 0; } (void)sqlite3SafetyOff(pParse->db); WHERETRACE(("xBestIndex for %s\n", pTab->zName)); |
︙ | ︙ | |||
1675 1676 1677 1678 1679 1680 1681 | sqlite3DbFree(pParse->db, pVtab->zErrMsg); pVtab->zErrMsg = 0; for(i=0; i<pIdxInfo->nConstraint; i++){ if( !pIdxInfo->aConstraint[i].usable && pUsage[i].argvIndex>0 ){ sqlite3ErrorMsg(pParse, "table %s: xBestIndex returned an invalid plan", pTab->zName); | > | | 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 | sqlite3DbFree(pParse->db, pVtab->zErrMsg); pVtab->zErrMsg = 0; for(i=0; i<pIdxInfo->nConstraint; i++){ if( !pIdxInfo->aConstraint[i].usable && pUsage[i].argvIndex>0 ){ sqlite3ErrorMsg(pParse, "table %s: xBestIndex returned an invalid plan", pTab->zName); /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ return (double)0; } } *(int*)&pIdxInfo->nOrderBy = nOrderBy; return pIdxInfo->estimatedCost; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
︙ | ︙ | |||
3088 3089 3090 3091 3092 3093 3094 | ppIdxInfo); sCost.plan.wsFlags = WHERE_VIRTUALTABLE; sCost.plan.u.pVtabIdx = pVtabIdx = *ppIdxInfo; if( pVtabIdx && pVtabIdx->orderByConsumed ){ sCost.plan.wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY; } sCost.plan.nEq = 0; | > | > | | 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 | ppIdxInfo); sCost.plan.wsFlags = WHERE_VIRTUALTABLE; sCost.plan.u.pVtabIdx = pVtabIdx = *ppIdxInfo; if( pVtabIdx && pVtabIdx->orderByConsumed ){ sCost.plan.wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY; } sCost.plan.nEq = 0; /* (double)2 In case of SQLITE_OMIT_FLOATING_POINT... */ if( (SQLITE_BIG_DBL/((double)2))<sCost.rCost ){ /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the ** inital value of lowestCost in this loop. If it is, then ** the (cost<lowestCost) test below will never be true. */ /* (double)2 In case of SQLITE_OMIT_FLOATING_POINT... */ sCost.rCost = (SQLITE_BIG_DBL/((double)2)); } }else #endif { bestIndex(pParse, pWC, pTabItem, notReady, (i==0 && ppOrderBy) ? *ppOrderBy : 0, &sCost); } |
︙ | ︙ |
Changes to test/expr.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # 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 expressions. # | | > | | > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # 2001 September 15 # # 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 expressions. # # $Id: expr.test,v 1.67 2009/02/04 03:59:25 shane Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a table to work with. # ifcapable floatingpoint { execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)} execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')} } ifcapable !floatingpoint { execsql {CREATE TABLE test1(i1 int, i2 int, t1 text, t2 text)} execsql {INSERT INTO test1 VALUES(1,2,'hello','world')} } proc test_expr {name settings expr result} { do_test $name [format { execsql {BEGIN; UPDATE test1 SET %s; SELECT %s FROM test1; ROLLBACK;} } $settings $expr] $result } test_expr expr-1.1 {i1=10, i2=20} {i1+i2} 30 |
︙ | ︙ | |||
43 44 45 46 47 48 49 | test_expr expr-1.15 {i1=20, i2=20} {i2<=i1} 1 test_expr expr-1.16 {i1=20, i2=20} {i2>i1} 0 test_expr expr-1.17 {i1=20, i2=20} {i2>=i1} 1 test_expr expr-1.18 {i1=20, i2=20} {i2!=i1} 0 test_expr expr-1.19 {i1=20, i2=20} {i2=i1} 1 test_expr expr-1.20 {i1=20, i2=20} {i2<>i1} 0 test_expr expr-1.21 {i1=20, i2=20} {i2==i1} 1 | > | | > | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | test_expr expr-1.15 {i1=20, i2=20} {i2<=i1} 1 test_expr expr-1.16 {i1=20, i2=20} {i2>i1} 0 test_expr expr-1.17 {i1=20, i2=20} {i2>=i1} 1 test_expr expr-1.18 {i1=20, i2=20} {i2!=i1} 0 test_expr expr-1.19 {i1=20, i2=20} {i2=i1} 1 test_expr expr-1.20 {i1=20, i2=20} {i2<>i1} 0 test_expr expr-1.21 {i1=20, i2=20} {i2==i1} 1 ifcapable floatingpoint { test_expr expr-1.22 {i1=1, i2=2, r1=3.0} {i1+i2*r1} {7.0} test_expr expr-1.23 {i1=1, i2=2, r1=3.0} {(i1+i2)*r1} {9.0} } test_expr expr-1.24 {i1=1, i2=2} {min(i1,i2,i1+i2,i1-i2)} {-1} test_expr expr-1.25 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3} test_expr expr-1.26 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3} test_expr expr-1.27 {i1=1, i2=2} {i1==1 AND i2=2} {1} test_expr expr-1.28 {i1=1, i2=2} {i1=2 AND i2=1} {0} test_expr expr-1.29 {i1=1, i2=2} {i1=1 AND i2=1} {0} test_expr expr-1.30 {i1=1, i2=2} {i1=2 AND i2=2} {0} |
︙ | ︙ | |||
130 131 132 133 134 135 136 | test_expr expr-1.98 {i1=NULL, i2=NULL} {coalesce(i1|i2,99)} 99 test_expr expr-1.99 {i1=32, i2=NULL} {coalesce(i1&i2,99)} 99 test_expr expr-1.100 {i1=1, i2=''} {i1=i2} 0 test_expr expr-1.101 {i1=0, i2=''} {i1=i2} 0 # Check for proper handling of 64-bit integer values. # | > | | > > | | | | > > | > > > > | | > > | | | > > | | | | | | | | | | | | | | | | | | | | | | | | | | > | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | test_expr expr-1.98 {i1=NULL, i2=NULL} {coalesce(i1|i2,99)} 99 test_expr expr-1.99 {i1=32, i2=NULL} {coalesce(i1&i2,99)} 99 test_expr expr-1.100 {i1=1, i2=''} {i1=i2} 0 test_expr expr-1.101 {i1=0, i2=''} {i1=i2} 0 # Check for proper handling of 64-bit integer values. # if {[working_64bit_int]} { test_expr expr-1.102 {i1=40, i2=1} {i2<<i1} 1099511627776 } ifcapable floatingpoint { test_expr expr-1.103 {i1=0} {(-2147483648.0 % -1)} 0.0 test_expr expr-1.104 {i1=0} {(-9223372036854775808.0 % -1)} 0.0 test_expr expr-1.105 {i1=0} {(-9223372036854775808.0 / -1)>1} 1 } if {[working_64bit_int]} { test_expr expr-1.106 {i1=0} {(1<<63)/-1} -9223372036854775808 } test_expr expr-1.107 {i1=0} {(1<<63)%-1} 0 test_expr expr-1.108 {i1=0} {1%0} {{}} test_expr expr-1.109 {i1=0} {1/0} {{}} if {[working_64bit_int]} { test_expr expr-1.110 {i1=0} {-9223372036854775807/-1} 9223372036854775807 } ifcapable floatingpoint { test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57 test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11 test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782 } set tcl_precision 15 ifcapable floatingpoint { test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641025641026 test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90243902439024 test_expr expr-2.6 {r1=1.23, r2=2.34} {r2<r1} 0 test_expr expr-2.7 {r1=1.23, r2=2.34} {r2<=r1} 0 test_expr expr-2.8 {r1=1.23, r2=2.34} {r2>r1} 1 test_expr expr-2.9 {r1=1.23, r2=2.34} {r2>=r1} 1 test_expr expr-2.10 {r1=1.23, r2=2.34} {r2!=r1} 1 test_expr expr-2.11 {r1=1.23, r2=2.34} {r2=r1} 0 test_expr expr-2.12 {r1=1.23, r2=2.34} {r2<>r1} 1 test_expr expr-2.13 {r1=1.23, r2=2.34} {r2==r1} 0 test_expr expr-2.14 {r1=2.34, r2=2.34} {r2<r1} 0 test_expr expr-2.15 {r1=2.34, r2=2.34} {r2<=r1} 1 test_expr expr-2.16 {r1=2.34, r2=2.34} {r2>r1} 0 test_expr expr-2.17 {r1=2.34, r2=2.34} {r2>=r1} 1 test_expr expr-2.18 {r1=2.34, r2=2.34} {r2!=r1} 0 test_expr expr-2.19 {r1=2.34, r2=2.34} {r2=r1} 1 test_expr expr-2.20 {r1=2.34, r2=2.34} {r2<>r1} 0 test_expr expr-2.21 {r1=2.34, r2=2.34} {r2==r1} 1 test_expr expr-2.22 {r1=1.23, r2=2.34} {min(r1,r2,r1+r2,r1-r2)} {-1.11} test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57} test_expr expr-2.24 {r1=25.0, r2=11.0} {r1%r2} 3.0 test_expr expr-2.25 {r1=1.23, r2=NULL} {coalesce(r1+r2,99.0)} 99.0 test_expr expr-2.26 {r1=1e300, r2=1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0 test_expr expr-2.26b {r1=1e300, r2=-1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0 test_expr expr-2.27 {r1=1.1, r2=0.0} {r1/r2} {{}} test_expr expr-2.28 {r1=1.1, r2=0.0} {r1%r2} {{}} } test_expr expr-3.1 {t1='abc', t2='xyz'} {t1<t2} 1 test_expr expr-3.2 {t1='xyz', t2='abc'} {t1<t2} 0 test_expr expr-3.3 {t1='abc', t2='abc'} {t1<t2} 0 test_expr expr-3.4 {t1='abc', t2='xyz'} {t1<=t2} 1 test_expr expr-3.5 {t1='xyz', t2='abc'} {t1<=t2} 0 test_expr expr-3.6 {t1='abc', t2='abc'} {t1<=t2} 1 |
︙ | ︙ | |||
229 230 231 232 233 234 235 | test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1<t2} 0 test_expr expr-4.4 {t1='abc', t2='Bbc'} {t1>t2} 1 test_expr expr-4.5 {t1='0', t2='0.0'} {t1==t2} 0 test_expr expr-4.6 {t1='0.000', t2='0.0'} {t1==t2} 0 test_expr expr-4.7 {t1=' 0.000', t2=' 0.0'} {t1==t2} 0 test_expr expr-4.8 {t1='0.0', t2='abc'} {t1<t2} 1 test_expr expr-4.9 {t1='0.0', t2='abc'} {t1==t2} 0 | > > | | | | | | | | | | | > | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1<t2} 0 test_expr expr-4.4 {t1='abc', t2='Bbc'} {t1>t2} 1 test_expr expr-4.5 {t1='0', t2='0.0'} {t1==t2} 0 test_expr expr-4.6 {t1='0.000', t2='0.0'} {t1==t2} 0 test_expr expr-4.7 {t1=' 0.000', t2=' 0.0'} {t1==t2} 0 test_expr expr-4.8 {t1='0.0', t2='abc'} {t1<t2} 1 test_expr expr-4.9 {t1='0.0', t2='abc'} {t1==t2} 0 ifcapable floatingpoint { test_expr expr-4.10 {r1='0.0', r2='abc'} {r1>r2} 0 test_expr expr-4.11 {r1='abc', r2='Abc'} {r1<r2} 0 test_expr expr-4.12 {r1='abc', r2='Abc'} {r1>r2} 1 test_expr expr-4.13 {r1='abc', r2='Bbc'} {r1<r2} 0 test_expr expr-4.14 {r1='abc', r2='Bbc'} {r1>r2} 1 test_expr expr-4.15 {r1='0', r2='0.0'} {r1==r2} 1 test_expr expr-4.16 {r1='0.000', r2='0.0'} {r1==r2} 1 test_expr expr-4.17 {r1=' 0.000', r2=' 0.0'} {r1==r2} 0 test_expr expr-4.18 {r1='0.0', r2='abc'} {r1<r2} 1 test_expr expr-4.19 {r1='0.0', r2='abc'} {r1==r2} 0 test_expr expr-4.20 {r1='0.0', r2='abc'} {r1>r2} 0 } # CSL is true if LIKE is case sensitive and false if not. # NCSL is the opposite. Use these variables as the result # on operations where case makes a difference. set CSL $sqlite_options(casesensitivelike) set NCSL [expr {!$CSL}] |
︙ | ︙ | |||
571 572 573 574 575 576 577 | test_expr2 expr-7.33 {(b=0 OR a<0) AND a IS NULL} {{}} test_expr2 expr-7.34 {(a<0 AND b=0) AND a IS NULL} {} test_expr2 expr-7.35 {(b=0 AND a<0) AND a IS NULL} {} test_expr2 expr-7.36 {a<2 OR (a<0 OR b=0)} {{} 1} test_expr2 expr-7.37 {a<2 OR (b=0 OR a<0)} {{} 1} test_expr2 expr-7.38 {a<2 OR (a<0 AND b=0)} {1} test_expr2 expr-7.39 {a<2 OR (b=0 AND a<0)} {1} | > | > | 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | test_expr2 expr-7.33 {(b=0 OR a<0) AND a IS NULL} {{}} test_expr2 expr-7.34 {(a<0 AND b=0) AND a IS NULL} {} test_expr2 expr-7.35 {(b=0 AND a<0) AND a IS NULL} {} test_expr2 expr-7.36 {a<2 OR (a<0 OR b=0)} {{} 1} test_expr2 expr-7.37 {a<2 OR (b=0 OR a<0)} {{} 1} test_expr2 expr-7.38 {a<2 OR (a<0 AND b=0)} {1} test_expr2 expr-7.39 {a<2 OR (b=0 AND a<0)} {1} ifcapable floatingpoint { test_expr2 expr-7.40 {((a<2 OR a IS NULL) AND b<3) OR b>1e10} {{} 1} } test_expr2 expr-7.41 {a BETWEEN -1 AND 1} {1} test_expr2 expr-7.42 {a NOT BETWEEN 2 AND 100} {1} test_expr2 expr-7.43 {(b+1234)||'this is a string that is at least 32 characters long' BETWEEN 1 AND 2} {} test_expr2 expr-7.44 {123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a BETWEEN '123a' AND '123b'} {} test_expr2 expr-7.45 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123b')<0} {} test_expr2 expr-7.46 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123z')>0} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} |
︙ | ︙ | |||
610 611 612 613 614 615 616 | test_expr2 expr-7.65 {b = abs(+-2)} {1} test_expr2 expr-7.66 {b = abs(++-2)} {1} test_expr2 expr-7.67 {b = abs(+-+-2)} {1} test_expr2 expr-7.68 {b = abs(+-++-2)} {1} test_expr2 expr-7.69 {b = abs(++++-2)} {1} test_expr2 expr-7.70 {b = 5 - abs(+3)} {1} test_expr2 expr-7.71 {b = 5 - abs(-3)} {1} | > | > > | | > | | | | | | | | | | > > | | | > | 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | test_expr2 expr-7.65 {b = abs(+-2)} {1} test_expr2 expr-7.66 {b = abs(++-2)} {1} test_expr2 expr-7.67 {b = abs(+-+-2)} {1} test_expr2 expr-7.68 {b = abs(+-++-2)} {1} test_expr2 expr-7.69 {b = abs(++++-2)} {1} test_expr2 expr-7.70 {b = 5 - abs(+3)} {1} test_expr2 expr-7.71 {b = 5 - abs(-3)} {1} ifcapable floatingpoint { test_expr2 expr-7.72 {b = abs(-2.0)} {1} } test_expr2 expr-7.73 {b = 6 - abs(-a)} {2} ifcapable floatingpoint { test_expr2 expr-7.74 {b = abs(8.0)} {3} } # Test the CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP expressions. # ifcapable {floatingpoint} { set sqlite_current_time 1157124849 do_test expr-8.1 { execsql {SELECT CURRENT_TIME} } {15:34:09} do_test expr-8.2 { execsql {SELECT CURRENT_DATE} } {2006-09-01} do_test expr-8.3 { execsql {SELECT CURRENT_TIMESTAMP} } {{2006-09-01 15:34:09}} } ifcapable datetime { do_test expr-8.4 { execsql {SELECT CURRENT_TIME==time('now');} } 1 do_test expr-8.5 { execsql {SELECT CURRENT_DATE==date('now');} } 1 do_test expr-8.6 { execsql {SELECT CURRENT_TIMESTAMP==datetime('now');} } 1 } set sqlite_current_time 0 ifcapable floatingpoint { do_test expr-9.1 { execsql {SELECT round(-('-'||'123'))} } 123.0 } # Test an error message that can be generated by the LIKE expression do_test expr-10.1 { catchsql {SELECT 'abc' LIKE 'abc' ESCAPE ''} } {1 {ESCAPE expression must be a single character}} do_test expr-10.2 { catchsql {SELECT 'abc' LIKE 'abc' ESCAPE 'ab'} |
︙ | ︙ | |||
685 686 687 688 689 690 691 | } {real} do_test expr-11.11 { execsql {SELECT typeof(-9223372036854775808)} } {integer} do_test expr-11.12 { execsql {SELECT typeof(-00000009223372036854775808)} } {integer} | > | | | | | | > > | | | | | | > > | | | | | | | | | | | > > | | | | | | | | | | > | 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | } {real} do_test expr-11.11 { execsql {SELECT typeof(-9223372036854775808)} } {integer} do_test expr-11.12 { execsql {SELECT typeof(-00000009223372036854775808)} } {integer} ifcapable floatingpoint { do_test expr-11.13 { execsql {SELECT typeof(-9223372036854775809)} } {real} do_test expr-11.14 { execsql {SELECT typeof(-00000009223372036854775809)} } {real} } # These two statements used to leak memory (because of missing %destructor # directives in parse.y). do_test expr-12.1 { catchsql { SELECT (CASE a>4 THEN 1 ELSE 0 END) FROM test1; } } {1 {near "THEN": syntax error}} do_test expr-12.2 { catchsql { SELECT (CASE WHEN a>4 THEN 1 ELSE 0) FROM test1; } } {1 {near ")": syntax error}} ifcapable floatingpoint { do_test expr-13.1 { execsql { SELECT 12345678901234567890; } } {1.23456789012346e+19} } # Implicit String->Integer conversion is used when possible. # if {[working_64bit_int]} { do_test expr-13.2 { execsql { SELECT 0+'9223372036854775807' } } {9223372036854775807} do_test expr-13.3 { execsql { SELECT '9223372036854775807'+0 } } {9223372036854775807} } # If the value is too large, use String->Float conversion. # ifcapable floatingpoint { do_test expr-13.4 { execsql { SELECT 0+'9223372036854775808' } } {9.22337203685478e+18} do_test expr-13.5 { execsql { SELECT '9223372036854775808'+0 } } {9.22337203685478e+18} } # Use String->float conversion if the value is explicitly a floating # point value. # do_test expr-13.6 { execsql { SELECT 0+'9223372036854775807.0' |
︙ | ︙ |
Changes to test/func.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # 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 built-in functions. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2001 September 15 # # 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 built-in functions. # # $Id: func.test,v 1.91 2009/02/04 03:59:25 shane Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a table to work with. # do_test func-0.0 { |
︙ | ︙ | |||
145 146 147 148 149 150 151 | execsql {SELECT t1 FROM tbl1} } {this program is free software} } ;# End \u1234!=u1234 # Test the abs() and round() functions. # | > | | | | > > > > > > > > > > > | | | | | > > | | | | | | > > > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | execsql {SELECT t1 FROM tbl1} } {this program is free software} } ;# End \u1234!=u1234 # Test the abs() and round() functions. # ifcapable !floatingpoint { do_test func-4.1 { execsql { CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3); INSERT INTO t1 VALUES(2,12345678901234,-1234567890); INSERT INTO t1 VALUES(3,-2,-5); } catchsql {SELECT abs(a,b) FROM t1} } {1 {wrong number of arguments to function abs()}} } ifcapable floatingpoint { do_test func-4.1 { execsql { CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3); INSERT INTO t1 VALUES(2,1.2345678901234,-12345.67890); INSERT INTO t1 VALUES(3,-2,-5); } catchsql {SELECT abs(a,b) FROM t1} } {1 {wrong number of arguments to function abs()}} } do_test func-4.2 { catchsql {SELECT abs() FROM t1} } {1 {wrong number of arguments to function abs()}} ifcapable floatingpoint { do_test func-4.3 { catchsql {SELECT abs(b) FROM t1 ORDER BY a} } {0 {2 1.2345678901234 2}} do_test func-4.4 { catchsql {SELECT abs(c) FROM t1 ORDER BY a} } {0 {3 12345.6789 5}} } ifcapable !floatingpoint { if {[working_64bit_int]} { do_test func-4.3 { catchsql {SELECT abs(b) FROM t1 ORDER BY a} } {0 {2 12345678901234 2}} } do_test func-4.4 { catchsql {SELECT abs(c) FROM t1 ORDER BY a} } {0 {3 1234567890 5}} } do_test func-4.4.1 { execsql {SELECT abs(a) FROM t2} } {1 {} 345 {} 67890} do_test func-4.4.2 { execsql {SELECT abs(t1) FROM tbl1} } {0.0 0.0 0.0 0.0 0.0} ifcapable floatingpoint { do_test func-4.5 { catchsql {SELECT round(a,b,c) FROM t1} } {1 {wrong number of arguments to function round()}} do_test func-4.6 { catchsql {SELECT round(b,2) FROM t1 ORDER BY b} } {0 {-2.0 1.23 2.0}} do_test func-4.7 { catchsql {SELECT round(b,0) FROM t1 ORDER BY a} } {0 {2.0 1.0 -2.0}} do_test func-4.8 { catchsql {SELECT round(c) FROM t1 ORDER BY a} } {0 {3.0 -12346.0 -5.0}} do_test func-4.9 { catchsql {SELECT round(c,a) FROM t1 ORDER BY a} } {0 {3.0 -12345.68 -5.0}} do_test func-4.10 { catchsql {SELECT 'x' || round(c,a) || 'y' FROM t1 ORDER BY a} } {0 {x3.0y x-12345.68y x-5.0y}} do_test func-4.11 { catchsql {SELECT round() FROM t1 ORDER BY a} } {1 {wrong number of arguments to function round()}} do_test func-4.12 { execsql {SELECT coalesce(round(a,2),'nil') FROM t2} } {1.0 nil 345.0 nil 67890.0} do_test func-4.13 { execsql {SELECT round(t1,2) FROM tbl1} } {0.0 0.0 0.0 0.0 0.0} do_test func-4.14 { execsql {SELECT typeof(round(5.1,1));} } {real} do_test func-4.15 { execsql {SELECT typeof(round(5.1));} } {real} do_test func-4.16 { catchsql {SELECT round(b,2.0) FROM t1 ORDER BY b} } {0 {-2.0 1.23 2.0}} } # Test the upper() and lower() functions # do_test func-5.1 { execsql {SELECT upper(t1) FROM tbl1} } {THIS PROGRAM IS FREE SOFTWARE} do_test func-5.2 { |
︙ | ︙ | |||
252 253 254 255 256 257 258 | # do_test func-7.1 { execsql {SELECT last_insert_rowid()} } [db last_insert_rowid] # Tests for aggregate functions and how they handle NULLs. # | > | | | | | | | | > > > > > > > > > > > | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | # do_test func-7.1 { execsql {SELECT last_insert_rowid()} } [db last_insert_rowid] # Tests for aggregate functions and how they handle NULLs. # ifcapable floatingpoint { do_test func-8.1 { ifcapable explain { execsql {EXPLAIN SELECT sum(a) FROM t2;} } execsql { SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2; } } {68236 3 22745.33 1 67890 5} } ifcapable !floatingpoint { do_test func-8.1 { ifcapable explain { execsql {EXPLAIN SELECT sum(a) FROM t2;} } execsql { SELECT sum(a), count(a), avg(a), min(a), max(a), count(*) FROM t2; } } {68236 3 22745.0 1 67890 5} } do_test func-8.2 { execsql { SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2; } } {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} ifcapable tempdb { |
︙ | ︙ | |||
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | } {integer} do_test func-8.7 { execsql { SELECT typeof(sum(x)) FROM (SELECT '9223372036' || '854775808' AS x UNION ALL SELECT -9223372036854775807) } } {real} do_test func-8.8 { execsql { SELECT sum(x)>0.0 FROM (SELECT '9223372036' || '854775808' AS x UNION ALL SELECT -9223372036850000000) } } {1} } # How do you test the random() function in a meaningful, deterministic way? # do_test func-9.1 { execsql { SELECT random() is not null; | > > > > > > > > > > | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | } {integer} do_test func-8.7 { execsql { SELECT typeof(sum(x)) FROM (SELECT '9223372036' || '854775808' AS x UNION ALL SELECT -9223372036854775807) } } {real} ifcapable floatingpoint { do_test func-8.8 { execsql { SELECT sum(x)>0.0 FROM (SELECT '9223372036' || '854775808' AS x UNION ALL SELECT -9223372036850000000) } } {1} } ifcapable !floatingpoint { do_test func-8.8 { execsql { SELECT sum(x)>0 FROM (SELECT '9223372036' || '854775808' AS x UNION ALL SELECT -9223372036850000000) } } {1} } } # How do you test the random() function in a meaningful, deterministic way? # do_test func-9.1 { execsql { SELECT random() is not null; |
︙ | ︙ | |||
402 403 404 405 406 407 408 | execsql { SELECT testfunc( 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'string', NULL ); } } {{}} | > > | | | | | | | | | | | | | | | | | | | | | | | | | | > | 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | execsql { SELECT testfunc( 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'string', NULL ); } } {{}} ifcapable floatingpoint { do_test func-10.4 { execsql { SELECT testfunc( 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'double', 1.234 ); } } {1.234} do_test func-10.5 { execsql { SELECT testfunc( 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'int', 1234, 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'string', NULL, 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'double', 1.234, 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'int', 1234, 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'string', NULL, 'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'double', 1.234 ); } } {1.234} } # Test the built-in sqlite_version(*) SQL function. # do_test func-11.1 { execsql { SELECT sqlite_version(*); } |
︙ | ︙ | |||
606 607 608 609 610 611 612 | CREATE TABLE t5(x); INSERT INTO t5 VALUES(1); INSERT INTO t5 VALUES(-99); INSERT INTO t5 VALUES(10000); SELECT sum(x) FROM t5; } } {9902} | > | | | | | | > | 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | CREATE TABLE t5(x); INSERT INTO t5 VALUES(1); INSERT INTO t5 VALUES(-99); INSERT INTO t5 VALUES(10000); SELECT sum(x) FROM t5; } } {9902} ifcapable floatingpoint { do_test func-18.2 { execsql { INSERT INTO t5 VALUES(0.0); SELECT sum(x) FROM t5; } } {9902.0} } # The sum of nothing is NULL. But the sum of all NULLs is NULL. # # The TOTAL of nothing is 0.0. # do_test func-18.3 { execsql { |
︙ | ︙ | |||
659 660 661 662 663 664 665 | } } 0 do_test func-18.11 { execsql { SELECT typeof(sum(x)) FROM t6 } } integer | > | | | | | | | | | | | > > > > > > > > > > > > > > > | | | | | | > | | | | | | | | | | | | | | > | 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | } } 0 do_test func-18.11 { execsql { SELECT typeof(sum(x)) FROM t6 } } integer ifcapable floatingpoint { do_test func-18.12 { catchsql { INSERT INTO t6 VALUES(1<<62); SELECT sum(x) - ((1<<62)*2.0+1) from t6; } } {1 {integer overflow}} do_test func-18.13 { execsql { SELECT total(x) - ((1<<62)*2.0+1) FROM t6 } } 0.0 } ifcapable !floatingpoint { do_test func-18.12 { catchsql { INSERT INTO t6 VALUES(1<<62); SELECT sum(x) - ((1<<62)*2+1) from t6; } } {1 {integer overflow}} do_test func-18.13 { execsql { SELECT total(x) - ((1<<62)*2+1) FROM t6 } } 0.0 } if {[working_64bit_int]} { do_test func-18.14 { execsql { SELECT sum(-9223372036854775805); } } -9223372036854775805 } ifcapable compound&&subquery { do_test func-18.15 { catchsql { SELECT sum(x) FROM (SELECT 9223372036854775807 AS x UNION ALL SELECT 10 AS x); } } {1 {integer overflow}} if {[working_64bit_int]} { do_test func-18.16 { catchsql { SELECT sum(x) FROM (SELECT 9223372036854775807 AS x UNION ALL SELECT -10 AS x); } } {0 9223372036854775797} do_test func-18.17 { catchsql { SELECT sum(x) FROM (SELECT -9223372036854775807 AS x UNION ALL SELECT 10 AS x); } } {0 -9223372036854775797} } do_test func-18.18 { catchsql { SELECT sum(x) FROM (SELECT -9223372036854775807 AS x UNION ALL SELECT -10 AS x); } } {1 {integer overflow}} |
︙ | ︙ | |||
731 732 733 734 735 736 737 | } } {0 1} } ;# ifcapable compound&&subquery # Integer overflow on abs() # | > | | | | | > | 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 | } } {0 1} } ;# ifcapable compound&&subquery # Integer overflow on abs() # if {[working_64bit_int]} { do_test func-18.31 { catchsql { SELECT abs(-9223372036854775807); } } {0 9223372036854775807} } do_test func-18.32 { catchsql { SELECT abs(-9223372036854775807-1); } } {1 {integer overflow}} # The MATCH function exists but is only a stub and always throws an error. |
︙ | ︙ |