mirror of
https://github.com/simonw/datasette.git
synced 2026-06-06 09:07:00 +02:00
* Fix for execute write returning, closes #2762 * Fix stored write returning rowcount message * Add configurable execute_write returning limit * Return rows/truncated from execute query if it used RETURNING * INSERT ... RETURNING shows rows in /-/execute-write * Skip RETURNING tests if SQLite version does not support it Screenshot: https://github.com/simonw/datasette/issues/2762#issuecomment-4588111545
88 lines
4.1 KiB
HTML
88 lines
4.1 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}{{ database }}{% if query and query.sql %}: {{ query.sql }}{% endif %}{% endblock %}
|
|
|
|
{% block extra_head %}
|
|
{{- super() -}}
|
|
{% if columns %}
|
|
<style>
|
|
@media only screen and (max-width: 576px) {
|
|
{% for column in columns %}
|
|
.rows-and-columns td:nth-of-type({{ loop.index }}):before { content: "{{ column|escape_css_string }}"; }
|
|
{% endfor %}
|
|
}
|
|
</style>
|
|
{% endif %}
|
|
{% include "_codemirror.html" %}
|
|
{% include "_sql_parameter_styles.html" %}
|
|
{% endblock %}
|
|
|
|
{% block body_class %}query db-{{ database|to_css_class }}{% if stored_query %} query-{{ stored_query|to_css_class }}{% endif %}{% endblock %}
|
|
|
|
{% block crumbs %}
|
|
{{ crumbs.nav(request=request, database=database) }}
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
|
|
{% if stored_query_write and db_is_immutable %}
|
|
<p class="message-error">This query cannot be executed because the database is immutable.</p>
|
|
{% endif %}
|
|
|
|
<h1 style="padding-left: 10px; border-left: 10px solid #{{ database_color }}">{{ metadata.title or database }}{% if stored_query and not metadata.title %}: {{ stored_query }}{% endif %}{% if private %} 🔒{% endif %}</h1>
|
|
{% set action_links, action_title = query_actions(), "Query actions" %}
|
|
{% include "_action_menu.html" %}
|
|
|
|
{% if stored_query %}{{ top_stored_query() }}{% else %}{{ top_query() }}{% endif %}
|
|
|
|
{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %}
|
|
|
|
<form class="sql core" action="{{ urls.database(database) }}{% if stored_query %}/{{ stored_query }}{% endif %}" method="{% if stored_query_write %}post{% else %}get{% endif %}" data-parameters-url="{{ urls.database(database) }}/-/query/parameters">
|
|
<h3>Custom SQL query{% if display_rows %} returning {% if truncated %}more than {% endif %}{{ "{:,}".format(display_rows|length) }} row{% if display_rows|length == 1 %}{% else %}s{% endif %}{% endif %}{% if not query_error %}
|
|
<span class="show-hide-sql">(<a href="{{ show_hide_link }}">{{ show_hide_text }}</a>)</span>
|
|
{% endif %}</h3>
|
|
{% if error %}
|
|
<p class="message-error">{{ error }}</p>
|
|
{% endif %}
|
|
{% if not hide_sql %}
|
|
{% if editable and allow_execute_sql %}
|
|
<p class="sql-editor"><textarea id="sql-editor" name="sql"{% if query and query.sql %} style="height: {{ query.sql.split("\n")|length + 2 }}em"{% endif %}
|
|
>{% if query and query.sql %}{{ query.sql }}{% elif tables %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}</textarea></p>
|
|
{% else %}
|
|
<pre id="sql-query">{% if query %}{{ query.sql }}{% endif %}</pre>
|
|
{% endif %}
|
|
{% else %}
|
|
{% if not stored_query %}
|
|
<input type="hidden" name="sql"
|
|
value="{% if query and query.sql %}{{ query.sql }}{% elif tables %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}"
|
|
>
|
|
{% endif %}
|
|
{% endif %}
|
|
{% set parameter_names = named_parameter_values.keys()|list %}
|
|
{% set parameter_values = named_parameter_values %}
|
|
{% set sql_parameters_allow_expand = false %}
|
|
{% include "_sql_parameters.html" %}
|
|
<p>
|
|
{% if not hide_sql %}<button id="sql-format" type="button" hidden>Format SQL</button>{% endif %}
|
|
<input type="submit" value="Run SQL"{% if stored_query_write and db_is_immutable %} disabled{% endif %}>
|
|
{{ show_hide_hidden }}
|
|
{% if save_query_url %}<a href="{{ save_query_url }}" class="save-query">Save this query</a>{% endif %}
|
|
{% if stored_query and edit_sql_url %}<a href="{{ edit_sql_url }}" class="stored-query-edit-sql">Edit SQL</a>{% endif %}
|
|
</p>
|
|
</form>
|
|
|
|
{% if display_rows %}
|
|
<p class="export-links">This data as {% for name, url in renderers.items() %}<a href="{{ url }}">{{ name }}</a>{{ ", " if not loop.last }}{% endfor %}, <a href="{{ url_csv }}">CSV</a></p>
|
|
{% endif %}
|
|
{% set show_zero_results = not stored_query_write and not error %}
|
|
{% include "_query_results.html" %}
|
|
|
|
{% include "_codemirror_foot.html" %}
|
|
{% include "_sql_parameter_scripts.html" %}
|
|
<script>
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
window.datasetteSqlParameters.setupSqlParameterRefresh({});
|
|
});
|
|
</script>
|
|
|
|
{% endblock %}
|