Skip to content

Commit 8e57e84

Browse files
authored
Merge pull request #205 from dbcli/check-db-connection
Check for a DB connection before running an LLM query.
2 parents fb981ba + 6155cf3 commit 8e57e84

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
## TBD
1+
## 1.14.3 - 2025-01-29
22

33
### Bug Fixes
44

55
* Fix [misleading "0 rows affected" status for CTEs](https://github.com/dbcli/litecli/issues/203)
66
by never displaying rows affected when the connector tells us -1
7+
* Show an error message when `\llm "question"` is invoked without a database connection.
78

89
## 1.14.2 - 2025-01-26
910

litecli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def one_iteration(text=None):
444444
if special.is_llm_command(text):
445445
try:
446446
start = time()
447-
cur = self.sqlexecute.conn.cursor()
447+
cur = self.sqlexecute.conn and self.sqlexecute.conn.cursor()
448448
context, sql = special.handle_llm(text, cur)
449449
if context:
450450
click.echo(context)

litecli/packages/special/llm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ def is_llm_command(command) -> bool:
285285

286286
@export
287287
def sql_using_llm(cur, question=None, verbose=False) -> Tuple[str, Optional[str]]:
288+
if cur is None:
289+
raise RuntimeError("Connect to a datbase and try again.")
288290
schema_query = """
289291
SELECT sql FROM sqlite_master
290292
WHERE sql IS NOT NULL

0 commit comments

Comments
 (0)