aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authordrh <>2021-07-30 18:39:59 +0000
committerdrh <>2021-07-30 18:39:59 +0000
commit77441faff5f4d5cee08c747116fae97b48eeb9b0 (patch)
treef6691599a4454725ced373b181b39d32819e56a1 /src/util.c
parent7b3c514b5324156c8ba4c9fbb0548f374ccdb629 (diff)
downloadsqlite-77441faff5f4d5cee08c747116fae97b48eeb9b0.tar.gz
sqlite-77441faff5f4d5cee08c747116fae97b48eeb9b0.zip
Avoid clownfeet in the names columns when the column names are quoted
in the original CREATE TABLE statement. FossilOrigin-Name: 980f7292afd45a8e73272e2139b55b99ab86167febec9fd0bf0356e8167b2ee9
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index fc0c2042b..8bcf1d261 100644
--- a/src/util.c
+++ b/src/util.c
@@ -89,8 +89,11 @@ int sqlite3Strlen30(const char *z){
** the column name if and only if the COLFLAG_HASTYPE flag is set.
*/
char *sqlite3ColumnType(Column *pCol, char *zDflt){
- if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt;
- return pCol->zName + strlen(pCol->zName) + 1;
+ if( pCol->colFlags & COLFLAG_HASTYPE ){
+ return pCol->zName + strlen(pCol->zName) + 1;
+ }else{
+ return zDflt;
+ }
}
/*
@@ -267,6 +270,28 @@ void sqlite3DequoteExpr(Expr *p){
}
/*
+** If the input token p is quoted, try to adjust the token to remove
+** the quotes. This is not always possible:
+**
+** "abc" -> abc
+** "ab""cd" -> (not possible because of the interior "")
+**
+** Remove the quotes if possible. This is a optimization. The overall
+** system should still return the correct answer even if this routine
+** is always a no-op.
+*/
+void sqlite3DequoteToken(Token *p){
+ int i;
+ if( p->n<2 ) return;
+ if( !sqlite3Isquote(p->z[0]) ) return;
+ for(i=1; i<p->n-1; i++){
+ if( sqlite3Isquote(p->z[i]) ) return;
+ }
+ p->n -= 2;
+ p->z++;
+}
+
+/*
** Generate a Token object from a string
*/
void sqlite3TokenInit(Token *p, char *z){