]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Initial implementation of a highly experimental interface for listing all
authordrh <drh@noemail.net>
Thu, 6 Jul 2017 17:36:30 +0000 (17:36 +0000)
committerdrh <drh@noemail.net>
Thu, 6 Jul 2017 17:36:30 +0000 (17:36 +0000)
keywords and symbolic names for an SQLite database connection.

FossilOrigin-Name: 04ef6783a56d87ef7ddc8c58f899d2dd3f5d9c95ac435246e92a670c1eb861e9

manifest
manifest.uuid
src/sqlite.h.in
src/tclsqlite.c
src/tokenize.c

index a6685636f43d433233e0a4f11bf811a64b6648ca..af8ac4f55592c97e0447f9d570efc9b418e28711 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Change\sthe\s(machine-generated)\skeywordhash.h\sfile\sto\sincrease\sthe\sscope\sof\sthe\ntables\sused\sfor\skeyword\smatching,\sso\sthat\sthe\stables\sare\saccessible\sto\nfunctions\sother\sthen\skeywordCode().
-D 2017-07-06T16:33:14.765
+C Initial\simplementation\sof\sa\shighly\sexperimental\sinterface\sfor\slisting\sall\nkeywords\sand\ssymbolic\snames\sfor\san\sSQLite\sdatabase\sconnection.
+D 2017-07-06T17:36:30.817
 F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 4ebb1d257cac7fb1bcb4ba59278416d410ff1c4bf59447a9c37a415f3516056a
@@ -450,14 +450,14 @@ F src/resolve.c d1e69759e7a79c156c692793f5d16f82f9a60ce5e82efd95e4374b2423034946
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
 F src/select.c c9f7b7196e196e93979665680d055a789938b8e025556097bf484b184c0dd576
 F src/shell.c a2b148e4ca8eb81b96e1050207c83d4a16ea6bf9182374faee4dd2a43628c291
-F src/sqlite.h.in 651cba56f8df64ff4418aa981cdfd5bc2d65e5fef95c1671f9826f1a164a5fa3
+F src/sqlite.h.in 35afb0f728107946d24cd19079893b6abdc50c66e2776f6a7e1b8a740fb1517a
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 58fd0676d3111d02e62e5a35992a7d3da5d3f88753acc174f2d37b774fbbdd28
 F src/sqliteInt.h 7a7cd6f682471cce4afe64216f71fd64c622712aeb9d947c33c38337a7cf19a9
 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
 F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1
 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
-F src/tclsqlite.c 2c29b0b76e91edfd1b43bf135c32c8674710089197327682b6b7e6af88062c3d
+F src/tclsqlite.c c18cf90f93f5ba6d2f9ed90d072bf25b973f490e1c16b3f79d9d6f2db00aa80e
 F src/test1.c 1c0726cdf7389ed053a9b9aa0dc3c63f3b9bbc607a25decae6549682008510b3
 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b
@@ -508,7 +508,7 @@ F src/test_windirent.c 17f91f5f2aa1bb7328abb49414c363b5d2a9d3ff
 F src/test_windirent.h 5d67483a55442e31e1bde0f4a230e6e932ad5906
 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
-F src/tokenize.c 1003d6d90c6783206c711f0a9397656fa5b055209f4d092caa43bb3bf5215db5
+F src/tokenize.c 939ad705dcd99a934921e7467e255f46b8d8005594212fc257cde4041d1d52a8
 F src/treeview.c 6cf8d7fe9e63fae57dad1bb57f6615e14eac0c527e43d868e805042cae8ed1f7
 F src/trigger.c d1cae560bfacc8bfb3a072d73658245c1714c0389097da69b4cb23877a082d7e
 F src/update.c c443935c652af9365e033f756550b5032d02e1b06eb2cb890ed7511ae0c051dc
@@ -1628,7 +1628,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P efb4aab0caa4145732a5438cc2a193bc12c455b4007220564d240e75900ea8ad
-R 77ecc187246c1c337a58790c9818d2e8
+P c5ed5ebdf660501fde7cc8aefaaaeae2a68e5899a64ac93f26684842a235281d
+R bb0af586f209e5b11ed2ecdf0681df64
+T *branch * experimental-namelist
+T *sym-experimental-namelist *
+T -sym-trunk *
 U drh
