### Download Plain Text File using Data URL Source: https://sql-page.com/documentation.sql/index This example demonstrates how to use the download component to serve a plain text file. It utilizes a data URL with URL encoding for the text content. The `sqlpage.url_encode` function is recommended for ensuring proper encoding of textual data. ```sql SELECT sqlpage.download_file_as_data_url(content => sqlpage.url_encode('Hello world'), filename => 'hello.txt'); ``` -------------------------------- ### Download Binary File using Base64 Data URL Source: https://sql-page.com/documentation.sql/index This example illustrates how to download a binary file, such as an image or PDF, using a Base64 encoded data URL. The `sqlpage.read_file_as_data_url` function is used here to read the file content from the server and return it in the required format. ```sql SELECT sqlpage.download_file_as_data_url(content => sqlpage.read_file_as_data_url('path/to/your/binary/file'), filename => 'binary_data.bin'); ``` -------------------------------- ### Creating a Table with SQL Data Source: https://sql-page.com/documentation.sql/index Illustrates how to create an interactive table from SQL query results using the table component. The component automatically renders columns based on the properties returned by the query. It supports filtering, sorting, rich text content, and custom styling for rows and columns. ```sql SELECT 'table' AS component, 'My Data Table' AS title, column1, column2, column3 FROM your_data_table; -- Example with custom styling for rows: SELECT 'table' AS component, *, '_sqlpage_css_class' AS _sqlpage_css_class FROM ( SELECT 'highlighted-row' AS _sqlpage_css_class, 'value1' AS column1, 'value2' AS column2 FROM your_data_table WHERE some_condition ) AS highlighted_data UNION ALL SELECT 'table' AS component, column1, column2 FROM your_data_table WHERE NOT some_condition; ``` -------------------------------- ### Download JSON File using Data URL Source: https://sql-page.com/documentation.sql/index This snippet shows how to download a JSON file. It constructs a data URL with the content type set to 'application/json' and the JSON data URL-encoded. The `sqlpage.url_encode` function is used for safe encoding of the JSON string. ```sql SELECT sqlpage.download_file_as_data_url(content => sqlpage.url_encode('{ "message": "Hi" }'), filename => 'data.json'); ``` -------------------------------- ### Conditional Redirect in SQL Source: https://sql-page.com/documentation.sql/index Demonstrates how to conditionally redirect a user to a different page in SQLPage. This is useful for error handling or enforcing pre-conditions before executing the rest of the page's logic. It relies on SQL's CASE expression and must be placed at the beginning of the SQL file. ```sql SELECT 'redirect' AS component, 'error_page.sql' AS link WHERE NOT your_condition; -- The rest of the page is only executed if the condition is true ``` -------------------------------- ### SQLPage: Select Component and Set Top-Level Parameters Source: https://sql-page.com/documentation.sql/index This SQL statement is used in SQLPage to select a component and define its top-level parameters. It's the first step in defining a UI element and its basic properties within an SQLPage application. ```sql SELECT 'component_name' AS component, 'my value' AS top_level_parameter_1; ``` -------------------------------- ### Setting HTTP Response Status Code Source: https://sql-page.com/documentation.sql/index Shows how to set the HTTP response status code for a page using the status_code component. This is essential for building APIs, handling errors (404, 500), data validation (400), access control (403, 401), and SEO (301, 302). ```sql -- Example: Setting a 404 Not Found status code SELECT 'status_code' AS component, 404 AS code; -- Example: Setting a 200 OK status code SELECT 'status_code' AS component, 200 AS code; -- Example: Setting a 301 Moved Permanently status code for redirection SELECT 'status_code' AS component, 301 AS code, 'new_page.sql' AS url; ``` -------------------------------- ### Generating RSS Feed Data Flow Source: https://sql-page.com/documentation.sql/index Illustrates the process of generating an RSS data flow using SQLPage. This involves setting the appropriate HTTP content type using the http_header component and then using the shell-empty component to prevent HTML generation, ensuring the output is purely RSS. ```sql -- Example: First, set the HTTP header for RSS. SELECT 'http_header' AS component, 'application/rss+xml' AS content_type; -- Then, use shell-empty to output only the RSS data. SELECT 'shell-empty' AS component; -- Your SQL query to generate RSS content would follow here. -- SELECT ... FROM your_rss_data_table; ``` -------------------------------- ### Displaying Interactive Map with SQL Data Source: https://sql-page.com/documentation.sql/index Demonstrates the use of the map component to visualize SQL data, specifically focusing on plotting points from latitude and longitude columns. It can be extended to use GeoJSON for richer geospatial visualizations with databases like PostgreSQL's PostGIS or SQLite's spatialite. ```sql SELECT 'map' AS component, latitude, longitude FROM your_location_table; -- Example with GeoJSON data for advanced visualization: SELECT 'map' AS component, geojson FROM your_gis_data_table; ``` -------------------------------- ### SQLPage: Set Row-Level Parameters Source: https://sql-page.com/documentation.sql/index This SQL statement is used in SQLPage to define the row-level parameters for a component. It specifies the data to be displayed by mapping columns from a table to the component's row-level properties. ```sql SELECT my_column_1 AS row_level_parameter_1, my_column_2 AS row_level_parameter_2 FROM my_table; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.