Skip to content

Commit

Permalink
Use select colnames, not select * for table view - refs #615
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 11, 2019
1 parent d3e9387 commit daab48a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions datasette/views/table.py
Expand Up @@ -235,13 +235,17 @@ async def data(
raise NotFound("Table not found: {}".format(table))

pks = await db.primary_keys(table)
table_columns = await db.table_columns(table)

select_columns = ", ".join(escape_sqlite(t) for t in table_columns)

use_rowid = not pks and not is_view
if use_rowid:
select = "rowid, *"
select = "rowid, {}".format(select_columns)
order_by = "rowid"
order_by_pks = "rowid"
else:
select = "*"
select = select_columns
order_by_pks = ", ".join([escape_sqlite(pk) for pk in pks])
order_by = order_by_pks

Expand Down
3 changes: 2 additions & 1 deletion tests/test_api.py
Expand Up @@ -610,7 +610,8 @@ def test_table_json(app_client):
assert response.status == 200
data = response.json
assert (
data["query"]["sql"] == "select * from simple_primary_key order by id limit 51"
data["query"]["sql"]
== "select id, content from simple_primary_key order by id limit 51"
)
assert data["query"]["params"] == {}
assert data["rows"] == [
Expand Down

0 comments on commit daab48a

Please sign in to comment.