Skip to content

Commit 4c65542

Browse files
dandan
authored andcommitted
Have the shell tool automatically enable SQLITE_CONFIG_DQS_DDL when executing a ".dump" script against an empty db.
FossilOrigin-Name: f47a5f4e0ce078e6cc1183e6cbb3c4013af379b496efae94863a42e5c39928ed
1 parent e5b2132 commit 4c65542

6 files changed

Lines changed: 86 additions & 57 deletions

File tree

manifest

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
C Fix\sa\scomment\sin\ssessions.\s\sNo\sfunctional\schanges.\n[forum:/forumpost/8c20dc935b|Forum\spost\s8c20dc935b].
2-
D 2024-01-11T14:13:17.382
1+
C Have\sthe\sshell\stool\sautomatically\senable\sSQLITE_CONFIG_DQS_DDL\swhen\sexecuting\sa\s".dump"\sscript\sagainst\san\sempty\sdb.
2+
D 2024-01-12T11:44:49.861
33
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
44
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
55
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -738,7 +738,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
738738
F src/resolve.c e25f51a473a5f30a0d978e4df2aaa98aeec84eac29ecae1ad4708a6c3e669345
739739
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
740740
F src/select.c f1a81ff4f8e9e76c224e2ab3a4baa799add0db22158c7fcede65d8cc4a6fa2da
741-
F src/shell.c.in 3d19abd924ed1cec9c9908d5a10cb1580b8ca30df24c26bfe80efa0c00f664d8
741+
F src/shell.c.in d1ed426aae2d547932971e8019939cacb4dfda8258e45b8924b250e488e2d53d
742742
F src/sqlite.h.in 61a60b4ea04db8ead15e1579b20b64cb56e9f55d52c5f9f9694de630110593a3
743743
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
744744
F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
@@ -1583,12 +1583,12 @@ F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
15831583
F test/shell1.test c7127a5e780ffc9e14c476773127fdf292c6db226529c44c1676f37b3793123f
15841584
F test/shell2.test 35226c070a8c7f64fd016dfac2a0db2a40f709b3131f61daacd9dad61536c9cb
15851585
F test/shell3.test 91febeac0412812bf6370abb8ed72700e32bf8f9878849414518f662dfd55e8a
1586-
F test/shell4.test 9abd0c12a7e20a4c49e84d5be208d2124fa6c09e728f56f1f4bee0f02853935f
1586+
F test/shell4.test 947029e5a9efae9054d424b309fc0311439c0c3a0866ebfa3b8a771120708220
15871587
F test/shell5.test c8b6c54f26ec537f8558273d7ed293ca3725ef42e6b12b8f151718628bd1473b
15881588
F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3
15891589
F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f
15901590
F test/shell8.test 3fd093d481aaa94dc77fb73f1044c1f19c7efe3477a395cc4f7450133bc54915
1591-
F test/shell9.test fe41f890a89f57bdde7351d7a828a1d4b503ebe239d413137369f20faf7f8865
1591+
F test/shell9.test f457a96c088344908e0518dbabffd02eda8ac2a8733f278679e5f47c103efbab
15921592
F test/shmlock.test 3dbf017d34ab0c60abe6a44e447d3552154bd0c87b41eaf5ceacd408dd13fda5
15931593
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
15941594
F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5
@@ -1666,7 +1666,7 @@ F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30
16661666
F test/temptable2.test 76821347810ecc88203e6ef0dd6897b6036ac788e9dd3e6b04fd4d1631311a16
16671667
F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637
16681668
F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc
1669-
F test/tester.tcl 6f6e53981b4bdd42ef088f52e23236bc1ba0ca41ed395cbd7f33cbcff7d74d3c
1669+
F test/tester.tcl fe617b88c7eb08bdf983d2aaa31c20fbf439eee7b8e0d61ca636fcd0c305bbbf
16701670
F test/testrunner.tcl 8e2a5c7550b78d3283eee6103104ae2bcf56aa1df892dbd1608f27b93ebf4de8
16711671
F test/testrunner_data.tcl 7ffd951527bbc614e723fd8d123b6834321878530696adecfdf6035100bac64e
16721672
F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899
@@ -2157,8 +2157,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
21572157
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
21582158
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
21592159
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
2160-
P ccf552319a62bfb329820a3bc1f490bacbaa6e90694a257fc65a568a605542c3
2161-
R e84faaffaa9b0edb5d8970e83a2a63a0
2162-
U drh
2163-
Z e07a25d21af32a3184818d2053f19bcc
2160+
P b0eb6d3628c1f70399a22d9fd3b79a796bc343adfeba50515440db609565961a
2161+
R ab5a4296dc153e787688d4ab18626d94
2162+
U dan
2163+
Z 9795dc3f51dc5999429a02089c48c9c6
21642164
# Remove this line to create a well-formed Fossil manifest.

