Fossil SCM

Introduce a new version of db_multi_exec() that does not do printf-style formatting.

drh 2020-03-15 15:43 trunk
Commit 0ea56bb239024a38a13e68507cd24fb1e1602715490f1ed7f9890b4d8b932e82
+1 -1
--- src/alerts.c
+++ src/alerts.c
@@ -114,11 +114,11 @@
114114
if( bOnlyIfEnabled
115115
&& fossil_strcmp(db_get("email-send-method",0),"off")==0
116116
){
117117
return; /* Don't create table for disabled email */
118118
}
119
- db_multi_exec(zAlertInit/*works-like:""*/);
119
+ db_exec_sql(zAlertInit);
120120
alert_triggers_enable();
121121
}else if( !db_table_has_column("repository","pending_alert","sentMod") ){
122122
db_multi_exec(
123123
"ALTER TABLE repository.pending_alert"
124124
" ADD COLUMN sentMod BOOLEAN DEFAULT false;"
125125
--- src/alerts.c
+++ src/alerts.c
@@ -114,11 +114,11 @@
114 if( bOnlyIfEnabled
115 && fossil_strcmp(db_get("email-send-method",0),"off")==0
116 ){
117 return; /* Don't create table for disabled email */
118 }
119 db_multi_exec(zAlertInit/*works-like:""*/);
120 alert_triggers_enable();
121 }else if( !db_table_has_column("repository","pending_alert","sentMod") ){
122 db_multi_exec(
123 "ALTER TABLE repository.pending_alert"
124 " ADD COLUMN sentMod BOOLEAN DEFAULT false;"
125
--- src/alerts.c
+++ src/alerts.c
@@ -114,11 +114,11 @@
114 if( bOnlyIfEnabled
115 && fossil_strcmp(db_get("email-send-method",0),"off")==0
116 ){
117 return; /* Don't create table for disabled email */
118 }
119 db_exec_sql(zAlertInit);
120 alert_triggers_enable();
121 }else if( !db_table_has_column("repository","pending_alert","sentMod") ){
122 db_multi_exec(
123 "ALTER TABLE repository.pending_alert"
124 " ADD COLUMN sentMod BOOLEAN DEFAULT false;"
125
+1 -1
--- src/branch.c
+++ src/branch.c
@@ -245,11 +245,11 @@
245245
@ GROUP BY 1;
246246
;
247247
248248
/* Call this routine to create the TEMP table */
249249
static void brlist_create_temp_table(void){
250
- db_multi_exec(createBrlistQuery/*works-like:""*/);
250
+ db_exec_sql(createBrlistQuery);
251251
}
252252
253253
254254
#if INTERFACE
255255
/*
256256
--- src/branch.c
+++ src/branch.c
@@ -245,11 +245,11 @@
245 @ GROUP BY 1;
246 ;
247
248 /* Call this routine to create the TEMP table */
249 static void brlist_create_temp_table(void){
250 db_multi_exec(createBrlistQuery/*works-like:""*/);
251 }
252
253
254 #if INTERFACE
255 /*
256
--- src/branch.c
+++ src/branch.c
@@ -245,11 +245,11 @@
245 @ GROUP BY 1;
246 ;
247
248 /* Call this routine to create the TEMP table */
249 static void brlist_create_temp_table(void){
250 db_exec_sql(createBrlistQuery);
251 }
252
253
254 #if INTERFACE
255 /*
256
+1 -1
--- src/browse.c
+++ src/browse.c
@@ -918,11 +918,11 @@
918918
** mtime on that check-in. If zGlob and *zGlob then only files matching
919919
** the given glob are computed.
920920
*/
921921
int compute_fileage(int vid, const char* zGlob){
922922
Stmt q;
923
- db_multi_exec(zComputeFileAgeSetup /*works-like:"constant"*/);
923
+ db_exec_sql(zComputeFileAgeSetup);
924924
db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
925925
db_bind_int(&q, ":ckin", vid);
926926
db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
927927
db_exec(&q);
928928
db_finalize(&q);
929929
--- src/browse.c
+++ src/browse.c
@@ -918,11 +918,11 @@
918 ** mtime on that check-in. If zGlob and *zGlob then only files matching
919 ** the given glob are computed.
920 */
921 int compute_fileage(int vid, const char* zGlob){
922 Stmt q;
923 db_multi_exec(zComputeFileAgeSetup /*works-like:"constant"*/);
924 db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
925 db_bind_int(&q, ":ckin", vid);
926 db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
927 db_exec(&q);
928 db_finalize(&q);
929
--- src/browse.c
+++ src/browse.c
@@ -918,11 +918,11 @@
918 ** mtime on that check-in. If zGlob and *zGlob then only files matching
919 ** the given glob are computed.
920 */
921 int compute_fileage(int vid, const char* zGlob){
922 Stmt q;
923 db_exec_sql(zComputeFileAgeSetup);
924 db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
925 db_bind_int(&q, ":ckin", vid);
926 db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
927 db_exec(&q);
928 db_finalize(&q);
929
+25 -15
--- src/db.c
+++ src/db.c
@@ -653,23 +653,17 @@
653653
blob_reset(&sql);
654654
return rc;
655655
}
656656
657657
/*
658
-** Execute multiple SQL statements.
658
+** Execute multiple SQL statements. The input text is executed
659
+** directly without any formatting.
659660
*/
660
-int db_multi_exec(const char *zSql, ...){
661
- Blob sql;
661
+int db_exec_sql(const char *z){
662662
int rc = SQLITE_OK;
663
- va_list ap;
664
- const char *z, *zEnd;
665663
sqlite3_stmt *pStmt;
666
- blob_init(&sql, 0, 0);
667
- va_start(ap, zSql);
668
- blob_vappendf(&sql, zSql, ap);
669
- va_end(ap);
670
- z = blob_str(&sql);
664
+ const char *zEnd;
671665
while( rc==SQLITE_OK && z[0] ){
672666
pStmt = 0;
673667
rc = sqlite3_prepare_v2(g.db, z, -1, &pStmt, &zEnd);
674668
if( rc ){
675669
db_err("%s: {%s}", sqlite3_errmsg(g.db), z);
@@ -679,10 +673,26 @@
679673
rc = sqlite3_finalize(pStmt);
680674
if( rc ) db_err("%s: {%.*s}", sqlite3_errmsg(g.db), (int)(zEnd-z), z);
681675
}
682676
z = zEnd;
683677
}
678
+ return rc;
679
+}
680
+
681
+/*
682
+** Execute multiple SQL statements using printf-style formatting.
683
+*/
684
+int db_multi_exec(const char *zSql, ...){
685
+ Blob sql;
686
+ int rc;
687
+ va_list ap;
688
+
689
+ blob_init(&sql, 0, 0);
690
+ va_start(ap, zSql);
691
+ blob_vappendf(&sql, zSql, ap);
692
+ va_end(ap);
693
+ rc = db_exec_sql(blob_str(&sql));
684694
blob_reset(&sql);
685695
return rc;
686696
}
687697
688698
/*
@@ -1286,17 +1296,17 @@
12861296
blob_init(&key, 0, 0);
12871297
db_maybe_obtain_encryption_key(zDbName, &key);
12881298
if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
12891299
char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY %Q",
12901300
zDbName, zLabel, blob_str(&key));
1291
- db_multi_exec("%s", zCmd /*safe-for-%s*/);
1301
+ db_exec_sql(zCmd);
12921302
fossil_secure_zero(zCmd, strlen(zCmd));
12931303
sqlite3_free(zCmd);
12941304
}else{
12951305
char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY ''",
12961306
zDbName, zLabel);
1297
- db_multi_exec("%s", zCmd /*safe-for-%s*/);
1307
+ db_exec_sql(zCmd);
12981308
sqlite3_free(zCmd);
12991309
#if USE_SEE
13001310
if( blob_size(&key)>0 ){
13011311
sqlite3_key_v2(g.db, zLabel, blob_str(&key), -1);
13021312
}
@@ -1762,13 +1772,13 @@
17621772
"UPDATE vfile"
17631773
" SET mhash=(SELECT uuid FROM blob WHERE blob.rid=vfile.mrid)"
17641774
" WHERE mrid!=rid;"
17651775
);
17661776
if( !db_table_has_column("localdb", "vmerge", "mhash") ){
1767
- db_multi_exec("ALTER TABLE vmerge RENAME TO old_vmerge;");
1768
- db_multi_exec(zLocalSchemaVmerge /*works-like:""*/);
1769
- db_multi_exec(
1777
+ db_exec_sql("ALTER TABLE vmerge RENAME TO old_vmerge;");
1778
+ db_exec_sql(zLocalSchemaVmerge);
1779
+ db_exec_sql(
17701780
"INSERT OR IGNORE INTO vmerge(id,merge,mhash)"
17711781
" SELECT id, merge, blob.uuid FROM old_vmerge, blob"
17721782
" WHERE old_vmerge.merge=blob.rid;"
17731783
"DROP TABLE old_vmerge;"
17741784
);
17751785
--- src/db.c
+++ src/db.c
@@ -653,23 +653,17 @@
653 blob_reset(&sql);
654 return rc;
655 }
656
657 /*
658 ** Execute multiple SQL statements.
 
659 */
660 int db_multi_exec(const char *zSql, ...){
661 Blob sql;
662 int rc = SQLITE_OK;
663 va_list ap;
664 const char *z, *zEnd;
665 sqlite3_stmt *pStmt;
666 blob_init(&sql, 0, 0);
667 va_start(ap, zSql);
668 blob_vappendf(&sql, zSql, ap);
669 va_end(ap);
670 z = blob_str(&sql);
671 while( rc==SQLITE_OK && z[0] ){
672 pStmt = 0;
673 rc = sqlite3_prepare_v2(g.db, z, -1, &pStmt, &zEnd);
674 if( rc ){
675 db_err("%s: {%s}", sqlite3_errmsg(g.db), z);
@@ -679,10 +673,26 @@
679 rc = sqlite3_finalize(pStmt);
680 if( rc ) db_err("%s: {%.*s}", sqlite3_errmsg(g.db), (int)(zEnd-z), z);
681 }
682 z = zEnd;
683 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684 blob_reset(&sql);
685 return rc;
686 }
687
688 /*
@@ -1286,17 +1296,17 @@
1286 blob_init(&key, 0, 0);
1287 db_maybe_obtain_encryption_key(zDbName, &key);
1288 if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
1289 char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY %Q",
1290 zDbName, zLabel, blob_str(&key));
1291 db_multi_exec("%s", zCmd /*safe-for-%s*/);
1292 fossil_secure_zero(zCmd, strlen(zCmd));
1293 sqlite3_free(zCmd);
1294 }else{
1295 char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY ''",
1296 zDbName, zLabel);
1297 db_multi_exec("%s", zCmd /*safe-for-%s*/);
1298 sqlite3_free(zCmd);
1299 #if USE_SEE
1300 if( blob_size(&key)>0 ){
1301 sqlite3_key_v2(g.db, zLabel, blob_str(&key), -1);
1302 }
@@ -1762,13 +1772,13 @@
1762 "UPDATE vfile"
1763 " SET mhash=(SELECT uuid FROM blob WHERE blob.rid=vfile.mrid)"
1764 " WHERE mrid!=rid;"
1765 );
1766 if( !db_table_has_column("localdb", "vmerge", "mhash") ){
1767 db_multi_exec("ALTER TABLE vmerge RENAME TO old_vmerge;");
1768 db_multi_exec(zLocalSchemaVmerge /*works-like:""*/);
1769 db_multi_exec(
1770 "INSERT OR IGNORE INTO vmerge(id,merge,mhash)"
1771 " SELECT id, merge, blob.uuid FROM old_vmerge, blob"
1772 " WHERE old_vmerge.merge=blob.rid;"
1773 "DROP TABLE old_vmerge;"
1774 );
1775
--- src/db.c
+++ src/db.c
@@ -653,23 +653,17 @@
653 blob_reset(&sql);
654 return rc;
655 }
656
657 /*
658 ** Execute multiple SQL statements. The input text is executed
659 ** directly without any formatting.
660 */
661 int db_exec_sql(const char *z){
 
662 int rc = SQLITE_OK;
 
 
663 sqlite3_stmt *pStmt;
664 const char *zEnd;
 
 
 
 
665 while( rc==SQLITE_OK && z[0] ){
666 pStmt = 0;
667 rc = sqlite3_prepare_v2(g.db, z, -1, &pStmt, &zEnd);
668 if( rc ){
669 db_err("%s: {%s}", sqlite3_errmsg(g.db), z);
@@ -679,10 +673,26 @@
673 rc = sqlite3_finalize(pStmt);
674 if( rc ) db_err("%s: {%.*s}", sqlite3_errmsg(g.db), (int)(zEnd-z), z);
675 }
676 z = zEnd;
677 }
678 return rc;
679 }
680
681 /*
682 ** Execute multiple SQL statements using printf-style formatting.
683 */
684 int db_multi_exec(const char *zSql, ...){
685 Blob sql;
686 int rc;
687 va_list ap;
688
689 blob_init(&sql, 0, 0);
690 va_start(ap, zSql);
691 blob_vappendf(&sql, zSql, ap);
692 va_end(ap);
693 rc = db_exec_sql(blob_str(&sql));
694 blob_reset(&sql);
695 return rc;
696 }
697
698 /*
@@ -1286,17 +1296,17 @@
1296 blob_init(&key, 0, 0);
1297 db_maybe_obtain_encryption_key(zDbName, &key);
1298 if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
1299 char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY %Q",
1300 zDbName, zLabel, blob_str(&key));
1301 db_exec_sql(zCmd);
1302 fossil_secure_zero(zCmd, strlen(zCmd));
1303 sqlite3_free(zCmd);
1304 }else{
1305 char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY ''",
1306 zDbName, zLabel);
1307 db_exec_sql(zCmd);
1308 sqlite3_free(zCmd);
1309 #if USE_SEE
1310 if( blob_size(&key)>0 ){
1311 sqlite3_key_v2(g.db, zLabel, blob_str(&key), -1);
1312 }
@@ -1762,13 +1772,13 @@
1772 "UPDATE vfile"
1773 " SET mhash=(SELECT uuid FROM blob WHERE blob.rid=vfile.mrid)"
1774 " WHERE mrid!=rid;"
1775 );
1776 if( !db_table_has_column("localdb", "vmerge", "mhash") ){
1777 db_exec_sql("ALTER TABLE vmerge RENAME TO old_vmerge;");
1778 db_exec_sql(zLocalSchemaVmerge);
1779 db_exec_sql(
1780 "INSERT OR IGNORE INTO vmerge(id,merge,mhash)"
1781 " SELECT id, merge, blob.uuid FROM old_vmerge, blob"
1782 " WHERE old_vmerge.merge=blob.rid;"
1783 "DROP TABLE old_vmerge;"
1784 );
1785
+2 -2
--- src/undo.c
+++ src/undo.c
@@ -178,11 +178,11 @@
178178
@ DROP TABLE IF EXISTS undo_vfile;
179179
@ DROP TABLE IF EXISTS undo_vmerge;
180180
@ DROP TABLE IF EXISTS undo_stash;
181181
@ DROP TABLE IF EXISTS undo_stashfile;
182182
;
183
- db_multi_exec(zSql /*works-like:""*/);
183
+ db_exec_sql(zSql);
184184
db_lset_int("undo_available", 0);
185185
db_lset_int("undo_checkout", 0);
186186
}
187187
188188
/*
@@ -235,11 +235,11 @@
235235
@ CREATE TABLE localdb.undo_vfile AS SELECT * FROM vfile;
236236
@ CREATE TABLE localdb.undo_vmerge AS SELECT * FROM vmerge;
237237
;
238238
if( undoDisable ) return;
239239
undo_reset();
240
- db_multi_exec(zSql/*works-like:""*/);
240
+ db_exec_sql(zSql);
241241
cid = db_lget_int("checkout", 0);
242242
db_lset_int("undo_checkout", cid);
243243
db_lset_int("undo_available", 1);
244244
db_lset("undo_cmdline", undoCmd);
245245
undoActive = 1;
246246
--- src/undo.c
+++ src/undo.c
@@ -178,11 +178,11 @@
178 @ DROP TABLE IF EXISTS undo_vfile;
179 @ DROP TABLE IF EXISTS undo_vmerge;
180 @ DROP TABLE IF EXISTS undo_stash;
181 @ DROP TABLE IF EXISTS undo_stashfile;
182 ;
183 db_multi_exec(zSql /*works-like:""*/);
184 db_lset_int("undo_available", 0);
185 db_lset_int("undo_checkout", 0);
186 }
187
188 /*
@@ -235,11 +235,11 @@
235 @ CREATE TABLE localdb.undo_vfile AS SELECT * FROM vfile;
236 @ CREATE TABLE localdb.undo_vmerge AS SELECT * FROM vmerge;
237 ;
238 if( undoDisable ) return;
239 undo_reset();
240 db_multi_exec(zSql/*works-like:""*/);
241 cid = db_lget_int("checkout", 0);
242 db_lset_int("undo_checkout", cid);
243 db_lset_int("undo_available", 1);
244 db_lset("undo_cmdline", undoCmd);
245 undoActive = 1;
246
--- src/undo.c
+++ src/undo.c
@@ -178,11 +178,11 @@
178 @ DROP TABLE IF EXISTS undo_vfile;
179 @ DROP TABLE IF EXISTS undo_vmerge;
180 @ DROP TABLE IF EXISTS undo_stash;
181 @ DROP TABLE IF EXISTS undo_stashfile;
182 ;
183 db_exec_sql(zSql);
184 db_lset_int("undo_available", 0);
185 db_lset_int("undo_checkout", 0);
186 }
187
188 /*
@@ -235,11 +235,11 @@
235 @ CREATE TABLE localdb.undo_vfile AS SELECT * FROM vfile;
236 @ CREATE TABLE localdb.undo_vmerge AS SELECT * FROM vmerge;
237 ;
238 if( undoDisable ) return;
239 undo_reset();
240 db_exec_sql(zSql);
241 cid = db_lget_int("checkout", 0);
242 db_lset_int("undo_checkout", cid);
243 db_lset_int("undo_available", 1);
244 db_lset("undo_cmdline", undoCmd);
245 undoActive = 1;
246

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button