The sqlite3_normalized_sql() interface should not be transforming quoted
identifier names into wildcards. Fix this, and at the same time simplify the code substantially. FossilOrigin-Name: e8540377ec66fa5f9ae3c93bedb5c094057698199c37fc211f7ea95429e815e4
This commit is contained in:
parent
d4a4dd6ebc
commit
253a6af532
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Fix\san\simbalanced\slock\sproblem\sin\ssqlite3Normalize()\sintroduced\sby\sthe\nsimplification\sin\s[94ea6379178e3ff6a].
|
||||
D 2018-12-05T21:55:39.342
|
||||
C The\ssqlite3_normalized_sql()\sinterface\sshould\snot\sbe\stransforming\squoted\nidentifier\snames\sinto\swildcards.\s\sFix\sthis,\sand\sat\sthe\ssame\stime\ssimplify\nthe\scode\ssubstantially.
|
||||
D 2018-12-05T23:45:46.950
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F Makefile.in 68d0ba0f0b533d5bc84c78c13a6ce84ee81183a67014caa47a969e67f028fa1c
|
||||
@ -459,7 +459,7 @@ F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957
|
||||
F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7
|
||||
F src/dbstat.c 3c8bd4e77f0244fd2bd7cc90acf116ad2f8e82d70e536637f35ac2bc99b726f9
|
||||
F src/delete.c f7938125847e8ef485448db5fbad29acb2991381a02887dd854c1617315ab9fb
|
||||
F src/expr.c 9aacc0b72348ba90010b672dcbbbe2fa56e1182043bc917a3a147b2bc57a5497
|
||||
F src/expr.c a3e90131d7f92b77a6a6ae2e71f0d2882237041ed11dbe3c914e5e278ddc2d24
|
||||
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
|
||||
F src/fkey.c 972a4ba14296bef2303a0abbad1e3d82bc3c61f9e6ce4e8e9528bdee68748812
|
||||
F src/func.c 7c288b4ce309b5a8b8473514b88e1f8e69a80134509a8c0db8e39c858e367e7f
|
||||
@ -502,7 +502,7 @@ F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
|
||||
F src/pcache1.c ad0ffc5b35b0280d045ac569d34d4b842e3e6a4a118f6396b320987a0957afcc
|
||||
F src/pragma.c 4e056f042683b99c4ea0db395f68d051b1a95833ab40951c40d3ef7e1fee1354
|
||||
F src/pragma.h fdd03d78a7497f74a3f652909f945328480089189526841ae829ce7313d98d13
|
||||
F src/prepare.c 733d34a557cf2fb81af31fcf7c8df6a8070fcbef1a535ae120d2ff4fda99452d
|
||||
F src/prepare.c 90099721296d9646addc5dda092464da21546e7410406818dde1600467b120c4
|
||||
F src/printf.c 0f1177cf1dd4d7827bf64d840768514ec76409abecaca9e8b577dbd065150381
|
||||
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
|
||||
F src/resolve.c 976e7879286a1eecdc71ceff64f6d1b3f58c8f8096537ba668b3dc0887f410c1
|
||||
@ -512,7 +512,7 @@ F src/shell.c.in 1f0819e69fb1ebd2eb44695530dc43936608bf9b752981a0ffd4e2e4a9e3883
|
||||
F src/sqlite.h.in cce9feede1c1c03923c091b4bbbd081dd77aaf92024cc2cdbf65f712c2f668c3
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683
|
||||
F src/sqliteInt.h e96520f27310016d0dabb496e13346244bbea83a6adc3134810e026f1d4a02b6
|
||||
F src/sqliteInt.h 8a9a4c1cce0cfd95d0fa8527ee12dbba0e7e1ec9983109626d4932cd48c5d571
|
||||
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
|
||||
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
|
||||
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
|
||||
@ -1142,7 +1142,7 @@ F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
|
||||
F test/nan.test 437d40e6d0778b050d7750726c0cbd2c9936b81962926e8f8c48ca698f00f4d1
|
||||
F test/nockpt.test 8c43b25af63b0bd620cf1b003529e37b6f1dc53bd22690e96a1bd73f78dde53a
|
||||
F test/nolock.test f196cf8b8fbea4e2ca345140a2b3f3b0da45c76e
|
||||
F test/normalize.test 17ff5c732bc16b100f4e479da3a59735ed24f4ed574fccf8e46279fad182f81e
|
||||
F test/normalize.test 7fe7674d83e37c635ea2e88a27b54a0fe1afddb192d636d5672b1639859800f1
|
||||
F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf
|
||||
F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161
|
||||
F test/notify3.test 10ff25cde502e72a92053a2f215d64bece4ef934
|
||||
@ -1782,7 +1782,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 8f8d682825d065bcaebda4cba63f8b67789b923d8b62eb7c576a5bc01536f577
|
||||
R 54e3066009cd3484077d0fae620be2a9
|
||||
P f69624373e33c4d370a9264a317ffdb0adbce967a950f243de2b41161a8c7ded
|
||||
R f3aa45194b952de0676e91bd1b04c704
|
||||
U drh
|
||||
Z dbd77411550a9172a53b37194b8bf655
|
||||
Z 5f1f0ed88784c364d2e88ebae6a00a1f
|
||||
|
@ -1 +1 @@
|
||||
f69624373e33c4d370a9264a317ffdb0adbce967a950f243de2b41161a8c7ded
|
||||
e8540377ec66fa5f9ae3c93bedb5c094057698199c37fc211f7ea95429e815e4
|
@ -2149,14 +2149,6 @@ int sqlite3IsRowid(const char *z){
|
||||
if( sqlite3StrICmp(z, "OID")==0 ) return 1;
|
||||
return 0;
|
||||
}
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
int sqlite3IsRowidN(const char *z, int n){
|
||||
if( sqlite3StrNICmp(z, "_ROWID_", n)==0 ) return 1;
|
||||
if( sqlite3StrNICmp(z, "ROWID", n)==0 ) return 1;
|
||||
if( sqlite3StrNICmp(z, "OID", n)==0 ) return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** pX is the RHS of an IN operator. If pX is a SELECT statement
|
||||
|
@ -710,93 +710,6 @@ static int sqlite3LockAndPrepare(
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
/*
|
||||
** Checks if the specified token is a table, column, or function name,
|
||||
** based on the databases associated with the statement being prepared.
|
||||
** If the function fails, zero is returned and pRc is filled with the
|
||||
** error code.
|
||||
*/
|
||||
static int shouldTreatAsIdentifier(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const char *zToken, /* Pointer to start of token to be checked */
|
||||
int nToken, /* Length of token to be checked */
|
||||
int *pRc /* Pointer to error code upon failure */
|
||||
){
|
||||
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 done1;
|
||||
}
|
||||
if( nToken>0 ){
|
||||
int hash = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zToken[0]], nToken);
|
||||
if( sqlite3FunctionSearch(hash, zId) ){
|
||||
bFound = 1;
|
||||
goto done1;
|
||||
}
|
||||
}
|
||||
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;
|
||||
if( pHash==0 ){
|
||||
pTab->pColHash = pHash = sqlite3_malloc(sizeof(Hash));
|
||||
if( pHash ){
|
||||
sqlite3HashInit(pHash);
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
Column *pCol = &pTab->aCol[j];
|
||||
sqlite3HashInsert(pHash, pCol->zName, pCol);
|
||||
}
|
||||
}else{
|
||||
*pRc = SQLITE_NOMEM_BKPT;
|
||||
bFound = 0;
|
||||
goto done2;
|
||||
}
|
||||
}
|
||||
if( pHash && sqlite3HashFind(pHash, zId) ){
|
||||
bFound = 1;
|
||||
goto done2;
|
||||
}
|
||||
}
|
||||
}
|
||||
done2:
|
||||
sqlite3BtreeLeaveAll(db);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
done1:
|
||||
if( zId!=zSpace ) sqlite3DbFree(db, zId);
|
||||
return bFound;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to estimate the final output buffer size needed for the fully
|
||||
@ -972,19 +885,12 @@ char *sqlite3Normalize(
|
||||
z[j++] = ' ';
|
||||
}
|
||||
if( tokenType==TK_ID ){
|
||||
int i2 = i, n2 = n, rc = SQLITE_OK;
|
||||
int i2 = i, n2 = n;
|
||||
if( nParen>0 ){
|
||||
assert( nParen<nSql );
|
||||
sqlite3HashInsert(&inHash, zSql+nParen, 0);
|
||||
}
|
||||
if( flags&SQLITE_TOKEN_QUOTED ){ i2++; n2-=2; }
|
||||
if( shouldTreatAsIdentifier(db, zSql+i2, n2, &rc)==0 ){
|
||||
if( rc!=SQLITE_OK ) goto normalizeError;
|
||||
if( sqlite3_keyword_check(zSql+i2, n2)==0 ){
|
||||
z[j++] = '?';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
copyNormalizedToken(zSql, i, n, flags, z, &j);
|
||||
break;
|
||||
|
@ -4027,9 +4027,6 @@ int sqlite3ExprIsInteger(Expr*, int*);
|
||||
int sqlite3ExprCanBeNull(const Expr*);
|
||||
int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
|
||||
int sqlite3IsRowid(const char*);
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
int sqlite3IsRowidN(const char*, int);
|
||||
#endif
|
||||
void sqlite3GenerateRowDelete(
|
||||
Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int);
|
||||
void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
|
||||
|
@ -207,7 +207,7 @@ foreach {tnum sql flags norm} {
|
||||
430
|
||||
{SELECT "a" FROM t1 WHERE "x" IN ("1","2",'3');}
|
||||
0x2
|
||||
{0 {SELECT"a"FROM t1 WHERE"x"IN(?,?,?);}}
|
||||
{0 {SELECT"a"FROM t1 WHERE"x"IN("1","2",?);}}
|
||||
|
||||
440
|
||||
{SELECT 'a' FROM t1 WHERE 'x';}
|
||||
|
Loading…
Reference in New Issue
Block a user