Fossil SCM

Improve the "fossil sql" command so that it opens all database - repository, localdb, and configdb. Use the latest command-line shell code from the SQLite project so that the ".tables" command correctly shows all tables.

drh 2016-12-24 18:07 trunk
Commit 070815585a1e69185b087f56aa286b5d3e8aacee
2 files changed +4 -4 +15
+4 -4
--- src/shell.c
+++ src/shell.c
@@ -3705,12 +3705,12 @@
37053705
open_db(p, 0);
37063706
memcpy(&data, p, sizeof(data));
37073707
data.showHeader = 1;
37083708
data.cMode = data.mode = MODE_Column;
37093709
data.colWidth[0] = 3;
3710
- data.colWidth[1] = 15;
3711
- data.colWidth[2] = 58;
3710
+ data.colWidth[1] = 0;
3711
+ data.colWidth[2] = 0;
37123712
data.cnt = 0;
37133713
sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
37143714
if( zErrMsg ){
37153715
utf8_printf(stderr,"Error: %s\n", zErrMsg);
37163716
sqlite3_free(zErrMsg);
@@ -4976,13 +4976,13 @@
49764976
zSql = sqlite3_mprintf(
49774977
"SELECT name FROM sqlite_master"
49784978
" WHERE type IN ('table','view')"
49794979
" AND name NOT LIKE 'sqlite_%%'"
49804980
" AND name LIKE ?1");
4981
- while( zSql && sqlite3_step(pStmt)==SQLITE_ROW ){
4981
+ for(ii=0; zSql && sqlite3_step(pStmt)==SQLITE_ROW; ii++){
49824982
const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
4983
- if( zDbName==0 || strcmp(zDbName,"main")==0 ) continue;
4983
+ if( zDbName==0 || ii==0 ) continue;
49844984
if( strcmp(zDbName,"temp")==0 ){
49854985
zSql = sqlite3_mprintf(
49864986
"%z UNION ALL "
49874987
"SELECT 'temp.' || name FROM sqlite_temp_master"
49884988
" WHERE type IN ('table','view')"
49894989
--- src/shell.c
+++ src/shell.c
@@ -3705,12 +3705,12 @@
3705 open_db(p, 0);
3706 memcpy(&data, p, sizeof(data));
3707 data.showHeader = 1;
3708 data.cMode = data.mode = MODE_Column;
3709 data.colWidth[0] = 3;
3710 data.colWidth[1] = 15;
3711 data.colWidth[2] = 58;
3712 data.cnt = 0;
3713 sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
3714 if( zErrMsg ){
3715 utf8_printf(stderr,"Error: %s\n", zErrMsg);
3716 sqlite3_free(zErrMsg);
@@ -4976,13 +4976,13 @@
4976 zSql = sqlite3_mprintf(
4977 "SELECT name FROM sqlite_master"
4978 " WHERE type IN ('table','view')"
4979 " AND name NOT LIKE 'sqlite_%%'"
4980 " AND name LIKE ?1");
4981 while( zSql && sqlite3_step(pStmt)==SQLITE_ROW ){
4982 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
4983 if( zDbName==0 || strcmp(zDbName,"main")==0 ) continue;
4984 if( strcmp(zDbName,"temp")==0 ){
4985 zSql = sqlite3_mprintf(
4986 "%z UNION ALL "
4987 "SELECT 'temp.' || name FROM sqlite_temp_master"
4988 " WHERE type IN ('table','view')"
4989
--- src/shell.c
+++ src/shell.c
@@ -3705,12 +3705,12 @@
3705 open_db(p, 0);
3706 memcpy(&data, p, sizeof(data));
3707 data.showHeader = 1;
3708 data.cMode = data.mode = MODE_Column;
3709 data.colWidth[0] = 3;
3710 data.colWidth[1] = 0;
3711 data.colWidth[2] = 0;
3712 data.cnt = 0;
3713 sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
3714 if( zErrMsg ){
3715 utf8_printf(stderr,"Error: %s\n", zErrMsg);
3716 sqlite3_free(zErrMsg);
@@ -4976,13 +4976,13 @@
4976 zSql = sqlite3_mprintf(
4977 "SELECT name FROM sqlite_master"
4978 " WHERE type IN ('table','view')"
4979 " AND name NOT LIKE 'sqlite_%%'"
4980 " AND name LIKE ?1");
4981 for(ii=0; zSql && sqlite3_step(pStmt)==SQLITE_ROW; ii++){
4982 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
4983 if( zDbName==0 || ii==0 ) continue;
4984 if( strcmp(zDbName,"temp")==0 ){
4985 zSql = sqlite3_mprintf(
4986 "%z UNION ALL "
4987 "SELECT 'temp.' || name FROM sqlite_temp_master"
4988 " WHERE type IN ('table','view')"
4989
+15
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -149,10 +149,21 @@
149149
re_add_sql_func(db);
150150
search_sql_setup(db);
151151
foci_register(db);
152152
g.repositoryOpen = 1;
153153
g.db = db;
154
+ sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
155
+ if( g.zLocalDbName ){
156
+ char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb'", g.zLocalDbName);
157
+ sqlite3_exec(db, zSql, 0, 0, 0);
158
+ sqlite3_free(zSql);
159
+ }
160
+ if( g.zConfigDbName ){
161
+ char *zSql = sqlite3_mprintf("ATTACH %Q AS 'configdb'", g.zConfigDbName);
162
+ sqlite3_exec(db, zSql, 0, 0, 0);
163
+ sqlite3_free(zSql);
164
+ }
154165
return SQLITE_OK;
155166
}
156167
157168
/*
158169
** COMMAND: sqlite3
@@ -197,20 +208,24 @@
197208
** all files contained in check-in X. Example:
198209
** SELECT * FROM files_of_checkin('trunk');
199210
*/
200211
void cmd_sqlite3(void){
201212
int noRepository;
213
+ char *zConfigDb;
202214
extern int sqlite3_shell(int, char**);
203215
noRepository = find_option("no-repository", 0, 0)!=0;
204216
if( !noRepository ){
205217
db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
206218
}
219
+ db_open_config(1,0);
220
+ zConfigDb = g.zConfigDbName;
207221
fossil_close(1, noRepository);
208222
sqlite3_shutdown();
209223
#ifndef _WIN32
210224
linenoiseSetMultiLine(1);
211225
#endif
226
+ g.zConfigDbName = zConfigDb;
212227
sqlite3_shell(g.argc-1, g.argv+1);
213228
sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
214229
fossil_close(0, noRepository);
215230
}
216231
217232
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -149,10 +149,21 @@
149 re_add_sql_func(db);
150 search_sql_setup(db);
151 foci_register(db);
152 g.repositoryOpen = 1;
153 g.db = db;
 
 
 
 
 
 
 
 
 
 
 
154 return SQLITE_OK;
155 }
156
157 /*
158 ** COMMAND: sqlite3
@@ -197,20 +208,24 @@
197 ** all files contained in check-in X. Example:
198 ** SELECT * FROM files_of_checkin('trunk');
199 */
200 void cmd_sqlite3(void){
201 int noRepository;
 
202 extern int sqlite3_shell(int, char**);
203 noRepository = find_option("no-repository", 0, 0)!=0;
204 if( !noRepository ){
205 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
206 }
 
 
207 fossil_close(1, noRepository);
208 sqlite3_shutdown();
209 #ifndef _WIN32
210 linenoiseSetMultiLine(1);
211 #endif
 
212 sqlite3_shell(g.argc-1, g.argv+1);
213 sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
214 fossil_close(0, noRepository);
215 }
216
217
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -149,10 +149,21 @@
149 re_add_sql_func(db);
150 search_sql_setup(db);
151 foci_register(db);
152 g.repositoryOpen = 1;
153 g.db = db;
154 sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
155 if( g.zLocalDbName ){
156 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb'", g.zLocalDbName);
157 sqlite3_exec(db, zSql, 0, 0, 0);
158 sqlite3_free(zSql);
159 }
160 if( g.zConfigDbName ){
161 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'configdb'", g.zConfigDbName);
162 sqlite3_exec(db, zSql, 0, 0, 0);
163 sqlite3_free(zSql);
164 }
165 return SQLITE_OK;
166 }
167
168 /*
169 ** COMMAND: sqlite3
@@ -197,20 +208,24 @@
208 ** all files contained in check-in X. Example:
209 ** SELECT * FROM files_of_checkin('trunk');
210 */
211 void cmd_sqlite3(void){
212 int noRepository;
213 char *zConfigDb;
214 extern int sqlite3_shell(int, char**);
215 noRepository = find_option("no-repository", 0, 0)!=0;
216 if( !noRepository ){
217 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
218 }
219 db_open_config(1,0);
220 zConfigDb = g.zConfigDbName;
221 fossil_close(1, noRepository);
222 sqlite3_shutdown();
223 #ifndef _WIN32
224 linenoiseSetMultiLine(1);
225 #endif
226 g.zConfigDbName = zConfigDb;
227 sqlite3_shell(g.argc-1, g.argv+1);
228 sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
229 fossil_close(0, noRepository);
230 }
231
232

Keyboard Shortcuts

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