-Z a448086e00aa693e2477a7bd0d12a0df
+Z 3279b6448dfe0804da535abc64fe9bce
index eed343f04b88f097ed91ee6e642cd3e5217a5d84..bed8d2a51148720e685d3d5fbd4e67ac06e3d48a 100644 (file)
@@ -1 +1 @@
-c5ed5ebdf660501fde7cc8aefaaaeae2a68e5899a64ac93f26684842a235281d
\ No newline at end of file
+04ef6783a56d87ef7ddc8c58f899d2dd3f5d9c95ac435246e92a670c1eb861e9
\ No newline at end of file
index a29ec7bc5af646969d8e3f7e62f968f52beb791f..f1c32d02fdf4f117481980b4594a84ec1563bc07 100644 (file)
@@ -8469,6 +8469,48 @@ int sqlite3_preupdate_depth(sqlite3 *);
 int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 #endif
 
+/*
+** CAPI3REF: List Of Symbolic Names
+**
+** ^The sqlite3_namelist(D,P,F) interface returns a list of symbolic names
+** and keywords that might appear in valid SQL statements for [connection]
+** D and that all begin with the prefix P.  ^The F parameter is a bitmask
+** that determines the kinds of symbolic names and keywords that are found
+** in the list.  ^Matching against the prefix P is performed using
+** [sqlite3_strnicmp()] and is thus case insensitive for ASCII characters.
+**
+** ^The value returned by sqlite3_namelist() is stored in memory obtained
+** from [sqlite3_malloc()] and must be released by the caller using
+** [sqlite3_free()].  ^The sqlite3_namelist() interface returns NULL if a
+** memory allocation error occurs.
+**
+** ^Elements of the list are in no particular order and may include duplicates.
+** ^Each element is separated from the next by a single 0x00 byte.  ^The list
+** is terminated by a single zero-length entry.
+**
+** This interface is intended to facilitate tab-completion for interactive
+** interfaces for SQLite.
+*/
+char *sqlite3_namelist(sqlite3 *db, const char *zPrefix, int typeMask);
+
+/*
+** CAPI3REF: Symbolic Name Typemask Values
+**
+** ^These bitmask values are used to determine the kinds of symbolic names
+** and keywords that are returned by [sqlite3_namelist()].  The third
+** parameter to [sqlite3_namelist()] should be an OR-ed combination of
+** one or more of the following value.
+*/
+#define SQLITE_NAMETYPE_KEYWORD    0x0001
+#define SQLITE_NAMETYPE_SCHEMA     0x0002
+#define SQLITE_NAMETYPE_TABLE      0x0004
+#define SQLITE_NAMETYPE_INDEX      0x0008
+#define SQLITE_NAMETYPE_TRIGGER    0x0010
+#define SQLITE_NAMETYPE_FUNCTION   0x0020
+#define SQLITE_NAMETYPE_MODULE     0x0040
+#define SQLITE_NAMETYPE_COLLATION  0x0080
+#define SQLITE_NAMETYPE_COLUMN     0x0100
+
 /*
 ** CAPI3REF: Low-level system error code
 **
index 341d3f0dc49774651a337db9d0f750251cab48c7..35c991b2797ec01de65a0834c094552877f5378b 100644 (file)
@@ -1850,14 +1850,13 @@ static int SQLITE_TCLAPI DbObjCmd(
     "complete",           "copy",              "enable_load_extension",
     "errorcode",          "eval",              "exists",
     "function",           "incrblob",          "interrupt",
-    "last_insert_rowid",  "nullvalue",         "onecolumn",
-    "preupdate",          "profile",           "progress",
-    "rekey",              "restore",           "rollback_hook",
-    "status",             "timeout",           "total_changes",
-    "trace",              "trace_v2",          "transaction",
-    "unlock_notify",      "update_hook",       "version",
-    "wal_hook",
-    0
+    "last_insert_rowid",  "namelist",          "nullvalue",
+    "onecolumn",          "preupdate",         "profile",
+    "progress",           "rekey",             "restore",
+    "rollback_hook",      "status",            "timeout",
+    "total_changes",      "trace",             "trace_v2",
+    "transaction",        "unlock_notify",     "update_hook",
+    "version",            "wal_hook",          0
   };
   enum DB_enum {
     DB_AUTHORIZER,        DB_BACKUP,           DB_BUSY,
@@ -1866,13 +1865,13 @@ static int SQLITE_TCLAPI DbObjCmd(
     DB_COMPLETE,          DB_COPY,             DB_ENABLE_LOAD_EXTENSION,
     DB_ERRORCODE,         DB_EVAL,             DB_EXISTS,
     DB_FUNCTION,          DB_INCRBLOB,         DB_INTERRUPT,
-    DB_LAST_INSERT_ROWID, DB_NULLVALUE,        DB_ONECOLUMN,
-    DB_PREUPDATE,         DB_PROFILE,          DB_PROGRESS,
-    DB_REKEY,             DB_RESTORE,          DB_ROLLBACK_HOOK,
-    DB_STATUS,            DB_TIMEOUT,          DB_TOTAL_CHANGES,
-    DB_TRACE,             DB_TRACE_V2,         DB_TRANSACTION,
-    DB_UNLOCK_NOTIFY,     DB_UPDATE_HOOK,      DB_VERSION,
-    DB_WAL_HOOK,
+    DB_LAST_INSERT_ROWID, DB_NAMELIST,         DB_NULLVALUE,
+    DB_ONECOLUMN,         DB_PREUPDATE,        DB_PROFILE,
+    DB_PROGRESS,          DB_REKEY,            DB_RESTORE,
+    DB_ROLLBACK_HOOK,     DB_STATUS,           DB_TIMEOUT,
+    DB_TOTAL_CHANGES,     DB_TRACE,            DB_TRACE_V2,
+    DB_TRANSACTION,       DB_UNLOCK_NOTIFY,    DB_UPDATE_HOOK,
+    DB_VERSION,           DB_WAL_HOOK,         
   };
   /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
 
@@ -2665,6 +2664,33 @@ static int SQLITE_TCLAPI DbObjCmd(
     break;
   }
 
+  /*
+  **     $db namelist PREFIX MASK
+  */
+  case DB_NAMELIST: {
+    const char *zPrefix;
+    int mask;
+    char *zList;
+    if( objc!=4 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "PREFIX MASK");
+      return TCL_ERROR;
+    }
+    zPrefix = Tcl_GetString(objv[2]);
+    if( Tcl_GetIntFromObj(interp, objv[3], &mask) ) return TCL_ERROR;
+    zList = sqlite3_namelist(pDb->db, zPrefix, mask);
+    if( zList ){
+      Tcl_Obj *pList = Tcl_NewObj();
+      int i, n;
+      for(i=0; zList[i]; i += n+1){
+        n = (int)strlen(&zList[i]);
+        Tcl_ListObjAppendElement(interp, pList, Tcl_NewStringObj(&zList[i],-1));
+      }
+      sqlite3_free(zList);
+      Tcl_SetObjResult(interp, pList);
+    }
+    break;
+  }
+
   /*
   **     $db nullvalue ?STRING?
   **
index 2aab334ae968e9b6a3c6bc450fddb4abe3994b60..9521e9ea842f54ed17bbb8284ad0d69d38029db4 100644 (file)
@@ -614,3 +614,52 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
   assert( nErr==0 || pParse->rc!=SQLITE_OK );
   return nErr;
 }
+
+/* An instance of the following object is used to accumulate a list
+** of names for the sqlite3_namelist() interface
+*/
+struct NameAccum {
+  StrAccum x;              /* Name list string stored here */
+  const char *zPrefix;     /* All names must start with this prefix */
+  int nPrefix;             /* Size of the prefix in bytes */
+};
+
+/*
+** Examine zName to see if it belongs on the list (if it has a matching
+** prefix) and add it to the list if it belongs.  nName is the length
+** of the name in bytes, or -1 if zName is zero-terminated.
+*/
+static void addName(struct NameAccum *p, const char *zName, int nName){
+  if( nName<0 ) nName = sqlite3Strlen30(zName);
+  if( nName<p->nPrefix ) return;
+  if( sqlite3StrNICmp(p->zPrefix, zName, p->nPrefix)!=0 ) return;
+  sqlite3StrAccumAppend(&p->x, zName, nName);
+  sqlite3StrAccumAppend(&p->x, "", 1);
+}
+
+/*
+** Return a list of text words or identifiers that might appear in an
+** SQL statement.  The typeMask parameter is a bitmask that determines
+** specifically what kinds of names should be returned.  All names
+** returned must begin with zPrefix.
+**
+** The returned list is from a single memory allocation.  The caller owns
+** the allocation and should release it using sqlite3_free() when it has
+** finished using the list.
+**
+** Each word is separated from the next by a single 0x00 byte.  The list
+** is terminated by two 0x00 bytes in a row.
+*/
+char *sqlite3_namelist(sqlite3 *db, const char *zPrefix, int typeMask){
+  struct NameAccum x;
+  int i;
+  x.zPrefix = zPrefix;
+  x.nPrefix = sqlite3Strlen30(zPrefix);
+  sqlite3StrAccumInit(&x.x, 0, 0, 0, 100000000);
+  if( typeMask & SQLITE_NAMETYPE_KEYWORD ){
+    for(i=0; i<ArraySize(aKWOffset); i++){
+      addName(&x, zKWText + aKWOffset[i], aKWLen[i]);
+    }
+  }
+  return sqlite3StrAccumFinish(&x.x);
+}