simonw / datasette-edit-schema

Datasette plugin for modifying table schemas
Apache License 2.0
16 stars 0 forks source link

Breaks on column called "Representative's Address" #43

Closed simonw closed 10 months ago

simonw commented 10 months ago

Trying this against a CSV exported from https://www.regulations.gov/bulkdownload I got an exception visiting /-/edit-schema/data/tablename - error was:

OperationalError: near "Address": syntax error

One of the columns in the table was called Representative's Address and I think the ' broke it.

The traceback highlighted examples_for_columns:

CleanShot 2023-11-04 at 14 02 05@2x

https://datasette-cloud.sentry.io/issues/4380834663/?project=2050376&query=is%3Aunresolved&referrer=issue-stream&stream_index=0

simonw commented 10 months ago

Function: https://github.com/simonw/datasette-edit-schema/blob/05a155e8c46cfa6f1fc164370b73cf5f047f4010/datasette_edit_schema/utils.py#L92-L125

simonw commented 10 months ago

Here's the bug: https://github.com/simonw/datasette-edit-schema/blob/05a155e8c46cfa6f1fc164370b73cf5f047f4010/datasette_edit_schema/utils.py#L101

Resulted in:

select 'photo's' as label, "photo's" as value from col4),
simonw commented 10 months ago

Another error:

  File "/Users/simon/Dropbox/Development/datasette-edit-schema/datasette_edit_schema/utils.py", line 66, in potential_primary_keys
    cursor.execute(sql)
sqlite3.OperationalError: near "s": syntax error
simonw commented 10 months ago

https://github.com/simonw/datasette-edit-schema/blob/05a155e8c46cfa6f1fc164370b73cf5f047f4010/datasette_edit_schema/utils.py#L54-L89

That generated SQL like this:

select count(*) as _count,
count(distinct "Document ID") as 'distinct.Document ID',
count(distinct "Agency ID") as 'distinct.Agency ID',
count(distinct "Representative's Address") as 'distinct.Representative's Address'
from "lok-imd8-3w1z"