Quote SQL identifiers as best practice and to avoid any problem in the future

This commit is contained in:
Gregoo 2025-01-20 19:39:12 +01:00
parent 5e99371b39
commit ebe0585a40
41 changed files with 388 additions and 388 deletions

View File

@ -1,62 +1,62 @@
-- description: Database initialization -- description: Original database initialization
-- FROM sqlite3 app.db .schema > init.sql with extra IF NOT EXISTS and transaction -- FROM sqlite3 app.db .schema > init.sql with extra IF NOT EXISTS, transaction and quotes
BEGIN transaction; BEGIN transaction;
CREATE TABLE IF NOT EXISTS wishlist ( CREATE TABLE IF NOT EXISTS "wishlist" (
set_num TEXT, "set_num" TEXT,
name TEXT, "name" TEXT,
year INTEGER, "year" INTEGER,
theme_id INTEGER, "theme_id" INTEGER,
num_parts INTEGER, "num_parts" INTEGER,
set_img_url TEXT, "set_img_url" TEXT,
set_url TEXT, "set_url" TEXT,
last_modified_dt TEXT "last_modified_dt" TEXT
); );
CREATE TABLE IF NOT EXISTS sets ( CREATE TABLE IF NOT EXISTS "sets" (
set_num TEXT, "set_num" TEXT,
name TEXT, "name" TEXT,
year INTEGER, "year" INTEGER,
theme_id INTEGER, "theme_id" INTEGER,
num_parts INTEGER, "num_parts" INTEGER,
set_img_url TEXT, "set_img_url" TEXT,
set_url TEXT, "set_url" TEXT,
last_modified_dt TEXT, "last_modified_dt" TEXT,
mini_col BOOLEAN, "mini_col" BOOLEAN,
set_check BOOLEAN, "set_check" BOOLEAN,
set_col BOOLEAN, "set_col" BOOLEAN,
u_id TEXT "u_id" TEXT
); );
CREATE TABLE IF NOT EXISTS inventory ( CREATE TABLE IF NOT EXISTS "inventory" (
set_num TEXT, "set_num" TEXT,
id INTEGER, "id" INTEGER,
part_num TEXT, "part_num" TEXT,
name TEXT, "name" TEXT,
part_img_url TEXT, "part_img_url" TEXT,
part_img_url_id TEXT, "part_img_url_id" TEXT,
color_id INTEGER, "color_id" INTEGER,
color_name TEXT, "color_name" TEXT,
quantity INTEGER, "quantity" INTEGER,
is_spare BOOLEAN, "is_spare" BOOLEAN,
element_id INTEGER, "element_id" INTEGER,
u_id TEXT "u_id" TEXT
); );
CREATE TABLE IF NOT EXISTS minifigures ( CREATE TABLE IF NOT EXISTS "minifigures" (
fig_num TEXT, "fig_num" TEXT,
set_num TEXT, "set_num" TEXT,
name TEXT, "name" TEXT,
quantity INTEGER, "quantity" INTEGER,
set_img_url TEXT, "set_img_url" TEXT,
u_id TEXT "u_id" TEXT
); );
CREATE TABLE IF NOT EXISTS missing ( CREATE TABLE IF NOT EXISTS "missing" (
set_num TEXT, "set_num" TEXT,
id INTEGER, "id" INTEGER,
part_num TEXT, "part_num" TEXT,
part_img_url_id TEXT, "part_img_url_id" TEXT,
color_id INTEGER, "color_id" INTEGER,
quantity INTEGER, "quantity" INTEGER,
element_id INTEGER, "element_id" INTEGER,
u_id TEXT "u_id" TEXT
); );
COMMIT; COMMIT;

View File

@ -6,8 +6,8 @@ PRAGMA journal_mode = WAL;
BEGIN transaction; BEGIN transaction;
-- Fix a bug where 'None' was inserted in missing instead of NULL -- Fix a bug where 'None' was inserted in missing instead of NULL
UPDATE missing UPDATE "missing"
SET element_id = NULL SET "element_id" = NULL
WHERE element_id = 'None'; WHERE "missing"."element_id" = 'None';
COMMIT; COMMIT;

View File

@ -1,20 +1,20 @@
SELECT SELECT
minifigures.fig_num, "minifigures"."fig_num",
minifigures.set_num, "minifigures"."set_num",
minifigures.name, "minifigures"."name",
minifigures.quantity, "minifigures"."quantity",
minifigures.set_img_url, "minifigures"."set_img_url",
minifigures.u_id, "minifigures"."u_id",
{% block total_missing %} {% block total_missing %}
NULL AS total_missing, -- dummy for order: total_missing NULL AS "total_missing", -- dummy for order: total_missing
{% endblock %} {% endblock %}
{% block total_quantity %} {% block total_quantity %}
NULL AS total_quantity, -- dummy for order: total_quantity NULL AS "total_quantity", -- dummy for order: total_quantity
{% endblock %} {% endblock %}
{% block total_sets %} {% block total_sets %}
NULL AS total_sets -- dummy for order: total_sets NULL AS "total_sets" -- dummy for order: total_sets
{% endblock %} {% endblock %}
FROM minifigures FROM "minifigures"
{% block join %}{% endblock %} {% block join %}{% endblock %}

