aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/in_abstraction_artefacts.org
diff options
context:
space:
mode:
Diffstat (limited to 'org/in_abstraction_artefacts.org')
-rw-r--r--org/in_abstraction_artefacts.org43
1 files changed, 35 insertions, 8 deletions
diff --git a/org/in_abstraction_artefacts.org b/org/in_abstraction_artefacts.org
index 9da6d32..c2b4c7a 100644
--- a/org/in_abstraction_artefacts.org
+++ b/org/in_abstraction_artefacts.org
@@ -659,16 +659,41 @@ template spineAbstractionDbRead() {
default: return "";
}
}
- @trusted SSPdocument dbReadFile(string db_file) {
+ @trusted SSPdocument dbReadFile(string db_file, string _lang = "") {
SSPdocument doc;
if (!db_file.exists) {
writeln("ERROR: no such file: ", db_file);
return doc;
}
auto db = Database(db_file, SQLITE_OPEN_READONLY);
+ /+ ↓ which document in the file. A file holds one per language; with
+ no language named, take the only one, and say so if there is a
+ choice to be made rather than picking for the caller.
+ +/
+ long _doc_id = -1;
+ {
+ string[] _langs;
+ foreach (row; db.execute("SELECT id, lang FROM documents ORDER BY id")) {
+ string _l = row["lang"].as!string;
+ _langs ~= _l;
+ if (_lang.length > 0 && _l == _lang) { _doc_id = row["id"].as!long; }
+ else if (_lang.length == 0 && _doc_id < 0) { _doc_id = row["id"].as!long; }
+ }
+ if (_doc_id < 0) {
+ writeln("ERROR: ", db_file, " holds no document in '", _lang,
+ "'; it has: ", _langs.join(" "));
+ return doc;
+ }
+ if (_lang.length == 0 && _langs.length > 1) {
+ writeln("ERROR: ", db_file, " holds ", _langs.length,
+ " languages and none was named: ", _langs.join(" "));
+ return doc;
+ }
+ }
/+ ↓ the four header blocks, from the metadata table. the key prefix
says which block a row belongs to, and insertion order is kept +/
- foreach (row; db.execute("SELECT key, value FROM metadata ORDER BY rowid")) {
+ foreach (row; db.execute("SELECT key, value FROM metadata WHERE doc_id = " ~ _doc_id.to!string
+ ~ " OR doc_id IS NULL ORDER BY rowid")) {
string _k = row["key"].as!string;
string _v = row["value"].as!string;
if (_k.startsWith("make.")) {
@@ -717,7 +742,7 @@ template spineAbstractionDbRead() {
string[][long] _subtoc_by_id;
foreach (r; db.execute(
"SELECT object_id, name, bytes, sha256, width, height, missing"
- ~ " FROM object_images ORDER BY object_id, seq")
+ ~ " FROM object_images WHERE object_id IN (SELECT id FROM objects WHERE doc_id = " ~ _doc_id.to!string ~ ") ORDER BY object_id, seq")
) {
ST_file_name_hash_size_ _img;
_img.fileName = r["name"].as!string;
@@ -729,18 +754,19 @@ template spineAbstractionDbRead() {
_images_by_id[r["object_id"].as!long] ~= _img;
}
foreach (r; db.execute(
- "SELECT object_id, url FROM object_links ORDER BY object_id, seq")
+ "SELECT object_id, url FROM object_links WHERE object_id IN (SELECT id FROM objects WHERE doc_id = " ~ _doc_id.to!string ~ ") ORDER BY object_id, seq")
) { _links_by_id[r["object_id"].as!long] ~= r["url"].as!string; }
foreach (r; db.execute(
- "SELECT object_id, anchor FROM object_anchors ORDER BY object_id, seq")
+ "SELECT object_id, anchor FROM object_anchors WHERE object_id IN (SELECT id FROM objects WHERE doc_id = " ~ _doc_id.to!string ~ ") ORDER BY object_id, seq")
) { _anchors_by_id[r["object_id"].as!long] ~= r["anchor"].as!string; }
foreach (r; db.execute(
- "SELECT object_id, entry FROM object_subtoc ORDER BY object_id, seq")
+ "SELECT object_id, entry FROM object_subtoc WHERE object_id IN (SELECT id FROM objects WHERE doc_id = " ~ _doc_id.to!string ~ ") ORDER BY object_id, seq")
) { _subtoc_by_id[r["object_id"].as!long] ~= r["entry"].as!string; }
/+ ↓ the objects, section by section, in the order they were written +/
string[] _sections;
foreach (row; db.execute(
- "SELECT section FROM objects GROUP BY section ORDER BY MIN(id)")
+ "SELECT section FROM objects WHERE doc_id = " ~ _doc_id.to!string
+ ~ " GROUP BY section ORDER BY MIN(id)")
) {
_sections ~= row["section"].as!string;
}
@@ -758,7 +784,8 @@ template spineAbstractionDbRead() {
+/
int[string] _col;
foreach (row; db.execute(
- "SELECT * FROM objects WHERE section = '" ~ section ~ "' ORDER BY seq")
+ "SELECT * FROM objects WHERE doc_id = " ~ _doc_id.to!string
+ ~ " AND section = '" ~ section ~ "' ORDER BY seq")
) {
if (_col.length == 0) {
foreach (_i; 0 .. row.length) { _col[row.columnName(_i)] = _i.to!int; }