... with $SQLITE3_HISTSIZE. Positive numbers limits history size, zero - don't
write to history at all (but read existing and keep in memory), negative -
always append to history file (useful when you run few instances of sqlite3 at
time and want to save history from all).
Default - 100, same as currently hardwired.

The author or authors of this code dedicate any and all copyright interest
in this code to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and successors.
We intend this dedication to be an overt act of relinquishment in perpetuity
of all present and future rights to this code under copyright law.

Signed-off-by: Yuriy M. Kaminskiy <yum...@gmail.com>

Index: sqlite3-3.7.7/sqlite3.1
===================================================================
--- sqlite3-3.7.7.orig/sqlite3.1        2011-08-31 23:03:27.000000000 +0400
+++ sqlite3-3.7.7/sqlite3.1     2011-08-31 23:03:27.000000000 +0400
@@ -234,6 +234,14 @@ o If the -init option is present, the sp

 o All other command line options are processed.

+.SH ENVIRONMENT
+.TP
+.B $SQLITE3_HISTSIZE
+The maximum number of lines contained in the history file.
+When negative, only append new commands to the history file (useful to prevent
lossing some history when running few sqlite3 instances in parallel).
+When zero, history is not saved.
+The default value is 100.
+
 .SH SEE ALSO
 http://www.sqlite.org/
 .br
Index: sqlite3-3.7.7/src/shell.c
===================================================================
--- sqlite3-3.7.7.orig/src/shell.c      2011-08-31 23:02:39.000000000 +0400
+++ sqlite3-3.7.7/src/shell.c   2011-08-31 23:05:07.000000000 +0400
@@ -51,6 +51,9 @@
 # define read_history(X)
 # define write_history(X)
 # define stifle_history(X)
+# define append_history(X,Y)
+# define where_history() (0)
+# define using_history()
 #endif

 #if defined(_WIN32) || defined(WIN32)
@@ -2900,11 +2902,23 @@ int main(int argc, char **argv){
       }
 #if defined(HAVE_READLINE) && HAVE_READLINE==1
       if( zHistory ) read_history(zHistory);
 #endif
+      using_history(); /* initialize where_history() */
+      nHistory = where_history();
       rc = process_input(&data, 0);
       if( zHistory ){
-        stifle_history(100);
+        const char *history_size_str = getenv("SQLITE3_HISTSIZE");
+        int history_size = 100;
+        if( history_size_str!=NULL )
+          history_size = strtol(history_size_str, NULL, 0);
+        if( history_size>0 ){
+          stifle_history(history_size);
         write_history(zHistory);
+        }else if( history_size==0 ){
+          /* do nothing */
+        }else{
+          append_history(where_history()-nHistory, zHistory);
+        }
         free(zHistory);
       }
       free(zHome);


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to