aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sisudoc/outputs/io_out
diff options
context:
space:
mode:
Diffstat (limited to 'src/sisudoc/outputs/io_out')
-rw-r--r--src/sisudoc/outputs/io_out/sqlite_ocda_db.d52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/sisudoc/outputs/io_out/sqlite_ocda_db.d b/src/sisudoc/outputs/io_out/sqlite_ocda_db.d
index 998c317..aa91e89 100644
--- a/src/sisudoc/outputs/io_out/sqlite_ocda_db.d
+++ b/src/sisudoc/outputs/io_out/sqlite_ocda_db.d
@@ -78,7 +78,7 @@ template spineAbstractionDb() {
pod/<doc>/ the source tree
pod/<doc>.zip the same, zipped
pod/<doc>.digests.txt what is in them
- pod/<uid>.ocda.db the abstraction, one per language
+ pod/<doc>.ocda.db the abstraction, every language of it
+/
auto pths_pod = spinePathsPods!()(doc_matters);
string base_pth = pths_pod.pod_dir_();
@@ -752,3 +752,53 @@ template spineAbstractionDb() {
db.run("COMMIT TRANSACTION");
}
}
+/+ ↓ a metadata row for one language of a database, written after the fact.
+ .
+ For the one thing a language cannot know while it is being written: how
+ it compares with its siblings. The ocn alignment check can only run when
+ every language of a document has been abstracted, which is after this
+ database has been written, so the outcome is noted here in a pass of its
+ own rather than held for by the writer.
+ .
+ A row that is about the artefact and not in the .ssp, as source.ssp_digest
+ already is. It is INSERT OR REPLACE against UNIQUE(doc_id, key), so a
+ second run over the same file restates rather than accumulates.
+ .
+ Its own template: writing one row should not instantiate the writer.
++/
+template spineOcdaDbDocNote() {
+ @trusted void spineOcdaDbDocNote(
+ string db_file,
+ string lang,
+ string key,
+ string value,
+ ) {
+ import std.file : exists;
+ import d2sqlite3;
+ if (db_file.length == 0 || !db_file.exists) { return; }
+ try {
+ auto db = Database(db_file);
+ long _doc_id = -1;
+ {
+ auto _q = db.prepare("SELECT id FROM documents WHERE lang = :lang");
+ _q.bind(":lang", lang);
+ foreach (row; _q.execute()) { _doc_id = row["id"].as!long; }
+ _q.finalize();
+ }
+ if (_doc_id < 0) { return; }
+ auto _s = db.prepare(
+ "INSERT OR REPLACE INTO metadata (doc_id, key, value)"
+ ~ " VALUES (:doc_id, :key, :value)"
+ );
+ _s.bind(":doc_id", _doc_id);
+ _s.bind(":key", key);
+ _s.bind(":value", value);
+ _s.execute();
+ _s.finalize();
+ } catch (Exception ex) {
+ import std.stdio : stderr;
+ stderr.writeln("WARNING: could not note ", key, " in ", db_file,
+ ": ", ex.msg);
+ }
+ }
+}