Skip to content

Commit

Permalink
reparse as JSON, fix #98
Browse files Browse the repository at this point in the history
SQLite 3.39 is stricter about serializing things to TEXT format
when it escapes a subquery/CTE. Adding json(...) is compatible
on the newer versions and the older versions

I guess to test this we could run tests with multiple versions
of pysqlite3-binary? Seems kinda unfortunate :(
  • Loading branch information
cldellow committed Feb 27, 2023
1 parent 5001e79 commit 22641df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions datasette_ui_extras/column_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def update_distincts(conn, table_id, column_id, sql, where_args):
GROUP BY 1, 2
ORDER BY 3 DESC
)
SELECT value, hash, count, (select json_group_array(value) from (select value from json_each(keys) limit 10)) AS keys
SELECT value, hash, count, (select json_group_array(json(value)) from (select value from json_each(keys) limit 10)) AS keys
FROM distincts
'''.format(sql)

Expand Down Expand Up @@ -522,7 +522,7 @@ def update_json_distincts(conn, table_id, column_id, sql, where_args):
GROUP BY 1, 2
ORDER BY 3 DESC
)
SELECT value, hash, count, (select json_group_array(value) from (select value from json_each(keys) limit 10)) AS keys
SELECT value, hash, count, (select json_group_array(json(value)) from (select value from json_each(keys) limit 10)) AS keys
FROM distincts
'''.format(sql)

Expand Down
6 changes: 6 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@
"insert-row": true,
"update-row": true,
"delete-row": true
},
"tables": {
"users": {
"label_column": "display_name"
}
}

}
},
"plugins": {
Expand Down

0 comments on commit 22641df

Please sign in to comment.