From e6b4d00e3a586be753c3d457c5153380392bda32 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 19 Jun 2022 08:58:18 +0200 Subject: Merging upstream version 1.9.0. Signed-off-by: Daniel Baumann --- litecli/packages/completion_engine.py | 4 +-- litecli/packages/special/dbcommands.py | 53 ++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 20 deletions(-) (limited to 'litecli/packages') diff --git a/litecli/packages/completion_engine.py b/litecli/packages/completion_engine.py index 0397857..0e2a30f 100644 --- a/litecli/packages/completion_engine.py +++ b/litecli/packages/completion_engine.py @@ -105,14 +105,14 @@ def suggest_special(text): if cmd in ["\\f", "\\fs", "\\fd"]: return [{"type": "favoritequery"}] - if cmd in ["\\d", "\\dt", "\\dt+", ".schema"]: + if cmd in ["\\d", "\\dt", "\\dt+", ".schema", ".indexes"]: return [ {"type": "table", "schema": []}, {"type": "view", "schema": []}, {"type": "schema"}, ] - if cmd in ["\\.", "source", ".open"]: + if cmd in ["\\.", "source", ".open", ".read"]: return [{"type": "file_name"}] if cmd in [".import"]: diff --git a/litecli/packages/special/dbcommands.py b/litecli/packages/special/dbcommands.py index a7eaa0c..203e1a8 100644 --- a/litecli/packages/special/dbcommands.py +++ b/litecli/packages/special/dbcommands.py @@ -110,6 +110,41 @@ def list_databases(cur, **_): return [(None, None, None, "")] +@special_command( + ".indexes", + ".indexes [tablename]", + "List indexes.", + arg_type=PARSED_QUERY, + case_sensitive=True, + aliases=("\\di",), +) +def list_indexes(cur, arg=None, arg_type=PARSED_QUERY, verbose=False): + if arg: + args = ("{0}%".format(arg),) + query = """ + SELECT name FROM sqlite_master + WHERE type = 'index' AND tbl_name LIKE ? AND name NOT LIKE 'sqlite_%' + ORDER BY 1 + """ + else: + args = tuple() + query = """ + SELECT name FROM sqlite_master + WHERE type = 'index' AND name NOT LIKE 'sqlite_%' + ORDER BY 1 + """ + + log.debug(query) + cur.execute(query, args) + indexes = cur.fetchall() + status = "" + if cur.description: + headers = [x[0] for x in cur.description] + else: + return [(None, None, None, "")] + return [(None, indexes, headers, status)] + + @special_command( ".status", "\\s", @@ -202,24 +237,6 @@ def describe(cur, arg, **_): return [(None, tables, headers, status)] -@special_command( - ".read", - ".read path", - "Read input from path", - arg_type=PARSED_QUERY, - case_sensitive=True, -) -def read_script(cur, arg, **_): - args = shlex.split(arg) - if len(args) != 1: - raise TypeError(".read accepts exactly one path") - path = args[0] - with open(path, "r") as f: - script = f.read() - cur.executescript(script) - return [(None, None, None, "")] - - @special_command( ".import", ".import filename table", -- cgit v1.2.3