Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Implement type affinity for table and index records (CVS 1375) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
dbfe6e93166d9557d66cab9dca7977ba |
User & Date: | danielk1977 2004-05-14 11:00:53.000 |
Context
2004-05-14
| ||
11:16 | Delete some code no longer in use (CVS 1376) (check-in: f24aedc2b0 user: danielk1977 tags: trunk) | |
11:00 | Implement type affinity for table and index records (CVS 1375) (check-in: dbfe6e9316 user: danielk1977 tags: trunk) | |
01:58 | Changes to btree and pager in preparation for moving to run-time page size determination. (CVS 1374) (check-in: f63fb6dd4e user: drh tags: trunk) | |
Changes
Changes to src/build.c.
︙ | ︙ | |||
19 20 21 22 23 24 25 | ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** PRAGMA ** | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** PRAGMA ** ** $Id: build.c,v 1.183 2004/05/14 11:00:53 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** This routine is called when a new SQL statement is beginning to ** be parsed. Check to see if the schema for the database needs |
︙ | ︙ | |||
346 347 348 349 350 351 352 353 354 355 356 357 358 359 | for(i=0; i<pTable->nCol; i++){ sqliteFree(pTable->aCol[i].zName); sqliteFree(pTable->aCol[i].zDflt); sqliteFree(pTable->aCol[i].zType); } sqliteFree(pTable->zName); sqliteFree(pTable->aCol); sqlite3SelectDelete(pTable->pSelect); sqliteFree(pTable); } /* ** Unlink the given table from the hash tables and the delete the ** table structure with all its indices and foreign keys. | > > > | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | for(i=0; i<pTable->nCol; i++){ sqliteFree(pTable->aCol[i].zName); sqliteFree(pTable->aCol[i].zDflt); sqliteFree(pTable->aCol[i].zType); } sqliteFree(pTable->zName); sqliteFree(pTable->aCol); if( pTable->zColAff ){ sqliteFree(pTable->zColAff); } sqlite3SelectDelete(pTable->pSelect); sqliteFree(pTable); } /* ** Unlink the given table from the hash tables and the delete the ** table structure with all its indices and foreign keys. |
︙ | ︙ |
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.19 2004/05/14 11:00:53 danielk1977 Exp $ ** ** NOTES: ** ** 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. |
︙ | ︙ | |||
317 318 319 320 321 322 323 | double r; if( sqlite3OsCurrentTime(&r)==0 ){ p->rJD = r; p->validJD = 1; return 0; } return 1; | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | double r; if( sqlite3OsCurrentTime(&r)==0 ){ p->rJD = r; p->validJD = 1; return 0; } return 1; }else if( sqlite3IsNumber(zDate, 0) ){ p->rJD = sqlite3AtoF(zDate, 0); p->validJD = 1; return 0; } return 1; } |
︙ | ︙ |
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.47 2004/05/14 11:00:53 danielk1977 Exp $ */ #include <ctype.h> #include <math.h> #include <stdlib.h> #include <assert.h> #include "sqliteInt.h" #include "os.h" |
︙ | ︙ | |||
291 292 293 294 295 296 297 | ** "NULL". Otherwise, the argument is enclosed in single quotes with ** single-quote escapes. */ static void quoteFunc(sqlite_func *context, int argc, const char **argv){ if( argc<1 ) return; if( argv[0]==0 ){ sqlite3_set_result_string(context, "NULL", 4); | | | 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | ** "NULL". Otherwise, the argument is enclosed in single quotes with ** single-quote escapes. */ static void quoteFunc(sqlite_func *context, int argc, const char **argv){ if( argc<1 ) return; if( argv[0]==0 ){ sqlite3_set_result_string(context, "NULL", 4); }else if( sqlite3IsNumber(argv[0], 0) ){ sqlite3_set_result_string(context, argv[0], -1); }else{ int i,j,n; char *z; for(i=n=0; argv[0][i]; i++){ if( argv[0][i]=='\'' ) n++; } z = sqliteMalloc( i+n+3 ); if( z==0 ) return; |
︙ | ︙ |
Changes to src/insert.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 C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** ** $Id: insert.c,v 1.98 2004/05/14 11:00:53 danielk1977 Exp $ */ #include "sqliteInt.h" /* ** Set P3 of the most recently inserted opcode to a column affinity ** string for table pTab. A column affinity string has one character ** for each column in the table, according to the affinity of the column: ** ** Character Column affinity ** ------------------------------ ** 'n' NUMERIC ** 'i' INTEGER ** 't' TEXT ** 'o' NONE */ int sqlite3AddRecordType(Vdbe *v, Table *pTab){ assert( pTab ); /* The first time a column affinity string for a particular table ** is required, it is allocated and populated here. It is then ** stored as a member of the Table structure for subsequent use. ** ** The column affinity string will eventually be deleted by ** sqlite3DeleteTable() when the Table structure itself is cleaned up. */ if( !pTab->zColAff ){ char *zColAff; int i; zColAff = sqliteMalloc(pTab->nCol+1); if( !zColAff ){ return SQLITE_NOMEM; } for(i=0; i<pTab->nCol; i++){ if( pTab->aCol[i].sortOrder&SQLITE_SO_TEXT ){ zColAff[i] = 't'; }else{ zColAff[i] = 'n'; } } zColAff[pTab->nCol] = '\0'; pTab->zColAff = zColAff; } /* Set the memory management at the vdbe to P3_STATIC, as the column ** affinity string is managed as part of the Table structure. */ sqlite3VdbeChangeP3(v, -1, pTab->zColAff, P3_STATIC); return SQLITE_OK; } /* ** This routine is call to handle SQL of the following forms: ** ** insert into TABLE (IDLIST) values(EXPRLIST) ** insert into TABLE (IDLIST) select ** |
︙ | ︙ | |||
212 213 214 215 216 217 218 219 220 221 222 223 224 225 | if( useTempTable ){ /* Generate the subroutine that SELECT calls to process each row of ** the result. Store the result in a temporary table */ srcTab = pParse->nTab++; sqlite3VdbeResolveLabel(v, iInsertBlock); sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); sqlite3VdbeAddOp(v, OP_NewRecno, srcTab, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, srcTab, 0); sqlite3VdbeAddOp(v, OP_Return, 0, 0); /* The following code runs first because the GOTO at the very top ** of the program jumps to it. Create the temporary table, then jump | > | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | if( useTempTable ){ /* Generate the subroutine that SELECT calls to process each row of ** the result. Store the result in a temporary table */ srcTab = pParse->nTab++; sqlite3VdbeResolveLabel(v, iInsertBlock); sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); sqlite3AddRecordType(v, pTab); sqlite3VdbeAddOp(v, OP_NewRecno, srcTab, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, srcTab, 0); sqlite3VdbeAddOp(v, OP_Return, 0, 0); /* The following code runs first because the GOTO at the very top ** of the program jumps to it. Create the temporary table, then jump |
︙ | ︙ | |||
390 391 392 393 394 395 396 397 398 399 400 401 402 403 | }else if( pSelect ){ sqlite3VdbeAddOp(v, OP_Dup, nColumn-j-1, 1); }else{ sqlite3ExprCode(pParse, pList->a[j].pExpr); } } sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0); /* Fire BEFORE or INSTEAD OF triggers */ if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab, newIdx, -1, onError, endOfLoop) ){ goto insert_cleanup; } | > | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | }else if( pSelect ){ sqlite3VdbeAddOp(v, OP_Dup, nColumn-j-1, 1); }else{ sqlite3ExprCode(pParse, pList->a[j].pExpr); } } sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); sqlite3AddRecordType(v, pTab); sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0); /* Fire BEFORE or INSTEAD OF triggers */ if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab, newIdx, -1, onError, endOfLoop) ){ goto insert_cleanup; } |
︙ | ︙ | |||
879 880 881 882 883 884 885 886 887 888 889 890 891 892 | assert( pTab->pSelect==0 ); /* This table is not a VIEW */ for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){} for(i=nIdx-1; i>=0; i--){ if( aIdxUsed && aIdxUsed[i]==0 ) continue; sqlite3VdbeAddOp(v, OP_IdxPut, base+i+1, 0); } sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); if( newIdx>=0 ){ sqlite3VdbeAddOp(v, OP_Dup, 1, 0); sqlite3VdbeAddOp(v, OP_Dup, 1, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0); } sqlite3VdbeAddOp(v, OP_PutIntKey, base, (pParse->trigStack?0:OPFLAG_NCHANGE) | | > | 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | assert( pTab->pSelect==0 ); /* This table is not a VIEW */ for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){} for(i=nIdx-1; i>=0; i--){ if( aIdxUsed && aIdxUsed[i]==0 ) continue; sqlite3VdbeAddOp(v, OP_IdxPut, base+i+1, 0); } sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); sqlite3AddRecordType(v, pTab); if( newIdx>=0 ){ sqlite3VdbeAddOp(v, OP_Dup, 1, 0); sqlite3VdbeAddOp(v, OP_Dup, 1, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0); } sqlite3VdbeAddOp(v, OP_PutIntKey, base, (pParse->trigStack?0:OPFLAG_NCHANGE) | |
︙ | ︙ |
Changes to src/shell.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 to implement the "sqlite" command line ** utility for accessing SQLite databases. ** | | | 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 to implement the "sqlite" command line ** utility for accessing SQLite databases. ** ** $Id: shell.c,v 1.96 2004/05/14 11:00:53 danielk1977 Exp $ */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include "sqlite.h" #include <ctype.h> |
︙ | ︙ | |||
76 77 78 79 80 81 82 | static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */ /* ** Determines if a string is a number of not. */ | | | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */ /* ** Determines if a string is a number of not. */ extern int sqlite3IsNumber(const char*, int*); /* ** This routine reads a line of text from standard input, stores ** the text in memory obtained from malloc() and returns a pointer ** to the text. NULL is returned at end of file, or if malloc() ** fails. ** |
︙ | ︙ | |||
388 389 390 391 392 393 394 | case MODE_Insert: { if( azArg==0 ) break; fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable); for(i=0; i<nArg; i++){ char *zSep = i>0 ? ",": ""; if( azArg[i]==0 ){ fprintf(p->out,"%sNULL",zSep); | | | 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | case MODE_Insert: { if( azArg==0 ) break; fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable); for(i=0; i<nArg; i++){ char *zSep = i>0 ? ",": ""; if( azArg[i]==0 ){ fprintf(p->out,"%sNULL",zSep); }else if( sqlite3IsNumber(azArg[i], 0) ){ fprintf(p->out,"%s%s",zSep, azArg[i]); }else{ if( zSep[0] ) fprintf(p->out,"%s",zSep); output_quoted_string(p->out, azArg[i]); } } fprintf(p->out,");\n"); |
︙ | ︙ |
Changes to src/sqliteInt.h.
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. ** ************************************************************************* ** Internal interface definitions for SQLite. ** | | | 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. ** ************************************************************************* ** Internal interface definitions for SQLite. ** ** @(#) $Id: sqliteInt.h,v 1.232 2004/05/14 11:00:53 danielk1977 Exp $ */ #include "config.h" #include "sqlite.h" #include "hash.h" #include "parse.h" #include <stdio.h> #include <stdlib.h> |
︙ | ︙ | |||
516 517 518 519 520 521 522 523 524 525 526 527 528 529 | u8 readOnly; /* True if this table should not be written by the user */ u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */ u8 isTransient; /* True if automatically deleted when VDBE finishes */ u8 hasPrimKey; /* True if there exists a primary key */ u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ Trigger *pTrigger; /* List of SQL triggers on this table */ FKey *pFKey; /* Linked list of all foreign keys in this table */ }; /* ** Each foreign key constraint is an instance of the following structure. ** ** A foreign key is associated with two tables. The "from" table is ** the table that contains the REFERENCES clause that creates the foreign | > | 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | u8 readOnly; /* True if this table should not be written by the user */ u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */ u8 isTransient; /* True if automatically deleted when VDBE finishes */ u8 hasPrimKey; /* True if there exists a primary key */ u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ Trigger *pTrigger; /* List of SQL triggers on this table */ FKey *pFKey; /* Linked list of all foreign keys in this table */ char *zColAff; /* String defining the affinity of each column */ }; /* ** Each foreign key constraint is an instance of the following structure. ** ** A foreign key is associated with two tables. The "from" table is ** the table that contains the REFERENCES clause that creates the foreign |
︙ | ︙ | |||
1106 1107 1108 1109 1110 1111 1112 | /* ** Internal function prototypes */ int sqlite3StrICmp(const char *, const char *); int sqlite3StrNICmp(const char *, const char *, int); int sqlite3HashNoCase(const char *, int); | | | 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | /* ** Internal function prototypes */ int sqlite3StrICmp(const char *, const char *); int sqlite3StrNICmp(const char *, const char *, int); int sqlite3HashNoCase(const char *, int); int sqlite3IsNumber(const char*, int*); int sqlite3Compare(const char *, const char *); int sqlite3SortCompare(const char *, const char *); void sqlite3RealToSortable(double r, char *); #ifdef MEMORY_DEBUG void *sqlite3Malloc_(int,int,char*,int); void sqlite3Free_(void*,char*,int); void *sqlite3Realloc_(void*,int,char*,int); |
︙ | ︙ | |||
1285 1286 1287 1288 1289 1290 1291 1292 1293 | void *sqlite3utf8to16be(const unsigned char *pIn, int N); void *sqlite3utf8to16le(const unsigned char *pIn, int N); void sqlite3utf16to16le(void *pData, int N); void sqlite3utf16to16be(void *pData, int N); int sqlite3PutVarint(unsigned char *, u64); int sqlite3GetVarint(const unsigned char *, u64 *); int sqlite3VarintLen(u64 v); | > | 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 | void *sqlite3utf8to16be(const unsigned char *pIn, int N); void *sqlite3utf8to16le(const unsigned char *pIn, int N); void sqlite3utf16to16le(void *pData, int N); void sqlite3utf16to16be(void *pData, int N); int sqlite3PutVarint(unsigned char *, u64); int sqlite3GetVarint(const unsigned char *, u64 *); int sqlite3VarintLen(u64 v); int sqlite3AddRecordType(Vdbe*, Table*); |
Changes to src/update.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 C code routines that are called by the parser ** to handle UPDATE statements. ** | | | 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 C code routines that are called by the parser ** to handle UPDATE statements. ** ** $Id: update.c,v 1.73 2004/05/14 11:00:53 danielk1977 Exp $ */ #include "sqliteInt.h" /* ** Process an UPDATE statement. ** ** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL; |
︙ | ︙ | |||
283 284 285 286 287 288 289 290 291 292 293 294 295 296 | if( j<0 ){ sqlite3VdbeAddOp(v, OP_Column, iCur, i); }else{ sqlite3ExprCode(pParse, pChanges->a[j].pExpr); } } sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0); if( !isView ){ sqlite3VdbeAddOp(v, OP_Close, iCur, 0); } /* Fire the BEFORE and INSTEAD OF triggers */ | > | 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | if( j<0 ){ sqlite3VdbeAddOp(v, OP_Column, iCur, i); }else{ sqlite3ExprCode(pParse, pChanges->a[j].pExpr); } } sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); sqlite3AddRecordType(v, pTab); sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0); if( !isView ){ sqlite3VdbeAddOp(v, OP_Close, iCur, 0); } /* Fire the BEFORE and INSTEAD OF triggers */ |
︙ | ︙ |
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 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** ** $Id: util.c,v 1.81 2004/05/14 11:00:53 danielk1977 Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> /* ** If malloc() ever fails, this global variable gets set to 1. |
︙ | ︙ | |||
512 513 514 515 516 517 518 | b = (unsigned char *)zRight; while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } return N<0 ? 0 : *a - *b; } /* ** Return TRUE if z is a pure numeric string. Return FALSE if the | | > > | > > > | 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | b = (unsigned char *)zRight; while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } return N<0 ? 0 : *a - *b; } /* ** Return TRUE if z is a pure numeric string. Return FALSE if the ** string contains any character which is not part of a number. If ** the string is numeric and contains the '.' character, set *realnum ** to TRUE (otherwise FALSE). ** ** Am empty string is considered non-numeric. */ int sqlite3IsNumber(const char *z, int *realnum){ if( *z=='-' || *z=='+' ) z++; if( !isdigit(*z) ){ return 0; } z++; if( realnum ) *realnum = 0; while( isdigit(*z) ){ z++; } if( *z=='.' ){ z++; if( !isdigit(*z) ) return 0; while( isdigit(*z) ){ z++; } if( realnum ) *realnum = 1; } if( *z=='e' || *z=='E' ){ z++; if( *z=='+' || *z=='-' ) z++; if( !isdigit(*z) ) return 0; while( isdigit(*z) ){ z++; } if( realnum ) *realnum = 1; } return *z==0; } /* ** The string z[] is an ascii representation of a real number. ** Convert this string to a double. |
︙ | ︙ | |||
640 641 642 643 644 645 646 | int result; int isNumA, isNumB; if( atext==0 ){ return -1; }else if( btext==0 ){ return 1; } | | | | 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | int result; int isNumA, isNumB; if( atext==0 ){ return -1; }else if( btext==0 ){ return 1; } isNumA = sqlite3IsNumber(atext, 0); isNumB = sqlite3IsNumber(btext, 0); if( isNumA ){ if( !isNumB ){ result = -1; }else{ double rA, rB; rA = sqlite3AtoF(atext, 0); rB = sqlite3AtoF(btext, 0); |
︙ | ︙ | |||
732 733 734 735 736 737 738 | break; } assert( a[0]==b[0] ); if( (dir=a[0])=='A' || a[0]=='D' ){ res = strcmp(&a[1],&b[1]); if( res ) break; }else{ | | | | 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | break; } assert( a[0]==b[0] ); if( (dir=a[0])=='A' || a[0]=='D' ){ res = strcmp(&a[1],&b[1]); if( res ) break; }else{ isNumA = sqlite3IsNumber(&a[1], 0); isNumB = sqlite3IsNumber(&b[1], 0); if( isNumA ){ double rA, rB; if( !isNumB ){ res = -1; break; } rA = sqlite3AtoF(&a[1], 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.288 2004/05/14 11:00:53 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
281 282 283 284 285 286 287 | ** the value of the integer into *pNum. If zNum is not an integer ** or is an integer that is too large to be expressed with just 32 ** bits, then return false. ** ** Under Linux (RedHat 7.2) this routine is much faster than atoi() ** for converting strings into integers. */ | | | | > | 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 | ** the value of the integer into *pNum. If zNum is not an integer ** or is an integer that is too large to be expressed with just 32 ** bits, then return false. ** ** Under Linux (RedHat 7.2) this routine is much faster than atoi() ** for converting strings into integers. */ static int toInt(const char *zNum, i64 *pNum){ i64 v = 0; int neg; int i, c; if( *zNum=='-' ){ neg = 1; zNum++; }else if( *zNum=='+' ){ neg = 0; zNum++; }else{ neg = 0; } for(i=0; (c=zNum[i])>='0' && c<='9'; i++){ v = v*10 + c - '0'; } *pNum = neg ? -v : v; return c==0 && i>0 && (i<10 || (i==19 && memcmp(zNum,"9223372036854775807",19)<=0)); } /* ** Convert the given stack entity into a integer if it isn't one ** already. ** ** Any prior string or real representation is invalidated. |
︙ | ︙ | |||
416 417 418 419 420 421 422 423 424 425 426 427 428 429 | if( aCsr==0 ) return 1; p->aCsr = aCsr; memset(&p->aCsr[p->nCursor], 0, sizeof(Cursor)*(mxCursor+1-p->nCursor)); p->nCursor = mxCursor+1; } return 0; } #ifdef VDBE_PROFILE /* ** The following routine only works on pentium-class processors. ** It uses the RDTSC opcode to read cycle count value out of the ** processor and returns that value. This can be used for high-res ** profiling. | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | if( aCsr==0 ) return 1; p->aCsr = aCsr; memset(&p->aCsr[p->nCursor], 0, sizeof(Cursor)*(mxCursor+1-p->nCursor)); p->nCursor = mxCursor+1; } return 0; } /* ** Apply any conversion required by the supplied column affinity to ** memory cell pRec. affinity may be one of: ** ** SQLITE_AFF_NUM ** SQLITE_AFF_TEXT ** SQLITE_AFF_NONE ** SQLITE_AFF_INTEGER ** */ static void applyAffinity(Mem *pRec, int affinity){ switch( affinity ){ case SQLITE_SO_NUM: if( 0==(pRec->flags&(MEM_Real|MEM_Int)) ){ /* pRec does not have a valid integer or real representation. ** Attempt a conversion if pRec has a string representation and ** it looks like a number. */ int realnum; if( pRec->flags&MEM_Str && sqlite3IsNumber(pRec->z, &realnum) ){ if( realnum ){ Realify(pRec); }else{ Integerify(pRec); } } } break; case SQLITE_SO_TEXT: /* Only attempt the conversion if there is an integer or real ** representation (blob and NULL do not get converted) but no string ** representation. */ if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){ Stringify(pRec); } pRec->flags &= ~(MEM_Real|MEM_Int); break; /* case SQLITE_AFF_INTEGER: case SQLITE_AFF_NONE: break; */ default: assert(0); } } /* ** This function interprets the character 'affinity' according to the ** following table and calls the applyAffinity() function. */ static void applyAffinityByChar(Mem *pRec, char affinity){ switch( affinity ){ case 'n': return applyAffinity(pRec, SQLITE_SO_NUM); case 't': return applyAffinity(pRec, SQLITE_SO_TEXT); default: assert(0); } } #ifdef VDBE_PROFILE /* ** The following routine only works on pentium-class processors. ** It uses the RDTSC opcode to read cycle count value out of the ** processor and returns that value. This can be used for high-res ** profiling. |
︙ | ︙ | |||
495 496 497 498 499 500 501 502 503 504 505 506 507 508 | unsigned long long start; /* CPU clock count at start of opcode */ int origPc; /* Program counter at start of opcode */ #endif #ifndef SQLITE_OMIT_PROGRESS_CALLBACK int nProgressOps = 0; /* Opcodes executed since progress callback. */ #endif if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE; assert( db->magic==SQLITE_MAGIC_BUSY ); assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY ); p->rc = SQLITE_OK; assert( p->explain==0 ); if( sqlite3_malloc_failed ) goto no_mem; pTos = p->pTos; | > > > | 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | unsigned long long start; /* CPU clock count at start of opcode */ int origPc; /* Program counter at start of opcode */ #endif #ifndef SQLITE_OMIT_PROGRESS_CALLBACK int nProgressOps = 0; /* Opcodes executed since progress callback. */ #endif /* FIX ME. */ expandCursorArraySize(p, 100); if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE; assert( db->magic==SQLITE_MAGIC_BUSY ); assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY ); p->rc = SQLITE_OK; assert( p->explain==0 ); if( sqlite3_malloc_failed ) goto no_mem; pTos = p->pTos; |
︙ | ︙ | |||
1209 1210 1211 1212 1213 1214 1215 | ** current value if P1==0, or to the least integer that is strictly ** greater than its current value if P1==1. */ case OP_ForceInt: { int v; assert( pTos>=p->aStack ); if( (pTos->flags & (MEM_Int|MEM_Real))==0 | | | 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | ** current value if P1==0, or to the least integer that is strictly ** greater than its current value if P1==1. */ case OP_ForceInt: { int v; assert( pTos>=p->aStack ); if( (pTos->flags & (MEM_Int|MEM_Real))==0 && ((pTos->flags & MEM_Str)==0 || sqlite3IsNumber(pTos->z, 0)==0) ){ Release(pTos); pTos--; pc = pOp->p2 - 1; break; } if( pTos->flags & MEM_Int ){ v = pTos->i + (pOp->p1!=0); |
︙ | ︙ | |||
1252 1253 1254 1255 1256 1257 1258 | int i = (int)pTos->r; double r = (double)i; if( r!=pTos->r ){ goto mismatch; } pTos->i = i; }else if( pTos->flags & MEM_Str ){ | | | | 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 | int i = (int)pTos->r; double r = (double)i; if( r!=pTos->r ){ goto mismatch; } pTos->i = i; }else if( pTos->flags & MEM_Str ){ i64 v; if( !toInt(pTos->z, &v) ){ double r; if( !sqlite3IsNumber(pTos->z, 0) ){ goto mismatch; } Realify(pTos); v = (int)pTos->r; r = (double)v; if( r!=pTos->r ){ goto mismatch; |
︙ | ︙ | |||
1402 1403 1404 1405 1406 1407 1408 | case OP_Eq: case OP_Ne: case OP_Lt: case OP_Le: case OP_Gt: case OP_Ge: { Mem *pNos = &pTos[-1]; | | | 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | case OP_Eq: case OP_Ne: case OP_Lt: case OP_Le: case OP_Gt: case OP_Ge: { Mem *pNos = &pTos[-1]; i64 c, v; int ft, fn; assert( pNos>=p->aStack ); ft = pTos->flags; fn = pNos->flags; if( (ft | fn) & MEM_Null ){ popStack(&pTos, 2); if( pOp->p2 ){ |
︙ | ︙ | |||
2019 2020 2021 2022 2023 2024 2025 | sqliteFree(aTypes); if( freeZdata ){ sqliteFree(zData); } break; } | | > > > > > > > > > > > > > > | 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 | sqliteFree(aTypes); if( freeZdata ){ sqliteFree(zData); } break; } /* Opcode MakeRecord P1 * P3 ** ** This opcode (not yet in use) is a replacement for the current ** OP_MakeRecord that supports the SQLite3 manifest typing feature. ** It drops the (P2==1) option that was never use. ** ** Convert the top P1 entries of the stack into a single entry ** suitable for use as a data record in a database table. The ** details of the format are irrelavant as long as the OP_Column ** opcode can decode the record later. Refer to source code ** comments for the details of the record format. ** ** P3 may be a string that is P1 characters long. The nth character of the ** string indicates the column affinity that should be used for the nth ** field of the index key (i.e. the first character of P3 corresponds to the ** lowest element on the stack). ** ** Character Column affinity ** ------------------------------ ** 'n' NUMERIC ** 'i' INTEGER ** 't' TEXT ** 'o' NONE ** ** If P3 is NULL then all index fields have the affinity NONE. */ case OP_MakeRecord: { /* Assuming the record contains N fields, the record format looks ** like this: ** ** -------------------------------------------------------------------------- ** | num-fields | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | |
︙ | ︙ | |||
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 | ** ** TODO: Even when the record is short enough for Mem::zShort, this opcode ** allocates it dynamically. */ int nField = pOp->p1; unsigned char *zNewRecord; unsigned char *zCsr; Mem *pRec; int nBytes; /* Space required for this record */ Mem *pData0 = &pTos[1-nField]; assert( pData0>=p->aStack ); /* Loop through the elements that will make up the record to figure ** out how much space is required for the new record. */ nBytes = sqlite3VarintLen(nField); for(pRec=pData0; pRec<=pTos; pRec++){ | > > > > > > | | 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 | ** ** TODO: Even when the record is short enough for Mem::zShort, this opcode ** allocates it dynamically. */ int nField = pOp->p1; unsigned char *zNewRecord; unsigned char *zCsr; char *zAffinity; Mem *pRec; int nBytes; /* Space required for this record */ Mem *pData0 = &pTos[1-nField]; assert( pData0>=p->aStack ); zAffinity = pOp->p3; /* Loop through the elements that will make up the record to figure ** out how much space is required for the new record. */ nBytes = sqlite3VarintLen(nField); for(pRec=pData0; pRec<=pTos; pRec++){ u64 serial_type; if( zAffinity ){ applyAffinityByChar(pRec, zAffinity[pRec-pData0]); } serial_type = sqlite3VdbeSerialType(pRec); nBytes += sqlite3VdbeSerialTypeLen(serial_type); nBytes += sqlite3VarintLen(serial_type); } if( nBytes>MAX_BYTES_PER_ROW ){ rc = SQLITE_TOOBIG; goto abort_due_to_error; |
︙ | ︙ | |||
2209 2210 2211 2212 2213 2214 2215 | if( flags & MEM_Null ){ nByte += 2; containsNull = 1; }else if( pOp->p3 && pOp->p3[j]=='t' ){ Stringify(pRec); pRec->flags &= ~(MEM_Int|MEM_Real); nByte += pRec->n+1; | | | 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 | if( flags & MEM_Null ){ nByte += 2; containsNull = 1; }else if( pOp->p3 && pOp->p3[j]=='t' ){ Stringify(pRec); pRec->flags &= ~(MEM_Int|MEM_Real); nByte += pRec->n+1; }else if( (flags & (MEM_Real|MEM_Int))!=0 || sqlite3IsNumber(pRec->z, 0) ){ if( (flags & (MEM_Real|MEM_Int))==MEM_Int ){ pRec->r = pRec->i; }else if( (flags & (MEM_Real|MEM_Int))==0 ){ pRec->r = sqlite3AtoF(pRec->z, 0); } Release(pRec); z = pRec->zShort; |
︙ | ︙ | |||
2281 2282 2283 2284 2285 2286 2287 | }else{ pTos->z = zNewKey; pTos->flags = MEM_Str | MEM_Dyn; } break; } | > > > > > > > > > | | > > > | > > > > > > > > > > > > > > > > > > | > > > > > | > | > > | | > > > > > > > > > > > | 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 | }else{ pTos->z = zNewKey; pTos->flags = MEM_Str | MEM_Dyn; } break; } /* Opcode: MakeKey P1 P2 P3 ** ** Convert the top P1 entries of the stack into a single entry suitable ** for use as the key in an index. If P2 is not zero, then the original ** entries are popped off the stack. If P2 is zero, the original entries ** remain on the stack. ** ** P3 is interpreted in the same way as for MakeIdxKey. */ /* Opcode: MakeIdxKey P1 P2 P3 ** ** Convert the top P1 entries of the stack into a single entry suitable ** for use as the key in an index. In addition, take one additional integer ** off of the stack, treat that integer as an eight-byte record number, and ** append the integer to the key as a varint. Thus a total of P1+1 entries ** are popped from the stack for this instruction and a single entry is ** pushed back. ** ** If P2 is not zero and one or more of the P1 entries that go into the ** generated key is NULL, then jump to P2 after the new key has been ** pushed on the stack. In other words, jump to P2 if the key is ** guaranteed to be unique. This jump can be used to skip a subsequent ** uniqueness test. ** ** P3 may be a string that is P1 characters long. The nth character of the ** string indicates the column affinity that should be used for the nth ** field of the index key (i.e. the first character of P3 corresponds to the ** lowest element on the stack). ** ** Character Column affinity ** ------------------------------ ** 'n' NUMERIC ** 'i' INTEGER ** 't' TEXT ** 'o' NONE ** ** If P3 is NULL then all index fields have the affinity NUMERIC. */ case OP_MakeKey: case OP_MakeIdxKey: { Mem *pRec; Mem *pData0; int nField; u64 rowid; int nByte = 0; int addRowid; int containsNull = 0; char *zKey; /* The new key */ int offset = 0; char *zAffinity = pOp->p3; assert( zAffinity ); nField = pOp->p1; pData0 = &pTos[1-nField]; assert( pData0>=p->aStack ); addRowid = ((pOp->opcode==OP_MakeIdxKey)?1:0); /* Loop through the P1 elements that will make up the new index ** key. Call applyAffinity() to perform any conversion required ** the column affinity string P3 to modify stack elements in place. ** Set containsNull to 1 if a NULL value is encountered. ** ** Once the value has been coerced, figure out how much space is required ** to store the coerced values serial-type and blob, and add this ** quantity to nByte. ** ** TODO: Figure out if the in-place coercion causes a problem for ** OP_MakeKey when P2 is 0 (used by DISTINCT). */ for(pRec=pData0; pRec<=pTos; pRec++){ u64 serial_type; if( zAffinity ){ applyAffinityByChar(pRec, zAffinity[pRec-pData0]); }else{ applyAffinity(pRec, SQLITE_SO_NUM); } if( pRec->flags&MEM_Null ){ containsNull = 1; } serial_type = sqlite3VdbeSerialType(pRec); nByte += sqlite3VarintLen(serial_type); nByte += sqlite3VdbeSerialTypeLen(serial_type); } /* If we have to append a varint rowid to this record, set 'rowid' ** to the value of the rowid and increase nByte by the amount of space ** required to store it and the 0x00 seperator byte. */ if( addRowid ){ pRec = &pTos[0-nField]; assert( pRec>=p->aStack ); Integerify(pRec); rowid = pRec->i; nByte += sqlite3VarintLen(rowid); nByte++; |
︙ | ︙ | |||
2362 2363 2364 2365 2366 2367 2368 | popStack(&pTos, nField+addRowid); } pTos++; pTos->flags = MEM_Str|MEM_Dyn; /* TODO: should eventually be MEM_Blob */ pTos->z = zKey; pTos->n = nByte; | > > > | > > > > > > | 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 | popStack(&pTos, nField+addRowid); } pTos++; pTos->flags = MEM_Str|MEM_Dyn; /* TODO: should eventually be MEM_Blob */ pTos->z = zKey; pTos->n = nByte; /* If P2 is non-zero, and if the key contains a NULL value, and if this ** was an OP_MakeIdxKey instruction, not OP_MakeKey, jump to P2. */ if( pOp->p2 && containsNull && addRowid ){ pc = pOp->p2 - 1; } break; } /* Opcode: IncrKey * * * ** ** The top of the stack should contain an index key generated by ** The MakeKey opcode. This routine increases the least significant ** byte of that key by one. This is used so that the MoveTo opcode ** will move to the first entry greater than the key rather than to ** the key itself. ** */ case OP_IncrKey: { assert( pTos>=p->aStack ); /* The IncrKey opcode is only applied to keys generated by ** MakeKey or MakeIdxKey and the results of those operands ** are always dynamic strings or zShort[] strings. So we ** are always free to modify the string in place. */ assert( pTos->flags & (MEM_Dyn|MEM_Short) ); /* ** FIX ME: This technique is now broken due to manifest types in index ** keys. */ assert(0); pTos->z[pTos->n-1]++; break; } /* Opcode: Checkpoint P1 * * ** ** Begin a checkpoint. A checkpoint is the beginning of a operation that |
︙ | ︙ | |||
2680 2681 2682 2683 2684 2685 2686 | pCur->nullRow = 1; if( pX==0 ) break; do{ /* When opening cursors, always supply the comparison function ** sqlite3VdbeKeyCompare(). If the table being opened is of type ** INTKEY, the btree layer won't call the comparison function anyway. */ | | | 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 | pCur->nullRow = 1; if( pX==0 ) break; do{ /* When opening cursors, always supply the comparison function ** sqlite3VdbeKeyCompare(). If the table being opened is of type ** INTKEY, the btree layer won't call the comparison function anyway. */ rc = sqlite3BtreeCursor(pX, p2, wrFlag, sqlite3VdbeKeyCompare, pCur, &pCur->pCursor); switch( rc ){ case SQLITE_BUSY: { if( db->xBusyCallback==0 ){ p->pc = pc; p->rc = SQLITE_BUSY; p->pTos = &pTos[1 + (pOp->p2<=0)]; /* Operands must remain on stack */ |
︙ | ︙ | |||
2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 | ** ** Pop the top of the stack and use its value as a key. Reposition ** cursor P1 so that it points to an entry with a matching key. If ** the table contains no record with a matching key, then the cursor ** is left pointing at the first record that is greater than the key. ** If there are no records greater than the key and P2 is not zero, ** then an immediate jump to P2 is made. ** ** See also: Found, NotFound, Distinct, MoveLt */ /* Opcode: MoveLt P1 P2 * ** ** Pop the top of the stack and use its value as a key. Reposition ** cursor P1 so that it points to the entry with the largest key that is ** less than the key popped from the stack. ** If there are no records less than than the key and P2 ** is not zero then an immediate jump to P2 is made. ** ** See also: MoveTo */ case OP_MoveLt: case OP_MoveTo: { int i = pOp->p1; Cursor *pC; assert( pTos>=p->aStack ); assert( i>=0 && i<p->nCursor ); pC = &p->aCsr[i]; if( pC->pCursor!=0 ){ int res, oc; pC->nullRow = 0; if( pC->intKey ){ i64 iKey; Integerify(pTos); iKey = intToKey(pTos->i); if( pOp->p2==0 && pOp->opcode==OP_MoveTo ){ pC->movetoTarget = iKey; pC->deferredMoveto = 1; Release(pTos); pTos--; break; } sqlite3BtreeMoveto(pC->pCursor, 0, (u64)iKey, &res); pC->lastRecno = pTos->i; pC->recnoIsValid = res==0; }else{ Stringify(pTos); sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res); pC->recnoIsValid = 0; } pC->deferredMoveto = 0; sqlite3_search_count++; oc = pOp->opcode; if( oc==OP_MoveTo && res<0 ){ sqlite3BtreeNext(pC->pCursor, &res); pC->recnoIsValid = 0; if( res && pOp->p2>0 ){ pc = pOp->p2 - 1; | > > > > > > > > > > > > > > > > | 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 | ** ** Pop the top of the stack and use its value as a key. Reposition ** cursor P1 so that it points to an entry with a matching key. If ** the table contains no record with a matching key, then the cursor ** is left pointing at the first record that is greater than the key. ** If there are no records greater than the key and P2 is not zero, ** then an immediate jump to P2 is made. ** ** If P3 is not NULL, then the cursor is left pointing at the first ** record that is greater than the key of which the key is not a prefix. ** This is the same effect that executing OP_IncrKey on the key value ** before OP_MoveTo used to have. ** ** See also: Found, NotFound, Distinct, MoveLt */ /* Opcode: MoveLt P1 P2 * ** ** Pop the top of the stack and use its value as a key. Reposition ** cursor P1 so that it points to the entry with the largest key that is ** less than the key popped from the stack. ** If there are no records less than than the key and P2 ** is not zero then an immediate jump to P2 is made. ** ** If P3 is not NULL, and keys exist in the index of which the stack key ** is a prefix, leave the cursor pointing at the largest of these. ** This is the same effect that executing OP_IncrKey on the key value ** before OP_MoveLt used to have. ** ** See also: MoveTo */ case OP_MoveLt: case OP_MoveTo: { int i = pOp->p1; Cursor *pC; assert( pTos>=p->aStack ); assert( i>=0 && i<p->nCursor ); pC = &p->aCsr[i]; if( pC->pCursor!=0 ){ int res, oc; pC->nullRow = 0; if( pC->intKey ){ i64 iKey; assert( !pOp->p3 ); Integerify(pTos); iKey = intToKey(pTos->i); if( pOp->p2==0 && pOp->opcode==OP_MoveTo ){ pC->movetoTarget = iKey; pC->deferredMoveto = 1; Release(pTos); pTos--; break; } sqlite3BtreeMoveto(pC->pCursor, 0, (u64)iKey, &res); pC->lastRecno = pTos->i; pC->recnoIsValid = res==0; }else{ if( pOp->p3 ){ pC->incrKey = 1; } Stringify(pTos); sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res); pC->incrKey = 0; pC->recnoIsValid = 0; } pC->deferredMoveto = 0; pC->incrKey = 0; sqlite3_search_count++; oc = pOp->opcode; if( oc==OP_MoveTo && res<0 ){ sqlite3BtreeNext(pC->pCursor, &res); pC->recnoIsValid = 0; if( res && pOp->p2>0 ){ pc = pOp->p2 - 1; |
︙ | ︙ | |||
3011 3012 3013 3014 3015 3016 3017 | if( res<0 ){ rc = sqlite3BtreeNext(pCrsr, &res); if( res ){ pc = pOp->p2 - 1; break; } } | | | 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 | if( res<0 ){ rc = sqlite3BtreeNext(pCrsr, &res); if( res ){ pc = pOp->p2 - 1; break; } } rc = sqlite3VdbeIdxKeyCompare(pCx, len, zKey, 0, &res); if( rc!=SQLITE_OK ) goto abort_due_to_error; if( res>0 ){ pc = pOp->p2 - 1; break; } /* At this point, pCrsr is pointing to an entry in P1 where all but |
︙ | ︙ | |||
3641 3642 3643 3644 3645 3646 3647 | while( zKey[len] && --len ); rc = sqlite3BtreeMoveto(pCrsr, zKey, len, &res); if( rc!=SQLITE_OK ) goto abort_due_to_error; while( res!=0 ){ int c; sqlite3BtreeKeySize(pCrsr, &n); | | | | 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 | while( zKey[len] && --len ); rc = sqlite3BtreeMoveto(pCrsr, zKey, len, &res); if( rc!=SQLITE_OK ) goto abort_due_to_error; while( res!=0 ){ int c; sqlite3BtreeKeySize(pCrsr, &n); if( n==nKey && sqlite3VdbeIdxKeyCompare(&p->aCsr[i], len, zKey, 0, &c)==SQLITE_OK && c==0 ){ rc = SQLITE_CONSTRAINT; if( pOp->p3 && pOp->p3[0] ){ sqlite3SetString(&p->zErrMsg, pOp->p3, (char*)0); } goto abort_due_to_error; |
︙ | ︙ | |||
3707 3708 3709 3710 3711 3712 3713 | case OP_IdxRecno: { int i = pOp->p1; BtCursor *pCrsr; assert( i>=0 && i<p->nCursor ); pTos++; if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ | | < < > > > | > > > > | | 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 | case OP_IdxRecno: { int i = pOp->p1; BtCursor *pCrsr; assert( i>=0 && i<p->nCursor ); pTos++; if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ i64 rowid; assert( p->aCsr[i].deferredMoveto==0 ); assert( p->aCsr[i].intKey==0 ); rc = sqlite3VdbeIdxRowid(pCrsr, &rowid); if( rc!=SQLITE_OK ){ goto abort_due_to_error; } pTos->flags = MEM_Int; pTos->i = rowid; #if 0 /* Read the final 9 bytes of the key into buf[]. If the whole key is ** less than 9 bytes then just load the whole thing. Set len to the ** number of bytes read. */ sqlite3BtreeKeySize(pCrsr, &sz); len = ((sz>10)?10:sz); rc = sqlite3BtreeKey(pCrsr, sz-len, len, buf); if( rc!=SQLITE_OK ){ goto abort_due_to_error; } len--; if( buf[len]&0x80 ){ |
︙ | ︙ | |||
3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 | while( len && buf[len-1] ){ len--; } sqlite3GetVarint(&buf[len], &sz); pTos->flags = MEM_Int; pTos->i = sz; } }else{ pTos->flags = MEM_Null; } break; } /* Opcode: IdxGT P1 P2 * | > | 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 | while( len && buf[len-1] ){ len--; } sqlite3GetVarint(&buf[len], &sz); pTos->flags = MEM_Int; pTos->i = sz; } #endif }else{ pTos->flags = MEM_Null; } break; } /* Opcode: IdxGT P1 P2 * |
︙ | ︙ | |||
3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 | int i= pOp->p1; BtCursor *pCrsr; assert( i>=0 && i<p->nCursor ); assert( pTos>=p->aStack ); if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int res, rc; Stringify(pTos); assert( p->aCsr[i].deferredMoveto==0 ); | > > > > | > | 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 | int i= pOp->p1; BtCursor *pCrsr; assert( i>=0 && i<p->nCursor ); assert( pTos>=p->aStack ); if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int res, rc; Cursor *pC = &p->aCsr[i]; Stringify(pTos); assert( p->aCsr[i].deferredMoveto==0 ); if( pOp->p3 ){ pC->incrKey = 1; } rc = sqlite3VdbeIdxKeyCompare(pC, pTos->n, pTos->z, 0, &res); pC->incrKey = 0; if( rc!=SQLITE_OK ){ break; } if( pOp->opcode==OP_IdxLT ){ res = -res; }else if( pOp->opcode==OP_IdxGE ){ res++; |
︙ | ︙ | |||
3824 3825 3826 3827 3828 3829 3830 | const char *z; assert( pTos>=p->aStack ); assert( pTos->flags & MEM_Str ); z = pTos->z; n = pTos->n; for(k=0; k<n && i>0; i--){ | > | > | < | 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 | const char *z; assert( pTos>=p->aStack ); assert( pTos->flags & MEM_Str ); z = pTos->z; n = pTos->n; for(k=0; k<n && i>0; i--){ u64 serial_type; k += sqlite3GetVarint(&z[k], &serial_type); if( serial_type==6 ){ /* Serial type 6 is a NULL */ pc = pOp->p2-1; break; } k += sqlite3VdbeSerialTypeLen(serial_type); } Release(pTos); pTos--; break; } /* Opcode: Destroy P1 P2 * |
︙ | ︙ | |||
3951 3952 3953 3954 3955 3956 3957 | assert( iSet>=0 && iSet<p->nSet ); pTos++; pSet = &p->aSet[iSet]; nRoot = sqliteHashCount(&pSet->hash); aRoot = sqliteMallocRaw( sizeof(int)*(nRoot+1) ); if( aRoot==0 ) goto no_mem; for(j=0, i=sqliteHashFirst(&pSet->hash); i; i=sqliteHashNext(i), j++){ | > | > | 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 | assert( iSet>=0 && iSet<p->nSet ); pTos++; pSet = &p->aSet[iSet]; nRoot = sqliteHashCount(&pSet->hash); aRoot = sqliteMallocRaw( sizeof(int)*(nRoot+1) ); if( aRoot==0 ) goto no_mem; for(j=0, i=sqliteHashFirst(&pSet->hash); i; i=sqliteHashNext(i), j++){ i64 root64; toInt((char*)sqliteHashKey(i), &root64); aRoot[j] = root64; } aRoot[j] = 0; sqlite3HashClear(&pSet->hash); pSet->prev = 0; z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot); if( z==0 || z[0]==0 ){ if( z ) sqliteFree(z); |
︙ | ︙ |
Changes to src/vdbeInt.h.
︙ | ︙ | |||
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | Bool useRandomRowid; /* Generate new record numbers semi-randomly */ Bool nullRow; /* True if pointing to a row with no data */ Bool nextRowidValid; /* True if the nextRowid field is valid */ Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */ Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ Bool intKey; /* True if the table requires integer keys */ Bool zeroData; /* True if table contains keys only - no data */ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ Btree *pBt; /* Separate file holding temporary table */ int nData; /* Number of bytes in pData */ char *pData; /* Data for a NEW or OLD pseudo-table */ i64 iKey; /* Key for the NEW or OLD pseudo-table row */ }; typedef struct Cursor Cursor; | > | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | Bool useRandomRowid; /* Generate new record numbers semi-randomly */ Bool nullRow; /* True if pointing to a row with no data */ Bool nextRowidValid; /* True if the nextRowid field is valid */ Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */ Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ Bool intKey; /* True if the table requires integer keys */ Bool zeroData; /* True if table contains keys only - no data */ Bool incrKey; /* Searches on the table simulate OP_IncrKey */ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ Btree *pBt; /* Separate file holding temporary table */ int nData; /* Number of bytes in pData */ char *pData; /* Data for a NEW or OLD pseudo-table */ i64 iKey; /* Key for the NEW or OLD pseudo-table row */ }; typedef struct Cursor Cursor; |
︙ | ︙ | |||
318 319 320 321 322 323 324 | #endif int sqlite3VdbeSerialTypeLen(u64); u64 sqlite3VdbeSerialType(const Mem *); int sqlite3VdbeSerialPut(unsigned char *, const Mem *); int sqlite3VdbeSerialGet(const unsigned char *, u64, Mem *); int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); | | | 319 320 321 322 323 324 325 326 327 | #endif int sqlite3VdbeSerialTypeLen(u64); u64 sqlite3VdbeSerialType(const Mem *); int sqlite3VdbeSerialPut(unsigned char *, const Mem *); int sqlite3VdbeSerialGet(const unsigned char *, u64, Mem *); int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int, int*); int sqlite3VdbeIdxRowid(BtCursor *, i64 *); |
Changes to src/vdbeaux.c.
︙ | ︙ | |||
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 | extern int sqlite3_search_count; assert( p->intKey ); if( p->intKey ){ sqlite3BtreeMoveto(p->pCursor, 0, p->movetoTarget, &res); }else{ sqlite3BtreeMoveto(p->pCursor,(char*)&p->movetoTarget,sizeof(i64),&res); } p->lastRecno = keyToInt(p->movetoTarget); p->recnoIsValid = res==0; if( res<0 ){ sqlite3BtreeNext(p->pCursor, &res); } sqlite3_search_count++; p->deferredMoveto = 0; | > | 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 | extern int sqlite3_search_count; assert( p->intKey ); if( p->intKey ){ sqlite3BtreeMoveto(p->pCursor, 0, p->movetoTarget, &res); }else{ sqlite3BtreeMoveto(p->pCursor,(char*)&p->movetoTarget,sizeof(i64),&res); } p->incrKey = 0; p->lastRecno = keyToInt(p->movetoTarget); p->recnoIsValid = res==0; if( res<0 ){ sqlite3BtreeNext(p->pCursor, &res); } sqlite3_search_count++; p->deferredMoveto = 0; |
︙ | ︙ | |||
1343 1344 1345 1346 1347 1348 1349 | pMem2->r = pMem2->i; } if( pMem1->r < pMem2->r ) return -1; if( pMem1->r > pMem2->r ) return 1; return 0; } | | > | > > | < < < < < < | | > | 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 | pMem2->r = pMem2->i; } if( pMem1->r < pMem2->r ) return -1; if( pMem1->r > pMem2->r ) return 1; return 0; } return (pMem1->i - pMem2->i); } rc = (pMem2->flags&MEM_Null) - (pMem1->flags&MEM_Null); if( rc ){ return rc; } /* Both values must be strings or blobs. If only one is a string, then ** that value is less. Otherwise, compare with memcmp(). If memcmp() ** returns 0 and one value is longer than the other, then that value ** is greater. */ rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n); if( rc ){ return rc; } return (pMem1->n - pMem2->n); } /* ** The following is the comparison function for (non-integer) ** keys in the btrees. This function returns negative, zero, or ** positive if the first key is less than, equal to, or greater than ** the second. ** ** This function assumes that each key consists of one or more type/blob ** pairs, encoded using the sqlite3VdbeSerialXXX() functions above. ** ** Following the type/blob pairs, each key may have a single 0x00 byte ** followed by a varint. A key may only have this traling 0x00/varint ** pair if it has at least as many type/blob pairs as the key it is being ** compared to. */ int sqlite3VdbeKeyCompare( void *userData, int nKey1, const void *pKey1, int nKey2, const void *pKey2 ){ Cursor *pC = (Cursor *)userData; int offset1 = 0; int offset2 = 0; const unsigned char *aKey1 = (const unsigned char *)pKey1; const unsigned char *aKey2 = (const unsigned char *)pKey2; while( offset1<nKey1 && offset2<nKey2 ){ Mem mem1; |
︙ | ︙ | |||
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 | /* If either of the varints just read in are 0 (not a type), then ** this is the end of the keys. The remaining data in each key is ** the varint rowid. Compare these as signed integers and return ** the result. */ if( !serial_type1 || !serial_type2 ){ assert( !serial_type1 && !serial_type2 ); sqlite3GetVarint(&aKey1[offset1], &serial_type1); sqlite3GetVarint(&aKey2[offset2], &serial_type2); return ( (i64)serial_type1 - (i64)serial_type2 ); } /* Assert that there is enough space left in each key for the blob of ** data to go with the serial type just read. This assert may fail if | > | 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 | /* If either of the varints just read in are 0 (not a type), then ** this is the end of the keys. The remaining data in each key is ** the varint rowid. Compare these as signed integers and return ** the result. */ if( !serial_type1 || !serial_type2 ){ assert( !serial_type1 && !serial_type2 ); assert( !pC || !pC->incrKey ); sqlite3GetVarint(&aKey1[offset1], &serial_type1); sqlite3GetVarint(&aKey2[offset2], &serial_type2); return ( (i64)serial_type1 - (i64)serial_type2 ); } /* Assert that there is enough space left in each key for the blob of ** data to go with the serial type just read. This assert may fail if |
︙ | ︙ | |||
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 | if( mem2.flags&MEM_Dyn ){ sqliteFree(mem2.z); } if( rc!=0 ){ return rc; } } if( offset1<nKey1 ){ return 1; } if( offset2<nKey2 ){ return -1; } return 0; } /* ** pCur points at an index entry. Read the rowid (varint occuring at ** the end of the entry and store it in *rowid. Return SQLITE_OK if ** everything works, or an error code otherwise. */ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){ i64 sz; int rc; | > > > > > > > > > > > > | | > > > > > > | > > > | | | | > | 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 | if( mem2.flags&MEM_Dyn ){ sqliteFree(mem2.z); } if( rc!=0 ){ return rc; } } /* One of the keys ran out of fields, but all the fields up to that point ** were equal. If the incrKey flag is true, then the second key is ** treated as larger. */ if( pC && pC->incrKey ){ assert( offset2==nKey2 ); return -1; } if( offset1<nKey1 ){ return 1; } if( offset2<nKey2 ){ return -1; } return_result: return 0; } /* ** pCur points at an index entry. Read the rowid (varint occuring at ** the end of the entry and store it in *rowid. Return SQLITE_OK if ** everything works, or an error code otherwise. */ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){ i64 sz; int rc; char buf[10]; int len; u64 r; rc = sqlite3BtreeKeySize(pCur, &sz); if( rc!=SQLITE_OK ){ return rc; } len = ((sz>10)?10:sz); /* If there are less than 2 bytes in the key, this cannot be ** a valid index entry. In practice this comes up for a query ** of the sort "SELECT max(x) FROM t1;" when t1 is an empty table ** with an index on x. In this case just call the rowid 0. */ if( len<2 ){ *rowid = 0; return SQLITE_OK; } rc = sqlite3BtreeKey(pCur, sz-len, len, buf); if( rc!=SQLITE_OK ){ return rc; } len--; while( buf[len-1] && --len ); sqlite3GetVarint(&buf[len], &r); *rowid = r; return SQLITE_OK; } int sqlite3VdbeIdxKeyCompare( Cursor *pC, int nKey, const unsigned char *pKey, int ignorerowid, int *res ){ unsigned char *pCellKey; u64 nCellKey; int freeCellKey = 0; int rc; int len; BtCursor *pCur = pC->pCursor; sqlite3BtreeKeySize(pCur, &nCellKey); if( nCellKey<=0 ){ *res = 0; return SQLITE_OK; } |
︙ | ︙ | |||
1514 1515 1516 1517 1518 1519 1520 | len = nCellKey-2; while( pCellKey[len] && --len ); if( ignorerowid ){ nKey--; while( pKey[nKey] && --nKey ); } | | | 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 | len = nCellKey-2; while( pCellKey[len] && --len ); if( ignorerowid ){ nKey--; while( pKey[nKey] && --nKey ); } *res = sqlite3VdbeKeyCompare(pC, len, pCellKey, nKey, pKey); if( freeCellKey ){ sqliteFree(pCellKey); } return SQLITE_OK; } |
Changes to src/where.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 module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. ** | | | 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 module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. ** ** $Id: where.c,v 1.92 2004/05/14 11:00:53 danielk1977 Exp $ */ #include "sqliteInt.h" /* ** The query generator uses an array of instances of this structure to ** help it analyze the subexpressions of the WHERE clause. Each WHERE ** clause subexpression is separated from the others by an AND operator. |
︙ | ︙ | |||
795 796 797 798 799 800 801 | pLevel->iMem = pParse->nMem++; cont = pLevel->cont = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeKey, nColumn, 0); sqlite3AddIdxKeyType(v, pIdx); | < | > > > | > > > > | 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | pLevel->iMem = pParse->nMem++; cont = pLevel->cont = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeKey, nColumn, 0); sqlite3AddIdxKeyType(v, pIdx); sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 0); if( nColumn==pIdx->nColumn || pLevel->bRev ){ testOp = OP_IdxGT; }else{ /* sqlite3VdbeAddOp(v, OP_Dup, 0, 0); sqlite3VdbeAddOp(v, OP_IncrKey, 0, 0); sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); */ testOp = OP_IdxGE; } if( pLevel->bRev ){ /* Scan in reverse order */ /* sqlite3VdbeAddOp(v, OP_IncrKey, 0, 0); */ sqlite3VdbeAddOp(v, OP_MoveLt, pLevel->iCur, brk); sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC); start = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeAddOp(v, OP_IdxLT, pLevel->iCur, brk); pLevel->op = OP_Prev; }else{ /* Scan in the forward order */ sqlite3VdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk); start = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeAddOp(v, testOp, pLevel->iCur, brk); if( testOp==OP_IdxGE ){ sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC); } pLevel->op = OP_Next; } sqlite3VdbeAddOp(v, OP_RowKey, pLevel->iCur, 0); sqlite3VdbeAddOp(v, OP_IdxIsNull, nColumn, cont); sqlite3VdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0); if( i==pTabList->nSrc-1 && pushKey ){ haveKey = 1; |
︙ | ︙ | |||
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | int nCol = nEqColumn + (score & 1); pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_NotNull, -nCol, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nCol, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeKey, nCol, 0); sqlite3AddIdxKeyType(v, pIdx); if( leFlag ){ sqlite3VdbeAddOp(v, OP_IncrKey, 0, 0); } if( pLevel->bRev ){ sqlite3VdbeAddOp(v, OP_MoveLt, pLevel->iCur, brk); }else{ sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); } }else if( pLevel->bRev ){ sqlite3VdbeAddOp(v, OP_Last, pLevel->iCur, brk); } | > > > > > | 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | int nCol = nEqColumn + (score & 1); pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_NotNull, -nCol, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nCol, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeKey, nCol, 0); sqlite3AddIdxKeyType(v, pIdx); /* if( leFlag ){ sqlite3VdbeAddOp(v, OP_IncrKey, 0, 0); } */ if( pLevel->bRev ){ sqlite3VdbeAddOp(v, OP_MoveLt, pLevel->iCur, brk); if( !geFlag ){ sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC); } }else{ sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); } }else if( pLevel->bRev ){ sqlite3VdbeAddOp(v, OP_Last, pLevel->iCur, brk); } |
︙ | ︙ | |||
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | if( nEqColumn>0 || (score&2)!=0 ){ int nCol = nEqColumn + ((score&2)!=0); sqlite3VdbeAddOp(v, OP_NotNull, -nCol, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nCol, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeKey, nCol, 0); sqlite3AddIdxKeyType(v, pIdx); if( !geFlag ){ sqlite3VdbeAddOp(v, OP_IncrKey, 0, 0); } if( pLevel->bRev ){ pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); testOp = OP_IdxLT; }else{ sqlite3VdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk); } }else if( pLevel->bRev ){ testOp = OP_Noop; }else{ sqlite3VdbeAddOp(v, OP_Rewind, pLevel->iCur, brk); } /* Generate the the top of the loop. If there is a termination ** key we have to test for that key and abort at the top of the ** loop. */ start = sqlite3VdbeCurrentAddr(v); if( testOp!=OP_Noop ){ sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeAddOp(v, testOp, pLevel->iCur, brk); } sqlite3VdbeAddOp(v, OP_RowKey, pLevel->iCur, 0); sqlite3VdbeAddOp(v, OP_IdxIsNull, nEqColumn + (score & 1), cont); sqlite3VdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0); if( i==pTabList->nSrc-1 && pushKey ){ haveKey = 1; }else{ | > > > > > > > > | 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 | if( nEqColumn>0 || (score&2)!=0 ){ int nCol = nEqColumn + ((score&2)!=0); sqlite3VdbeAddOp(v, OP_NotNull, -nCol, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nCol, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeKey, nCol, 0); sqlite3AddIdxKeyType(v, pIdx); /* if( !geFlag ){ sqlite3VdbeAddOp(v, OP_IncrKey, 0, 0); } */ if( pLevel->bRev ){ pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); testOp = OP_IdxLT; }else{ sqlite3VdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk); if( !geFlag ){ sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC); } } }else if( pLevel->bRev ){ testOp = OP_Noop; }else{ sqlite3VdbeAddOp(v, OP_Rewind, pLevel->iCur, brk); } /* Generate the the top of the loop. If there is a termination ** key we have to test for that key and abort at the top of the ** loop. */ start = sqlite3VdbeCurrentAddr(v); if( testOp!=OP_Noop ){ sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeAddOp(v, testOp, pLevel->iCur, brk); if( (leFlag && !pLevel->bRev) || (!geFlag && pLevel->bRev) ){ sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC); } } sqlite3VdbeAddOp(v, OP_RowKey, pLevel->iCur, 0); sqlite3VdbeAddOp(v, OP_IdxIsNull, nEqColumn + (score & 1), cont); sqlite3VdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0); if( i==pTabList->nSrc-1 && pushKey ){ haveKey = 1; }else{ |
︙ | ︙ |
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.17 2004/05/14 11:00:53 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a table to work with. # do_test func-0.0 { |
︙ | ︙ | |||
163 164 165 166 167 168 169 | catchsql {SELECT abs() FROM t1} } {1 {wrong number of arguments to function abs()}} 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} | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | catchsql {SELECT abs() FROM t1} } {1 {wrong number of arguments to function abs()}} 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}} 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} } {this program is free software} |
︙ | ︙ |
Changes to test/index.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 the CREATE INDEX statement. # | | | 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 the CREATE INDEX statement. # # $Id: index.test,v 1.25 2004/05/14 11:00:53 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic index and verify it is added to sqlite_master # do_test index-1.1 { |
︙ | ︙ | |||
331 332 333 334 335 336 337 | ); } for {set i 1} {$i<=50} {incr i} { execsql "INSERT INTO t3 VALUES('x${i}x',$i,0.$i)" } set sqlite_search_count 0 concat [execsql {SELECT c FROM t3 WHERE b==10}] $sqlite_search_count | | > > > | | | | | | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | ); } for {set i 1} {$i<=50} {incr i} { execsql "INSERT INTO t3 VALUES('x${i}x',$i,0.$i)" } set sqlite_search_count 0 concat [execsql {SELECT c FROM t3 WHERE b==10}] $sqlite_search_count } {0.1 3} integrity_check index-11.2 # Numeric strings should compare as if they were numbers. So even if the # strings are not character-by-character the same, if they represent the # same number they should compare equal to one another. Verify that this # is true in indices. # # Updated for sqlite v3: SQLite will now store these values as numbers # (because the affinity of column a is NUMERIC) so the quirky # representations are not retained. i.e. '+1.0' becomes '1'. do_test index-12.1 { execsql { CREATE TABLE t4(a,b); INSERT INTO t4 VALUES('0.0',1); INSERT INTO t4 VALUES('0.00',2); INSERT INTO t4 VALUES('abc',3); INSERT INTO t4 VALUES('-1.0',4); INSERT INTO t4 VALUES('+1.0',5); INSERT INTO t4 VALUES('0',6); INSERT INTO t4 VALUES('00000',7); SELECT a FROM t4 ORDER BY b; } } {0 0 abc -1 1 0 0} do_test index-12.2 { execsql { SELECT a FROM t4 WHERE a==0 ORDER BY b } } {0 0 0 0} do_test index-12.3 { execsql { SELECT a FROM t4 WHERE a<0.5 ORDER BY b } } {0 0 -1 0 0} do_test index-12.4 { execsql { SELECT a FROM t4 WHERE a>-0.5 ORDER BY b } } {0 0 abc 1 0 0} do_test index-12.5 { execsql { CREATE INDEX t4i1 ON t4(a); SELECT a FROM t4 WHERE a==0 ORDER BY b } } {0 0 0 0} do_test index-12.6 { execsql { SELECT a FROM t4 WHERE a<0.5 ORDER BY b } } {0 0 -1 0 0} do_test index-12.7 { execsql { SELECT a FROM t4 WHERE a>-0.5 ORDER BY b } } {0 0 abc 1 0 0} integrity_check index-12.8 # Make sure we cannot drop an automatically created index. # do_test index-13.1 { execsql { CREATE TABLE t5( |
︙ | ︙ |
Changes to test/quick.test.
1 2 3 4 5 6 7 8 9 10 11 12 | # 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 runs all tests. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # 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 runs all tests. # # $Id: quick.test,v 1.11 2004/05/14 11:00:53 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl rename finish_test really_finish_test proc finish_test {} {} set ISQUICK 1 |
︙ | ︙ | |||
28 29 30 31 32 33 34 | format3.test } lappend EXCLUDE interrupt.test ;# assert() fails in btree lappend EXCLUDE ioerr.test ;# seg-faults (?) lappend EXCLUDE memdb.test ;# fails - malformed database lappend EXCLUDE misc3.test ;# seg-faults (?) | < > | | < < < < < | < < < < | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | format3.test } lappend EXCLUDE interrupt.test ;# assert() fails in btree lappend EXCLUDE ioerr.test ;# seg-faults (?) lappend EXCLUDE memdb.test ;# fails - malformed database lappend EXCLUDE misc3.test ;# seg-faults (?) lappend EXCLUDE table.test ;# assert() fails in pager lappend EXCLUDE trans.test ;# assert() fails in pager lappend EXCLUDE vacuum.test ;# seg-fault lappend EXCLUDE printf.test ;# sqlite3_XX vs sqlite_XX problem lappend EXCLUDE auth.test ;# Cannot attach empty databases. lappend EXCLUDE tableapi.test ;# sqlite3_XX vs sqlite_XX problem lappend EXCLUDE version.test ;# uses the btree_meta API (not updated) # Some tests fail in these file as a result of the partial manifest types # implementation. lappend EXCLUDE misc1.test lappend EXCLUDE capi2.test lappend EXCLUDE sort.test lappend EXCLUDE where.test if {[sqlite -has-codec]} { lappend EXCLUDE \ attach.test \ attach2.test \ auth.test \ |
︙ | ︙ |
Changes to test/select2.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 the SELECT statement. # | | | 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 the SELECT statement. # # $Id: select2.test,v 1.20 2004/05/14 11:00:53 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a table with some data # execsql {CREATE TABLE tbl1(f1 int, f2 int)} |
︙ | ︙ | |||
79 80 81 82 83 84 85 | execsql {SELECT count(*) FROM tbl2 WHERE f2>1000} } {29500} do_test select2-3.1 { execsql {SELECT f1 FROM tbl2 WHERE 1000=f2} } {500} | < < < | | | | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | execsql {SELECT count(*) FROM tbl2 WHERE f2>1000} } {29500} do_test select2-3.1 { execsql {SELECT f1 FROM tbl2 WHERE 1000=f2} } {500} do_test select2-3.2a { execsql {CREATE INDEX idx1 ON tbl2(f2)} } {} do_test select2-3.2b { execsql {SELECT f1 FROM tbl2 WHERE 1000=f2} } {500} do_test select2-3.2c { execsql {SELECT f1 FROM tbl2 WHERE f2=1000} } {500} do_test select2-3.2d { set sqlite_search_count 0 execsql {SELECT * FROM tbl2 WHERE 1000=f2} set sqlite_search_count } {3} do_test select2-3.2e { set sqlite_search_count 0 execsql {SELECT * FROM tbl2 WHERE f2=1000} set sqlite_search_count } {3} # Make sure queries run faster with an index than without # do_test select2-3.3 { execsql {DROP INDEX idx1} |
︙ | ︙ |
Changes to test/select4.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # 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 UNION, INTERSECT and EXCEPT operators # in SELECT statements. # | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # 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 UNION, INTERSECT and EXCEPT operators # in SELECT statements. # # $Id: select4.test,v 1.15 2004/05/14 11:00:53 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Build some test data # set fd [open data1.txt w] |
︙ | ︙ | |||
193 194 195 196 197 198 199 | SELECT DISTINCT log FROM t1 INTERSECT SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {5} | < < < < | | | | 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 | SELECT DISTINCT log FROM t1 INTERSECT SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {5} do_test select4-4.1.2 { execsql { SELECT DISTINCT log FROM t1 UNION ALL SELECT 6 INTERSECT SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {5 6} do_test select4-4.1.3 { execsql { CREATE TABLE t2 AS SELECT DISTINCT log FROM t1 UNION ALL SELECT 6 INTERSECT SELECT n FROM t1 WHERE log=3 ORDER BY log; SELECT * FROM t2; } } {5 6} execsql {DROP TABLE t2} do_test select4-4.1.4 { execsql { CREATE TABLE t2 AS SELECT DISTINCT log FROM t1 UNION ALL SELECT 6 INTERSECT SELECT n FROM t1 WHERE log=3 ORDER BY log DESC; SELECT * FROM t2; } } {6 5} execsql {DROP TABLE t2} |
︙ | ︙ | |||
469 470 471 472 473 474 475 | execsql2 { SELECT * FROM t1 WHERE n IN (SELECT n FROM t1 UNION SELECT x FROM t2) ORDER BY n LIMIT 2 } } {n 1 log 0 n 2 log 1} # Make sure DISTINCT works appropriately on TEXT and NUMERIC columns. | < < < | | | | | | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | execsql2 { SELECT * FROM t1 WHERE n IN (SELECT n FROM t1 UNION SELECT x FROM t2) ORDER BY n LIMIT 2 } } {n 1 log 0 n 2 log 1} # Make sure DISTINCT works appropriately on TEXT and NUMERIC columns. do_test select4-8.1 { execsql { BEGIN; CREATE TABLE t3(a text, b float, c text); INSERT INTO t3 VALUES(1, 1.1, '1.1'); INSERT INTO t3 VALUES(2, 1.10, '1.10'); INSERT INTO t3 VALUES(3, 1.10, '1.1'); INSERT INTO t3 VALUES(4, 1.1, '1.10'); INSERT INTO t3 VALUES(5, 1.2, '1.2'); INSERT INTO t3 VALUES(6, 1.3, '1.3'); COMMIT; } execsql { SELECT DISTINCT b FROM t3 ORDER BY c; } } {1.1 1.2 1.3} do_test select4-8.2 { |
︙ | ︙ |
Changes to test/sort.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 the CREATE TABLE statement. # | | | 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 the CREATE TABLE statement. # # $Id: sort.test,v 1.10 2004/05/14 11:00:53 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a bunch of data to sort against # do_test sort-1.0 { |
︙ | ︙ | |||
62 63 64 65 66 67 68 | execsql {SELECT n FROM t1 ORDER BY v} } {8 5 4 1 7 6 3 2} do_test sort-1.4 { execsql {SELECT n FROM t1 ORDER BY v DESC} } {2 3 6 7 1 4 5 8} do_test sort-1.5 { execsql {SELECT flt FROM t1 ORDER BY flt} | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | execsql {SELECT n FROM t1 ORDER BY v} } {8 5 4 1 7 6 3 2} do_test sort-1.4 { execsql {SELECT n FROM t1 ORDER BY v DESC} } {2 3 6 7 1 4 5 8} do_test sort-1.5 { execsql {SELECT flt FROM t1 ORDER BY flt} } {-11 -1.6 -0.0013442 0.123 2.15 3.141592653 123 4221} do_test sort-1.6 { execsql {SELECT flt FROM t1 ORDER BY flt DESC} } {4221 123 3.141592653 2.15 0.123 -0.0013442 -1.6 -11} do_test sort-1.7 { execsql {SELECT roman FROM t1 ORDER BY roman} } {I II III IV V VI VII VIII} do_test sort-1.8 { execsql {SELECT n FROM t1 ORDER BY log, flt} } {1 2 3 5 4 6 7 8} do_test sort-1.8.1 { |
︙ | ︙ | |||
352 353 354 355 356 357 358 | do_test sort-8.1 { execsql { CREATE TABLE t5(a real, b text); INSERT INTO t5 VALUES(100,'A1'); INSERT INTO t5 VALUES(100.0,'A2'); SELECT * FROM t5 ORDER BY a, b; } | | | 352 353 354 355 356 357 358 359 360 361 | do_test sort-8.1 { execsql { CREATE TABLE t5(a real, b text); INSERT INTO t5 VALUES(100,'A1'); INSERT INTO t5 VALUES(100.0,'A2'); SELECT * FROM t5 ORDER BY a, b; } } {100 A1 100 A2} finish_test |