summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2023-10-03 10:02:11 -0700
committerGitHub <noreply@github.com>2023-10-03 10:02:11 -0700
commitf5bf97a82fc9b60acedb894281329fcfbeeb9f25 (patch)
treee1a47a443a4568cb635aae451a1f6c47c3986fc8
parente18bdb2b2222881d5367aace7f51513d30c05c53 (diff)
parenta9f4b27e8d8bef03a77bbf7cddbd6deb0a7e9531 (diff)
Merge branch 'main' into fix_once
-rw-r--r--CHANGELOG.md3
-rw-r--r--litecli/main.py20
-rw-r--r--litecli/sqlexecute.py18
3 files changed, 7 insertions, 34 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 535f7de..81d0ba2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,9 @@
naming.
* Fixed `.once -o <file>` by opening the output file once per statement instead
of for every line of output ([#148](https://github.com/dbcli/litecli/issues/148)).
+* Use the sqlite3 API to cancel a running query on interrupt
+ ([#164](https://github.com/dbcli/litecli/issues/164)).
+
## 1.9.0 - 2022-06-06
diff --git a/litecli/main.py b/litecli/main.py
index e532d9d..e608da7 100644
--- a/litecli/main.py
+++ b/litecli/main.py
@@ -490,29 +490,17 @@ class LiteCli(object):
except EOFError as e:
raise e
except KeyboardInterrupt:
- # get last connection id
- connection_id_to_kill = sqlexecute.connection_id
- logger.debug("connection id to kill: %r", connection_id_to_kill)
- # Restart connection to the database
- sqlexecute.connect()
try:
- for title, cur, headers, status in sqlexecute.run(
- "kill %s" % connection_id_to_kill
- ):
- status_str = str(status).lower()
- if status_str.find("ok") > -1:
- logger.debug(
- "cancelled query, connection id: %r, sql: %r",
- connection_id_to_kill,
- text,
- )
- self.echo("cancelled query", err=True, fg="red")
+ sqlexecute.conn.interrupt()
except Exception as e:
self.echo(
"Encountered error while cancelling query: {}".format(e),
err=True,
fg="red",
)
+ else:
+ logger.debug("cancelled query")
+ self.echo("cancelled query", err=True, fg="red")
except NotImplementedError:
self.echo("Not Yet Implemented.", fg="yellow")
except OperationalError as e:
diff --git a/litecli/sqlexecute.py b/litecli/sqlexecute.py
index 5d00277..2392472 100644
--- a/litecli/sqlexecute.py
+++ b/litecli/sqlexecute.py
@@ -1,6 +1,5 @@
import logging
import sqlite3
-import uuid
from contextlib import closing
from sqlite3 import OperationalError
from litecli.packages.special.utils import check_if_sqlitedotcommand
@@ -51,7 +50,6 @@ class SQLExecute(object):
def __init__(self, database):
self.dbname = database
self._server_type = None
- self.connection_id = None
self.conn = None
if not database:
_logger.debug("Database is not specified. Skip connection.")
@@ -76,8 +74,6 @@ class SQLExecute(object):
# Update them after the connection is made to ensure that it was a
# successful connection.
self.dbname = db
- # retrieve connection id
- self.reset_connection_id()
def run(self, statement):
"""Execute the sql in the database and return the results. The results
@@ -207,17 +203,3 @@ class SQLExecute(object):
def server_type(self):
self._server_type = ("sqlite3", "3")
return self._server_type
-
- def get_connection_id(self):
- if not self.connection_id:
- self.reset_connection_id()
- return self.connection_id
-
- def reset_connection_id(self):
- # Remember current connection id
- _logger.debug("Get current connection id")
- # res = self.run('select connection_id()')
- self.connection_id = uuid.uuid4()
- # for title, cur, headers, status in res:
- # self.connection_id = cur.fetchone()[0]
- _logger.debug("Current connection id: %s", self.connection_id)