diff --git a/CHANGELOG.md b/CHANGELOG.md index 328261f..8d079b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 1.14.4 - 2025-01-31 + +### Bug Fixes + +* Fix the usage instructions in the `\llm` command. + +## 1.14.3 - 2025-01-29 + +### Bug Fixes + +* Fix [misleading "0 rows affected" status for CTEs](https://github.com/dbcli/litecli/issues/203) + by never displaying rows affected when the connector tells us -1 +* Show an error message when `\llm "question"` is invoked without a database connection. + ## 1.14.2 - 2025-01-26 ### Bug Fixes diff --git a/litecli/main.py b/litecli/main.py index 7e5a817..1f3f442 100644 --- a/litecli/main.py +++ b/litecli/main.py @@ -444,7 +444,7 @@ class LiteCli(object): if special.is_llm_command(text): try: start = time() - cur = self.sqlexecute.conn.cursor() + cur = self.sqlexecute.conn and self.sqlexecute.conn.cursor() context, sql = special.handle_llm(text, cur) if context: click.echo(context) diff --git a/litecli/packages/special/llm.py b/litecli/packages/special/llm.py index 69375d7..ff02bd5 100644 --- a/litecli/packages/special/llm.py +++ b/litecli/packages/special/llm.py @@ -138,14 +138,14 @@ qwq > \\llm models default llama3 # Set api key (not required for local models) -> \\llm keys set openai sg-1234 -API key set for openai. +> \\llm keys set openai + # Install a model plugin > \\llm install llm-ollama llm-ollama installed. -# Models directory +# Plugins directory # https://llm.datasette.io/en/stable/plugins/directory.html """ @@ -285,6 +285,8 @@ def is_llm_command(command) -> bool: @export def sql_using_llm(cur, question=None, verbose=False) -> Tuple[str, Optional[str]]: + if cur is None: + raise RuntimeError("Connect to a datbase and try again.") schema_query = """ SELECT sql FROM sqlite_master WHERE sql IS NOT NULL diff --git a/litecli/sqlexecute.py b/litecli/sqlexecute.py index 4f88764..2c4813e 100644 --- a/litecli/sqlexecute.py +++ b/litecli/sqlexecute.py @@ -138,16 +138,19 @@ class SQLExecute(object): # e.g. SELECT. if cursor.description is not None: headers = [x[0] for x in cursor.description] - status = "{0} row{1} in set" + status = "{count} row{s} in set" cursor = list(cursor) rowcount = len(cursor) else: _logger.debug("No rows in result.") - status = "Query OK, {0} row{1} affected" - rowcount = 0 if cursor.rowcount == -1 else cursor.rowcount + if cursor.rowcount == -1: + status = "Query OK" + else: + status = "Query OK, {count} row{s} affected" + rowcount = cursor.rowcount cursor = None - status = status.format(rowcount, "" if rowcount == 1 else "s") + status = status.format(count=rowcount, s="" if rowcount == 1 else "s") return (title, cursor, headers, status)