View File

@ -1,2 +1,2 @@
DELETE FROM minifigures DELETE FROM "minifigures"
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "minifigures"."u_id" IS NOT DISTINCT FROM :u_id

View File

@ -1,10 +1,10 @@
INSERT INTO minifigures ( INSERT INTO "minifigures" (
fig_num, "fig_num",
set_num, "set_num",
name, "name",
quantity, "quantity",
set_img_url, "set_img_url",
u_id "u_id"
) VALUES ( ) VALUES (
:fig_num, :fig_num,
:set_num, :set_num,

View File

@ -1,34 +1,34 @@
{% extends 'minifigure/base/select.sql' %} {% extends 'minifigure/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing_join.total, 0)) AS total_missing, SUM(IFNULL("missing_join"."total", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block total_quantity %} {% block "total_quantity" %}
SUM(IFNULL(minifigures.quantity, 0)) AS total_quantity, SUM(IFNULL("minifigures"."quantity", 0)) AS "total_quantity",
{% endblock %} {% endblock %}
{% block total_sets %} {% block total_sets %}
COUNT(minifigures.set_num) AS total_sets COUNT("minifigures"."set_num") AS "total_sets"
{% endblock %} {% endblock %}
{% block join %} {% block join %}
-- LEFT JOIN + SELECT to avoid messing the total -- LEFT JOIN + SELECT to avoid messing the total
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
set_num, "missing"."set_num",
u_id, "missing"."u_id",
SUM(quantity) AS total SUM("missing"."quantity") AS total
FROM missing FROM "missing"
GROUP BY GROUP BY
set_num, "missing"."set_num",
u_id "missing"."u_id"
) missing_join ) missing_join
ON minifigures.u_id IS NOT DISTINCT FROM missing_join.u_id ON "minifigures"."u_id" IS NOT DISTINCT FROM "missing_join"."u_id"
AND minifigures.fig_num IS NOT DISTINCT FROM missing_join.set_num AND "minifigures"."fig_num" IS NOT DISTINCT FROM "missing_join"."set_num"
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
minifigures.fig_num "minifigures"."fig_num"
{% endblock %} {% endblock %}

View File

@ -1,6 +1,6 @@
{% extends 'minifigure/base/select.sql' %} {% extends 'minifigure/base/select.sql' %}
{% block where %} {% block where %}
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "minifigures"."u_id" IS NOT DISTINCT FROM :u_id
AND set_num IS NOT DISTINCT FROM :set_num AND "minifigures"."set_num" IS NOT DISTINCT FROM :set_num
{% endblock %} {% endblock %}

View File

@ -1,17 +1,17 @@
{% extends 'minifigure/base/select.sql' %} {% extends 'minifigure/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing.quantity, 0)) AS total_missing, SUM(IFNULL("missing"."quantity", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block join %} {% block join %}
LEFT JOIN missing LEFT JOIN "missing"
ON minifigures.fig_num IS NOT DISTINCT FROM missing.set_num ON "minifigures"."fig_num" IS NOT DISTINCT FROM "missing"."set_num"
AND minifigures.u_id IS NOT DISTINCT FROM missing.u_id AND "minifigures"."u_id" IS NOT DISTINCT FROM "missing"."u_id"
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
minifigures.fig_num, "minifigures"."fig_num",
minifigures.u_id "minifigures"."u_id"
{% endblock %} {% endblock %}

View File

@ -1,30 +1,30 @@
{% extends 'minifigure/base/select.sql' %} {% extends 'minifigure/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing.quantity, 0)) AS total_missing, SUM(IFNULL("missing"."quantity", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block join %} {% block join %}
LEFT JOIN missing LEFT JOIN "missing"
ON minifigures.fig_num IS NOT DISTINCT FROM missing.set_num ON "minifigures"."fig_num" IS NOT DISTINCT FROM "missing"."set_num"
AND minifigures.u_id IS NOT DISTINCT FROM missing.u_id AND "minifigures"."u_id" IS NOT DISTINCT FROM "missing"."u_id"
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE minifigures.fig_num IN ( WHERE "minifigures"."fig_num" IN (
SELECT SELECT
missing.set_num "missing"."set_num"
FROM missing FROM "missing"
WHERE missing.color_id IS NOT DISTINCT FROM :color_id WHERE "missing"."color_id" IS NOT DISTINCT FROM :color_id
AND missing.element_id IS NOT DISTINCT FROM :element_id AND "missing"."element_id" IS NOT DISTINCT FROM :element_id
AND missing.part_num IS NOT DISTINCT FROM :part_num AND "missing"."part_num" IS NOT DISTINCT FROM :part_num
GROUP BY missing.set_num GROUP BY "missing"."set_num"
) )
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
minifigures.fig_num "minifigures"."fig_num"
{% endblock %} {% endblock %}

View File

@ -1,24 +1,24 @@
{% extends 'minifigure/base/select.sql' %} {% extends 'minifigure/base/select.sql' %}
{% block total_quantity %} {% block total_quantity %}
SUM(minifigures.quantity) AS total_quantity, SUM("minifigures"."quantity") AS "total_quantity",
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE minifigures.fig_num IN ( WHERE "minifigures"."fig_num" IN (
SELECT SELECT
inventory.set_num "inventory"."set_num"
FROM inventory FROM "inventory"
WHERE inventory.color_id IS NOT DISTINCT FROM :color_id WHERE "inventory"."color_id" IS NOT DISTINCT FROM :color_id
AND inventory.element_id IS NOT DISTINCT FROM :element_id AND "inventory"."element_id" IS NOT DISTINCT FROM :element_id
AND inventory.part_num IS NOT DISTINCT FROM :part_num AND "inventory"."part_num" IS NOT DISTINCT FROM :part_num
GROUP BY inventory.set_num GROUP BY "inventory"."set_num"
) )
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
minifigures.fig_num "minifigures"."fig_num"
{% endblock %} {% endblock %}

View File

@ -1,38 +1,38 @@
{% extends 'minifigure/base/select.sql' %} {% extends 'minifigure/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing_join.total, 0)) AS total_missing, SUM(IFNULL("missing_join"."total", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block total_quantity %} {% block total_quantity %}
SUM(IFNULL(minifigures.quantity, 0)) AS total_quantity, SUM(IFNULL("minifigures"."quantity", 0)) AS "total_quantity",
{% endblock %} {% endblock %}
{% block total_sets %} {% block total_sets %}
COUNT(minifigures.set_num) AS total_sets COUNT("minifigures"."set_num") AS "total_sets"
{% endblock %} {% endblock %}
{% block join %} {% block join %}
-- LEFT JOIN + SELECT to avoid messing the total -- LEFT JOIN + SELECT to avoid messing the total
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
set_num, "missing"."set_num",
u_id, "missing"."u_id",
SUM(quantity) AS total SUM("missing"."quantity") AS "total"
FROM missing FROM "missing"
GROUP BY GROUP BY
set_num, "missing"."set_num",
u_id "missing"."u_id"
) missing_join ) "missing_join"
ON minifigures.u_id IS NOT DISTINCT FROM missing_join.u_id ON "minifigures"."u_id" IS NOT DISTINCT FROM "missing_join"."u_id"
AND minifigures.fig_num IS NOT DISTINCT FROM missing_join.set_num AND "minifigures"."fig_num" IS NOT DISTINCT FROM "missing_join"."set_num"
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE fig_num IS NOT DISTINCT FROM :fig_num WHERE "minifigures"."fig_num" IS NOT DISTINCT FROM :fig_num
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
minifigures.fig_num "minifigures"."fig_num"
{% endblock %} {% endblock %}

View File

@ -1,7 +1,7 @@
{% extends 'minifigure/base/select.sql' %} {% extends 'minifigure/base/select.sql' %}
{% block where %} {% block where %}
WHERE fig_num IS NOT DISTINCT FROM :fig_num WHERE "minifigures"."fig_num" IS NOT DISTINCT FROM :fig_num
AND u_id IS NOT DISTINCT FROM :u_id AND "minifigures"."u_id" IS NOT DISTINCT FROM :u_id
AND set_num IS NOT DISTINCT FROM :set_num AND "minifigures"."set_num" IS NOT DISTINCT FROM :set_num
{% endblock %} {% endblock %}

View File

@ -1,2 +1,2 @@
DELETE FROM missing DELETE FROM "missing"
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "missing"."u_id" IS NOT DISTINCT FROM :u_id

View File

@ -1,4 +1,4 @@
DELETE FROM missing DELETE FROM "missing"
WHERE set_num IS NOT DISTINCT FROM :set_num WHERE "missing"."set_num" IS NOT DISTINCT FROM :set_num
AND id IS NOT DISTINCT FROM :id AND "missing"."id" IS NOT DISTINCT FROM :id
AND u_id IS NOT DISTINCT FROM :u_id AND "missing"."u_id" IS NOT DISTINCT FROM :u_id

View File

@ -1,12 +1,12 @@
INSERT INTO missing ( INSERT INTO "missing" (
set_num, "set_num",
id, "id",
part_num, "part_num",
part_img_url_id, "part_img_url_id",
color_id, "color_id",
quantity, "quantity",
element_id, "element_id",
u_id "u_id"
) )
VALUES( VALUES(
:set_num, :set_num,

View File

@ -1,5 +1,5 @@
UPDATE missing UPDATE "missing"
SET quantity = :quantity SET "quantity" = :quantity
WHERE set_num IS NOT DISTINCT FROM :set_num WHERE "missing"."set_num" IS NOT DISTINCT FROM :set_num
AND id IS NOT DISTINCT FROM :id AND "missing"."id" IS NOT DISTINCT FROM :id
AND u_id IS NOT DISTINCT FROM :u_id AND "missing"."u_id" IS NOT DISTINCT FROM :u_id

View File

@ -1,32 +1,32 @@
SELECT SELECT
inventory.set_num, "inventory"."set_num",
inventory.id, "inventory"."id",
inventory.part_num, "inventory"."part_num",
inventory.name, "inventory"."name",
inventory.part_img_url, "inventory"."part_img_url",
inventory.part_img_url_id, "inventory"."part_img_url_id",
inventory.color_id, "inventory"."color_id",
inventory.color_name, "inventory"."color_name",
inventory.quantity, "inventory"."quantity",
inventory.is_spare, "inventory"."is_spare",
inventory.element_id, "inventory"."element_id",
inventory.u_id, "inventory"."u_id",
{% block total_missing %} {% block total_missing %}
NULL AS total_missing, -- dummy for order: total_missing NULL AS "total_missing", -- dummy for order: total_missing
{% endblock %} {% endblock %}
{% block total_quantity %} {% block total_quantity %}
NULL AS total_quantity, -- dummy for order: total_quantity NULL AS "total_quantity", -- dummy for order: total_quantity
{% endblock %} {% endblock %}
{% block total_spare %} {% block total_spare %}
NULL AS total_spare, -- dummy for order: total_spare NULL AS "total_spare", -- dummy for order: total_spare
{% endblock %} {% endblock %}
{% block total_sets %} {% block total_sets %}
NULL AS total_sets, -- dummy for order: total_sets NULL AS "total_sets", -- dummy for order: total_sets
{% endblock %} {% endblock %}
{% block total_minifigures %} {% block total_minifigures %}
NULL AS total_minifigures -- dummy for order: total_minifigures NULL AS "total_minifigures" -- dummy for order: total_minifigures
{% endblock %} {% endblock %}
FROM inventory FROM "inventory"
{% block join %}{% endblock %} {% block join %}{% endblock %}

View File

@ -1,2 +1,2 @@
DELETE FROM inventory DELETE FROM "inventory"
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "inventory"."u_id" IS NOT DISTINCT FROM :u_id

View File

@ -1,16 +1,16 @@
INSERT INTO inventory ( INSERT INTO inventory (
set_num, "set_num",
id, "id",
part_num, "part_num",
name, "name",
part_img_url, "part_img_url",
part_img_url_id, "part_img_url_id",
color_id, "color_id",
color_name, "color_name",
quantity, "quantity",
is_spare, "is_spare",
element_id, "element_id",
u_id "u_id"
) VALUES ( ) VALUES (
:set_num, :set_num,
:id, :id,

View File

@ -1,43 +1,43 @@
{% extends 'part/base/select.sql' %} {% extends 'part/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing.quantity, 0)) AS total_missing, SUM(IFNULL("missing"."quantity", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block total_quantity %} {% block total_quantity %}
SUM(inventory.quantity * IFNULL(minifigures.quantity, 1)) AS total_quantity, SUM("inventory"."quantity" * IFNULL("minifigures"."quantity", 1)) AS "total_quantity",
{% endblock %} {% endblock %}
{% block total_sets %} {% block total_sets %}
COUNT(DISTINCT sets.u_id) AS total_sets, COUNT(DISTINCT "sets"."u_id") AS "total_sets",
{% endblock %} {% endblock %}
{% block total_minifigures %} {% block total_minifigures %}
SUM(IFNULL(minifigures.quantity, 0)) AS total_minifigures SUM(IFNULL("minifigures"."quantity", 0)) AS "total_minifigures"
{% endblock %} {% endblock %}
{% block join %} {% block join %}
LEFT JOIN missing LEFT JOIN "missing"
ON inventory.set_num IS NOT DISTINCT FROM missing.set_num ON "inventory"."set_num" IS NOT DISTINCT FROM "missing"."set_num"
AND inventory.id IS NOT DISTINCT FROM missing.id AND "inventory"."id" IS NOT DISTINCT FROM "missing"."id"
AND inventory.part_num IS NOT DISTINCT FROM missing.part_num AND "inventory"."part_num" IS NOT DISTINCT FROM "missing"."part_num"
AND inventory.color_id IS NOT DISTINCT FROM missing.color_id AND "inventory"."color_id" IS NOT DISTINCT FROM "missing"."color_id"
AND inventory.element_id IS NOT DISTINCT FROM missing.element_id AND "inventory"."element_id" IS NOT DISTINCT FROM "missing"."element_id"
AND inventory.u_id IS NOT DISTINCT FROM missing.u_id AND "inventory"."u_id" IS NOT DISTINCT FROM "missing"."u_id"
LEFT JOIN minifigures LEFT JOIN "minifigures"
ON inventory.set_num IS NOT DISTINCT FROM minifigures.fig_num ON "inventory"."set_num" IS NOT DISTINCT FROM "minifigures"."fig_num"
AND inventory.u_id IS NOT DISTINCT FROM minifigures.u_id AND "inventory"."u_id" IS NOT DISTINCT FROM "minifigures"."u_id"
LEFT JOIN sets LEFT JOIN sets
ON inventory.u_id IS NOT DISTINCT FROM sets.u_id ON "inventory"."u_id" IS NOT DISTINCT FROM "sets"."u_id"
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
inventory.part_num, "inventory"."part_num",
inventory.name, "inventory"."name",
inventory.color_id, "inventory"."color_id",
inventory.is_spare, "inventory"."is_spare",
inventory.element_id "inventory"."element_id"
{% endblock %} {% endblock %}

View File

@ -2,27 +2,27 @@
{% extends 'part/base/select.sql' %} {% extends 'part/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing.quantity, 0)) AS total_missing, SUM(IFNULL("missing"."quantity", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block join %} {% block join %}
LEFT JOIN missing LEFT JOIN "missing"
ON missing.set_num IS NOT DISTINCT FROM inventory.set_num ON "missing"."set_num" IS NOT DISTINCT FROM "inventory"."set_num"
AND missing.id IS NOT DISTINCT FROM inventory.id AND "missing"."id" IS NOT DISTINCT FROM "inventory"."id"
AND missing.part_num IS NOT DISTINCT FROM inventory.part_num AND "missing"."part_num" IS NOT DISTINCT FROM "inventory"."part_num"
AND missing.color_id IS NOT DISTINCT FROM inventory.color_id AND "missing"."color_id" IS NOT DISTINCT FROM "inventory"."color_id"
AND missing.element_id IS NOT DISTINCT FROM inventory.element_id AND "missing"."element_id" IS NOT DISTINCT FROM "inventory"."element_id"
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE inventory.set_num IS NOT DISTINCT FROM :set_num WHERE "inventory"."set_num" IS NOT DISTINCT FROM :set_num
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
inventory.part_num, "inventory"."part_num",
inventory.name, "inventory"."name",
inventory.color_id, "inventory"."color_id",
inventory.is_spare, "inventory"."is_spare",
inventory.element_id "inventory"."element_id"
{% endblock %} {% endblock %}

View File

@ -2,20 +2,20 @@
{% extends 'part/base/select.sql' %} {% extends 'part/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
IFNULL(missing.quantity, 0) AS total_missing, IFNULL("missing"."quantity", 0) AS "total_missing",
{% endblock %} {% endblock %}
{% block join %} {% block join %}
LEFT JOIN missing LEFT JOIN "missing"
ON inventory.set_num IS NOT DISTINCT FROM missing.set_num ON "inventory"."set_num" IS NOT DISTINCT FROM "missing"."set_num"
AND inventory.id IS NOT DISTINCT FROM missing.id AND "inventory"."id" IS NOT DISTINCT FROM "missing"."id"
AND inventory.part_num IS NOT DISTINCT FROM missing.part_num AND "inventory"."part_num" IS NOT DISTINCT FROM "missing"."part_num"
AND inventory.color_id IS NOT DISTINCT FROM missing.color_id AND "inventory"."color_id" IS NOT DISTINCT FROM "missing"."color_id"
AND inventory.element_id IS NOT DISTINCT FROM missing.element_id AND "inventory"."element_id" IS NOT DISTINCT FROM "missing"."element_id"
AND inventory.u_id IS NOT DISTINCT FROM missing.u_id AND "inventory"."u_id" IS NOT DISTINCT FROM "missing"."u_id"
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE inventory.u_id IS NOT DISTINCT FROM :u_id WHERE "inventory"."u_id" IS NOT DISTINCT FROM :u_id
AND inventory.set_num IS NOT DISTINCT FROM :set_num AND "inventory"."set_num" IS NOT DISTINCT FROM :set_num
{% endblock %} {% endblock %}

View File

@ -1,36 +1,36 @@
{% extends 'part/base/select.sql' %} {% extends 'part/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing.quantity, 0)) AS total_missing, SUM(IFNULL("missing"."quantity", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block total_sets %} {% block total_sets %}
COUNT(inventory.u_id) - COUNT(minifigures.u_id) AS total_sets, COUNT("inventory"."u_id") - COUNT("minifigures"."u_id") AS "total_sets",
{% endblock %} {% endblock %}
{% block total_minifigures %} {% block total_minifigures %}
SUM(IFNULL(minifigures.quantity, 0)) AS total_minifigures SUM(IFNULL("minifigures"."quantity", 0)) AS "total_minifigures"
{% endblock %} {% endblock %}
{% block join %} {% block join %}
INNER JOIN missing INNER JOIN "missing"
ON missing.set_num IS NOT DISTINCT FROM inventory.set_num ON "missing"."set_num" IS NOT DISTINCT FROM "inventory"."set_num"
AND missing.id IS NOT DISTINCT FROM inventory.id AND "missing"."id" IS NOT DISTINCT FROM "inventory"."id"
AND missing.part_num IS NOT DISTINCT FROM inventory.part_num AND "missing"."part_num" IS NOT DISTINCT FROM "inventory"."part_num"
AND missing.color_id IS NOT DISTINCT FROM inventory.color_id AND "missing"."color_id" IS NOT DISTINCT FROM "inventory"."color_id"
AND missing.element_id IS NOT DISTINCT FROM inventory.element_id AND "missing"."element_id" IS NOT DISTINCT FROM "inventory"."element_id"
AND missing.u_id IS NOT DISTINCT FROM inventory.u_id AND "missing"."u_id" IS NOT DISTINCT FROM "inventory"."u_id"
LEFT JOIN minifigures LEFT JOIN "minifigures"
ON missing.set_num IS NOT DISTINCT FROM minifigures.fig_num ON "missing"."set_num" IS NOT DISTINCT FROM "minifigures"."fig_num"
AND missing.u_id IS NOT DISTINCT FROM minifigures.u_id AND "missing"."u_id" IS NOT DISTINCT FROM "minifigures"."u_id"
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
inventory.part_num, "inventory"."part_num",
inventory.name, "inventory"."name",
inventory.color_id, "inventory"."color_id",
inventory.is_spare, "inventory"."is_spare",
inventory.element_id "inventory"."element_id"
{% endblock %} {% endblock %}

View File

@ -1,40 +1,40 @@
{% extends 'part/base/select.sql' %} {% extends 'part/base/select.sql' %}
{% block total_missing %} {% block total_missing %}
SUM(IFNULL(missing.quantity, 0)) AS total_missing, SUM(IFNULL("missing"."quantity", 0)) AS "total_missing",
{% endblock %} {% endblock %}
{% block total_quantity %} {% block total_quantity %}
SUM((NOT inventory.is_spare) * inventory.quantity * IFNULL(minifigures.quantity, 1)) AS total_quantity, SUM((NOT "inventory"."is_spare") * "inventory"."quantity" * IFNULL("minifigures"."quantity", 1)) AS "total_quantity",
{% endblock %} {% endblock %}
{% block total_spare %} {% block total_spare %}
SUM(inventory.is_spare * inventory.quantity * IFNULL(minifigures.quantity, 1)) AS total_spare, SUM("inventory"."is_spare" * "inventory"."quantity" * IFNULL("minifigures"."quantity", 1)) AS "total_spare",
{% endblock %} {% endblock %}
{% block join %} {% block join %}
LEFT JOIN missing LEFT JOIN "missing"
ON inventory.set_num IS NOT DISTINCT FROM missing.set_num ON "inventory"."set_num" IS NOT DISTINCT FROM "missing"."set_num"
AND inventory.id IS NOT DISTINCT FROM missing.id AND "inventory"."id" IS NOT DISTINCT FROM "missing"."id"
AND inventory.part_num IS NOT DISTINCT FROM missing.part_num AND "inventory"."part_num" IS NOT DISTINCT FROM "missing"."part_num"
AND inventory.color_id IS NOT DISTINCT FROM missing.color_id AND "inventory"."color_id" IS NOT DISTINCT FROM "missing"."color_id"
AND inventory.element_id IS NOT DISTINCT FROM missing.element_id AND "inventory"."element_id" IS NOT DISTINCT FROM "missing"."element_id"
AND inventory.u_id IS NOT DISTINCT FROM missing.u_id AND "inventory"."u_id" IS NOT DISTINCT FROM "missing"."u_id"
LEFT JOIN minifigures LEFT JOIN "minifigures"
ON inventory.set_num IS NOT DISTINCT FROM minifigures.fig_num ON "inventory"."set_num" IS NOT DISTINCT FROM "minifigures"."fig_num"
AND inventory.u_id IS NOT DISTINCT FROM minifigures.u_id AND "inventory"."u_id" IS NOT DISTINCT FROM "minifigures"."u_id"
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE inventory.part_num IS NOT DISTINCT FROM :part_num WHERE "inventory"."part_num" IS NOT DISTINCT FROM :part_num
AND inventory.color_id IS NOT DISTINCT FROM :color_id AND "inventory"."color_id" IS NOT DISTINCT FROM :color_id
AND inventory.element_id IS NOT DISTINCT FROM :element_id AND "inventory"."element_id" IS NOT DISTINCT FROM :element_id
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
inventory.part_num, "inventory"."part_num",
inventory.color_id, "inventory"."color_id",
inventory.element_id "inventory"."element_id"
{% endblock %} {% endblock %}

View File

@ -1,24 +1,24 @@
{% extends 'part/base/select.sql' %} {% extends 'part/base/select.sql' %}
{% block join %} {% block join %}
LEFT JOIN missing LEFT JOIN "missing"
ON inventory.set_num IS NOT DISTINCT FROM missing.set_num ON "inventory"."set_num" IS NOT DISTINCT FROM "missing"."set_num"
AND inventory.id IS NOT DISTINCT FROM missing.id AND "inventory"."id" IS NOT DISTINCT FROM "missing"."id"
AND inventory.u_id IS NOT DISTINCT FROM missing.u_id AND "inventory"."u_id" IS NOT DISTINCT FROM "missing"."u_id"
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE inventory.u_id IS NOT DISTINCT FROM :u_id WHERE "inventory"."u_id" IS NOT DISTINCT FROM :u_id
AND inventory.set_num IS NOT DISTINCT FROM :set_num AND "inventory"."set_num" IS NOT DISTINCT FROM :set_num
AND inventory.id IS NOT DISTINCT FROM :id AND "inventory"."id" IS NOT DISTINCT FROM :id
{% endblock %} {% endblock %}
{% block group %} {% block group %}
GROUP BY GROUP BY
inventory.set_num, "inventory"."set_num",
inventory.id, "inventory"."id",
inventory.part_num, "inventory"."part_num",
inventory.color_id, "inventory"."color_id",
inventory.element_id, "inventory"."element_id",
inventory.u_id "inventory"."u_id"
{% endblock %} {% endblock %}

View File

@ -1,2 +1,2 @@
SELECT COUNT(*) AS count SELECT COUNT(*) AS "count"
FROM {{ table }} FROM "{{ table }}"

View File

@ -1,9 +1,9 @@
BEGIN transaction; BEGIN transaction;
DROP TABLE IF EXISTS wishlist; DROP TABLE IF EXISTS "wishlist";
DROP TABLE IF EXISTS sets; DROP TABLE IF EXISTS "sets";
DROP TABLE IF EXISTS inventory; DROP TABLE IF EXISTS "inventory";
DROP TABLE IF EXISTS minifigures; DROP TABLE IF EXISTS "minifigures";
DROP TABLE IF EXISTS missing; DROP TABLE IF EXISTS "missing";
COMMIT; COMMIT;

View File

@ -1,45 +1,45 @@
SELECT SELECT
sets.set_num, "sets"."set_num",
sets.name, "sets"."name",
sets.year, "sets"."year",
sets.theme_id, "sets"."theme_id",
sets.num_parts, "sets"."num_parts",
sets.set_img_url, "sets"."set_img_url",
sets.set_url, "sets"."set_url",
sets.last_modified_dt, "sets"."last_modified_dt",
sets.mini_col, "sets"."mini_col",
sets.set_check, "sets"."set_check",
sets.set_col, "sets"."set_col",
sets.u_id, "sets"."u_id",
{% block number %} {% block number %}
CAST(SUBSTR(sets.set_num, 1, INSTR(sets.set_num, '-') - 1) AS INTEGER) AS set_number, CAST(SUBSTR("sets"."set_num", 1, INSTR("sets"."set_num", '-') - 1) AS INTEGER) AS "set_number",
CAST(SUBSTR(sets.set_num, 1, INSTR(sets.set_num, '-') + 1) AS INTEGER) AS set_version, CAST(SUBSTR("sets"."set_num", 1, INSTR("sets"."set_num", '-') + 1) AS INTEGER) AS "set_version",
{% endblock %} {% endblock %}
IFNULL(missing_join.total, 0) AS total_missing, IFNULL("missing_join"."total", 0) AS "total_missing",
IFNULL(minifigures_join.total, 0) AS total_minifigures IFNULL("minifigures_join"."total", 0) AS "total_minifigures"
FROM sets FROM sets
-- LEFT JOIN + SELECT to avoid messing the total -- LEFT JOIN + SELECT to avoid messing the total
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
u_id, "missing"."u_id",
SUM(quantity) AS total SUM("missing"."quantity") AS "total"
FROM missing FROM "missing"
{% block where_missing %}{% endblock %} {% block where_missing %}{% endblock %}
GROUP BY u_id GROUP BY "u_id"
) missing_join ) "missing_join"
ON sets.u_id IS NOT DISTINCT FROM missing_join.u_id ON "sets"."u_id" IS NOT DISTINCT FROM "missing_join"."u_id"
-- LEFT JOIN + SELECT to avoid messing the total -- LEFT JOIN + SELECT to avoid messing the total
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
u_id, "minifigures"."u_id",
SUM(quantity) AS total SUM("minifigures"."quantity") AS "total"
FROM minifigures FROM "minifigures"
{% block where_minifigures %}{% endblock %} {% block where_minifigures %}{% endblock %}
GROUP BY u_id GROUP BY "u_id"
) minifigures_join ) "minifigures_join"
ON sets.u_id IS NOT DISTINCT FROM minifigures_join.u_id ON "sets"."u_id" IS NOT DISTINCT FROM "minifigures_join"."u_id"
{% block where %}{% endblock %} {% block where %}{% endblock %}

View File

@ -1,2 +1,2 @@
DELETE FROM sets DELETE FROM "sets"
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "sets"."u_id" IS NOT DISTINCT FROM :u_id

View File

@ -1,16 +1,16 @@
INSERT INTO sets ( INSERT INTO sets (
set_num, "set_num",
name, "name",
year, "year",
theme_id, "theme_id",
num_parts, "num_parts",
set_img_url, "set_img_url",
set_url, "set_url",
last_modified_dt, "last_modified_dt",
mini_col, "mini_col",
set_check, "set_check",
set_col, "set_col",
u_id "u_id"
) VALUES ( ) VALUES (
:set_num, :set_num,
:name, :name,

View File

@ -1,12 +1,12 @@
SELECT SELECT
sets.set_num, "sets"."set_num",
sets.name, "sets"."name",
sets.year, "sets"."year",
sets.theme_id, "sets"."theme_id",
sets.num_parts, "sets"."num_parts",
sets.set_img_url, "sets"."set_img_url",
sets.set_url "sets"."set_url"
FROM sets FROM "sets"
GROUP BY GROUP BY
sets.set_num "sets"."set_num"

View File

@ -1,13 +1,13 @@
{% extends 'set/base/select.sql' %} {% extends 'set/base/select.sql' %}
{% block where %} {% block where %}
WHERE sets.u_id IN ( WHERE "sets"."u_id" IN (
SELECT SELECT
missing.u_id "missing"."u_id"
FROM missing FROM "missing"
WHERE missing.set_num IS NOT DISTINCT FROM :fig_num WHERE "missing"."set_num" IS NOT DISTINCT FROM :fig_num
GROUP BY missing.u_id GROUP BY "missing"."u_id"
) )
{% endblock %} {% endblock %}

View File

@ -1,15 +1,15 @@
{% extends 'set/base/select.sql' %} {% extends 'set/base/select.sql' %}
{% block where %} {% block where %}
WHERE sets.u_id IN ( WHERE "sets"."u_id" IN (
SELECT SELECT
missing.u_id "missing"."u_id"
FROM missing FROM "missing"
WHERE missing.color_id IS NOT DISTINCT FROM :color_id WHERE "missing"."color_id" IS NOT DISTINCT FROM :color_id
AND missing.element_id IS NOT DISTINCT FROM :element_id AND "missing"."element_id" IS NOT DISTINCT FROM :element_id
AND missing.part_num IS NOT DISTINCT FROM :part_num AND "missing"."part_num" IS NOT DISTINCT FROM :part_num
GROUP BY missing.u_id GROUP BY "missing"."u_id"
) )
{% endblock %} {% endblock %}

View File

@ -1,13 +1,13 @@
{% extends 'set/base/select.sql' %} {% extends 'set/base/select.sql' %}
{% block where %} {% block where %}
WHERE sets.u_id IN ( WHERE "sets"."u_id" IN (
SELECT SELECT
inventory.u_id "inventory"."u_id"
FROM inventory FROM "inventory"
WHERE inventory.set_num IS NOT DISTINCT FROM :fig_num WHERE "inventory"."set_num" IS NOT DISTINCT FROM :fig_num
GROUP BY inventory.u_id GROUP BY "inventory"."u_id"
) )
{% endblock %} {% endblock %}

View File

@ -1,15 +1,15 @@
{% extends 'set/base/select.sql' %} {% extends 'set/base/select.sql' %}
{% block where %} {% block where %}
WHERE sets.u_id IN ( WHERE "sets"."u_id" IN (
SELECT SELECT
inventory.u_id "inventory"."u_id"
FROM inventory FROM "inventory"
WHERE inventory.color_id IS NOT DISTINCT FROM :color_id WHERE "inventory"."color_id" IS NOT DISTINCT FROM :color_id
AND inventory.element_id IS NOT DISTINCT FROM :element_id AND "inventory"."element_id" IS NOT DISTINCT FROM :element_id
AND inventory.part_num IS NOT DISTINCT FROM :part_num AND "inventory"."part_num" IS NOT DISTINCT FROM :part_num
GROUP BY inventory.u_id GROUP BY "inventory"."u_id"
) )
{% endblock %} {% endblock %}

View File

@ -1,13 +1,13 @@
{% extends 'set/base/select.sql' %} {% extends 'set/base/select.sql' %}
{% block where_missing %} {% block where_missing %}
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "missing"."u_id" IS NOT DISTINCT FROM :u_id
{% endblock %} {% endblock %}
{% block where_minifigures %} {% block where_minifigures %}
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "minifigures"."u_id" IS NOT DISTINCT FROM :u_id
{% endblock %} {% endblock %}
{% block where %} {% block where %}
WHERE sets.u_id IS NOT DISTINCT FROM :u_id WHERE "sets"."u_id" IS NOT DISTINCT FROM :u_id
{% endblock %} {% endblock %}

View File

@ -1,3 +1,3 @@
UPDATE sets UPDATE "sets"
SET {{name}} = :status SET "{{name}}" = :status
WHERE u_id IS NOT DISTINCT FROM :u_id WHERE "sets"."u_id" IS NOT DISTINCT FROM :u_id

View File

@ -1,13 +1,13 @@
SELECT SELECT
wishlist.set_num, "wishlist"."set_num",
wishlist.name, "wishlist"."name",
wishlist.year, "wishlist"."year",
wishlist.theme_id, "wishlist"."theme_id",
wishlist.num_parts, "wishlist"."num_parts",
wishlist.set_img_url, "wishlist"."set_img_url",
wishlist.set_url, "wishlist"."set_url",
wishlist.last_modified_dt "wishlist"."last_modified_dt"
FROM wishlist FROM "wishlist"
{% block where %}{% endblock %} {% block where %}{% endblock %}

View File

@ -1,2 +1,2 @@
DELETE FROM wishlist DELETE FROM "wishlist"
WHERE set_num IS NOT DISTINCT FROM :set_num WHERE "wishlist"."set_num" IS NOT DISTINCT FROM :set_num

View File

@ -1,12 +1,12 @@
INSERT INTO wishlist ( INSERT INTO "wishlist" (
set_num, "set_num",
name, "name",
year, "year",
theme_id, "theme_id",
num_parts, "num_parts",
set_img_url, "set_img_url",
set_url, "set_url",
last_modified_dt "last_modified_dt"
) VALUES ( ) VALUES (
:set_num, :set_num,
:name, :name,

View File

@ -1,5 +1,5 @@
{% extends 'wish/base/select.sql' %} {% extends 'wish/base/select.sql' %}
{% block where %} {% block where %}
WHERE wishlist.set_num IS NOT DISTINCT FROM :set_num WHERE "wishlist"."set_num" IS NOT DISTINCT FROM :set_num
{% endblock %} {% endblock %}