Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Simplifications to the sqlite3_normalized_sql() implementation. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
94ea6379178e3ff6a0d1d5819ca4ac55 |
User & Date: | drh 2018-12-05 17:48:57.422 |
References
2018-12-05
| ||
21:55 | Fix an imbalanced lock problem in sqlite3Normalize() introduced by the simplification in [94ea6379178e3ff6a]. (check-in: f69624373e user: drh tags: trunk) | |
Context
2018-12-05
| ||
19:42 | Increase the version number to 3.27.0 for the next development cycle. (check-in: 8f8d682825 user: drh tags: trunk) | |
18:28 | Merge enhancements and the ALTER TABLE bug fix from trunk. (check-in: edfc2acfcd user: drh tags: apple-osx) | |
17:48 | Simplifications to the sqlite3_normalized_sql() implementation. (check-in: 94ea637917 user: drh tags: trunk) | |
13:49 | Ensure that ALTER TABLE modifies table and column names embedded in WITH clauses that are part of views and triggers. (check-in: f44bc7a8b3 user: dan tags: trunk) | |
Changes
Changes to src/callback.c.
︙ | ︙ | |||
279 280 281 282 283 284 285 | return match; } /* ** Search a FuncDefHash for a function with the given name. Return ** a pointer to the matching FuncDef if found, or 0 if there is no match. */ | | < < < < < < < < < < < < < < < | | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | return match; } /* ** Search a FuncDefHash for a function with the given name. Return ** a pointer to the matching FuncDef if found, or 0 if there is no match. */ FuncDef *sqlite3FunctionSearch( int h, /* Hash of the name */ const char *zFunc /* Name of function */ ){ FuncDef *p; for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){ if( sqlite3StrICmp(p->zName, zFunc)==0 ){ return p; } } return 0; } /* ** Insert a new FuncDef into a FuncDefHash hash table. */ void sqlite3InsertBuiltinFuncs( FuncDef *aDef, /* List of global functions to be inserted */ int nDef /* Length of the apDef[] list */ ){ int i; for(i=0; i<nDef; i++){ FuncDef *pOther; const char *zName = aDef[i].zName; int nName = sqlite3Strlen30(zName); int h = SQLITE_FUNC_HASH(zName[0], nName); assert( zName[0]>='a' && zName[0]<='z' ); pOther = sqlite3FunctionSearch(h, zName); if( pOther ){ assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] ); aDef[i].pNext = pOther->pNext; pOther->pNext = &aDef[i]; }else{ aDef[i].pNext = 0; aDef[i].u.pHash = sqlite3BuiltinFunctions.a[h]; |
︙ | ︙ | |||
399 400 401 402 403 404 405 | ** have fields overwritten with new information appropriate for the ** new function. But the FuncDefs for built-in functions are read-only. ** So we must not search for built-ins when creating a new function. */ if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){ bestScore = 0; h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName); | | | 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | ** have fields overwritten with new information appropriate for the ** new function. But the FuncDefs for built-in functions are read-only. ** So we must not search for built-ins when creating a new function. */ if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){ bestScore = 0; h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName); p = sqlite3FunctionSearch(h, zName); while( p ){ int score = matchQuality(p, nArg, enc); if( score>bestScore ){ pBest = p; bestScore = score; } p = p->pNext; |
︙ | ︙ |
Changes to src/hash.c.
︙ | ︙ | |||
60 61 62 63 64 65 66 | ** 0x9e3779b1 is 2654435761 which is the closest prime number to ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */ h += sqlite3UpperToLower[c]; h *= 0x9e3779b1; } return h; } | < < < < < < < < < < < < < < | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | ** 0x9e3779b1 is 2654435761 which is the closest prime number to ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */ h += sqlite3UpperToLower[c]; h *= 0x9e3779b1; } return h; } /* Link pNew element into the hash table pH. If pEntry!=0 then also ** insert pNew into the pEntry hash bucket. */ static void insertElement( Hash *pH, /* The complete hash table */ |
︙ | ︙ | |||
185 186 187 188 189 190 191 | if( sqlite3StrICmp(elem->pKey,pKey)==0 ){ return elem; } elem = elem->next; } return &nullElement; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | if( sqlite3StrICmp(elem->pKey,pKey)==0 ){ return elem; } elem = elem->next; } return &nullElement; } /* Remove a single entry from the hash table given a pointer to that ** element and a hash on the element's key. */ static void removeElementGivenHash( Hash *pH, /* The pH containing "elem" */ HashElem* elem, /* The element to be removed from the pH */ |
︙ | ︙ | |||
263 264 265 266 267 268 269 | ** found, or NULL if there is no match. */ void *sqlite3HashFind(const Hash *pH, const char *pKey){ assert( pH!=0 ); assert( pKey!=0 ); return findElementWithHash(pH, pKey, 0)->data; } | < < < < < < < < | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | ** found, or NULL if there is no match. */ void *sqlite3HashFind(const Hash *pH, const char *pKey){ assert( pH!=0 ); assert( pKey!=0 ); return findElementWithHash(pH, pKey, 0)->data; } /* Insert an element into the hash table pH. The key is pKey ** and the data is "data". ** ** If no element exists with a matching key, then a new ** element is created and NULL is returned. ** |
︙ | ︙ |
Changes to src/hash.h.
︙ | ︙ | |||
64 65 66 67 68 69 70 | /* ** Access routines. To delete, insert a NULL pointer. */ void sqlite3HashInit(Hash*); void *sqlite3HashInsert(Hash*, const char *pKey, void *pData); void *sqlite3HashFind(const Hash*, const char *pKey); | < < < | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | /* ** Access routines. To delete, insert a NULL pointer. */ void sqlite3HashInit(Hash*); void *sqlite3HashInsert(Hash*, const char *pKey, void *pData); void *sqlite3HashFind(const Hash*, const char *pKey); void sqlite3HashClear(Hash*); /* ** Macros for looping over all elements of a hash table. The idiom is ** like this: ** ** Hash h; |
︙ | ︙ |
Changes to src/prepare.c.
︙ | ︙ | |||
724 725 726 727 728 729 730 731 | ){ int bFound = 0; /* Non-zero if token is an identifier name. */ int i, j; /* Database and column loop indexes. */ Schema *pSchema; /* Schema for current database. */ Hash *pHash; /* Hash table of tables for current database. */ HashElem *e; /* Hash element for hash table iteration. */ Table *pTab; /* Database table for columns being checked. */ | > > > > > > > > > > | | > | > > > | | | 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | ){ int bFound = 0; /* Non-zero if token is an identifier name. */ int i, j; /* Database and column loop indexes. */ Schema *pSchema; /* Schema for current database. */ Hash *pHash; /* Hash table of tables for current database. */ HashElem *e; /* Hash element for hash table iteration. */ Table *pTab; /* Database table for columns being checked. */ char *zId; /* Zero terminated name of the identifier */ char zSpace[50]; /* Static space for the zero-terminated name */ if( nToken<sizeof(zSpace) ){ memcpy(zSpace, zToken, nToken); zSpace[nToken] = 0; zId = zSpace; }else{ zId = sqlite3DbStrNDup(db, zToken, nToken); if( zId==0 ) return 0; } if( sqlite3IsRowid(zId) ){ bFound = 1; goto done; } if( nToken>0 ){ int hash = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zToken[0]], nToken); if( sqlite3FunctionSearch(hash, zId) ){ bFound = 1; goto done; } } assert( db!=0 ); sqlite3_mutex_enter(db->mutex); sqlite3BtreeEnterAll(db); for(i=0; i<db->nDb; i++){ pHash = &db->aFunc; if( sqlite3HashFind(pHash, zId) ){ bFound = 1; break; } pSchema = db->aDb[i].pSchema; if( pSchema==0 ) continue; pHash = &pSchema->tblHash; if( sqlite3HashFind(pHash, zId) ){ bFound = 1; break; } for(e=sqliteHashFirst(pHash); e; e=sqliteHashNext(e)){ pTab = sqliteHashData(e); if( pTab==0 ) continue; pHash = pTab->pColHash; |
︙ | ︙ | |||
766 767 768 769 770 771 772 | } }else{ *pRc = SQLITE_NOMEM_BKPT; bFound = 0; goto done; } } | | > | 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | } }else{ *pRc = SQLITE_NOMEM_BKPT; bFound = 0; goto done; } } if( pHash && sqlite3HashFind(pHash, zId) ){ bFound = 1; goto done; } } } done: sqlite3BtreeLeaveAll(db); sqlite3_mutex_leave(db->mutex); if( zId!=zSpace ) sqlite3DbFree(db, zId); return bFound; } /* ** Attempt to estimate the final output buffer size needed for the fully ** normalized version of the specified SQL string. This should take into ** account any potential expansion that could occur (e.g. via IN clauses |
︙ | ︙ |
Changes to src/sqliteInt.h.
︙ | ︙ | |||
4052 4053 4054 4055 4056 4057 4058 | void sqlite3UniqueConstraint(Parse*, int, Index*); void sqlite3RowidConstraint(Parse*, int, Table*); Expr *sqlite3ExprDup(sqlite3*,Expr*,int); ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); IdList *sqlite3IdListDup(sqlite3*,IdList*); Select *sqlite3SelectDup(sqlite3*,Select*,int); | < | < | 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 | void sqlite3UniqueConstraint(Parse*, int, Index*); void sqlite3RowidConstraint(Parse*, int, Table*); Expr *sqlite3ExprDup(sqlite3*,Expr*,int); ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); IdList *sqlite3IdListDup(sqlite3*,IdList*); Select *sqlite3SelectDup(sqlite3*,Select*,int); FuncDef *sqlite3FunctionSearch(int,const char*); void sqlite3InsertBuiltinFuncs(FuncDef*,int); FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8); void sqlite3RegisterBuiltinFunctions(void); void sqlite3RegisterDateTimeFunctions(void); void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*); int sqlite3SafetyCheckOk(sqlite3*); int sqlite3SafetyCheckSickOrOk(sqlite3*); |
︙ | ︙ |