summaryrefslogtreecommitdiffstats
path: root/litecli/packages/special
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-10 10:18:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-10 10:18:47 +0000
commitf969bdef4f3403e22b0a7bf84d0d4e86c2428a77 (patch)
treec7ee1703b3aec5e43412c64fee1fea665c6b3086 /litecli/packages/special
parentReleasing debian version 1.9.0-3. (diff)
downloadlitecli-f969bdef4f3403e22b0a7bf84d0d4e86c2428a77.tar.xz
litecli-f969bdef4f3403e22b0a7bf84d0d4e86c2428a77.zip
Merging upstream version 1.10.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'litecli/packages/special')
-rw-r--r--litecli/packages/special/dbcommands.py5
-rw-r--r--litecli/packages/special/favoritequeries.py1
-rw-r--r--litecli/packages/special/iocommands.py41
-rw-r--r--litecli/packages/special/utils.py83
4 files changed, 107 insertions, 23 deletions
diff --git a/litecli/packages/special/dbcommands.py b/litecli/packages/special/dbcommands.py
index 203e1a8..dec3507 100644
--- a/litecli/packages/special/dbcommands.py
+++ b/litecli/packages/special/dbcommands.py
@@ -69,13 +69,14 @@ def show_schema(cur, arg=None, **_):
args = (arg,)
query = """
SELECT sql FROM sqlite_master
- WHERE name==?
+ WHERE name==? AND sql IS NOT NULL
ORDER BY tbl_name, type DESC, name
"""
else:
args = tuple()
query = """
SELECT sql FROM sqlite_master
+ WHERE sql IS NOT NULL
ORDER BY tbl_name, type DESC, name
"""
@@ -212,7 +213,7 @@ def load_extension(cur, arg, **_):
"Description of a table",
arg_type=PARSED_QUERY,
case_sensitive=True,
- aliases=("\\d", "describe", "desc"),
+ aliases=("\\d", "desc"),
)
def describe(cur, arg, **_):
if arg:
diff --git a/litecli/packages/special/favoritequeries.py b/litecli/packages/special/favoritequeries.py
index 7da6fbf..8eab521 100644
--- a/litecli/packages/special/favoritequeries.py
+++ b/litecli/packages/special/favoritequeries.py
@@ -3,7 +3,6 @@ from __future__ import unicode_literals
class FavoriteQueries(object):
-
section_name = "favorite_queries"
usage = """
diff --git a/litecli/packages/special/iocommands.py b/litecli/packages/special/iocommands.py
index 43c3577..ee254f0 100644
--- a/litecli/packages/special/iocommands.py
+++ b/litecli/packages/special/iocommands.py
@@ -21,7 +21,7 @@ from litecli.packages.prompt_utils import confirm_destructive_query
use_expanded_output = False
PAGER_ENABLED = True
tee_file = None
-once_file = written_to_once_file = None
+once_file = once_file_args = written_to_once_file = None
favoritequeries = FavoriteQueries(ConfigObj())
@@ -286,7 +286,7 @@ def delete_favorite_query(arg, **_):
return [(None, None, None, status)]
-@special_command("system", "system [command]", "Execute a system shell commmand.")
+@special_command("system", "system [command]", "Execute a system shell command.")
def execute_system_command(arg, **_):
"""Execute a system shell command."""
usage = "Syntax: system [command].\n"
@@ -377,9 +377,9 @@ def write_tee(output):
aliases=("\\o", "\\once"),
)
def set_once(arg, **_):
- global once_file
+ global once_file_args
- once_file = parseargfile(arg)
+ once_file_args = parseargfile(arg)
return [(None, None, None, "")]
@@ -387,27 +387,28 @@ def set_once(arg, **_):
@export
def write_once(output):
global once_file, written_to_once_file
- if output and once_file:
- try:
- f = open(**once_file)
- except (IOError, OSError) as e:
- once_file = None
- raise OSError(
- "Cannot write to file '{}': {}".format(e.filename, e.strerror)
- )
-
- with f:
- click.echo(output, file=f, nl=False)
- click.echo("\n", file=f, nl=False)
+ if output and once_file_args:
+ if once_file is None:
+ try:
+ once_file = open(**once_file_args)
+ except (IOError, OSError) as e:
+ once_file = None
+ raise OSError(
+ "Cannot write to file '{}': {}".format(e.filename, e.strerror)
+ )
+
+ click.echo(output, file=once_file, nl=False)
+ click.echo("\n", file=once_file, nl=False)
written_to_once_file = True
@export
def unset_once_if_written():
"""Unset the once file, if it has been written to."""
- global once_file
- if written_to_once_file:
- once_file = None
+ global once_file, once_file_args, written_to_once_file
+ if once_file and written_to_once_file:
+ once_file.close()
+ once_file = once_file_args = written_to_once_file = None
@special_command(
@@ -461,7 +462,7 @@ def watch_query(arg, **kwargs):
# Somewhere in the code the pager its activated after every yield,
# so we disable it in every iteration
set_pager_enabled(False)
- for (sql, title) in sql_list:
+ for sql, title in sql_list:
cur.execute(sql)
if cur.description:
headers = [x[0] for x in cur.description]
diff --git a/litecli/packages/special/utils.py b/litecli/packages/special/utils.py
index eed9306..4d3ad91 100644
--- a/litecli/packages/special/utils.py
+++ b/litecli/packages/special/utils.py
@@ -46,3 +46,86 @@ def format_uptime(uptime_in_seconds):
uptime = " ".join(uptime_values)
return uptime
+
+
+def check_if_sqlitedotcommand(command):
+ """Does a check if the command supplied is in the list of SQLite dot commands.
+
+ :param command: A command (str) supplied from the user
+ :returns: True/False
+ """
+
+ sqlite3dotcommands = [
+ ".archive",
+ ".auth",
+ ".backup",
+ ".bail",
+ ".binary",
+ ".cd",
+ ".changes",
+ ".check",
+ ".clone",
+ ".connection",
+ ".databases",
+ ".dbconfig",
+ ".dbinfo",
+ ".dump",
+ ".echo",
+ ".eqp",
+ ".excel",
+ ".exit",
+ ".expert",
+ ".explain",
+ ".filectrl",
+ ".fullschema",
+ ".headers",
+ ".help",
+ ".import",
+ ".imposter",
+ ".indexes",
+ ".limit",
+ ".lint",
+ ".load",
+ ".log",
+ ".mode",
+ ".nonce",
+ ".nullvalue",
+ ".once",
+ ".open",
+ ".output",
+ ".parameter",
+ ".print",
+ ".progress",
+ ".prompt",
+ ".quit",
+ ".read",
+ ".recover",
+ ".restore",
+ ".save",
+ ".scanstats",
+ ".schema",
+ ".selftest",
+ ".separator",
+ ".session",
+ ".sha3sum",
+ ".shell",
+ ".show",
+ ".stats",
+ ".system",
+ ".tables",
+ ".testcase",
+ ".testctrl",
+ ".timeout",
+ ".timer",
+ ".trace",
+ ".vfsinfo",
+ ".vfslist",
+ ".vfsname",
+ ".width",
+ ]
+
+ if isinstance(command, str):
+ command = command.split(" ", 1)[0].lower()
+ return command in sqlite3dotcommands
+ else:
+ return False