diff options
author | drh <drh@noemail.net> | 2002-05-21 13:43:04 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2002-05-21 13:43:04 +0000 |
commit | 2398937b7f408e955ab5b2644db9d59883ebc055 (patch) | |
tree | 6ab76352aff496544ab6673d77b5feeefc9abc29 /src/expr.c | |
parent | 1d1f30555d2e5c95a2675430d9d812582bba4c88 (diff) | |
download | sqlite-2398937b7f408e955ab5b2644db9d59883ebc055.tar.gz sqlite-2398937b7f408e955ab5b2644db9d59883ebc055.zip |
Double-quoted strings resolve to column names if possible. Single-quoted
strings continue to be interpreted as string literals. (CVS 576)
FossilOrigin-Name: 55e7d65496624c8e48673d8747f3123786bfedbc
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/expr.c b/src/expr.c index 008693efa..eafd09592 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.60 2002/05/19 23:43:14 danielk1977 Exp $ +** $Id: expr.c,v 1.61 2002/05/21 13:43:04 drh Exp $ */ #include "sqliteInt.h" @@ -285,6 +285,10 @@ void sqliteExprListDelete(ExprList *pList){ /* ** Walk an expression tree. Return 1 if the expression is constant ** and 0 if it involves variables. +** +** For the purposes of this function, a double-quoted string (ex: "abc") +** is considered a variable but a single-quoted string (ex: 'abc') is +** a constant. */ int sqliteExprIsConstant(Expr *p){ switch( p->op ){ @@ -292,9 +296,10 @@ int sqliteExprIsConstant(Expr *p){ case TK_COLUMN: case TK_DOT: return 0; + case TK_STRING: + return p->token.z[0]=='\''; case TK_INTEGER: case TK_FLOAT: - case TK_STRING: return 1; default: { if( p->pLeft && !sqliteExprIsConstant(p->pLeft) ) return 0; @@ -362,6 +367,14 @@ int sqliteExprResolveIds( if( pExpr==0 || pTabList==0 ) return 0; assert( base+pTabList->nId<=pParse->nTab ); switch( pExpr->op ){ + /* Double-quoted strings (ex: "abc") are used as identifiers if + ** possible. Otherwise they remain as strings. Single-quoted + ** strings (ex: 'abc') are always string literals. + */ + case TK_STRING: { + if( pExpr->token.z[0]=='\'' ) break; + /* Fall thru into the TK_ID case if this is a double-quoted string */ + } /* A lone identifier. Try and match it as follows: ** ** 1. To the name of a column of one of the tables in pTabList @@ -419,7 +432,7 @@ int sqliteExprResolveIds( pExpr->op = TK_COLUMN; } sqliteFree(z); - if( cnt==0 ){ + if( cnt==0 && pExpr->token.z[0]!='"' ){ sqliteSetNString(&pParse->zErrMsg, "no such column: ", -1, pExpr->token.z, pExpr->token.n, 0); pParse->nErr++; |