|
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') |
2 | 2 | --'/~/SQLiteEx/tcl/pkgs/thread2.8.7/tcl'
|
3 | 3 |
|
4 | 4 | WITH
|
@@ -1251,16 +1251,7 @@ SELECT * FROM terms;</sql><sql name="SQL 29">WITH
|
1251 | 1251 | FROM json_object_data AS jd, json_tree(jd.json_str) AS json_terms
|
1252 | 1252 | WHERE json_terms.parent IS NOT NULL
|
1253 | 1253 | )
|
1254 |
| -SELECT * FROM string_data;</sql><sql name="SQL 30">WITH |
1255 |
| - prefixes(ascii_id, prefix_json) AS (VALUES |
1256 |
| - ('0FDAF2C8', '["afc2e40a","40CF97B4","82A35587"]'), |
1257 |
| - ('BE0A8514', '["afc2e40a","40CF97B4","704BA7F4","F4CE4D5B","F5A2A524"]') |
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 |
1264 | 1255 | ids AS (SELECT value AS id FROM json_each('["BE0A8514", "0FDAF2C8"]')),
|
1265 | 1256 | node_rows AS (SELECT ascii_id, name, trim(prefix, '/') AS prefix FROM categories WHERE ascii_id IN ids),
|
1266 | 1257 | node_jsons AS (SELECT *, json('["' || replace(prefix, '/', '", "') || '"]') AS prefix_json FROM node_rows),
|
@@ -1649,7 +1640,7 @@ SELECT * FROM base_ops;
|
1649 | 1640 | SELECT bin_id AS id, asc_name AS name, asc_prefix AS prefix
|
1650 | 1641 | FROM path_terms, ids USING (counter)
|
1651 | 1642 | )
|
1652 |
| ---INSERT INTO categories (id, name, prefix) |
| 1643 | +INSERT INTO categories (id, name, prefix) |
1653 | 1644 | SELECT * FROM new_nodes;</sql><sql name="SQL 41">WITH
|
1654 | 1645 | json_nodes(ids) AS (
|
1655 | 1646 | VALUES
|
@@ -1709,7 +1700,107 @@ SELECT * FROM ancestors;</sql><sql name="SQL 42">WITH
|
1709 | 1700 | ORDER BY id, asc_path
|
1710 | 1701 | )
|
1711 | 1702 | 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 | + ('["tcl/compat/zlib1/", "tcl/pkgs/thread2.8.7/tcl/cmdsrv/"]') |
| 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('{"' || replace(rtrim(prefix, '/'), '/', '": {"') || |
| 1720 | + '":""' || 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("key", '^#^', '.') 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 | + '{"op":"delete", "path_old":"tcl/compat/zlib1/"},' || |
| 1738 | + '{"op":"delete", "path_old":"BAZ/dev/git4win/x32/mingw32/share/"}' || |
| 1739 | + ']' |
| 1740 | + )) |
| 1741 | + ), |
| 1742 | + base_ops AS ( |
| 1743 | + SELECT |
| 1744 | + "key" + 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 | + '{"op":"delete", "path_old":"tcl/compat/zlib1/"},' || |
| 1760 | + '{"op":"delete", "path_old":"BAZ/dev/git4win/x32/mingw32/share/"}' || |
| 1761 | + ']' |
| 1762 | + )) |
| 1763 | + ), |
| 1764 | + base_ops AS ( |
| 1765 | + SELECT |
| 1766 | + "key" + 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 "DELETE_TARGETS"; |
| 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 | + '{"op":"delete", "path_old":"tcl/compat/zlib1/"},' || |
| 1784 | + '{"op":"delete", "path_old":"BAZ/dev/git4win/x32/mingw32/share/"}' || |
| 1785 | + ']' |
| 1786 | + )) |
| 1787 | + ), |
| 1788 | + base_ops AS ( |
| 1789 | + SELECT |
| 1790 | + "key" + 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 "DELETE_TARGETS"; |
| 1806 | +</sql><sql name="&Foreign-Key Check">PRAGMA foreign_key_check;</sql><current_tab id="38"/></tab_sql></sqlb_project> |
|
0 commit comments