From e5d8d42eae6ce486678d87e33c1a7c26e2a6c1a1 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 15 Feb 2023 10:01:00 -0500 Subject: Added antogram and antophone querying --- lib/field.h | 18 +++++++++++++----- lib/form.cpp | 1 + lib/form.h | 1 + lib/pronunciation.cpp | 1 + lib/pronunciation.h | 1 + lib/statement.cpp | 4 ++-- 6 files changed, 19 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/field.h b/lib/field.h index f799900..93dab97 100644 --- a/lib/field.h +++ b/lib/field.h @@ -85,7 +85,7 @@ namespace verbly { object joinWith, bool nullable = false) { - return field(obj, type::join, name, nullable, 0, joinWith); + return field(obj, type::join, name, nullable, 0, joinWith, name); } static field joinField( @@ -94,7 +94,7 @@ namespace verbly { const char* table, bool nullable = false) { - return field(obj, type::join, name, nullable, table); + return field(obj, type::join, name, nullable, table, obj, name); } static field joinWhere( @@ -105,7 +105,7 @@ namespace verbly { int conditionValue, bool nullable = false) { - return field(obj, type::join_where, name, nullable, 0, joinWith, 0, 0, 0, conditionColumn, conditionValue); + return field(obj, type::join_where, name, nullable, 0, joinWith, name, 0, 0, conditionColumn, conditionValue); } static field joinThrough( @@ -153,6 +153,14 @@ namespace verbly { return field(obj, type::join_through, name, true, joinTable, obj, name, joinColumn, foreignJoinColumn); } + static field selfJoin( + object obj, + const char* name, + const char* foreignColumn) + { + return field(obj, type::join, name, true, 0, obj, foreignColumn); + } + static field hierarchalSelfJoin( object obj, const char* name, @@ -220,9 +228,9 @@ namespace verbly { const char* getForeignColumn() const { // We ignore hierarchal joins because they are always self joins. - return ((type_ == type::join_through) || (type_ == type::join_through_where)) + return ((type_ == type::join) || (type_ == type::join_through) || (type_ == type::join_through_where)) ? foreignColumn_ - : throw std::domain_error("Only many-to-many join fields have a foreign column"); + : throw std::domain_error("Only join fields have a foreign column"); } const char* getJoinColumn() const diff --git a/lib/form.cpp b/lib/form.cpp index 18b495d..eeb940a 100644 --- a/lib/form.cpp +++ b/lib/form.cpp @@ -20,6 +20,7 @@ namespace verbly { const field form::pronunciations = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id"); const field form::anagrams = field::joinField(object::form, "anagram_set_id", object::form); + const field form::antogram = field::selfJoin(object::form, "reverse_form_id", "form_id"); const field form::merographs = field::selfJoin(object::form, "form_id", "merography", "merograph_id", "holograph_id"); const field form::holographs = field::selfJoin(object::form, "form_id", "merography", "holograph_id", "merograph_id"); diff --git a/lib/form.h b/lib/form.h index fb6b733..8ac6a02 100644 --- a/lib/form.h +++ b/lib/form.h @@ -163,6 +163,7 @@ namespace verbly { static const field pronunciations; static const field anagrams; + static const field antogram; static const field merographs; static const field holographs; diff --git a/lib/pronunciation.cpp b/lib/pronunciation.cpp index b039da8..8bf34fd 100644 --- a/lib/pronunciation.cpp +++ b/lib/pronunciation.cpp @@ -19,6 +19,7 @@ namespace verbly { const field pronunciation::rhyme = field::stringField(object::pronunciation, "rhyme", true); const field pronunciation::anaphones = field::joinField(object::pronunciation, "anaphone_set_id", object::pronunciation); + const field pronunciation::antophone = field::selfJoin(object::pronunciation, "reverse_pronunciation_id", "pronunciation_id"); const field pronunciation::merophones = field::selfJoin(object::pronunciation, "pronunciation_id", "merophony", "merophone_id", "holophone_id"); const field pronunciation::holophones = field::selfJoin(object::pronunciation, "pronunciation_id", "merophony", "holophone_id", "merophone_id"); diff --git a/lib/pronunciation.h b/lib/pronunciation.h index 210d61d..b3625bd 100644 --- a/lib/pronunciation.h +++ b/lib/pronunciation.h @@ -149,6 +149,7 @@ namespace verbly { static const field forms; static const field anaphones; + static const field antophone; static const field merophones; static const field holophones; diff --git a/lib/statement.cpp b/lib/statement.cpp index 6e9e920..eb734dd 100644 --- a/lib/statement.cpp +++ b/lib/statement.cpp @@ -420,7 +420,7 @@ namespace verbly { topTable_, clause.getField().getColumn(), withInstName, - clause.getField().getColumn()); + clause.getField().getForeignColumn()); // All CTEs have to be in the main statement, so integrate any // CTEs that our subquery uses. Also, retrieve the table mapping, @@ -450,7 +450,7 @@ namespace verbly { topTable_, clause.getField().getColumn(), std::move(joinTable), - clause.getField().getColumn()); + clause.getField().getForeignColumn()); // Integrate the subquery's table mappings, joins, and CTEs into // this statement, and return the subquery condition as our -- cgit 1.4.1