Skip to content

Commit

Permalink
Improved interface to double-quoted string literal enabling/disabling.
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 923cfd53fcff2fcb91530bf819d2ecb0eda3f6a27dae29c7460f9ce3a3ffce7b
  • Loading branch information
drh committed Jun 17, 2019
1 parent 0a6873b commit d0ff601
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 51 deletions.
25 changes: 11 additions & 14 deletions manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
C Add\sSQLITE_DBCONFIG\soptions\sLEGACY_ALTER_TABLE,\sNO_DQS_SCHEMA,\sand\sNO_DQS.
D 2019-06-14T21:25:25.591
C Improved\sinterface\sto\sdouble-quoted\sstring\sliteral\senabling/disabling.
D 2019-06-17T13:56:11.777
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
Expand Down Expand Up @@ -486,7 +486,7 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c f20925c2c08144442dabeb73dcd0f5026f5f085d827f3d5635f7c45e5d195320
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 22afc33c3a61b4fd80a60a54f1882688371e6bc64685df2696b008fce65a999c
F src/main.c a511e378ab8e839f77e041347fe045194b9f4b2203050c6dbfdb75902ff628c2
F src/main.c e16c702032930fd9d8c0533fed7575f3900022c13a59cc2817e60f07096a005e
F src/malloc.c 0f9da2a66b230a5785af94b9672126845099b57b70a32c987d04ac28c69da990
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de
Expand Down Expand Up @@ -520,19 +520,19 @@ F src/pragma.h 4a9fabff14db4487a734dfeeb4be984ce662bfdccfae16145b9c732327735e13
F src/prepare.c 78027c6231fbb19ca186a5f5f0c0a1375d9c2cec0655273f9bd90d9ff74a34b3
F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 8fd2fca510e8ae7457f37f294809900d232a2e5c121943bb9e52068ae885a644
F src/resolve.c 93b7bc7c45efa6322d92293361c51a873690daed50cf77eeff88a448246b0d5a
F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
F src/select.c 9187f2c65744e975b191ccee49946732ee922f8bf40da998b322aca1633405ea
F src/shell.c.in 21e30c2cf16aa873c9ce2cd6ca1c8933c830e69b73c1e74f4fdffbda80e9c356
F src/sqlite.h.in e9a463ea16100b54f02b4063dc96a0add392c4a92963c50bfd6eb0324e118f3b
F src/shell.c.in 6edadde44b5b084cb0091340e73061e47c65a40c531befd7566fbfe64cfa85fc
F src/sqlite.h.in bc4aa09a59dcf3c34b8e57ce9ade8ff6aed8ef7a7ddc59951f59f9b009fc7cc0
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 9ecc93b8493bd20c0c07d52e2ac0ed8bab9b549c7f7955b59869597b650dd8b5
F src/sqliteInt.h 377ffa32933137d5ce140713315df34263ddf2f68150a63fce51e4cd52ed0194
F src/sqliteInt.h bf65dfa6565fae2e0d501088fc9c5212244adc1429a543827a16b2f5eaf41982
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
F src/tclsqlite.c cfe7f93daf9d8787f65e099efb67d7cdfc2c35236dec5d3f6758520bd3519424
F src/test1.c 15752c6299f43e3e96004516d6a4895cc02fce6cb6da71dd4eeeeb922b8e10fb
F src/test1.c f57c229ad7878215d0b3bb5d59ffe94772c099ce5b5e147a4a59d3157923a988
F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
F src/test3.c 61798bb0d38b915067a8c8e03f5a534b431181f802659a6616f9b4ff7d872644
F src/test4.c 405834f6a93ec395cc4c9bb8ecebf7c3d8079e7ca16ae65e82d01afd229694bb
Expand Down Expand Up @@ -1830,10 +1830,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 23e49f9984f74f242602c6e56bfc645585c7c86bcdd585c322ab0d8e20958d86
R 9bfbb0e600d24d42989c08db0f349d57
T *branch * new-dbconfig-options
T *sym-new-dbconfig-options *
T -sym-trunk *
P 1fad20925efa70d0c242e9cba8fa55456fb07a81229c1068da84c6e27d0c0be8
R 10b2e303dd1c5747406e48e4085cd8f9
U drh
Z 30e1c14e70d492d05922ad996c549711
Z 5e32c45febb886d78a377b0ce6c28269
2 changes: 1 addition & 1 deletion manifest.uuid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1fad20925efa70d0c242e9cba8fa55456fb07a81229c1068da84c6e27d0c0be8
923cfd53fcff2fcb91530bf819d2ecb0eda3f6a27dae29c7460f9ce3a3ffce7b
6 changes: 3 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
{ SQLITE_DBCONFIG_WRITABLE_SCHEMA, SQLITE_WriteSchema|
SQLITE_NoSchemaError },
{ SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, SQLITE_LegacyAlter },
{ SQLITE_DBCONFIG_NO_DQS_SCHEMA, SQLITE_NoDQSSchema },
{ SQLITE_DBCONFIG_NO_DQS, SQLITE_NoDQS },
{ SQLITE_DBCONFIG_DQS_DDL, SQLITE_DqsDDL },
{ SQLITE_DBCONFIG_DQS_DML, SQLITE_DqsDML },
};
unsigned int i;
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
Expand Down Expand Up @@ -3074,7 +3074,7 @@ static int openDatabase(
db->nextPagesize = 0;
db->nMaxSorterMmap = 0x7FFFFFFF;
db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
| SQLITE_NoDQSSchema
| SQLITE_DqsDML
#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
| SQLITE_AutoIndex
#endif
Expand Down
32 changes: 20 additions & 12 deletions src/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ int sqlite3MatchSpanName(
return 1;
}

/*
** Return TRUE if the double-quoted string mis-feature should be supported.
*/
static int areDoubleQuotedStringsEnabled(sqlite3 *db, NameContext *pTopNC){
if( db->init.busy ) return 1; /* Always support for legacy schemas */
if( pTopNC->ncFlags & NC_IsDDL ){
/* Currently parsing a DDL statement */
if( sqlite3WritableSchema(db) && (db->flags & SQLITE_DqsDML)!=0 ){
return 1;
}
return (db->flags & SQLITE_DqsDDL)!=0;
}else{
/* Currently parsing a DML statement */
return (db->flags & SQLITE_DqsDML)!=0;
}
}

/*
** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
** that name in the set of source tables in pSrcList and make the pExpr
Expand Down Expand Up @@ -476,9 +493,8 @@ static int lookupName(
*/
if( cnt==0 && zTab==0 ){
assert( pExpr->op==TK_ID );
if( ExprHasProperty(pExpr,EP_DblQuoted)
&& 0==(pTopNC->ncFlags&NC_NoDblQStr)
&& 0==(db->flags & SQLITE_NoDQS)
if( ExprHasProperty(pExpr,EP_DblQuoted)
&& areDoubleQuotedStringsEnabled(db, pTopNC)
){
/* If a double-quoted identifier does not match any known column name,
** then treat it as a string.
Expand Down Expand Up @@ -1771,15 +1787,7 @@ int sqlite3ResolveSelfReference(
}
sNC.pParse = pParse;
sNC.pSrcList = &sSrc;
sNC.ncFlags = type;
if( (pParse->db->flags & SQLITE_NoDQS)!=0
|| (!pParse->db->init.busy
&& !sqlite3WritableSchema(pParse->db)
&& (pParse->db->flags & SQLITE_NoDQSSchema)!=0
)
){
sNC.ncFlags |= NC_NoDblQStr;
}
sNC.ncFlags = type | NC_IsDDL;
if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
if( pList ) rc = sqlite3ResolveExprListNames(&sNC, pList);
return rc;
Expand Down
4 changes: 2 additions & 2 deletions src/shell.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -7086,8 +7086,8 @@ static int do_meta_command(char *zLine, ShellState *p){
{ "defensive", SQLITE_DBCONFIG_DEFENSIVE },
{ "wriable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
{ "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
{ "no_dqs_schema", SQLITE_DBCONFIG_NO_DQS_SCHEMA },
{ "no_dqs", SQLITE_DBCONFIG_NO_DQS },
{ "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
{ "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
};
int ii, v;
open_db(p, 0);
Expand Down
25 changes: 12 additions & 13 deletions src/sqlite.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2231,19 +2231,18 @@ struct sqlite3_mem_methods {
** using the [PRAGMA legacy_alter_table] statement.
** </dd>
**
** [[SQLITE_DBCONFIG_NO_DQS_SCHEMA]]
** <dt>SQLITE_DBCONFIG_NO_DQS_SCHEMA</td>
** <dd>The SQLITE_DBCONFIG_NO_DQS_SCHEMA option activates or deactivates
** the legacy [double-quoted string literal] misfeature for DDL statements.
** [[SQLITE_DBCONFIG_DQS_DML]]
** <dt>SQLITE_DBCONFIG_DQS_DML</td>
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
** the legacy [double-quoted string literal] misfeature for DML statement
** only, that is DELETE, INSERT, SELECT, and UPDATE statements.
** </dd>
**
** [[SQLITE_DBCONFIG_NO_DQS]]
** <dt>SQLITE_DBCONFIG_NO_DQS</td>
** <dd>The SQLITE_DBCONFIG_NO_DQS option activates or deactivates
** the legacy [double-quoted string literal] misfeature. The
** double-quoted string literal misfeature is on by default for
** compatibility, though it might become off by default in some
** future release of SQLite.
** [[SQLITE_DBCONFIG_DQS_DDL]]
** <dt>SQLITE_DBCONFIG_DQS_DDL</td>
** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
** the legacy [double-quoted string literal] misfeature for DDL statements,
** such as CREATE TABLE and CREATE INDEX.
** </dd>
** </dl>
*/
Expand All @@ -2260,8 +2259,8 @@ struct sqlite3_mem_methods {
#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
#define SQLITE_DBCONFIG_NO_DQS_SCHEMA 1013 /* int int* */
#define SQLITE_DBCONFIG_NO_DQS 1014 /* int int* */
#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
#define SQLITE_DBCONFIG_MAX 1014 /* Largest DBCONFIG */

/*
Expand Down
7 changes: 3 additions & 4 deletions src/sqliteInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1548,8 +1548,8 @@ struct sqlite3 {
#define SQLITE_LegacyAlter 0x04000000 /* Legacy ALTER TABLE behaviour */
#define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/
#define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */
#define SQLITE_NoDQSSchema 0x20000000 /* No dbl-quote strings in CREATE */
#define SQLITE_NoDQS 0x40000000 /* No double-quoted strings anywhere*/
#define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/
#define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/

/* Flags used only if debugging */
#define HI(X) ((u64)(X)<<32)
Expand Down Expand Up @@ -2796,8 +2796,7 @@ struct NameContext {
#define NC_Complex 0x2000 /* True if a function or subquery seen */
#define NC_AllowWin 0x4000 /* Window functions are allowed here */
#define NC_HasWin 0x8000 /* One or more window functions seen */
#define NC_NoDblQStr 0x10000 /* Do not allow double-quoted string hack.
** Mnemonic: "NO DouBLe-Quoted STRings" */
#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */

/*
** An instance of the following object describes a single ON CONFLICT
Expand Down
4 changes: 2 additions & 2 deletions src/test1.c
Original file line number Diff line number Diff line change
Expand Up @@ -7619,8 +7619,8 @@ static int SQLITE_TCLAPI test_sqlite3_db_config(
{ "DEFENSIVE", SQLITE_DBCONFIG_DEFENSIVE },
{ "WRITABLE_SCHEMA", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
{ "LEGACY_ALTER_TABLE", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
{ "NO_DQS_SCHEMA", SQLITE_DBCONFIG_NO_DQS_SCHEMA },
{ "NO_DQS", SQLITE_DBCONFIG_NO_DQS },
{ "DQS_DML", SQLITE_DBCONFIG_DQS_DML },
{ "DQS_DDL", SQLITE_DBCONFIG_DQS_DDL },
};
int i;
int v;
Expand Down

0 comments on commit d0ff601

Please sign in to comment.