Fossil SCM

Enhance the "fossil sql" command so that one or more SQL statements and/or dot-commands can be entered on the command-line. Also automatically ATTACH the local database and the config database, if they are available.

drh 2014-11-28 14:07 trunk
Commit f922f4e3cca0da7b36a4fc807b5d98353257371e
+2 -1
--- src/db.c
+++ src/db.c
@@ -962,20 +962,21 @@
962962
** is found, it is attached to the open database connection too.
963963
*/
964964
int db_open_local(const char *zDbName){
965965
int i, n;
966966
char zPwd[2000];
967
- static const char aDbName[][10] = { "_FOSSIL_", ".fslckout", ".fos" };
967
+ static const char *(aDbName[]) = { "_FOSSIL_", ".fslckout", ".fos" };
968968
969969
if( g.localOpen ) return 1;
970970
file_getcwd(zPwd, sizeof(zPwd)-20);
971971
n = strlen(zPwd);
972972
while( n>0 ){
973973
for(i=0; i<count(aDbName); i++){
974974
sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]);
975975
if( isValidLocalDb(zPwd) ){
976976
/* Found a valid checkout database file */
977
+ g.zLocalDbName = mprintf("%s", zPwd);
977978
zPwd[n] = 0;
978979
while( n>0 && zPwd[n-1]=='/' ){
979980
n--;
980981
zPwd[n] = 0;
981982
}
982983
--- src/db.c
+++ src/db.c
@@ -962,20 +962,21 @@
962 ** is found, it is attached to the open database connection too.
963 */
964 int db_open_local(const char *zDbName){
965 int i, n;
966 char zPwd[2000];
967 static const char aDbName[][10] = { "_FOSSIL_", ".fslckout", ".fos" };
968
969 if( g.localOpen ) return 1;
970 file_getcwd(zPwd, sizeof(zPwd)-20);
971 n = strlen(zPwd);
972 while( n>0 ){
973 for(i=0; i<count(aDbName); i++){
974 sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]);
975 if( isValidLocalDb(zPwd) ){
976 /* Found a valid checkout database file */
 
977 zPwd[n] = 0;
978 while( n>0 && zPwd[n-1]=='/' ){
979 n--;
980 zPwd[n] = 0;
981 }
982
--- src/db.c
+++ src/db.c
@@ -962,20 +962,21 @@
962 ** is found, it is attached to the open database connection too.
963 */
964 int db_open_local(const char *zDbName){
965 int i, n;
966 char zPwd[2000];
967 static const char *(aDbName[]) = { "_FOSSIL_", ".fslckout", ".fos" };
968
969 if( g.localOpen ) return 1;
970 file_getcwd(zPwd, sizeof(zPwd)-20);
971 n = strlen(zPwd);
972 while( n>0 ){
973 for(i=0; i<count(aDbName); i++){
974 sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]);
975 if( isValidLocalDb(zPwd) ){
976 /* Found a valid checkout database file */
977 g.zLocalDbName = mprintf("%s", zPwd);
978 zPwd[n] = 0;
979 while( n>0 && zPwd[n-1]=='/' ){
980 n--;
981 zPwd[n] = 0;
982 }
983
+1
--- src/main.c
+++ src/main.c
@@ -131,10 +131,11 @@
131131
const char *zConfigDbName;/* Path of the config database. NULL if not open */
132132
sqlite3_int64 now; /* Seconds since 1970 */
133133
int repositoryOpen; /* True if the main repository database is open */
134134
char *zRepositoryOption; /* Most recent cached repository option value */
135135
char *zRepositoryName; /* Name of the repository database */
136
+ char *zLocalDbName; /* Name of the local database */
136137
const char *zMainDbType;/* "configdb", "localdb", or "repository" */
137138
const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
138139
int localOpen; /* True if the local database is open */
139140
char *zLocalRoot; /* The directory holding the local database */
140141
int minPrefix; /* Number of digits needed for a distinct UUID */
141142
--- src/main.c
+++ src/main.c
@@ -131,10 +131,11 @@
131 const char *zConfigDbName;/* Path of the config database. NULL if not open */
132 sqlite3_int64 now; /* Seconds since 1970 */
133 int repositoryOpen; /* True if the main repository database is open */
134 char *zRepositoryOption; /* Most recent cached repository option value */
135 char *zRepositoryName; /* Name of the repository database */
 
136 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
137 const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
138 int localOpen; /* True if the local database is open */
139 char *zLocalRoot; /* The directory holding the local database */
140 int minPrefix; /* Number of digits needed for a distinct UUID */
141
--- src/main.c
+++ src/main.c
@@ -131,10 +131,11 @@
131 const char *zConfigDbName;/* Path of the config database. NULL if not open */
132 sqlite3_int64 now; /* Seconds since 1970 */
133 int repositoryOpen; /* True if the main repository database is open */
134 char *zRepositoryOption; /* Most recent cached repository option value */
135 char *zRepositoryName; /* Name of the repository database */
136 char *zLocalDbName; /* Name of the local database */
137 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
138 const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
139 int localOpen; /* True if the local database is open */
140 char *zLocalRoot; /* The directory holding the local database */
141 int minPrefix; /* Number of digits needed for a distinct UUID */
142
+65 -32
--- src/shell.c
+++ src/shell.c
@@ -4036,14 +4036,16 @@
40364036
40374037
int main(int argc, char **argv){
40384038
char *zErrMsg = 0;
40394039
ShellState data;
40404040
const char *zInitFile = 0;
4041
- char *zFirstCmd = 0;
40424041
int i;
40434042
int rc = 0;
40444043
int warnInmemoryDb = 0;
4044
+ int readStdin = 1;
4045
+ int nCmd = 0;
4046
+ char **azCmd = 0;
40454047
40464048
#if USE_SYSTEM_SQLITE+0!=1
40474049
if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
40484050
fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
40494051
sqlite3_sourceid(), SQLITE_SOURCE_ID);
@@ -4058,10 +4060,22 @@
40584060
** else is done.
40594061
*/
40604062
#ifdef SIGINT
40614063
signal(SIGINT, interrupt_handler);
40624064
#endif
4065
+
4066
+#ifdef SQLITE_SHELL_DBNAME_PROC
4067
+ {
4068
+ /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
4069
+ ** of a C-function that will provide the name of the database file. Use
4070
+ ** this compile-time option to embed this shell program in larger
4071
+ ** applications. */
4072
+ extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4073
+ SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4074
+ warnInmemoryDb = 0;
4075
+ }
4076
+#endif
40634077
40644078
/* Do an initial pass through the command-line argument to locate
40654079
** the name of the database file, the name of the initialization file,
40664080
** the size of the alternative malloc heap,
40674081
** and the first command to execute.
@@ -4070,19 +4084,22 @@
40704084
char *z;
40714085
z = argv[i];
40724086
if( z[0]!='-' ){
40734087
if( data.zDbFilename==0 ){
40744088
data.zDbFilename = z;
4075
- continue;
4076
- }
4077
- if( zFirstCmd==0 ){
4078
- zFirstCmd = z;
4079
- continue;
4080
- }
4081
- fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]);
4082
- fprintf(stderr,"Use -help for a list of options.\n");
4083
- return 1;
4089
+ }else{
4090
+ /* Excesss arguments are interpreted as SQL (or dot-commands) and
4091
+ ** mean that nothing is read from stdin */
4092
+ readStdin = 0;
4093
+ nCmd++;
4094
+ azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
4095
+ if( azCmd==0 ){
4096
+ fprintf(stderr, "out of memory\n");
4097
+ exit(1);
4098
+ }
4099
+ azCmd[nCmd-1] = z;
4100
+ }
40844101
}
40854102
if( z[1]=='-' ) z++;
40864103
if( strcmp(z,"-separator")==0
40874104
|| strcmp(z,"-nullvalue")==0
40884105
|| strcmp(z,"-newline")==0
@@ -4169,15 +4186,10 @@
41694186
warnInmemoryDb = argc==1;
41704187
#else
41714188
fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
41724189
return 1;
41734190
#endif
4174
-#ifdef SQLITE_SHELL_DBNAME_PROC
4175
- { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4176
- SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4177
- warnInmemoryDb = 0; }
4178
-#endif
41794191
}
41804192
data.out = stdout;
41814193
41824194
/* Go ahead and open the database file if it already exists. If the
41834195
** file does not exist, delay opening it. This prevents empty database
@@ -4194,10 +4206,22 @@
41944206
*/
41954207
rc = process_sqliterc(&data,zInitFile);
41964208
if( rc>0 ){
41974209
return rc;
41984210
}
4211
+
4212
+#ifdef SQLITE_SHELL_INIT_PROC
4213
+ {
4214
+ /* The SQLITE_SHELL_INIT_PROC is an application-defined function
4215
+ ** that can do additional initialization on the database connection
4216
+ ** after it has opened.
4217
+ */
4218
+ extern int SQLITE_SHELL_INIT_PROC(sqlite3*);
4219
+ rc = SQLITE_SHELL_INIT_PROC(data.db);
4220
+ if( rc ) return rc;
4221
+ }
4222
+#endif
41994223
42004224
/* Make a second pass through the command-line argument and set
42014225
** options. This second pass is delayed until after the initialization
42024226
** file is processed so that the command-line arguments will override
42034227
** settings in the initialization file.
@@ -4270,10 +4294,14 @@
42704294
i++;
42714295
#endif
42724296
}else if( strcmp(z,"-help")==0 ){
42734297
usage(1);
42744298
}else if( strcmp(z,"-cmd")==0 ){
4299
+ /* Run commands that follow -cmd first and separately from commands
4300
+ ** that simply appear on the command-line. This seems goofy. It would
4301
+ ** be better if all commands ran in the order that they appear. But
4302
+ ** we retain the goofy behavior for historical compatibility. */
42754303
if( i==argc-1 ) break;
42764304
z = cmdline_option_value(argc,argv,++i);
42774305
if( z[0]=='.' ){
42784306
rc = do_meta_command(z, &data);
42794307
if( rc && bail_on_error ) return rc==2 ? 0 : rc;
@@ -4293,27 +4321,32 @@
42934321
fprintf(stderr,"Use -help for a list of options.\n");
42944322
return 1;
42954323
}
42964324
}
42974325
4298
- if( zFirstCmd ){
4299
- /* Run just the command that follows the database name
4300
- */
4301
- if( zFirstCmd[0]=='.' ){
4302
- rc = do_meta_command(zFirstCmd, &data);
4303
- if( rc==2 ) rc = 0;
4304
- }else{
4305
- open_db(&data, 0);
4306
- rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
4307
- if( zErrMsg!=0 ){
4308
- fprintf(stderr,"Error: %s\n", zErrMsg);
4309
- return rc!=0 ? rc : 1;
4310
- }else if( rc!=0 ){
4311
- fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd);
4312
- return rc;
4313
- }
4314
- }
4326
+ if( !readStdin ){
4327
+ /* Run all arguments that do not begin with '-' as if they were separate
4328
+ ** command-line inputs, except for the argToSkip argument which contains
4329
+ ** the database filename.
4330
+ */
4331
+ for(i=0; i<nCmd; i++){
4332
+ if( azCmd[i][0]=='.' ){
4333
+ rc = do_meta_command(azCmd[i], &data);
4334
+ if( rc ) return rc==2 ? 0 : rc;
4335
+ }else{
4336
+ open_db(&data, 0);
4337
+ rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
4338
+ if( zErrMsg!=0 ){
4339
+ fprintf(stderr,"Error: %s\n", zErrMsg);
4340
+ return rc!=0 ? rc : 1;
4341
+ }else if( rc!=0 ){
4342
+ fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
4343
+ return rc;
4344
+ }
4345
+ }
4346
+ }
4347
+ free(azCmd);
43154348
}else{
43164349
/* Run commands received from standard input
43174350
*/
43184351
if( stdin_is_interactive ){
43194352
char *zHome;
43204353
--- src/shell.c
+++ src/shell.c
@@ -4036,14 +4036,16 @@
4036
4037 int main(int argc, char **argv){
4038 char *zErrMsg = 0;
4039 ShellState data;
4040 const char *zInitFile = 0;
4041 char *zFirstCmd = 0;
4042 int i;
4043 int rc = 0;
4044 int warnInmemoryDb = 0;
 
 
 
4045
4046 #if USE_SYSTEM_SQLITE+0!=1
4047 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
4048 fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
4049 sqlite3_sourceid(), SQLITE_SOURCE_ID);
@@ -4058,10 +4060,22 @@
4058 ** else is done.
4059 */
4060 #ifdef SIGINT
4061 signal(SIGINT, interrupt_handler);
4062 #endif
 
 
 
 
 
 
 
 
 
 
 
 
4063
4064 /* Do an initial pass through the command-line argument to locate
4065 ** the name of the database file, the name of the initialization file,
4066 ** the size of the alternative malloc heap,
4067 ** and the first command to execute.
@@ -4070,19 +4084,22 @@
4070 char *z;
4071 z = argv[i];
4072 if( z[0]!='-' ){
4073 if( data.zDbFilename==0 ){
4074 data.zDbFilename = z;
4075 continue;
4076 }
4077 if( zFirstCmd==0 ){
4078 zFirstCmd = z;
4079 continue;
4080 }
4081 fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]);
4082 fprintf(stderr,"Use -help for a list of options.\n");
4083 return 1;
 
 
 
4084 }
4085 if( z[1]=='-' ) z++;
4086 if( strcmp(z,"-separator")==0
4087 || strcmp(z,"-nullvalue")==0
4088 || strcmp(z,"-newline")==0
@@ -4169,15 +4186,10 @@
4169 warnInmemoryDb = argc==1;
4170 #else
4171 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4172 return 1;
4173 #endif
4174 #ifdef SQLITE_SHELL_DBNAME_PROC
4175 { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4176 SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4177 warnInmemoryDb = 0; }
4178 #endif
4179 }
4180 data.out = stdout;
4181
4182 /* Go ahead and open the database file if it already exists. If the
4183 ** file does not exist, delay opening it. This prevents empty database
@@ -4194,10 +4206,22 @@
4194 */
4195 rc = process_sqliterc(&data,zInitFile);
4196 if( rc>0 ){
4197 return rc;
4198 }
 
 
 
 
 
 
 
 
 
 
 
 
4199
4200 /* Make a second pass through the command-line argument and set
4201 ** options. This second pass is delayed until after the initialization
4202 ** file is processed so that the command-line arguments will override
4203 ** settings in the initialization file.
@@ -4270,10 +4294,14 @@
4270 i++;
4271 #endif
4272 }else if( strcmp(z,"-help")==0 ){
4273 usage(1);
4274 }else if( strcmp(z,"-cmd")==0 ){
 
 
 
 
4275 if( i==argc-1 ) break;
4276 z = cmdline_option_value(argc,argv,++i);
4277 if( z[0]=='.' ){
4278 rc = do_meta_command(z, &data);
4279 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
@@ -4293,27 +4321,32 @@
4293 fprintf(stderr,"Use -help for a list of options.\n");
4294 return 1;
4295 }
4296 }
4297
4298 if( zFirstCmd ){
4299 /* Run just the command that follows the database name
4300 */
4301 if( zFirstCmd[0]=='.' ){
4302 rc = do_meta_command(zFirstCmd, &data);
4303 if( rc==2 ) rc = 0;
4304 }else{
4305 open_db(&data, 0);
4306 rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
4307 if( zErrMsg!=0 ){
4308 fprintf(stderr,"Error: %s\n", zErrMsg);
4309 return rc!=0 ? rc : 1;
4310 }else if( rc!=0 ){
4311 fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd);
4312 return rc;
4313 }
4314 }
 
 
 
 
 
4315 }else{
4316 /* Run commands received from standard input
4317 */
4318 if( stdin_is_interactive ){
4319 char *zHome;
4320
--- src/shell.c
+++ src/shell.c
@@ -4036,14 +4036,16 @@
4036
4037 int main(int argc, char **argv){
4038 char *zErrMsg = 0;
4039 ShellState data;
4040 const char *zInitFile = 0;
 
4041 int i;
4042 int rc = 0;
4043 int warnInmemoryDb = 0;
4044 int readStdin = 1;
4045 int nCmd = 0;
4046 char **azCmd = 0;
4047
4048 #if USE_SYSTEM_SQLITE+0!=1
4049 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
4050 fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
4051 sqlite3_sourceid(), SQLITE_SOURCE_ID);
@@ -4058,10 +4060,22 @@
4060 ** else is done.
4061 */
4062 #ifdef SIGINT
4063 signal(SIGINT, interrupt_handler);
4064 #endif
4065
4066 #ifdef SQLITE_SHELL_DBNAME_PROC
4067 {
4068 /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
4069 ** of a C-function that will provide the name of the database file. Use
4070 ** this compile-time option to embed this shell program in larger
4071 ** applications. */
4072 extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4073 SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4074 warnInmemoryDb = 0;
4075 }
4076 #endif
4077
4078 /* Do an initial pass through the command-line argument to locate
4079 ** the name of the database file, the name of the initialization file,
4080 ** the size of the alternative malloc heap,
4081 ** and the first command to execute.
@@ -4070,19 +4084,22 @@
4084 char *z;
4085 z = argv[i];
4086 if( z[0]!='-' ){
4087 if( data.zDbFilename==0 ){
4088 data.zDbFilename = z;
4089 }else{
4090 /* Excesss arguments are interpreted as SQL (or dot-commands) and
4091 ** mean that nothing is read from stdin */
4092 readStdin = 0;
4093 nCmd++;
4094 azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
4095 if( azCmd==0 ){
4096 fprintf(stderr, "out of memory\n");
4097 exit(1);
4098 }
4099 azCmd[nCmd-1] = z;
4100 }
4101 }
4102 if( z[1]=='-' ) z++;
4103 if( strcmp(z,"-separator")==0
4104 || strcmp(z,"-nullvalue")==0
4105 || strcmp(z,"-newline")==0
@@ -4169,15 +4186,10 @@
4186 warnInmemoryDb = argc==1;
4187 #else
4188 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4189 return 1;
4190 #endif
 
 
 
 
 
4191 }
4192 data.out = stdout;
4193
4194 /* Go ahead and open the database file if it already exists. If the
4195 ** file does not exist, delay opening it. This prevents empty database
@@ -4194,10 +4206,22 @@
4206 */
4207 rc = process_sqliterc(&data,zInitFile);
4208 if( rc>0 ){
4209 return rc;
4210 }
4211
4212 #ifdef SQLITE_SHELL_INIT_PROC
4213 {
4214 /* The SQLITE_SHELL_INIT_PROC is an application-defined function
4215 ** that can do additional initialization on the database connection
4216 ** after it has opened.
4217 */
4218 extern int SQLITE_SHELL_INIT_PROC(sqlite3*);
4219 rc = SQLITE_SHELL_INIT_PROC(data.db);
4220 if( rc ) return rc;
4221 }
4222 #endif
4223
4224 /* Make a second pass through the command-line argument and set
4225 ** options. This second pass is delayed until after the initialization
4226 ** file is processed so that the command-line arguments will override
4227 ** settings in the initialization file.
@@ -4270,10 +4294,14 @@
4294 i++;
4295 #endif
4296 }else if( strcmp(z,"-help")==0 ){
4297 usage(1);
4298 }else if( strcmp(z,"-cmd")==0 ){
4299 /* Run commands that follow -cmd first and separately from commands
4300 ** that simply appear on the command-line. This seems goofy. It would
4301 ** be better if all commands ran in the order that they appear. But
4302 ** we retain the goofy behavior for historical compatibility. */
4303 if( i==argc-1 ) break;
4304 z = cmdline_option_value(argc,argv,++i);
4305 if( z[0]=='.' ){
4306 rc = do_meta_command(z, &data);
4307 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
@@ -4293,27 +4321,32 @@
4321 fprintf(stderr,"Use -help for a list of options.\n");
4322 return 1;
4323 }
4324 }
4325
4326 if( !readStdin ){
4327 /* Run all arguments that do not begin with '-' as if they were separate
4328 ** command-line inputs, except for the argToSkip argument which contains
4329 ** the database filename.
4330 */
4331 for(i=0; i<nCmd; i++){
4332 if( azCmd[i][0]=='.' ){
4333 rc = do_meta_command(azCmd[i], &data);
4334 if( rc ) return rc==2 ? 0 : rc;
4335 }else{
4336 open_db(&data, 0);
4337 rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
4338 if( zErrMsg!=0 ){
4339 fprintf(stderr,"Error: %s\n", zErrMsg);
4340 return rc!=0 ? rc : 1;
4341 }else if( rc!=0 ){
4342 fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
4343 return rc;
4344 }
4345 }
4346 }
4347 free(azCmd);
4348 }else{
4349 /* Run commands received from standard input
4350 */
4351 if( stdin_is_interactive ){
4352 char *zHome;
4353
+14 -5
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -117,30 +117,39 @@
117117
static int sqlcmd_autoinit(
118118
sqlite3 *db,
119119
const char **pzErrMsg,
120120
const void *notUsed
121121
){
122
+ char *zSql;
123
+ int rc = SQLITE_OK;
122124
sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0,
123125
sqlcmd_content, 0, 0);
124126
sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0,
125127
sqlcmd_compress, 0, 0);
126128
sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0,
127129
sqlcmd_decompress, 0, 0);
128130
re_add_sql_func(db);
131
+ g.zMainDbType = "repository";
129132
g.repositoryOpen = 1;
130133
g.db = db;
131
- return SQLITE_OK;
134
+ db_open_config(1);
135
+ if( g.zLocalDbName ){
136
+ zSql = sqlite3_mprintf("ATTACH %Q AS localdb;", g.zLocalDbName);
137
+ rc = sqlite3_exec(db, zSql, 0, 0, 0);
138
+ sqlite3_free(zSql);
139
+ }
140
+ return rc;
132141
}
133142
134143
/*
135144
** COMMAND: sqlite3
136145
**
137
-** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
146
+** Usage: %fossil sqlite3 ?SQL-COMMANDS? ?OPTIONS?
138147
**
139
-** Run the standalone sqlite3 command-line shell on DATABASE with OPTIONS.
140
-** If DATABASE is omitted, then the repository that serves the working
141
-** directory is opened.
148
+** Run the standalone sqlite3 command-line shell on the repository database
149
+** for the current checkout, or whatever repository is specified by the
150
+** -R command-line option.
142151
**
143152
** WARNING: Careless use of this command can corrupt a Fossil repository
144153
** in ways that are unrecoverable. Be sure you know what you are doing before
145154
** running any SQL commands that modifies the repository database.
146155
*/
147156
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -117,30 +117,39 @@
117 static int sqlcmd_autoinit(
118 sqlite3 *db,
119 const char **pzErrMsg,
120 const void *notUsed
121 ){
 
 
122 sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0,
123 sqlcmd_content, 0, 0);
124 sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0,
125 sqlcmd_compress, 0, 0);
126 sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0,
127 sqlcmd_decompress, 0, 0);
128 re_add_sql_func(db);
 
