Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Code cleanup: get rid of the sqlite3SetNString utility function. (CVS 1984) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
9ef4c24a9acc2128891303de1ffd2ef4 |
User & Date: | drh 2004-09-25 14:39:18.000 |
Context
2004-09-25
| ||
15:25 | Optimizations in the tokenizer. (CVS 1985) (check-in: 26898c57cb user: drh tags: trunk) | |
14:39 | Code cleanup: get rid of the sqlite3SetNString utility function. (CVS 1984) (check-in: 9ef4c24a9a user: drh tags: trunk) | |
13:12 | Code simplifications and size reductions. (CVS 1983) (check-in: cb631a135d 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.254 2004/09/25 14:39:18 drh 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 |
︙ | ︙ | |||
781 782 783 784 785 786 787 | Column *pCol; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; pCol = &p->aCol[i]; pz = &pCol->zType; n = pLast->n + Addr(pLast->z) - Addr(pFirst->z); | | | | 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | Column *pCol; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; pCol = &p->aCol[i]; pz = &pCol->zType; n = pLast->n + Addr(pLast->z) - Addr(pFirst->z); assert( pCol->zType==0 ); z = pCol->zType = sqlite3MPrintf("%.*s", n, pFirst->z); if( z==0 ) return; for(i=j=0; z[i]; i++){ int c = z[i]; if( isspace(c) ) continue; z[j++] = c; } z[j] = 0; |
︙ | ︙ | |||
804 805 806 807 808 809 810 | ** ** This routine is called by the parser while in the middle of ** parsing a CREATE TABLE statement. */ void sqlite3AddDefaultValue(Parse *pParse, Token *pVal, int minusFlag){ Table *p; int i; | | | | < < < < | | 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | ** ** This routine is called by the parser while in the middle of ** parsing a CREATE TABLE statement. */ void sqlite3AddDefaultValue(Parse *pParse, Token *pVal, int minusFlag){ Table *p; int i; char *z; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; assert( p->aCol[i].zDflt==0 ); z = p->aCol[i].zDflt = sqlite3MPrintf("%s%T", minusFlag ? "-" : "", pVal); sqlite3Dequote(z); } /* ** Designate the PRIMARY KEY for the table. pList is a list of names ** of columns that form the primary key. If pList is NULL, then the ** most recently added column of the table is the primary key. ** |
︙ | ︙ | |||
1012 1013 1014 1015 1016 1017 1018 | pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0); if( pColl2->xCmp!=0 ){ memcpy(pColl, pColl2, sizeof(CollSeq)); return SQLITE_OK; } } if( pParse->nErr==0 ){ | | < | 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 | pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0); if( pColl2->xCmp!=0 ){ memcpy(pColl, pColl2, sizeof(CollSeq)); return SQLITE_OK; } } if( pParse->nErr==0 ){ sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", n, z); } pParse->nErr++; return SQLITE_ERROR; } /* ** This routine is called on a collation sequence before it is used to |
︙ | ︙ | |||
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 | ** another error occurs, NULL is returned and an error message written into ** pParse. */ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){ u8 enc = pParse->db->enc; u8 initbusy = pParse->db->init.busy; CollSeq *pColl = sqlite3FindCollSeq(pParse->db, enc, zName, nName, initbusy); if( !initbusy && (!pColl || !pColl->xCmp) ){ /* No collation sequence of this type for this encoding is registered. ** Call the collation factory to see if it can supply us with one. */ callCollNeeded(pParse->db, zName, nName); pColl = sqlite3FindCollSeq(pParse->db, enc, zName, nName, 0); if( pColl && !pColl->xCmp ){ /* There may be a version of the collation sequence that requires ** translation between encodings. Search for it with synthCollSeq(). */ if( synthCollSeq(pParse, pColl) ){ return 0; } } } /* If nothing has been found, write the error message into pParse */ if( !initbusy && (!pColl || !pColl->xCmp) ){ if( pParse->nErr==0 ){ | > | < < | 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 | ** another error occurs, NULL is returned and an error message written into ** pParse. */ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){ u8 enc = pParse->db->enc; u8 initbusy = pParse->db->init.busy; CollSeq *pColl = sqlite3FindCollSeq(pParse->db, enc, zName, nName, initbusy); if( nName<0 ) nName = strlen(zName); if( !initbusy && (!pColl || !pColl->xCmp) ){ /* No collation sequence of this type for this encoding is registered. ** Call the collation factory to see if it can supply us with one. */ callCollNeeded(pParse->db, zName, nName); pColl = sqlite3FindCollSeq(pParse->db, enc, zName, nName, 0); if( pColl && !pColl->xCmp ){ /* There may be a version of the collation sequence that requires ** translation between encodings. Search for it with synthCollSeq(). */ if( synthCollSeq(pParse, pColl) ){ return 0; } } } /* If nothing has been found, write the error message into pParse */ if( !initbusy && (!pColl || !pColl->xCmp) ){ if( pParse->nErr==0 ){ sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", nName, zName); } pColl = 0; } return pColl; } |
︙ | ︙ |
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.261 2004/09/25 14:39:18 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** The following constant value is used by the SQLITE_BIGENDIAN and |
︙ | ︙ | |||
665 666 667 668 669 670 671 | /* ** Windows systems should call this routine to free memory that ** is returned in the in the errmsg parameter of sqlite3_open() when ** SQLite is a DLL. For some reason, it does not work to call free() ** directly. ** | | < < | 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 | /* ** Windows systems should call this routine to free memory that ** is returned in the in the errmsg parameter of sqlite3_open() when ** SQLite is a DLL. For some reason, it does not work to call free() ** directly. ** ** Note that we need to call free() not sqliteFree() here. */ void sqlite3_free(char *p){ free(p); } /* ** Create new user functions. */ int sqlite3_create_function( |
︙ | ︙ |
Changes to src/pragma.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2003 April 6 ** ** 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 contains code used to implement the PRAGMA command. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2003 April 6 ** ** 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 contains code used to implement the PRAGMA command. ** ** $Id: pragma.c,v 1.67 2004/09/25 14:39:19 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) # include "pager.h" # include "btree.h" |
︙ | ︙ | |||
203 204 205 206 207 208 209 | iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); if( iDb<0 ) return; pDb = &db->aDb[iDb]; zLeft = sqlite3NameFromToken(pId); if( !zLeft ) return; if( minusFlag ){ | | < | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); if( iDb<0 ) return; pDb = &db->aDb[iDb]; zLeft = sqlite3NameFromToken(pId); if( !zLeft ) return; if( minusFlag ){ zRight = sqlite3MPrintf("-%T", pValue); }else{ zRight = sqlite3NameFromToken(pValue); } zDb = ((iDb>0)?pDb->zName:0); if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ goto pragma_out; |
︙ | ︙ |
Changes to src/select.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 SELECT statements 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 C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** ** $Id: select.c,v 1.211 2004/09/25 14:39:19 drh Exp $ */ #include "sqliteInt.h" /* ** Allocate a new Select structure and return a pointer to that ** structure. |
︙ | ︙ | |||
112 113 114 115 116 117 118 | break; } } if( (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) || (jointype & JT_ERROR)!=0 ){ | < | > | | | | < | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | break; } } if( (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) || (jointype & JT_ERROR)!=0 ){ const char *zSp1 = " "; const char *zSp2 = " "; if( pB==0 ){ zSp1++; } if( pC==0 ){ zSp2++; } sqlite3ErrorMsg(pParse, "unknown or unsupported join type: " "%T%s%T%s%T", pA, zSp1, pB, zSp2, pC); jointype = JT_INNER; }else if( jointype & JT_RIGHT ){ sqlite3ErrorMsg(pParse, "RIGHT and FULL OUTER JOINs are not currently supported"); jointype = JT_INNER; } return jointype; |
︙ | ︙ | |||
476 477 478 479 480 481 482 | assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_NotNull, -1, addr1+3); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0); if( pOrderBy ){ pushOntoSorter(pParse, v, pOrderBy); }else{ | < | 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_NotNull, -1, addr1+3); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0); if( pOrderBy ){ pushOntoSorter(pParse, v, pOrderBy); }else{ char aff = (iParm>>16)&0xFF; aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff); sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &aff, 1); sqlite3VdbeAddOp(v, OP_String8, 0, 0); sqlite3VdbeAddOp(v, OP_PutStrKey, (iParm&0x0000FFFF), 0); } sqlite3VdbeChangeP2(v, addr2, sqlite3VdbeCurrentAddr(v)); |
︙ | ︙ |
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.324 2004/09/25 14:39:19 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ #include "config.h" #include "sqlite3.h" #include "hash.h" |
︙ | ︙ | |||
193 194 195 196 197 198 199 | #ifdef SQLITE_DEBUG # define sqliteMalloc(X) sqlite3Malloc_(X,1,__FILE__,__LINE__) # define sqliteMallocRaw(X) sqlite3Malloc_(X,0,__FILE__,__LINE__) # define sqliteFree(X) sqlite3Free_(X,__FILE__,__LINE__) # define sqliteRealloc(X,Y) sqlite3Realloc_(X,Y,__FILE__,__LINE__) # define sqliteStrDup(X) sqlite3StrDup_(X,__FILE__,__LINE__) # define sqliteStrNDup(X,Y) sqlite3StrNDup_(X,Y,__FILE__,__LINE__) | < < < | | | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | #ifdef SQLITE_DEBUG # define sqliteMalloc(X) sqlite3Malloc_(X,1,__FILE__,__LINE__) # define sqliteMallocRaw(X) sqlite3Malloc_(X,0,__FILE__,__LINE__) # define sqliteFree(X) sqlite3Free_(X,__FILE__,__LINE__) # define sqliteRealloc(X,Y) sqlite3Realloc_(X,Y,__FILE__,__LINE__) # define sqliteStrDup(X) sqlite3StrDup_(X,__FILE__,__LINE__) # define sqliteStrNDup(X,Y) sqlite3StrNDup_(X,Y,__FILE__,__LINE__) #else # define sqliteFree sqlite3FreeX # define sqliteMalloc sqlite3Malloc # define sqliteMallocRaw sqlite3MallocRaw # define sqliteRealloc sqlite3Realloc # define sqliteStrDup sqlite3StrDup # define sqliteStrNDup sqlite3StrNDup #endif /* ** This variable gets set if malloc() ever fails. After it gets set, ** the SQLite library shuts down permanently. */ extern int sqlite3_malloc_failed; |
︙ | ︙ | |||
1204 1205 1206 1207 1208 1209 1210 | #endif void sqlite3FreeX(void*); char *sqlite3MPrintf(const char*, ...); char *sqlite3VMPrintf(const char*, va_list); void sqlite3DebugPrintf(const char*, ...); void *sqlite3TextToPtr(const char*); void sqlite3SetString(char **, const char *, ...); | < | 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 | #endif void sqlite3FreeX(void*); char *sqlite3MPrintf(const char*, ...); char *sqlite3VMPrintf(const char*, va_list); void sqlite3DebugPrintf(const char*, ...); void *sqlite3TextToPtr(const char*); void sqlite3SetString(char **, const char *, ...); void sqlite3ErrorMsg(Parse*, const char*, ...); void sqlite3Dequote(char*); int sqlite3KeywordCode(const char*, int); int sqlite3RunParser(Parse*, const char*, char **); void sqlite3FinishCoding(Parse*); Expr *sqlite3Expr(int, Expr*, Expr*, Token*); Expr *sqlite3ExprAnd(Expr*, Expr*); |
︙ | ︙ |
Changes to src/table.c.
︙ | ︙ | |||
146 147 148 149 150 151 152 | res.azResult[0] = (char*)res.nData; } if( rc==SQLITE_ABORT ){ sqlite3_free_table(&res.azResult[1]); if( res.zErrMsg ){ if( pzErrMsg ){ free(*pzErrMsg); | | < < < > | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | res.azResult[0] = (char*)res.nData; } if( rc==SQLITE_ABORT ){ sqlite3_free_table(&res.azResult[1]); if( res.zErrMsg ){ if( pzErrMsg ){ free(*pzErrMsg); *pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg); } sqliteFree(res.zErrMsg); } return res.rc; } sqliteFree(res.zErrMsg); if( rc!=SQLITE_OK ){ sqlite3_free_table(&res.azResult[1]); return rc; |
︙ | ︙ |
Changes to src/tokenize.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** ** $Id: tokenize.c,v 1.88 2004/09/25 14:39:19 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include <stdlib.h> /* |
︙ | ︙ | |||
496 497 498 499 500 501 502 | pParse->rc = SQLITE_INTERRUPT; sqlite3SetString(pzErrMsg, "interrupt", (char*)0); goto abort_parse; } break; } case TK_ILLEGAL: { | > > | | > | 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | pParse->rc = SQLITE_INTERRUPT; sqlite3SetString(pzErrMsg, "interrupt", (char*)0); goto abort_parse; } break; } case TK_ILLEGAL: { if( pzErrMsg ){ sqliteFree(*pzErrMsg); *pzErrMsg = sqlite3MPrintf("unrecognized token: \"%T\"", &pParse->sLastToken); } nErr++; goto abort_parse; } case TK_SEMI: { pParse->zTail = &zSql[i]; /* Fall thru into the default case */ } |
︙ | ︙ |
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.118 2004/09/25 14:39:19 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> #if SQLITE_DEBUG>2 && defined(__GLIBC__) #include <execinfo.h> |
︙ | ︙ | |||
210 211 212 213 214 215 216 | print_stack_trace(); fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n", ++memcnt, oldN, n, (int)oldP, (int)p, zFile, line); #endif return p; } | < < < < < < < < < < < < < < < < < < < < < < | 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | print_stack_trace(); fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n", ++memcnt, oldN, n, (int)oldP, (int)p, zFile, line); #endif return p; } /* ** Make a copy of a string in memory obtained from sqliteMalloc() */ char *sqlite3StrDup_(const char *z, char *zFile, int line){ char *zNew; if( z==0 ) return 0; zNew = sqlite3Malloc_(strlen(z)+1, 0, zFile, line); |
︙ | ︙ | |||
385 386 387 388 389 390 391 | #ifdef SQLITE_DEBUG #if SQLITE_DEBUG>1 fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz); #endif #endif } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | #ifdef SQLITE_DEBUG #if SQLITE_DEBUG>1 fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz); #endif #endif } /* ** Set the most recent error code and error string for the sqlite ** handle "db". The error code is set to "err_code". ** ** If it is not NULL, string zFormat specifies the format of the ** error string in the style of the printf functions: The following ** format characters are allowed: |
︙ | ︙ |
Changes to src/vdbeaux.c.
︙ | ︙ | |||
300 301 302 303 304 305 306 | }else if( n==P3_KEYINFO_HANDOFF ){ pOp->p3 = (char*)zP3; pOp->p3type = P3_KEYINFO; }else if( n<0 ){ pOp->p3 = (char*)zP3; pOp->p3type = n; }else{ | > | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | }else if( n==P3_KEYINFO_HANDOFF ){ pOp->p3 = (char*)zP3; pOp->p3type = P3_KEYINFO; }else if( n<0 ){ pOp->p3 = (char*)zP3; pOp->p3type = n; }else{ if( n==0 ) n = strlen(zP3); pOp->p3 = sqliteStrNDup(zP3, n); pOp->p3type = P3_DYNAMIC; } } #ifndef NDEBUG /* ** Replace the P3 field of the most recently coded instruction with |
︙ | ︙ |