Skip to content

Commit e854af7

Browse files
committed
Link view and edit SQL to the right place
1 parent b866054 commit e854af7

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎datasette/templates/patterns.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ <h3>2 extra where clauses</h3>
246246
</div>
247247

248248
<div class="table-tools">
249-
<a class="quiet-button view-sql-button" title="select rowid, attraction_id, characteristic_id from roadside_attraction_characteristics where &#34;characteristic_id&#34; = :p0 order by rowid limit 101" href="{{ base_url }}fixtures?sql=select+rowid%2C+attraction_id%2C+characteristic_id+from+roadside_attraction_characteristics+where+%22characteristic_id%22+%3D+%3Ap0+order+by+rowid+limit+101&amp;p0=2">
249+
<a class="quiet-button view-sql-button" title="select rowid, attraction_id, characteristic_id from roadside_attraction_characteristics where &#34;characteristic_id&#34; = :p0 order by rowid limit 101" href="{{ base_url }}fixtures/-/query?sql=select+rowid%2C+attraction_id%2C+characteristic_id+from+roadside_attraction_characteristics+where+%22characteristic_id%22+%3D+%3Ap0+order+by+rowid+limit+101&amp;p0=2">
250250
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 18 6-6-6-6"></path><path d="m8 6-6 6 6 6"></path></svg>
251251
<span>View and edit SQL</span>
252252
</a>

‎datasette/templates/table.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ <h3>{{ extra_wheres_for_ui|length }} extra where clause{% if extra_wheres_for_ui
160160

161161
<div class="table-tools">
162162
{% if query.sql and allow_execute_sql %}
163-
<a class="quiet-button view-sql-button" title="{{ query.sql }}" href="{{ urls.database(database) }}?{{ {'sql': query.sql}|urlencode|safe }}{% if query.params %}&amp;{{ query.params|urlencode|safe }}{% endif %}">
163+
<a class="quiet-button view-sql-button" title="{{ query.sql }}" href="{{ urls.database(database) }}/-/query?{{ {'sql': query.sql}|urlencode|safe }}{% if query.params %}&amp;{{ query.params|urlencode|safe }}{% endif %}">
164164
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
165165
<path d="m16 18 6-6-6-6"></path>
166166
<path d="m8 6-6 6 6 6"></path>

‎tests/test_table_html.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,11 @@ async def test_table_view_and_edit_sql_button(ds_client):
772772
"Export data",
773773
]
774774
link = tools.select_one("a.quiet-button.view-sql-button")
775-
assert link["href"].startswith("/fixtures?sql=select+id")
775+
assert link["href"].startswith("/fixtures/-/query?sql=select+id")
776776
assert link["title"].startswith("select id, content from simple_primary_key")
777+
# The link should go straight to the query page, not via a redirect
778+
query_response = await ds_client.get(link["href"].replace("&amp;", "&"))
779+
assert query_response.status_code == 200
777780

778781

779782
def _export_urls(soup):

0 commit comments

Comments
 (0)