129 g.repositoryOpen = 1;
130 g.db = db;
131 return SQLITE_OK;
 
 
 
 
 
 
132 }
133
134 /*
135 ** COMMAND: sqlite3
136 **
137 ** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
138 **
139 ** Run the standalone sqlite3 command-line shell on DATABASE with OPTIONS.
140 ** If DATABASE is omitted, then the repository that serves the working
141 ** directory is opened.
142 **
143 ** WARNING: Careless use of this command can corrupt a Fossil repository
144 ** in ways that are unrecoverable. Be sure you know what you are doing before
145 ** running any SQL commands that modifies the repository database.
146 */
147
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -117,30 +117,39 @@
117 static int sqlcmd_autoinit(
118 sqlite3 *db,
119 const char **pzErrMsg,
120 const void *notUsed
121 ){
122 char *zSql;
123 int rc = SQLITE_OK;
124 sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0,
125 sqlcmd_content, 0, 0);
126 sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0,
127 sqlcmd_compress, 0, 0);
128 sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0,
129 sqlcmd_decompress, 0, 0);
130 re_add_sql_func(db);
131 g.zMainDbType = "repository";
132 g.repositoryOpen = 1;
133 g.db = db;
134 db_open_config(1);
135 if( g.zLocalDbName ){
136 zSql = sqlite3_mprintf("ATTACH %Q AS localdb;", g.zLocalDbName);
137 rc = sqlite3_exec(db, zSql, 0, 0, 0);
138 sqlite3_free(zSql);
139 }
140 return rc;
141 }
142
143 /*
144 ** COMMAND: sqlite3
145 **
146 ** Usage: %fossil sqlite3 ?SQL-COMMANDS? ?OPTIONS?
147 **
148 ** Run the standalone sqlite3 command-line shell on the repository database
149 ** for the current checkout, or whatever repository is specified by the
150 ** -R command-line option.
151 **
152 ** WARNING: Careless use of this command can corrupt a Fossil repository
153 ** in ways that are unrecoverable. Be sure you know what you are doing before
154 ** running any SQL commands that modifies the repository database.
155 */
156

Keyboard Shortcuts

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