Skip to content

Commit

Permalink
fix: always return database table columns (#429)
Browse files Browse the repository at this point in the history
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 obot-platform/obot#1702

Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale authored Feb 10, 2025
1 parent 8c7b6e0 commit 80a3fa7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions database/pkg/cmd/rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 80a3fa7

Please sign in to comment.