Fossil SCM

Merge the latest SQLite enhancements with the new and improved CLI prompt interface.

drh 2026-04-23 20:17 UTC trunk
Commit 87881e8d7b86858cda5fe4a6f8333c10302835b6a5fea5b93062547fe0f6966a
+156 -66
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -19886,20 +19886,21 @@
1988619886
sqlite3_value **argv
1988719887
){
1988819888
int rc;
1988919889
sqlite3_stmt *pStmt;
1989019890
int n;
19891
- sqlite3_int64 i64;
19891
+ sqlite3_int64 ii;
1989219892
sqlite3_int64 pgsz;
1989319893
sqlite3_int64 nPage;
1989419894
sqlite3_int64 nPageInUse;
1989519895
sqlite3_int64 nFreeList;
1989619896
sqlite3_int64 nIndex;
1989719897
sqlite3_int64 nWORowid;
1989819898
Analysis s;
1989919899
sqlite3_uint64 r[2];
1990019900
19901
+ (void)argc;
1990119902
memset(&s, 0, sizeof(s));
1990219903
s.db = sqlite3_context_db_handle(context);
1990319904
s.context = context;
1990419905
s.pOut = sqlite3_str_new(0);
1990519906
if( sqlite3_str_errcode(s.pOut) ){
@@ -19912,14 +19913,14 @@
1991219913
}else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){
1991319914
analysisReset(&s);
1991419915
sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC);
1991519916
return;
1991619917
}
19917
- i64 = 0;
19918
- rc = analysisSqlInt(&s,&i64,"SELECT 1 FROM pragma_database_list"
19918
+ ii = 0;
19919
+ rc = analysisSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list"
1991919920
" WHERE name=%Q COLLATE nocase",s.zSchema);
19920
- if( rc || i64==0 ){
19921
+ if( rc || ii==0 ){
1992119922
analysisReset(&s);
1992219923
sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC);
1992319924
return;
1992419925
}
1992519926
sqlite3_randomness(sizeof(r), &r);
@@ -20037,61 +20038,61 @@
2003720038
rc = analysisSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema);
2003820039
if( rc ) return;
2003920040
analysisLine(&s, "Pages on the freelist", "%-11lld ", nFreeList);
2004020041
analysisPercent(&s, (nFreeList*100.0)/(double)nPage);
2004120042
20042
- i64 = 0;
20043
- rc = analysisSqlInt(&s, &i64, "PRAGMA \"%w\".auto_vacuum", s.zSchema);
20043
+ ii = 0;
20044
+ rc = analysisSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema);
2004420045
if( rc ) return;
20045
- if( i64==0 || nPage<=1 ){
20046
- i64 = 0;
20046
+ if( ii==0 || nPage<=1 ){
20047
+ ii = 0;
2004720048
}else{
2004820049
double rPtrsPerPage = pgsz/5;
2004920050
double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0);
20050
- i64 = (sqlite3_int64)ceil(rAvPage);
20051
+ ii = (sqlite3_int64)ceil(rAvPage);
2005120052
}
20052
- analysisLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", i64);
20053
- analysisPercent(&s, (i64*100.0)/(double)nPage);
20053
+ analysisLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii);
20054
+ analysisPercent(&s, (ii*100.0)/(double)nPage);
2005420055
20055
- i64 = 0;
20056
- rc = analysisSqlInt(&s, &i64,
20056
+ ii = 0;
20057
+ rc = analysisSqlInt(&s, &ii,
2005720058
"SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'",
2005820059
s.zSchema);
2005920060
if( rc ) return;
20060
- analysisLine(&s, "Number of tables", "%lld\n", i64);
20061
+ analysisLine(&s, "Number of tables", "%lld\n", ii);
2006120062
nWORowid = 0;
2006220063
rc = analysisSqlInt(&s, &nWORowid,
2006320064
"SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr",
2006420065
s.zSchema);
2006520066
if( rc ) return;
2006620067
if( nWORowid>0 ){
2006720068
analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid);
20068
- analysisLine(&s, "Number of rowid tables", "%lld\n", i64 - nWORowid);
20069
+ analysisLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid);
2006920070
}
2007020071
nIndex = 0;
2007120072
rc = analysisSqlInt(&s, &nIndex,
2007220073
"SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'",
2007320074
s.zSchema);
2007420075
if( rc ) return;
2007520076
analysisLine(&s, "Number of indexes", "%lld\n", nIndex);
20076
- i64 = 0;
20077
- rc = analysisSqlInt(&s, &i64,
20077
+ ii = 0;
20078
+ rc = analysisSqlInt(&s, &ii,
2007820079
"SELECT count(*) FROM \"%w\".sqlite_schema"
2007920080
" WHERE name GLOB 'sqlite_autoindex_*' AND type='index'",
2008020081
s.zSchema);
2008120082
if( rc ) return;
20082
- analysisLine(&s, "Number of defined indexes", "%lld\n", nIndex - i64);
20083
- analysisLine(&s, "Number of implied indexes", "%lld\n", i64);
20083
+ analysisLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii);
20084
+ analysisLine(&s, "Number of implied indexes", "%lld\n", ii);
2008420085
analysisLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage);
20085
- i64 = 0;
20086
- rc = analysisSqlInt(&s, &i64,
20086
+ ii = 0;
20087
+ rc = analysisSqlInt(&s, &ii,
2008720088
"SELECT sum(payload) FROM temp.%s"
2008820089
" WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'",
2008920090
s.zSU);
2009020091
if( rc ) return;
20091
- analysisLine(&s, "Bytes of payload", "%-11lld ", i64);
20092
- analysisPercent(&s, i64*100.0/(double)(pgsz*nPage));
20092
+ analysisLine(&s, "Bytes of payload", "%-11lld ", ii);
20093
+ analysisPercent(&s, ii*100.0/(double)(pgsz*nPage));
2009320094
2009420095
analysisTitle(&s, "Page counts for all tables with their indexes");
2009520096
pStmt = analysisPrepare(&s,
2009620097
"SELECT upper(tblname),\n"
2009720098
" sum(int_pages+leaf_pages+ovfl_pages)\n"
@@ -24900,10 +24901,14 @@
2490024901
return rc;
2490124902
}
2490224903
static int cli_write(FILE *out, const char *zData, int nData){
2490324904
if( cli_output_capture && (out==stdout || out==stderr) ){
2490424905
sqlite3_str_append(cli_output_capture, zData, nData);
24906
+#ifdef _WIN32
24907
+ }else if( out==stdout || out==stderr ){
24908
+ nData = sqlite3_fprintf(out, "%.*s", nData, zData);
24909
+#endif
2490524910
}else{
2490624911
nData = (int)fwrite(zData, 1, nData, out);
2490724912
}
2490824913
return nData;
2490924914
}
@@ -25099,50 +25104,80 @@
2509925104
}
2510025105
return zLine;
2510125106
}
2510225107
2510325108
/*
25104
-** The default prompts.
25105
-*/
25106
-#ifndef SQLITE_PS1
25107
-# define SQLITE_PS1 "/A /f> "
25108
-#endif
25109
-#ifndef SQLITE_PS2
25110
-# define SQLITE_PS2 "/B.../H> "
25111
-#endif
25112
-
25113
-/*
25114
-** Redefinable name of a function that is used to find the text for
25115
-** some prompt expansions: /A /V /v
25116
-*/
25117
-#ifndef SQLITE_PS_APPDEF
25118
-# define SQLITE_PS_APPDEF shellPromptAppDef
25119
-#else
25109
+** The SQLITE_PS_APPDEF macro should be set to the name of a function
25110
+** that accepts a single "int" argument and returns a "const char *"
25111
+** that is guaranteed to be non-NULL. The value returned depends on the
25112
+** argument:
25113
+**
25114
+** 1 Default main prompt.
25115
+** 2 Default continuation prompt.
25116
+** 3 Environment variable to override main prompt ("SQLITE_PS1")
25117
+** 4 Environment variable to override continuatio ("SQLITE_PS2")
25118
+** 'A' The name of the application. (Nominally "SQLite")
25119
+** 'V' Version number including patch. (ex: "3.54.1")
25120
+** 'v' Version number without patch. (ex: "3.54")
25121
+**
25122
+*/
25123
+#ifdef SQLITE_PS_APPDEF
2512025124
extern const char *SQLITE_PS_APPDEF(int);
25121
-#endif
25122
-
25123
-/*
25124
-** Return a string appropriate for various prompt expansion characters.
25125
-** Return an empty string at least. Always return a valid string pointer.
25126
-*/
25125
+#else
25126
+# define SQLITE_PS_APPDEF shellPromptAppDef
2512725127
static const char *shellPromptAppDef(int c){
25128
- if( c=='A' ) return "SQLite";
25129
- if( c=='V' ) return sqlite3_libversion();
25130
- if( c=='v' ){
25131
- static char zRel[16];
25132
- const char *zF = sqlite3_libversion();
25133
- const char *zD = strrchr(zF,'.');
25134
- if( zD && (size_t)(zD-zF)<sizeof(zRel)-1 ){
25135
- memcpy(zRel,zF,(size_t)(zD-zF));
25136
- zRel[(size_t)(zD-zF)] = 0;
25137
- return zRel;
25138
- }else{
25139
- return zF;
25128
+ switch( c ){
25129
+ /* The default main prompt string */
25130
+ case 1:
25131
+#if defined(SQLITE_PS1)
25132
+ return SQLITE_PS1;
25133
+#elif defined(SQLITE_PS_NOANSI)
25134
+ return "/A-/v /~> ";
25135
+#else
25136
+ return "/e[1;/x33/:36/;m/A-/v /~>/e[0m ";
25137
+#endif
25138
+
25139
+ /* The default continuation prompt string */
25140
+ case 2:
25141
+#if defined(SQLITE_PS2)
25142
+ return SQLITE_PS2;
25143
+#elif defined(SQLITE_PS_NOANSI)
25144
+ return "/B/C> ";
25145
+#else
25146
+ return "/B/e[1;/x33/:36/;m/C>/e[0m ";
25147
+#endif
25148
+
25149
+ /* Name of environment variables that override the prompt strings
25150
+ ** of cases 1 and 2 */
25151
+ case 3: return "SQLITE_PS1";
25152
+ case 4: return "SQLITE_PS2";
25153
+
25154
+ /* Name of the application */
25155
+ case 'A': return "SQLite";
25156
+
25157
+ /* Full version number of the application, including patch level */
25158
+ case 'V': return sqlite3_libversion();
25159
+
25160
+ /* Version number without the patch level */
25161
+ case 'v': {
25162
+ static char zRel[16];
25163
+ const char *zF = sqlite3_libversion();
25164
+ const char *zD = strrchr(zF,'.');
25165
+ if( zD && (size_t)(zD-zF)<sizeof(zRel)-1 ){
25166
+ memcpy(zRel,zF,(size_t)(zD-zF));
25167
+ zRel[(size_t)(zD-zF)] = 0;
25168
+ return zRel;
25169
+ }else{
25170
+ return zF;
25171
+ }
2514025172
}
2514125173
}
2514225174
return "";
2514325175
}
25176
+#endif /* !defined(SQLITE_PS_APPDEF) */
25177
+
25178
+
2514425179
2514525180
/*
2514625181
** Return the raw (unexpanded) prompt string. This will be the
2514725182
** first of the following that exist:
2514825183
**
@@ -25158,18 +25193,14 @@
2515825193
assert( bContinue==0 || bContinue==1 );
2515925194
if( p->azPrompt[bContinue] ){
2516025195
return p->azPrompt[bContinue];
2516125196
}
2516225197
#ifndef SQLITE_SHELL_FIDDLE
25163
- zPS = getenv(bContinue ? "SQLITE_PS2" : "SQLITE_PS1");
25198
+ zPS = getenv(SQLITE_PS_APPDEF(3+bContinue));
2516425199
if( zPS ) return zPS;
2516525200
#endif
25166
- if( bContinue ){
25167
- return SQLITE_PS2;
25168
- }else{
25169
- return SQLITE_PS1;
25170
- }
25201
+ return SQLITE_PS_APPDEF(1+bContinue);
2517125202
}
2517225203
2517325204
/*
2517425205
** Return the name of the open database file, to be used for prompt
2517525206
** expansion purposes.
@@ -25188,10 +25219,49 @@
2518825219
zFN = "in-memory";
2518925220
}
2519025221
}
2519125222
return zFN;
2519225223
}
25224
+
25225
+/*
25226
+** Return the name of the computer on which we are running.
25227
+*/
25228
+static const char *prompt_hostname(int bFull){
25229
+#ifdef _WIN32
25230
+ const char *z = getenv("COMPUTERNAME");
25231
+ if( z==0 || z[0]==0 ) z = "?";
25232
+ return z;
25233
+#else
25234
+ static char zHost[256];
25235
+ if( gethostname(zHost, sizeof(zHost)) ){
25236
+ zHost[0] = '?';
25237
+ zHost[1] = 0;
25238
+ }
25239
+ if( !bFull ){
25240
+ char *p = strchr(zHost,'.');
25241
+ if( p ) p[0] = 0;
25242
+ }
25243
+ return zHost;
25244
+#endif
25245
+}
25246
+
25247
+/*
25248
+** Return the username. This is taken from an environment variable
25249
+** and can thus be forged. Do not depend on it.
25250
+*/
25251
+static const char *prompt_user(void){
25252
+ const char *z;
25253
+#ifdef _WIN32
25254
+ z = getenv("USERNAME");
25255
+ if( z==0 || z[0]==0 ) z = "?";
25256
+#else
25257
+ z = getenv("USER");
25258
+ if( z==0 || z[0]==0 ) z = getenv("LOGNAME");
25259
+ if( z==0 || z[0]==0 ) z = "?";
25260
+#endif
25261
+ return z;
25262
+}
2519325263
2519425264
/*
2519525265
** Expand escapes in the given input prompt string. Return the
2519625266
** expanded prompt in memory obtained from sqlite3_malloc(). The
2519725267
** caller is responsible for freeing the memory.
@@ -25334,12 +25404,32 @@
2533425404
zPrompt += 2;
2533525405
i = -1;
2533625406
continue;
2533725407
}
2533825408
25339
- if( c=='H' ){
25340
- /* /H becomes text needed to terminate current input */
25409
+ if( c=='h' || c=='H' ){
25410
+ /* /h becomes hostname up to the first '.' */
25411
+ /* /H is the full hostname */
25412
+ if( !mOff ){
25413
+ sqlite3_str_appendall(pOut, prompt_hostname(c=='H'));
25414
+ }
25415
+ zPrompt += 2;
25416
+ i = -1;
25417
+ continue;
25418
+ }
25419
+ if( c=='u' ){
25420
+ /* /u becomes the username (taken from environment variables) */
25421
+ if( !mOff ){
25422
+ sqlite3_str_appendall(pOut, prompt_user());
25423
+ }
25424
+ zPrompt += 2;
25425
+ i = -1;
25426
+ continue;
25427
+ }
25428
+
25429
+ if( c=='C' ){
25430
+ /* /C becomes text needed to terminate current input */
2534125431
if( !mOff ){
2534225432
sqlite3_int64 R = zPrior ? sqlite3_incomplete(zPrior) : 0;
2534325433
int cc = (R>>16)&0xff;
2534425434
int nParen = R>>32;
2534525435
int eSemi = (R>>8)&0xff;
@@ -37972,11 +38062,11 @@
3797238062
vfstrace_register("trace",0,vfstraceOut, &data, 1);
3797338063
}
3797438064
#ifndef SQLITE_SHELL_FIDDLE
3797538065
sqlite3_appendvfs_init(0,0,0);
3797638066
#ifdef SQLITE_DEBUG
37977
- sqlite3_auto_extension( (void (*)())auto_ext_leak_tester );
38067
+ sqlite3_auto_extension( (void(*)(void))auto_ext_leak_tester );
3797838068
#endif
3797938069
#endif
3798038070
modeDefault(&data);
3798138071
3798238072
/* Go ahead and open the database file if it already exists. If the
3798338073
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -19886,20 +19886,21 @@
19886 sqlite3_value **argv
19887 ){
19888 int rc;
19889 sqlite3_stmt *pStmt;
19890 int n;
19891 sqlite3_int64 i64;
19892 sqlite3_int64 pgsz;
19893 sqlite3_int64 nPage;
19894 sqlite3_int64 nPageInUse;
19895 sqlite3_int64 nFreeList;
19896 sqlite3_int64 nIndex;
19897 sqlite3_int64 nWORowid;
19898 Analysis s;
19899 sqlite3_uint64 r[2];
19900
 
19901 memset(&s, 0, sizeof(s));
19902 s.db = sqlite3_context_db_handle(context);
19903 s.context = context;
19904 s.pOut = sqlite3_str_new(0);
19905 if( sqlite3_str_errcode(s.pOut) ){
@@ -19912,14 +19913,14 @@
19912 }else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){
19913 analysisReset(&s);
19914 sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC);
19915 return;
19916 }
19917 i64 = 0;
19918 rc = analysisSqlInt(&s,&i64,"SELECT 1 FROM pragma_database_list"
19919 " WHERE name=%Q COLLATE nocase",s.zSchema);
19920 if( rc || i64==0 ){
19921 analysisReset(&s);
19922 sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC);
19923 return;
19924 }
19925 sqlite3_randomness(sizeof(r), &r);
@@ -20037,61 +20038,61 @@
20037 rc = analysisSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema);
20038 if( rc ) return;
20039 analysisLine(&s, "Pages on the freelist", "%-11lld ", nFreeList);
20040 analysisPercent(&s, (nFreeList*100.0)/(double)nPage);
20041
20042 i64 = 0;
20043 rc = analysisSqlInt(&s, &i64, "PRAGMA \"%w\".auto_vacuum", s.zSchema);
20044 if( rc ) return;
20045 if( i64==0 || nPage<=1 ){
20046 i64 = 0;
20047 }else{
20048 double rPtrsPerPage = pgsz/5;
20049 double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0);
20050 i64 = (sqlite3_int64)ceil(rAvPage);
20051 }
20052 analysisLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", i64);
20053 analysisPercent(&s, (i64*100.0)/(double)nPage);
20054
20055 i64 = 0;
20056 rc = analysisSqlInt(&s, &i64,
20057 "SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'",
20058 s.zSchema);
20059 if( rc ) return;
20060 analysisLine(&s, "Number of tables", "%lld\n", i64);
20061 nWORowid = 0;
20062 rc = analysisSqlInt(&s, &nWORowid,
20063 "SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr",
20064 s.zSchema);
20065 if( rc ) return;
20066 if( nWORowid>0 ){
20067 analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid);
20068 analysisLine(&s, "Number of rowid tables", "%lld\n", i64 - nWORowid);
20069 }
20070 nIndex = 0;
20071 rc = analysisSqlInt(&s, &nIndex,
20072 "SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'",
20073 s.zSchema);
20074 if( rc ) return;
20075 analysisLine(&s, "Number of indexes", "%lld\n", nIndex);
20076 i64 = 0;
20077 rc = analysisSqlInt(&s, &i64,
20078 "SELECT count(*) FROM \"%w\".sqlite_schema"
20079 " WHERE name GLOB 'sqlite_autoindex_*' AND type='index'",
20080 s.zSchema);
20081 if( rc ) return;
20082 analysisLine(&s, "Number of defined indexes", "%lld\n", nIndex - i64);
20083 analysisLine(&s, "Number of implied indexes", "%lld\n", i64);
20084 analysisLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage);
20085 i64 = 0;
20086 rc = analysisSqlInt(&s, &i64,
20087 "SELECT sum(payload) FROM temp.%s"
20088 " WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'",
20089 s.zSU);
20090 if( rc ) return;
20091 analysisLine(&s, "Bytes of payload", "%-11lld ", i64);
20092 analysisPercent(&s, i64*100.0/(double)(pgsz*nPage));
20093
20094 analysisTitle(&s, "Page counts for all tables with their indexes");
20095 pStmt = analysisPrepare(&s,
20096 "SELECT upper(tblname),\n"
20097 " sum(int_pages+leaf_pages+ovfl_pages)\n"
@@ -24900,10 +24901,14 @@
24900 return rc;
24901 }
24902 static int cli_write(FILE *out, const char *zData, int nData){
24903 if( cli_output_capture && (out==stdout || out==stderr) ){
24904 sqlite3_str_append(cli_output_capture, zData, nData);
 
 
 
 
24905 }else{
24906 nData = (int)fwrite(zData, 1, nData, out);
24907 }
24908 return nData;
24909 }
@@ -25099,50 +25104,80 @@
25099 }
25100 return zLine;
25101 }
25102
25103 /*
25104 ** The default prompts.
25105 */
25106 #ifndef SQLITE_PS1
25107 # define SQLITE_PS1 "/A /f> "
25108 #endif
25109 #ifndef SQLITE_PS2
25110 # define SQLITE_PS2 "/B.../H> "
25111 #endif
25112
25113 /*
25114 ** Redefinable name of a function that is used to find the text for
25115 ** some prompt expansions: /A /V /v
25116 */
25117 #ifndef SQLITE_PS_APPDEF
25118 # define SQLITE_PS_APPDEF shellPromptAppDef
25119 #else
25120 extern const char *SQLITE_PS_APPDEF(int);
25121 #endif
25122
25123 /*
25124 ** Return a string appropriate for various prompt expansion characters.
25125 ** Return an empty string at least. Always return a valid string pointer.
25126 */
25127 static const char *shellPromptAppDef(int c){
25128 if( c=='A' ) return "SQLite";
25129 if( c=='V' ) return sqlite3_libversion();
25130 if( c=='v' ){
25131 static char zRel[16];
25132 const char *zF = sqlite3_libversion();
25133 const char *zD = strrchr(zF,'.');
25134 if( zD && (size_t)(zD-zF)<sizeof(zRel)-1 ){
25135 memcpy(zRel,zF,(size_t)(zD-zF));
25136 zRel[(size_t)(zD-zF)] = 0;
25137 return zRel;
25138 }else{
25139 return zF;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25140 }
25141 }
25142 return "";
25143 }
 
 
 
25144
25145 /*
25146 ** Return the raw (unexpanded) prompt string. This will be the
25147 ** first of the following that exist:
25148 **
@@ -25158,18 +25193,14 @@
25158 assert( bContinue==0 || bContinue==1 );
25159 if( p->azPrompt[bContinue] ){
25160 return p->azPrompt[bContinue];
25161 }
25162 #ifndef SQLITE_SHELL_FIDDLE
25163 zPS = getenv(bContinue ? "SQLITE_PS2" : "SQLITE_PS1");
25164 if( zPS ) return zPS;
25165 #endif
25166 if( bContinue ){
25167 return SQLITE_PS2;
25168 }else{
25169 return SQLITE_PS1;
25170 }
25171 }
25172
25173 /*
25174 ** Return the name of the open database file, to be used for prompt
25175 ** expansion purposes.
@@ -25188,10 +25219,49 @@
25188 zFN = "in-memory";
25189 }
25190 }
25191 return zFN;
25192 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25193
25194 /*
25195 ** Expand escapes in the given input prompt string. Return the
25196 ** expanded prompt in memory obtained from sqlite3_malloc(). The
25197 ** caller is responsible for freeing the memory.
@@ -25334,12 +25404,32 @@
25334 zPrompt += 2;
25335 i = -1;
25336 continue;
25337 }
25338
25339 if( c=='H' ){
25340 /* /H becomes text needed to terminate current input */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25341 if( !mOff ){
25342 sqlite3_int64 R = zPrior ? sqlite3_incomplete(zPrior) : 0;
25343 int cc = (R>>16)&0xff;
25344 int nParen = R>>32;
25345 int eSemi = (R>>8)&0xff;
@@ -37972,11 +38062,11 @@
37972 vfstrace_register("trace",0,vfstraceOut, &data, 1);
37973 }
37974 #ifndef SQLITE_SHELL_FIDDLE
37975 sqlite3_appendvfs_init(0,0,0);
37976 #ifdef SQLITE_DEBUG
37977 sqlite3_auto_extension( (void (*)())auto_ext_leak_tester );
37978 #endif
37979 #endif
37980 modeDefault(&data);
37981
37982 /* Go ahead and open the database file if it already exists. If the
37983
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -19886,20 +19886,21 @@
19886 sqlite3_value **argv
19887 ){
19888 int rc;
19889 sqlite3_stmt *pStmt;
19890 int n;
19891 sqlite3_int64 ii;
19892 sqlite3_int64 pgsz;
19893 sqlite3_int64 nPage;
19894 sqlite3_int64 nPageInUse;
19895 sqlite3_int64 nFreeList;
19896 sqlite3_int64 nIndex;
19897 sqlite3_int64 nWORowid;
19898 Analysis s;
19899 sqlite3_uint64 r[2];
19900
19901 (void)argc;
19902 memset(&s, 0, sizeof(s));
19903 s.db = sqlite3_context_db_handle(context);
19904 s.context = context;
19905 s.pOut = sqlite3_str_new(0);
19906 if( sqlite3_str_errcode(s.pOut) ){
@@ -19912,14 +19913,14 @@
19913 }else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){
19914 analysisReset(&s);
19915 sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC);
19916 return;
19917 }
19918 ii = 0;
19919 rc = analysisSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list"
19920 " WHERE name=%Q COLLATE nocase",s.zSchema);
19921 if( rc || ii==0 ){
19922 analysisReset(&s);
19923 sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC);
19924 return;
19925 }
19926 sqlite3_randomness(sizeof(r), &r);
@@ -20037,61 +20038,61 @@
20038 rc = analysisSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema);
20039 if( rc ) return;
20040 analysisLine(&s, "Pages on the freelist", "%-11lld ", nFreeList);
20041 analysisPercent(&s, (nFreeList*100.0)/(double)nPage);
20042
20043 ii = 0;
20044 rc = analysisSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema);
20045 if( rc ) return;
20046 if( ii==0 || nPage<=1 ){
20047 ii = 0;
20048 }else{
20049 double rPtrsPerPage = pgsz/5;
20050 double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0);
20051 ii = (sqlite3_int64)ceil(rAvPage);
20052 }
20053 analysisLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii);
20054 analysisPercent(&s, (ii*100.0)/(double)nPage);
20055
20056 ii = 0;
20057 rc = analysisSqlInt(&s, &ii,
20058 "SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'",
20059 s.zSchema);
20060 if( rc ) return;
20061 analysisLine(&s, "Number of tables", "%lld\n", ii);
20062 nWORowid = 0;
20063 rc = analysisSqlInt(&s, &nWORowid,
20064 "SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr",
20065 s.zSchema);
20066 if( rc ) return;
20067 if( nWORowid>0 ){
20068 analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid);
20069 analysisLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid);
20070 }
20071 nIndex = 0;
20072 rc = analysisSqlInt(&s, &nIndex,
20073 "SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'",
20074 s.zSchema);
20075 if( rc ) return;
20076 analysisLine(&s, "Number of indexes", "%lld\n", nIndex);
20077 ii = 0;
20078 rc = analysisSqlInt(&s, &ii,
20079 "SELECT count(*) FROM \"%w\".sqlite_schema"
20080 " WHERE name GLOB 'sqlite_autoindex_*' AND type='index'",
20081 s.zSchema);
20082 if( rc ) return;
20083 analysisLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii);
20084 analysisLine(&s, "Number of implied indexes", "%lld\n", ii);
20085 analysisLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage);
20086 ii = 0;
20087 rc = analysisSqlInt(&s, &ii,
20088 "SELECT sum(payload) FROM temp.%s"
20089 " WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'",
20090 s.zSU);
20091 if( rc ) return;
20092 analysisLine(&s, "Bytes of payload", "%-11lld ", ii);
20093 analysisPercent(&s, ii*100.0/(double)(pgsz*nPage));
20094
20095 analysisTitle(&s, "Page counts for all tables with their indexes");
20096 pStmt = analysisPrepare(&s,
20097 "SELECT upper(tblname),\n"
20098 " sum(int_pages+leaf_pages+ovfl_pages)\n"
@@ -24900,10 +24901,14 @@
24901 return rc;
24902 }
24903 static int cli_write(FILE *out, const char *zData, int nData){
24904 if( cli_output_capture && (out==stdout || out==stderr) ){
24905 sqlite3_str_append(cli_output_capture, zData, nData);
24906 #ifdef _WIN32
24907 }else if( out==stdout || out==stderr ){
24908 nData = sqlite3_fprintf(out, "%.*s", nData, zData);
24909 #endif
24910 }else{
24911 nData = (int)fwrite(zData, 1, nData, out);
24912 }
24913 return nData;
24914 }
@@ -25099,50 +25104,80 @@
25104 }
25105 return zLine;
25106 }
25107
25108 /*
25109 ** The SQLITE_PS_APPDEF macro should be set to the name of a function
25110 ** that accepts a single "int" argument and returns a "const char *"
25111 ** that is guaranteed to be non-NULL. The value returned depends on the
25112 ** argument:
25113 **
25114 ** 1 Default main prompt.
25115 ** 2 Default continuation prompt.
25116 ** 3 Environment variable to override main prompt ("SQLITE_PS1")
25117 ** 4 Environment variable to override continuatio ("SQLITE_PS2")
25118 ** 'A' The name of the application. (Nominally "SQLite")
25119 ** 'V' Version number including patch. (ex: "3.54.1")
25120 ** 'v' Version number without patch. (ex: "3.54")
25121 **
25122 */
25123 #ifdef SQLITE_PS_APPDEF
 
25124 extern const char *SQLITE_PS_APPDEF(int);
25125 #else
25126 # define SQLITE_PS_APPDEF shellPromptAppDef
 
 
 
 
25127 static const char *shellPromptAppDef(int c){
25128 switch( c ){
25129 /* The default main prompt string */
25130 case 1:
25131 #if defined(SQLITE_PS1)
25132 return SQLITE_PS1;
25133 #elif defined(SQLITE_PS_NOANSI)
25134 return "/A-/v /~> ";
25135 #else
25136 return "/e[1;/x33/:36/;m/A-/v /~>/e[0m ";
25137 #endif
25138
25139 /* The default continuation prompt string */
25140 case 2:
25141 #if defined(SQLITE_PS2)
25142 return SQLITE_PS2;
25143 #elif defined(SQLITE_PS_NOANSI)
25144 return "/B/C> ";
25145 #else
25146 return "/B/e[1;/x33/:36/;m/C>/e[0m ";
25147 #endif
25148
25149 /* Name of environment variables that override the prompt strings
25150 ** of cases 1 and 2 */
25151 case 3: return "SQLITE_PS1";
25152 case 4: return "SQLITE_PS2";
25153
25154 /* Name of the application */
25155 case 'A': return "SQLite";
25156
25157 /* Full version number of the application, including patch level */
25158 case 'V': return sqlite3_libversion();
25159
25160 /* Version number without the patch level */
25161 case 'v': {
25162 static char zRel[16];
25163 const char *zF = sqlite3_libversion();
25164 const char *zD = strrchr(zF,'.');
25165 if( zD && (size_t)(zD-zF)<sizeof(zRel)-1 ){
25166 memcpy(zRel,zF,(size_t)(zD-zF));
25167 zRel[(size_t)(zD-zF)] = 0;
25168 return zRel;
25169 }else{
25170 return zF;
25171 }
25172 }
25173 }
25174 return "";
25175 }
25176 #endif /* !defined(SQLITE_PS_APPDEF) */
25177
25178
25179
25180 /*
25181 ** Return the raw (unexpanded) prompt string. This will be the
25182 ** first of the following that exist:
25183 **
@@ -25158,18 +25193,14 @@
25193 assert( bContinue==0 || bContinue==1 );
25194 if( p->azPrompt[bContinue] ){
25195 return p->azPrompt[bContinue];
25196 }
25197 #ifndef SQLITE_SHELL_FIDDLE
25198 zPS = getenv(SQLITE_PS_APPDEF(3+bContinue));
25199 if( zPS ) return zPS;
25200 #endif
25201 return SQLITE_PS_APPDEF(1+bContinue);
 
 
 
 
25202 }
25203
25204 /*
25205 ** Return the name of the open database file, to be used for prompt
25206 ** expansion purposes.
@@ -25188,10 +25219,49 @@
25219 zFN = "in-memory";
25220 }
25221 }
25222 return zFN;
25223 }
25224
25225 /*
25226 ** Return the name of the computer on which we are running.
25227 */
25228 static const char *prompt_hostname(int bFull){
25229 #ifdef _WIN32
25230 const char *z = getenv("COMPUTERNAME");
25231 if( z==0 || z[0]==0 ) z = "?";
25232 return z;
25233 #else
25234 static char zHost[256];
25235 if( gethostname(zHost, sizeof(zHost)) ){
25236 zHost[0] = '?';
25237 zHost[1] = 0;
25238 }
25239 if( !bFull ){
25240 char *p = strchr(zHost,'.');
25241 if( p ) p[0] = 0;
25242 }
25243 return zHost;
25244 #endif
25245 }
25246
25247 /*
25248 ** Return the username. This is taken from an environment variable
25249 ** and can thus be forged. Do not depend on it.
25250 */
25251 static const char *prompt_user(void){
25252 const char *z;
25253 #ifdef _WIN32
25254 z = getenv("USERNAME");
25255 if( z==0 || z[0]==0 ) z = "?";
25256 #else
25257 z = getenv("USER");
25258 if( z==0 || z[0]==0 ) z = getenv("LOGNAME");
25259 if( z==0 || z[0]==0 ) z = "?";
25260 #endif
25261 return z;
25262 }
25263
25264 /*
25265 ** Expand escapes in the given input prompt string. Return the
25266 ** expanded prompt in memory obtained from sqlite3_malloc(). The
25267 ** caller is responsible for freeing the memory.
@@ -25334,12 +25404,32 @@
25404 zPrompt += 2;
25405 i = -1;
25406 continue;
25407 }
25408
25409 if( c=='h' || c=='H' ){
25410 /* /h becomes hostname up to the first '.' */
25411 /* /H is the full hostname */
25412 if( !mOff ){
25413 sqlite3_str_appendall(pOut, prompt_hostname(c=='H'));
25414 }
25415 zPrompt += 2;
25416 i = -1;
25417 continue;
25418 }
25419 if( c=='u' ){
25420 /* /u becomes the username (taken from environment variables) */
25421 if( !mOff ){
25422 sqlite3_str_appendall(pOut, prompt_user());
25423 }
25424 zPrompt += 2;
25425 i = -1;
25426 continue;
25427 }
25428
25429 if( c=='C' ){
25430 /* /C becomes text needed to terminate current input */
25431 if( !mOff ){
25432 sqlite3_int64 R = zPrior ? sqlite3_incomplete(zPrior) : 0;
25433 int cc = (R>>16)&0xff;
25434 int nParen = R>>32;
25435 int eSemi = (R>>8)&0xff;
@@ -37972,11 +38062,11 @@
38062 vfstrace_register("trace",0,vfstraceOut, &data, 1);
38063 }
38064 #ifndef SQLITE_SHELL_FIDDLE
38065 sqlite3_appendvfs_init(0,0,0);
38066 #ifdef SQLITE_DEBUG
38067 sqlite3_auto_extension( (void(*)(void))auto_ext_leak_tester );
38068 #endif
38069 #endif
38070 modeDefault(&data);
38071
38072 /* Go ahead and open the database file if it already exists. If the
38073
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6 with changes in files:
21
+** 354ce4f5e2a86b621b2058a6372495a5919c with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-04-23 16:40:34 e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6ca6ecb7ff1a3a9a237715eed5d30"
472
+#define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-04-23T16:40:34.462Z"
475
+#define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -263478,11 +263478,11 @@
263478263478
int nArg, /* Number of args */
263479263479
sqlite3_value **apUnused /* Function arguments */
263480263480
){
263481263481
assert( nArg==0 );
263482263482
UNUSED_PARAM2(nArg, apUnused);
263483
- sqlite3_result_text(pCtx, "fts5: 2026-04-22 19:38:04 f0fc4e5ec334da3a1db8b0334e23d1911874c96675690da94210b2afb45f7307", -1, SQLITE_TRANSIENT);
263483
+ sqlite3_result_text(pCtx, "fts5: 2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002", -1, SQLITE_TRANSIENT);
263484263484
}
263485263485
263486263486
/*
263487263487
** Implementation of fts5_locale(LOCALE, TEXT) function.
263488263488
**
263489263489
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-04-23 16:40:34 e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6ca6ecb7ff1a3a9a237715eed5d30"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-04-23T16:40:34.462Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -263478,11 +263478,11 @@
263478 int nArg, /* Number of args */
263479 sqlite3_value **apUnused /* Function arguments */
263480 ){
263481 assert( nArg==0 );
263482 UNUSED_PARAM2(nArg, apUnused);
263483 sqlite3_result_text(pCtx, "fts5: 2026-04-22 19:38:04 f0fc4e5ec334da3a1db8b0334e23d1911874c96675690da94210b2afb45f7307", -1, SQLITE_TRANSIENT);
263484 }
263485
263486 /*
263487 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263488 **
263489
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 354ce4f5e2a86b621b2058a6372495a5919c with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -263478,11 +263478,11 @@
263478 int nArg, /* Number of args */
263479 sqlite3_value **apUnused /* Function arguments */
263480 ){
263481 assert( nArg==0 );
263482 UNUSED_PARAM2(nArg, apUnused);
263483 sqlite3_result_text(pCtx, "fts5: 2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002", -1, SQLITE_TRANSIENT);
263484 }
263485
263486 /*
263487 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263488 **
263489
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-04-23 16:40:34 e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6ca6ecb7ff1a3a9a237715eed5d30"
151
+#define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-04-23T16:40:34.462Z"
154
+#define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
160160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-04-23 16:40:34 e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6ca6ecb7ff1a3a9a237715eed5d30"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-04-23T16:40:34.462Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160
+41 -29
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -321,30 +321,53 @@
321321
g.repositoryOpen = 0;
322322
g.localOpen = 0;
323323
}
324324
325325
/*
326
-** Return text for /A, /V, or /v prompt excapes.
326
+** This routine overrides some of the prompt generation behavior in the
327
+** SQLite shell. Always return a static string. For invalid inputs,
328
+** return a zero-length string. Valid inputs:
329
+**
330
+** 1 Default main prompt.
331
+** 2 Default continuation prompt.
332
+** 3 Environment variable to override main prompt ("FOSSIL_PS1")
333
+** 4 Environment variable to override continuatio ("FOSSIL_PS2")
334
+** 'A' The name of the application. (Nominally "Fossil")
335
+** 'V' Version number including patch. (ex: "2.29.1")
336
+** 'v' Version number without patch. (ex: "2.29")
327337
*/
328338
const char *sqlcmd_ps_appdef(int c){
329
- if( c=='A' ) return "Fossil";
330
- if( c=='V' ) return RELEASE_VERSION;
331
- if( c=='v' ){
332
- const char *zFull = RELEASE_VERSION;
333
- const char *zD1, *zD2;
334
- size_t i;
335
- static char zRelease[16];
336
- zD2 = strrchr(zFull,'.');
337
- zD1 = strchr(zFull,'.');
338
- if( zD2==0 || zD2==zD1 ){
339
- return zFull;
340
- }
341
- i = zD2 - zFull;
342
- if( i>sizeof(zRelease)-1 ) return zFull;
343
- memcpy(zRelease, zFull, i);
344
- zRelease[i] = 0;
345
- return zRelease;
339
+ switch( c ){
340
+ /* Default prompt strings */
341
+ case 1: return "/e[1;/x33/:36/;m/A-/v /~>/e[0m ";
342
+ case 2: return "/B/e[1;/x33/:36/;m/H>/e[0m ";
343
+
344
+ /* Names of environment variables to override cases 1 and 2 */
345
+ case 3: return "FOSSIL_PS1";
346
+ case 4: return "FOSSIL_PS2";
347
+
348
+ /* Application name */
349
+ case 'A': return "Fossil";
350
+
351
+ /* Version numbers */
352
+ case 'V': return RELEASE_VERSION;
353
+ case 'v': {
354
+ const char *zFull = RELEASE_VERSION;
355
+ const char *zD1, *zD2;
356
+ size_t i;
357
+ static char zRelease[32];
358
+ zD2 = strrchr(zFull,'.');
359
+ zD1 = strchr(zFull,'.');
360
+ if( zD2==0 || zD2==zD1 ){
361
+ return zFull;
362
+ }
363
+ i = zD2 - zFull;
364
+ if( i>sizeof(zRelease)-1 ) return zFull;
365
+ memcpy(zRelease, zFull, i);
366
+ zRelease[i] = 0;
367
+ return zRelease;
368
+ }
346369
}
347370
return "";
348371
}
349372
350373
/*
@@ -432,11 +455,10 @@
432455
** name X.
433456
*/
434457
void cmd_sqlite3(void){
435458
int noRepository;
436459
char *zConfigDb;
437
- char *zPrompt;
438460
extern int sqlite3_shell(int, char**);
439461
#ifdef FOSSIL_ENABLE_TH1_HOOKS
440462
g.fNoThHook = 1;
441463
#endif
442464
noRepository = find_option("no-repository", 0, 0)!=0;
@@ -452,19 +474,9 @@
452474
linenoiseSetMultiLine(1);
453475
#endif
454476
atexit(sqlcmd_atexit);
455477
g.zConfigDbName = zConfigDb;
456478
g.argv[1] = "--noinit";
457
- zPrompt = fossil_getenv("FOSSIL_PS1");
458
- if( zPrompt ){
459
- fossil_setenv("SQLITE_PS1",zPrompt);
460
- }else{
461
- fossil_setenv("SQLITE_PS1","/A-/V /~> ");
462
- }
463
- zPrompt = fossil_getenv("FOSSIL_PS2");
464
- if( zPrompt ){
465
- fossil_setenv("SQLITE_PS2",zPrompt);
466
- }
467479
sqlite3_shell(g.argc, g.argv);
468480
sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
469481
fossil_close(0, noRepository);
470482
}
471483
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -321,30 +321,53 @@
321 g.repositoryOpen = 0;
322 g.localOpen = 0;
323 }
324
325 /*
326 ** Return text for /A, /V, or /v prompt excapes.
 
 
 
 
 
 
 
 
 
 
327 */
328 const char *sqlcmd_ps_appdef(int c){
329 if( c=='A' ) return "Fossil";
330 if( c=='V' ) return RELEASE_VERSION;
331 if( c=='v' ){
332 const char *zFull = RELEASE_VERSION;
333 const char *zD1, *zD2;
334 size_t i;
335 static char zRelease[16];
336 zD2 = strrchr(zFull,'.');
337 zD1 = strchr(zFull,'.');
338 if( zD2==0 || zD2==zD1 ){
339 return zFull;
340 }
341 i = zD2 - zFull;
342 if( i>sizeof(zRelease)-1 ) return zFull;
343 memcpy(zRelease, zFull, i);
344 zRelease[i] = 0;
345 return zRelease;
 
 
 
 
 
 
 
 
 
 
 
 
 
346 }
347 return "";
348 }
349
350 /*
@@ -432,11 +455,10 @@
432 ** name X.
433 */
434 void cmd_sqlite3(void){
435 int noRepository;
436 char *zConfigDb;
437 char *zPrompt;
438 extern int sqlite3_shell(int, char**);
439 #ifdef FOSSIL_ENABLE_TH1_HOOKS
440 g.fNoThHook = 1;
441 #endif
442 noRepository = find_option("no-repository", 0, 0)!=0;
@@ -452,19 +474,9 @@
452 linenoiseSetMultiLine(1);
453 #endif
454 atexit(sqlcmd_atexit);
455 g.zConfigDbName = zConfigDb;
456 g.argv[1] = "--noinit";
457 zPrompt = fossil_getenv("FOSSIL_PS1");
458 if( zPrompt ){
459 fossil_setenv("SQLITE_PS1",zPrompt);
460 }else{
461 fossil_setenv("SQLITE_PS1","/A-/V /~> ");
462 }
463 zPrompt = fossil_getenv("FOSSIL_PS2");
464 if( zPrompt ){
465 fossil_setenv("SQLITE_PS2",zPrompt);
466 }
467 sqlite3_shell(g.argc, g.argv);
468 sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
469 fossil_close(0, noRepository);
470 }
471
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -321,30 +321,53 @@
321 g.repositoryOpen = 0;
322 g.localOpen = 0;
323 }
324
325 /*
326 ** This routine overrides some of the prompt generation behavior in the
327 ** SQLite shell. Always return a static string. For invalid inputs,
328 ** return a zero-length string. Valid inputs:
329 **
330 ** 1 Default main prompt.
331 ** 2 Default continuation prompt.
332 ** 3 Environment variable to override main prompt ("FOSSIL_PS1")
333 ** 4 Environment variable to override continuatio ("FOSSIL_PS2")
334 ** 'A' The name of the application. (Nominally "Fossil")
335 ** 'V' Version number including patch. (ex: "2.29.1")
336 ** 'v' Version number without patch. (ex: "2.29")
337 */
338 const char *sqlcmd_ps_appdef(int c){
339 switch( c ){
340 /* Default prompt strings */
341 case 1: return "/e[1;/x33/:36/;m/A-/v /~>/e[0m ";
342 case 2: return "/B/e[1;/x33/:36/;m/H>/e[0m ";
343
344 /* Names of environment variables to override cases 1 and 2 */
345 case 3: return "FOSSIL_PS1";
346 case 4: return "FOSSIL_PS2";
347
348 /* Application name */
349 case 'A': return "Fossil";
350
351 /* Version numbers */
352 case 'V': return RELEASE_VERSION;
353 case 'v': {
354 const char *zFull = RELEASE_VERSION;
355 const char *zD1, *zD2;
356 size_t i;
357 static char zRelease[32];
358 zD2 = strrchr(zFull,'.');
359 zD1 = strchr(zFull,'.');
360 if( zD2==0 || zD2==zD1 ){
361 return zFull;
362 }
363 i = zD2 - zFull;
364 if( i>sizeof(zRelease)-1 ) return zFull;
365 memcpy(zRelease, zFull, i);
366 zRelease[i] = 0;
367 return zRelease;
368 }
369 }
370 return "";
371 }
372
373 /*
@@ -432,11 +455,10 @@
455 ** name X.
456 */
457 void cmd_sqlite3(void){
458 int noRepository;
459 char *zConfigDb;
 
460 extern int sqlite3_shell(int, char**);
461 #ifdef FOSSIL_ENABLE_TH1_HOOKS
462 g.fNoThHook = 1;
463 #endif
464 noRepository = find_option("no-repository", 0, 0)!=0;
@@ -452,19 +474,9 @@
474 linenoiseSetMultiLine(1);
475 #endif
476 atexit(sqlcmd_atexit);
477 g.zConfigDbName = zConfigDb;
478 g.argv[1] = "--noinit";
 
 
 
 
 
 
 
 
 
 
479 sqlite3_shell(g.argc, g.argv);
480 sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
481 fossil_close(0, noRepository);
482 }
483

Keyboard Shortcuts

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