diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/alter.c | 1 | ||||
-rw-r--r-- | src/build.c | 2 | ||||
-rw-r--r-- | src/resolve.c | 7 | ||||
-rw-r--r-- | src/select.c | 1 | ||||
-rw-r--r-- | src/sqliteInt.h | 2 | ||||
-rw-r--r-- | src/util.c | 13 |
6 files changed, 24 insertions, 2 deletions
diff --git a/src/alter.c b/src/alter.c index 7114757a2..b041291a2 100644 --- a/src/alter.c +++ b/src/alter.c @@ -469,6 +469,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ for(i=0; i<pNew->nCol; i++){ Column *pCol = &pNew->aCol[i]; pCol->zName = sqlite3DbStrDup(db, pCol->zName); + pCol->hName = sqlite3StrIHash(pCol->zName); pCol->zColl = 0; pCol->pDflt = 0; } diff --git a/src/build.c b/src/build.c index dcd035e99..cf36766ae 100644 --- a/src/build.c +++ b/src/build.c @@ -590,6 +590,7 @@ void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){ assert( pTable!=0 ); if( (pCol = pTable->aCol)!=0 ){ for(i=0; i<pTable->nCol; i++, pCol++){ + assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) ); sqlite3DbFree(db, pCol->zName); sqlite3ExprDelete(db, pCol->pDflt); sqlite3DbFree(db, pCol->zColl); @@ -1238,6 +1239,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ pCol = &p->aCol[p->nCol]; memset(pCol, 0, sizeof(p->aCol[0])); pCol->zName = z; + pCol->hName = sqlite3StrIHash(z); sqlite3ColumnPropertiesFromName(p, pCol); if( pType->n==0 ){ diff --git a/src/resolve.c b/src/resolve.c index 2def65f99..5877dfa37 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -294,6 +294,7 @@ static int lookupName( if( pSrcList ){ for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){ + u8 hCol; pTab = pItem->pTab; assert( pTab!=0 && pTab->zName!=0 ); assert( pTab->nCol>0 ); @@ -327,8 +328,9 @@ static int lookupName( if( 0==(cntTab++) ){ pMatch = pItem; } + hCol = sqlite3StrIHash(zCol); for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){ - if( sqlite3StrICmp(pCol->zName, zCol)==0 ){ + if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ /* If there has been exactly one prior match and this match ** is for the right-hand table of a NATURAL JOIN or is in a ** USING clause, then skip this match. @@ -389,10 +391,11 @@ static int lookupName( if( pTab ){ int iCol; + u8 hCol = sqlite3StrIHash(zCol); pSchema = pTab->pSchema; cntTab++; for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){ - if( sqlite3StrICmp(pCol->zName, zCol)==0 ){ + if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ if( iCol==pTab->iPKey ){ iCol = -1; } diff --git a/src/select.c b/src/select.c index ce85c91d0..76b9827e8 100644 --- a/src/select.c +++ b/src/select.c @@ -2023,6 +2023,7 @@ int sqlite3ColumnsFromExprList( if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } pCol->zName = zName; + pCol->hName = sqlite3StrIHash(zName); sqlite3ColumnPropertiesFromName(0, pCol); if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ sqlite3OomFault(db); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index d08c7ce1e..aaa99a43a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1949,6 +1949,7 @@ struct Column { u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ char affinity; /* One of the SQLITE_AFF_... values */ u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ + u8 hName; /* Column name hash for faster lookup */ u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ }; @@ -4567,6 +4568,7 @@ int sqlite3MatchEName( const char* ); Bitmask sqlite3ExprColUsed(Expr*); +u8 sqlite3StrIHash(const char*); int sqlite3ResolveExprNames(NameContext*, Expr*); int sqlite3ResolveExprListNames(NameContext*, ExprList*); void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); diff --git a/src/util.c b/src/util.c index 693759bff..09520d1d6 100644 --- a/src/util.c +++ b/src/util.c @@ -318,6 +318,19 @@ int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ } /* +** Compute an 8-bit hash on a string that is insensitive to case differences +*/ +u8 sqlite3StrIHash(const char *z){ + u8 h = 0; + if( z==0 ) return 0; + while( z[0] ){ + h += UpperToLower[(unsigned char)z[0]]; + z++; + } + return h; +} + +/* ** Compute 10 to the E-th power. Examples: E==1 results in 10. ** E==2 results in 100. E==50 results in 1.0e50. ** |