]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
The \H escape on a prompt string fills in with the characters needed
authordrh <>
Fri, 10 Apr 2026 19:33:15 +0000 (19:33 +0000)
committerdrh <>
Fri, 10 Apr 2026 19:33:15 +0000 (19:33 +0000)
to make the input "complete".  Add the shell_expand_prompt() SQL function
for testing purposes.

FossilOrigin-Name: 6aafb76c74b73aafef74250dae9c8cbe73226c0efb606e8f80ea761b3293cf9d

manifest
manifest.uuid
src/shell.c.in

index b46c2bb89352d0e344bf303d2181dba48825a8b0..e1b85d02e760223fd6ea245b6bfb10c448dc4735 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\strunk\sfixes\sand\senhancements\sinto\sthe\scli-prompt-redo\sbranch
-D 2026-04-10T18:53:13.643
+C The\s&#92;H\sescape\son\sa\sprompt\sstring\sfills\sin\swith\sthe\scharacters\sneeded\nto\smake\sthe\sinput\s"complete".\s\sAdd\sthe\sshell_expand_prompt()\sSQL\sfunction\nfor\stesting\spurposes.
+D 2026-04-10T19:33:15.316
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -735,7 +735,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 928ff887f2a7c64275182060d94d06fdddbe32226c569781cf7e7edc6f58d7fd
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c ffe199f025a0dd74670d2a77232bdea364a4d7b36f32c64a6572d39ba6a11576
-F src/shell.c.in e4093ccf2a9189ec34db7a34f011c6ecb9ec3721981526eb214bdf08ac2a590e
+F src/shell.c.in d94e528d5a6ad833228197794d9d6473d51902cc91a37baef0984574650e3896
 F src/sqlite.h.in a5605faa9479bbaac16c4ab43eb09ff50632004a8e05084d3fde56063ef73766
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 1b7a0ee438bb5c2896d0609c537e917d8057b3340f6ad004d2de44f03e3d3cca
@@ -2197,8 +2197,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P a698fbfb8bb256ee0d9802c01562c11492ca2800a45360b268ac6cf397a7fad7 6ab6f622be3e1ad93166d139b5fccf9628c86d1c14c6dfb4464cb8cf52c94785
-R 4d2bbb27b149398ceae03cca09977cdc
+P f3354ebf51e684ef680986bef9b606f63786c254f1c8774bcaf7a7f3d0d37056
+R eb9717568ba2a51cead72c45c6debdf8
 U drh
-Z 0e5a6f70160f3c705711d8f141e5cb21
+Z 98b23073eb30db46d4e741688a728681
 # Remove this line to create a well-formed Fossil manifest.
index 8ccff5afc768e6d33422150cc0707b207dbdbc31..8b5506f1022fe4de74123b9a9125a1c40ed46f4a 100644 (file)
@@ -1 +1 @@
-f3354ebf51e684ef680986bef9b606f63786c254f1c8774bcaf7a7f3d0d37056
+6aafb76c74b73aafef74250dae9c8cbe73226c0efb606e8f80ea761b3293cf9d
index 1b5db0768d0987189ace3515ec69ef58990241c8..7c3f75b1c3ac84b015e3855aae435387d63de7d7 100644 (file)
@@ -1040,6 +1040,38 @@ static char *expand_prompt(
       continue;
     }
 
+    if( c=='H' ){
+      /* \H becomes text needed to terminate current input */
+      if( onoff ){
+        sqlite3_int64 R = zPrior ? sqlite3_incomplete(zPrior) : 0;
+        int c = (R>>16)&0xff;
+        int nParen = R>>32;
+        int eSemi = (R>>8)&0xff;
+        if( c==0 ){
+          /* no-op */
+        }else if( c=='-' ){
+          sqlite3_str_append(pOut,"\\n",3);
+        }else if( c=='/' ){
+          sqlite3_str_append(pOut,"*/",2);
+        }else{
+          sqlite3_str_appendchar(pOut, 1, c);
+        }
+        if( nParen>0 ){
+          sqlite3_str_appendf(pOut, "%.*c",nParen,')');
+        }
+        if( eSemi==1 ){
+          sqlite3_str_append(pOut, ";", 1);
+        }else if( eSemi==2 ){
+          sqlite3_str_append(pOut, "END;", 4);
+        }else if( eSemi==3 ){
+          sqlite3_str_append(pOut, ";END;", 5);
+        }
+      }
+      zPrompt += 2;
+      i = -1;
+      continue;
+    }
+
     /* No match to a known escape.  Generate an error. */
     if( onoff ) sqlite3_str_appendf(pOut,"UNKNOWN(\"\\%c\")",c);
     zPrompt += 2;
@@ -1416,6 +1448,23 @@ static void shellAddSchemaName(
   sqlite3_result_value(pCtx, apVal[0]);
 }
 
+/*
+** SQL function:  shell_expand_prompt(PROMPT,PRIOR)
+**
+** Invoke the internal expand_prompt() function, for testing purposes.
+*/
+static void shellExpandPrompt(
+  sqlite3_context *pCtx,
+  int nVal,
+  sqlite3_value **apVal
+){
+  const char *zPrompt = (const char*)sqlite3_value_text(apVal[0]);
+  const char *zPrior = nVal>=2 ? (const char*)sqlite3_value_text(apVal[1]) : 0;
+  ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
+  char *zRes = expand_prompt(p, zPrior, zPrompt);
+  sqlite3_result_text(pCtx, zRes, -1, SQLITE_TRANSIENT);
+  sqlite3_free(zRes);
+}
 
 /************************* BEGIN PERFORMANCE TIMER *****************************/
 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
@@ -4638,6 +4687,11 @@ static void open_db(ShellState *p, int openFlags){
     sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
                             editFunc, 0, 0);
 #endif
+    sqlite3_create_function(p->db, "shell_expand_prompt", 1, SQLITE_UTF8,
+                            p, shellExpandPrompt, 0, 0);
+    sqlite3_create_function(p->db, "shell_expand_prompt", 2, SQLITE_UTF8,
+                            p, shellExpandPrompt, 0, 0);
+
 
     if( p->openMode==SHELL_OPEN_ZIPFILE ){
       char *zSql = sqlite3_mprintf(