Skip to content

Commit cddde47

Browse files
committed
Mock DB
1 parent 02244aa commit cddde47

File tree

2 files changed

+107
-16
lines changed

2 files changed

+107
-16
lines changed

Assets/database/Materialized Paths.db

0 Bytes
Binary file not shown.

Assets/database/Materialized Paths.sqbpro

Lines changed: 107 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="G:/Projects/GitHub/SQLite-SQL-Tutorial/Assets/database/Materialized Paths.db" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="1"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="5633"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,10:maincategories"/><default_encoding codec=""/><browse_table_settings><table schema="main" name="categories" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk="_rowid_"><sort/><column_widths><column index="1" value="140"/><column index="2" value="69"/><column index="3" value="221"/><column index="4" value="300"/><column index="5" value="300"/></column_widths><filter_values/><conditional_formats/><row_id_formats/><display_formats/><hidden_columns/><plot_y_axes/><global_filter/></table></browse_table_settings></tab_browse><tab_sql><sql name="SQL 30">--('BE0A8514'), ('0FDAF2C8'), ('65887f45')
1+
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="G:/Projects/GitHub/SQLite-SQL-Tutorial/Assets/database/Materialized Paths.db" readonly="0" foreign_keys="0" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="1"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="5633"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,10:maincategories"/><default_encoding codec=""/><browse_table_settings><table schema="main" name="categories" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk="_rowid_"><sort/><column_widths><column index="1" value="140"/><column index="2" value="69"/><column index="3" value="221"/><column index="4" value="300"/><column index="5" value="402"/></column_widths><filter_values><column index="5" value="~Trash/tcl/compat/zlib1/"/></filter_values><conditional_formats/><row_id_formats/><display_formats/><hidden_columns/><plot_y_axes/><global_filter/></table><table schema="main" name="files_categories" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk="_rowid_"><sort/><column_widths><column index="1" value="300"/><column index="2" value="81"/></column_widths><filter_values><column index="1" value="tcl/compat/zlib1/"/></filter_values><conditional_formats/><row_id_formats/><display_formats/><hidden_columns/><plot_y_axes/><global_filter/></table></browse_table_settings></tab_browse><tab_sql><sql name="SQL 30">--('BE0A8514'), ('0FDAF2C8'), ('65887f45')
22
--'/~/SQLiteEx/tcl/pkgs/thread2.8.7/tcl'
33

