d718c5a372
CI / windows_test (push) Waiting to run
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / docker_push (duckdb) (push) Waiting to run
CI / docker_push (minimal) (push) Waiting to run
CI / hurl (${{ matrix.example }}) (push) Has been skipped
105 lines
3.7 KiB
SQL
105 lines
3.7 KiB
SQL
-- Procesess CREATE/UPDATE/DELETE operations.
|
|
|
|
-- =============================================================================
|
|
-- =========================== Module Setting ==================================
|
|
-- =========================== Login / Logout ==================================
|
|
-- =============================================================================
|
|
|
|
-- $_curpath and $_session_required are required for header_shell_session.sql.
|
|
|
|
set _session_required = 1;
|
|
set _shell_enabled = 0;
|
|
|
|
SELECT
|
|
'dynamic' AS component,
|
|
sqlpage.run_sql('header_shell_session.sql') AS properties;
|
|
|
|
-- =============================================================================
|
|
-- Redirect target must be passed as $path
|
|
-- =============================================================================
|
|
|
|
set _err_msg = '&path URL GET parameter (redirect target) is not set!';
|
|
|
|
SELECT
|
|
'alert' AS component,
|
|
'red' AS color,
|
|
'alert-triangle' AS icon,
|
|
'Error' AS title,
|
|
$_err_msg AS description,
|
|
TRUE AS dismissible
|
|
WHERE
|
|
$path IS NULL AND $DEBUG IS NULL;
|
|
|
|
-- =============================================================================
|
|
-- Check new values for validity:
|
|
-- - UPDATE existing record:
|
|
-- :id IS NOT NULL
|
|
-- If :name is in the database, :id must match
|
|
-- If attempting to change :name, operation may fail due to FK constraint
|
|
-- - INSERT new record:
|
|
-- :id IS NULL
|
|
-- :name is not in the database
|
|
-- =============================================================================
|
|
|
|
-- Pass new values back as JSON object in $values GET variable for form population.
|
|
--
|
|
-- For new records, the id (INTEGER PRIMARY KEY AUTOINCREMENT) should be set to NULL.
|
|
-- The id field is set as hidden in the record edit form and passed as the :id POST
|
|
-- variable. NULL, however, cannot be passed as such and is converted to blank string.
|
|
-- Check :id for '' and set id (:id will return the same value).
|
|
|
|
set _id = iif(typeof(:id) = 'text' AND :id = '', NULL, :id);
|
|
|
|
set _values = json_object(
|
|
'id', CAST($_id AS INT),
|
|
'name', :name,
|
|
'to_rub', CAST(:to_rub AS NUMERIC)
|
|
);
|
|
|
|
set _op = iif($_id IS NULL, 'INSERT', 'UPDATE');
|
|
set _err_msg = sqlpage.url_encode('New currency already in the database');
|
|
|
|
SELECT
|
|
'redirect' AS component,
|
|
$path || '?' ||
|
|
'&op=' || $_op ||
|
|
'&values=' || $_values ||
|
|
'&error=' || $_err_msg AS link
|
|
FROM currencies
|
|
WHERE currencies.name = :name
|
|
AND ($_id IS NULL OR currencies.id <> $_id);
|
|
|
|
-- =============================================================================
|
|
-- UPSERT: If everything is OK and "UPDATE" is indicated, update the database
|
|
-- =============================================================================
|
|
|
|
INSERT INTO currencies(id, name, to_rub)
|
|
SELECT CAST($_id AS INT), :name, CAST(:to_rub AS NUMERIC)
|
|
WHERE $action = 'UPDATE'
|
|
ON CONFLICT(id) DO
|
|
UPDATE SET name = excluded.name, to_rub = excluded.to_rub
|
|
RETURNING
|
|
'redirect' AS component,
|
|
$path || '?' ||
|
|
'&id=' || id ||
|
|
'&info=' || $_op || ' completed successfully' AS link;
|
|
|
|
-- =============================================================================
|
|
-- DELETE
|
|
-- =============================================================================
|
|
|
|
DELETE FROM currencies
|
|
WHERE $action = 'DELETE' AND id = $_id
|
|
RETURNING
|
|
'redirect' AS component,
|
|
$path || '?' ||
|
|
'&info=DELETE completed successfully' AS link;
|
|
|
|
-- =============================================================================
|
|
-- DEBUG
|
|
-- =============================================================================
|
|
|
|
SELECT
|
|
'dynamic' AS component,
|
|
sqlpage.run_sql('footer_debug_post-get-set.sql') AS properties;
|