manifest.uuid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b0eb6d3628c1f70399a22d9fd3b79a796bc343adfeba50515440db609565961a
1+
f47a5f4e0ce078e6cc1183e6cbb3c4013af379b496efae94863a42e5c39928ed

src/shell.c.in

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11424,61 +11424,69 @@ static int line_is_complete(char *zSql, int nSql){
1142411424
**
1142511425
** 0: Have not seen any SQL.
1142611426
** 1: Have seen "PRAGMA foreign_keys=OFF;".
11427-
** 2: Currently assuming we are parsing ".dump" restore, defensive mode
11428-
** should be disabled following the current transaction.
11429-
** 3: Nothing left to do.
11427+
** 2-6: Currently running .dump transaction. If the "2" bit is set,
11428+
** disable DEFENSIVE when done. If "4" is set, disable DQS_DDL.
11429+
** 7: Nothing left to do. This function becomes a no-op.
1143011430
*/
1143111431
static int doAutoDetectRestore(ShellState *p, const char *zSql){
1143211432
int rc = SQLITE_OK;
1143311433

11434-
switch( p->eRestoreState ){
11435-
case 0: {
11436-
int bDefense = 0; /* True if in defensive mode */
11437-
const char *zExpect = "PRAGMA foreign_keys=OFF;";
11438-
assert( strlen(zExpect)==24 );
11439-
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &bDefense);
11440-
if( p->bSafeMode==0 && bDefense && memcmp(zSql, zExpect, 25)==0 ){
11441-
p->eRestoreState = 1;
11442-
}else{
11443-
p->eRestoreState = 3;
11444-
}
11445-
break;
11446-
};
11447-
11448-
case 1: {
11449-
const char *zExpect = "BEGIN TRANSACTION;";
11450-
assert( strlen(zExpect)==18 );
11451-
if( memcmp(zSql, zExpect, 19)==0 ){
11452-
/* Now check if the database is empty. */
11453-
const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
11454-
sqlite3_stmt *pStmt = 0;
11455-
int bEmpty = 1;
11456-
11457-
shellPrepare(p->db, &rc, zQuery, &pStmt);
11458-
if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
11459-
bEmpty = 0;
11434+
if( p->eRestoreState<7 ){
11435+
switch( p->eRestoreState ){
11436+
case 0: {
11437+
const char *zExpect = "PRAGMA foreign_keys=OFF;";
11438+
assert( strlen(zExpect)==24 );
11439+
if( p->bSafeMode==0 && memcmp(zSql, zExpect, 25)==0 ){
11440+
p->eRestoreState = 1;
11441+
}else{
11442+
p->eRestoreState = 7;
1146011443
}
11461-
shellFinalize(&rc, pStmt);
11462-
if( bEmpty && rc==SQLITE_OK ){
11444+
break;
11445+
};
11446+
11447+
case 1: {
11448+
int bIsDump = 0;
11449+
const char *zExpect = "BEGIN TRANSACTION;";
11450+
assert( strlen(zExpect)==18 );
11451+
if( memcmp(zSql, zExpect, 19)==0 ){
11452+
/* Now check if the database is empty. */
11453+
const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
11454+
sqlite3_stmt *pStmt = 0;
11455+
11456+
bIsDump = 1;
11457+
shellPrepare(p->db, &rc, zQuery, &pStmt);
11458+
if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
11459+
bIsDump = 0;
11460+
}
11461+
shellFinalize(&rc, pStmt);
11462+
}
11463+
if( bIsDump && rc==SQLITE_OK ){
11464+
int bDefense = 0;
11465+
int bDqsDdl = 0;
11466+
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &bDefense);
11467+
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, -1, &bDqsDdl);
1146311468
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
11469+
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 1, 0);
11470+
p->eRestoreState = (bDefense ? 2 : 0) + (bDqsDdl ? 4 : 0);
1146411471
}else{
11465-
p->eRestoreState = 3;
11472+
p->eRestoreState = 7;
1146611473
}
11474+
break;
1146711475
}
11468-
break;
11469-
}
11470-
11471-
case 2: {
11472-
if( sqlite3_get_autocommit(p->db) ){
11473-
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
11474-
p->eRestoreState = 3;
11476+
11477+
default: {
11478+
if( sqlite3_get_autocommit(p->db) ){
11479+
if( (p->eRestoreState & 2) ){
11480+
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 1, 0);
11481+
}
11482+
if( (p->eRestoreState & 4) ){
11483+
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 0, 0);
11484+
}
11485+
p->eRestoreState = 7;
11486+
}
11487+
break;
1147511488
}
11476-
break;
1147711489
}
11478-
11479-
default: /* Nothing to do */
11480-
assert( p->eRestoreState==3 );
11481-
break;
1148211490
}
1148311491

