2017-12-05 16:17:02 +00:00
{% extends "base.html" %}
2018-04-03 15:24:04 +00:00
{% block title %}{{ database }}{% if query and query.sql %}: {{ query.sql }}{% endif %}{% endblock %}
2017-12-05 16:17:02 +00:00
{% block extra_head %}
2022-02-02 21:21:11 +00:00
{{- super() -}}
2017-12-05 16:17:02 +00:00
{% if columns %}
< style >
@media only screen and (max-width: 576px) {
{% for column in columns %}
2018-05-20 17:45:01 +00:00
.rows-and-columns td:nth-of-type({{ loop.index }}):before { content: "{{ column|escape_css_string }}"; }
2017-12-05 16:17:02 +00:00
{% endfor %}
}
< / style >
{% endif %}
{% include "_codemirror.html" %}
{% endblock %}
2020-04-15 21:06:12 +00:00
{% block body_class %}query db-{{ database|to_css_class }}{% if canned_query %} query-{{ canned_query|to_css_class }}{% endif %}{% endblock %}
2017-12-05 16:17:02 +00:00
2022-10-13 21:42:52 +00:00
{% block crumbs %}
{{ crumbs.nav(request=request, database=database) }}
2019-07-14 02:05:39 +00:00
{% endblock %}
2017-12-05 16:17:02 +00:00
2019-07-14 02:05:39 +00:00
{% block content %}
2020-06-03 15:16:50 +00:00
2023-08-09 15:26:52 +00:00
{% if canned_query_write and db_is_immutable %}
2022-08-14 16:34:31 +00:00
< p class = "message-error" > This query cannot be executed because the database is immutable.< / p >
{% endif %}
2023-08-11 05:16:19 +00:00
< h1 style = "padding-left: 10px; border-left: 10px solid #{{ database_color }}" > {{ metadata.title or database }}{% if canned_query and not metadata.title %}: {{ canned_query }}{% endif %}{% if private %} 🔒{% endif %}< / h1 >
2024-02-28 05:55:16 +00:00
{% set links = query_actions() %}{% if links %}
< div class = "page-action-menu" >
< details class = "actions-menu-links details-menu" >
< summary >
< div class = "icon-text" >
< svg class = "icon" aria-labelledby = "actions-menu-links-title" role = "img" style = "color: #fff" xmlns = "http://www.w3.org/2000/svg" width = "28" height = "28" viewBox = "0 0 28 28" fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" >
< title id = "actions-menu-links-title" > Query actions< / title >
< circle cx = "12" cy = "12" r = "3" > < / circle >
< path d = "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" > < / path >
< / svg >
< span > Query actions< / span >
< / div >
< / summary >
< div class = "dropdown-menu" >
< div class = "hook" > < / div >
{% if links %}
< ul >
{% for link in links %}
2024-03-07 03:54:06 +00:00
< li > < a href = "{{ link.href }}" > {{ link.label }}
{% if link.description %}
< p class = "dropdown-description" > {{ link.description }}< / p >
{% endif %}< / a >
< / li >
2024-02-28 05:55:16 +00:00
{% endfor %}
< / ul >
{% endif %}
< / div >
< / details >
< / div >
{% endif %}
2018-07-16 02:33:30 +00:00
2024-01-31 03:54:03 +00:00
{% if canned_query %}{{ top_canned_query() }}{% else %}{{ top_query() }}{% endif %}
2018-07-16 02:33:30 +00:00
{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %}
2017-12-05 16:17:02 +00:00
2023-08-09 15:26:52 +00:00
< form class = "sql" action = "{{ urls.database(database) }}{% if canned_query %}/{{ canned_query }}{% endif %}" method = "{% if canned_query_write %}post{% else %}get{% endif %}" >
2021-08-07 05:09:00 +00:00
< 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 >
2021-06-02 03:59:29 +00:00
{% if error %}
< p class = "message-error" > {{ error }}< / p >
2021-06-02 03:46:20 +00:00
{% endif %}
2019-03-15 05:22:24 +00:00
{% if not hide_sql %}
2020-06-09 00:05:44 +00:00
{% if editable and allow_execute_sql %}
2022-08-18 16:06:02 +00:00
< p > < 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 }}{% else %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}< / textarea > < / p >
2019-03-15 05:22:24 +00:00
{% else %}
2019-10-14 03:46:12 +00:00
< pre id = "sql-query" > {% if query %}{{ query.sql }}{% endif %}< / pre >
2019-03-15 05:22:24 +00:00
{% endif %}
2019-04-12 05:00:47 +00:00
{% else %}
2021-08-07 05:09:00 +00:00
{% if not canned_query %}
< input type = "hidden" name = "sql"
value="{% if query and query.sql %}{{ query.sql }}{% else %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}"
>
{% endif %}
2017-12-05 16:17:02 +00:00
{% endif %}
{% if named_parameter_values %}
< h3 > Query parameters< / h3 >
{% for name, value in named_parameter_values.items() %}
2017-12-09 21:57:36 +00:00
< p > < label for = "qp{{ loop.index }}" > {{ name }}< / label > < input type = "text" id = "qp{{ loop.index }}" name = "{{ name }}" value = "{{ value }}" > < / p >
2017-12-05 16:17:02 +00:00
{% endfor %}
{% endif %}
2019-10-14 03:46:12 +00:00
< p >
2021-08-07 05:09:00 +00:00
{% if not hide_sql %}< button id = "sql-format" type = "button" hidden > Format SQL< / button > {% endif %}
2023-08-09 15:26:52 +00:00
{% if canned_query_write %}< input type = "hidden" name = "csrftoken" value = "{{ csrftoken() }}" > {% endif %}
< input type = "submit" value = "Run SQL" { % if canned_query_write and db_is_immutable % } disabled { % endif % } >
2021-08-07 05:09:00 +00:00
{{ show_hide_hidden }}
2020-10-14 03:44:18 +00:00
{% if canned_query and edit_sql_url %}< a href = "{{ edit_sql_url }}" class = "canned-query-edit-sql" > Edit SQL< / a > {% endif %}
2019-10-14 03:46:12 +00:00
< / p >
2017-12-05 16:17:02 +00:00
< / form >
2018-07-24 03:56:32 +00:00
{% if display_rows %}
2020-10-27 07:56:35 +00:00
< 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 >
< div class = "table-wrapper" > < table class = "rows-and-columns" >
2017-12-05 16:17:02 +00:00
< thead >
< tr >
2018-04-19 15:36:14 +00:00
{% for column in columns %}< th class = "col-{{ column|to_css_class }}" scope = "col" > {{ column }}< / th > {% endfor %}
2017-12-05 16:17:02 +00:00
< / tr >
< / thead >
< tbody >
2018-07-24 03:56:32 +00:00
{% for row in display_rows %}
2017-12-05 16:17:02 +00:00
< tr >
2018-04-19 15:36:14 +00:00
{% for column, td in zip(columns, row) %}
2020-10-29 22:01:38 +00:00
< td class = "col-{{ column|to_css_class }}" > {{ td }}< / td >
2017-12-05 16:17:02 +00:00
{% endfor %}
< / tr >
{% endfor %}
< / tbody >
2020-10-27 07:56:35 +00:00
< / table > < / div >
2019-11-23 06:07:01 +00:00
{% else %}
2023-08-09 15:26:52 +00:00
{% if not canned_query_write and not error %}
2020-06-03 15:16:50 +00:00
< p class = "zero-results" > 0 results< / p >
{% endif %}
2017-12-05 16:17:02 +00:00
{% endif %}
{% include "_codemirror_foot.html" %}
{% endblock %}