44
WITH
@@ -1251,16 +1251,7 @@ SELECT * FROM terms;</sql><sql name="SQL 29">WITH
12511251
FROM json_object_data AS jd, json_tree(jd.json_str) AS json_terms
12521252
WHERE json_terms.parent IS NOT NULL
12531253
)
1254-
SELECT * FROM string_data;</sql><sql name="SQL 30">WITH
1255-
prefixes(ascii_id, prefix_json) AS (VALUES
1256-
('0FDAF2C8', '[&quot;afc2e40a&quot;,&quot;40CF97B4&quot;,&quot;82A35587&quot;]'),
1257-
('BE0A8514', '[&quot;afc2e40a&quot;,&quot;40CF97B4&quot;,&quot;704BA7F4&quot;,&quot;F4CE4D5B&quot;,&quot;F5A2A524&quot;]')
1258-
),
1259-
ancestors AS (
1260-
SELECT ascii_id, ancestor_ids.id AS ancestor_level, ancestor_ids.value AS ancestor_id
1261-
FROM prefixes, json_each(prefixes.prefix_json) AS ancestor_ids
1262-
)
1263-
SELECT * FROM ancestors;</sql><sql name="SQL 31">WITH
1254+
SELECT * FROM string_data;</sql><sql name="SQL 31">WITH
12641255
ids AS (SELECT value AS id FROM json_each('[&quot;BE0A8514&quot;, &quot;0FDAF2C8&quot;]')),
12651256
node_rows AS (SELECT ascii_id, name, trim(prefix, '/') AS prefix FROM categories WHERE ascii_id IN ids),
12661257
node_jsons AS (SELECT *, json('[&quot;' || replace(prefix, '/', '&quot;, &quot;') || '&quot;]') AS prefix_json FROM node_rows),
@@ -1649,7 +1640,7 @@ SELECT * FROM base_ops;
16491640
SELECT bin_id AS id, asc_name AS name, asc_prefix AS prefix
16501641
FROM path_terms, ids USING (counter)
16511642
)
1652-
--INSERT INTO categories (id, name, prefix)
1643+
INSERT INTO categories (id, name, prefix)
16531644
SELECT * FROM new_nodes;</sql><sql name="SQL 41">WITH
16541645
json_nodes(ids) AS (
16551646
VALUES
@@ -1709,7 +1700,107 @@ SELECT * FROM ancestors;</sql><sql name="SQL 42">WITH
17091700
ORDER BY id, asc_path
17101701
)
17111702
SELECT * FROM ancestors;
1712-
</sql><sql name="SQL 44">SELECT cats.*
1713-
FROM categories AS cats
1714-
LEFT JOIN categories AS parents
1715-
ON cats.prefix = parents.path</sql><current_tab id="34"/></tab_sql></sqlb_project>
1703+
</sql><sql name="SQL 44">WITH
1704+
json_nodes(ids) AS (
1705+
VALUES
1706+
('[&quot;tcl/compat/zlib1/&quot;, &quot;tcl/pkgs/thread2.8.7/tcl/cmdsrv/&quot;]')
1707+
),
1708+
nodes AS (
1709+
SELECT node_ids.value AS node_id
1710+
FROM json_nodes AS jn, json_each(jn.ids) AS node_ids
1711+
),
1712+
tops AS (SELECT node_id AS path FROM nodes),
1713+
prefixes AS (
1714+
SELECT ascii_id, prefix,
1715+
length(prefix) - length(replace(prefix, '/', '')) AS depth
1716+
FROM categories WHERE path IN tops
1717+
),
1718+
json_prefixes AS (
1719+
SELECT *, json('{&quot;' || replace(rtrim(prefix, '/'), '/', '&quot;: {&quot;') ||
1720+
'&quot;:&quot;&quot;' || replace(hex(zeroblob(depth)), '00', '}')) AS prefix_json
1721+
FROM prefixes
1722+
),
1723+
ancestors AS (
1724+
SELECT ascii_id,
1725+
replace(replace(substr(fullkey, 3), '.', '/'), '^#^', '.') || '/' AS asc_path,
1726+
replace(&quot;key&quot;, '^#^', '.') AS asc_name
1727+
FROM
1728+
json_prefixes AS jp,
1729+
json_tree(replace(jp.prefix_json, '.', '^#^')) AS prefixes
1730+
WHERE prefixes.parent IS NOT NULL
1731+
)
1732+
SELECT * FROM ancestors;</sql><sql name="SQL 30">WITH
1733+
json_ops(ops) AS (
1734+
VALUES
1735+
(json(
1736+
'[' ||
1737+
'{&quot;op&quot;:&quot;delete&quot;, &quot;path_old&quot;:&quot;tcl/compat/zlib1/&quot;},' ||
1738+
'{&quot;op&quot;:&quot;delete&quot;, &quot;path_old&quot;:&quot;BAZ/dev/git4win/x32/mingw32/share/&quot;}' ||
1739+
']'
1740+
))
1741+
),
1742+
base_ops AS (
1743+
SELECT
1744+
&quot;key&quot; + 1 AS opid,
1745+
json_extract(value, '$.op') AS op,
1746+
json_extract(value, '$.path_old') AS path_old,
1747+
json_extract(value, '$.path_new') AS path_new
1748+
FROM json_ops AS jo, json_each(jo.ops) AS terms
1749+
),
1750+
targets AS (SELECT cat_id FROM files_categories, base_ops WHERE cat_id like path_old || '%')
1751+
DELETE FROM files_categories WHERE cat_id IN targets;
1752+
1753+
1754+
WITH
1755+
json_ops(ops) AS (
1756+
VALUES
1757+
(json(
1758+
'[' ||
1759+
'{&quot;op&quot;:&quot;delete&quot;, &quot;path_old&quot;:&quot;tcl/compat/zlib1/&quot;},' ||
1760+
'{&quot;op&quot;:&quot;delete&quot;, &quot;path_old&quot;:&quot;BAZ/dev/git4win/x32/mingw32/share/&quot;}' ||
1761+
']'
1762+
))
1763+
),
1764+
base_ops AS (
1765+
SELECT
1766+
&quot;key&quot; + 1 AS opid,
1767+
json_extract(value, '$.op') AS op,
1768+
json_extract(value, '$.path_old') AS path_old,
1769+
json_extract(value, '$.path_new') AS path_new
1770+
FROM json_ops AS jo, json_each(jo.ops) AS terms
1771+
),
1772+
targets AS (SELECT path FROM categories, base_ops WHERE path like path_old || '%')
1773+
DELETE FROM categories WHERE path IN targets;
1774+
</sql><sql name="SQL 48">--SAVEPOINT &quot;DELETE_TARGETS&quot;;
1775+
DROP VIEW IF EXISTS delete_targets;
1776+
1777+
CREATE VIEW delete_targets AS
1778+
WITH
1779+
json_ops(ops) AS (
1780+
VALUES
1781+
(json(
1782+
'[' ||
1783+
'{&quot;op&quot;:&quot;delete&quot;, &quot;path_old&quot;:&quot;tcl/compat/zlib1/&quot;},' ||
1784+
'{&quot;op&quot;:&quot;delete&quot;, &quot;path_old&quot;:&quot;BAZ/dev/git4win/x32/mingw32/share/&quot;}' ||
1785+
']'
1786+
))
1787+
),
1788+
base_ops AS (
1789+
SELECT
1790+
&quot;key&quot; + 1 AS opid,
1791+
json_extract(value, '$.op') AS op,
1792+
json_extract(value, '$.path_old') AS path_old,
1793+
json_extract(value, '$.path_new') AS path_new
1794+
FROM json_ops AS jo, json_each(jo.ops) AS terms
1795+
)
1796+
SELECT path FROM categories, base_ops WHERE path like path_old || '%' ORDER BY path DESC;
1797+
1798+
DELETE FROM files_categories WHERE cat_id IN delete_targets;
1799+
1800+
UPDATE categories
1801+
SET (name, prefix) = (name || '~' || ascii_id, '~Trash/' || prefix)
1802+
WHERE path IN delete_targets;
1803+
1804+
DROP VIEW delete_targets;
1805+
--RELEASE &quot;DELETE_TARGETS&quot;;
1806+
</sql><sql name="&amp;Foreign-Key Check">PRAGMA foreign_key_check;</sql><current_tab id="38"/></tab_sql></sqlb_project>

0 commit comments

Comments
 (0)