1148411492
return rc;

test/shell4.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ do_test shell4-2.2 {
117117
} {0 {}}
118118
do_test shell4-2.3 {
119119
catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
120-
} {/^0 {PRAGMA.*}$/}
120+
} {/^0 {SELECT.*}$/}
121121
do_test shell4-2.4 {
122122
catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
123123
} {0 {CREATE TABLE t1(x);

test/shell9.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# testing that it is possible to run a ".dump" script that creates
1414
# virtual tables without explicitly disabling defensive mode.
1515
#
16+
# And, that it can process a ".dump" script that contains strings
17+
# delimited using double-quotes in the schema (DQS_DDL setting).
18+
#
1619

1720
# Test plan:
1821
#
@@ -124,4 +127,22 @@ do_test 2.2.2 {
124127
contains_warning [catchcmd test.db ".dump r1"]
125128
} 1
126129

130+
#-------------------------------------------------------------------------
131+
reset_db
132+
sqlite3_db_config db DQS_DDL 1
133+
do_execsql_test 3.1.0 {
134+
CREATE TABLE t4(hello, check( hello IS NOT "xyz") );
135+
}
136+
db close
137+
138+
# Create .dump file in "testdump.txt".
139+
#
140+
set out [open testdump.txt w]
141+
puts $out [lindex [catchcmd test.db .dump] 1]
142+
close $out
143+
do_test 3.1.1 {
144+
forcedelete test.db
145+
catchcmd test.db ".read testdump.txt"
146+
} {0 {}}
147+
127148
finish_test

test/tester.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ if {[info exists cmdlinearg]==0} {
554554
}
555555
unset -nocomplain a
556556
set testdir [file normalize $testdir]
557-
set cmdlinearg(TESTFIXTURE_HOME) [pwd]
557+
set cmdlinearg(TESTFIXTURE_HOME) [file dirname [info nameofexec]]
558558
set cmdlinearg(INFO_SCRIPT) [file normalize [info script]]
559559
set argv0 [file normalize $argv0]
560560
if {$cmdlinearg(testdir)!=""} {

0 commit comments

Comments
 (0)