From 80a3fa7fd45965d88f175dc794b930b2f961d3f9 Mon Sep 17 00:00:00 2001 From: Nick Hale <4175918+njhale@users.noreply.github.com> Date: Mon, 10 Feb 2025 15:53:44 -0500 Subject: [PATCH] fix: always return database table columns (#429) When there are no rows in a table, the `list_database_table_rows` tool doesn't return table column names. To fix this, use an explicit query to fetch the table columns instead of relying on sqlite3's `-header` option. Addresses https://github.com/obot-platform/obot/issues/1702 Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com> --- database/pkg/cmd/rows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/pkg/cmd/rows.go b/database/pkg/cmd/rows.go index 524a81ae..3227b213 100644 --- a/database/pkg/cmd/rows.go +++ b/database/pkg/cmd/rows.go @@ -20,10 +20,10 @@ func ListDatabaseTableRows(ctx context.Context, dbFile *os.File, table string) ( } // Build the query to fetch all rows from the table - query := fmt.Sprintf("SELECT * FROM %q;", table) + query := fmt.Sprintf("SELECT group_concat(name, '|') FROM pragma_table_info(%q); SELECT * FROM %q;", table, table) // Execute the query using RunDatabaseCommand - rawOutput, err := RunDatabaseCommand(ctx, dbFile, fmt.Sprintf("-header %q", query)) + rawOutput, err := RunDatabaseCommand(ctx, dbFile, fmt.Sprintf("%q", query)) if err != nil { return "", fmt.Errorf("error executing query for table %q: %w", table, err) }