diff options
Diffstat (limited to 'lib/verb_query.cpp')
-rw-r--r-- | lib/verb_query.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/verb_query.cpp b/lib/verb_query.cpp index 173a04e..929ecc7 100644 --- a/lib/verb_query.cpp +++ b/lib/verb_query.cpp | |||
@@ -65,6 +65,7 @@ namespace verbly { | |||
65 | std::stringstream construct; | 65 | std::stringstream construct; |
66 | construct << "SELECT verb_id, infinitive, past_tense, past_participle, ing_form, s_form FROM verbs"; | 66 | construct << "SELECT verb_id, infinitive, past_tense, past_participle, ing_form, s_form FROM verbs"; |
67 | std::list<std::string> conditions; | 67 | std::list<std::string> conditions; |
68 | std::list<binding> bindings; | ||
68 | 69 | ||
69 | if (_has_prn) | 70 | if (_has_prn) |
70 | { | 71 | { |
@@ -73,14 +74,20 @@ namespace verbly { | |||
73 | 74 | ||
74 | if (!_rhymes.empty()) | 75 | if (!_rhymes.empty()) |
75 | { | 76 | { |
76 | std::list<std::string> clauses(_rhymes.size(), "pronunciation LIKE @RHMPRN"); | 77 | std::list<std::string> clauses(_rhymes.size(), "pronunciation LIKE ?"); |
77 | std::string cond = "verb_id IN (SELECT verb_id FROM verb_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | 78 | std::string cond = "verb_id IN (SELECT verb_id FROM verb_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; |
78 | conditions.push_back(cond); | 79 | conditions.push_back(cond); |
80 | |||
81 | for (auto rhyme : _rhymes) | ||
82 | { | ||
83 | bindings.emplace_back("%" + rhyme); | ||
84 | } | ||
79 | } | 85 | } |
80 | 86 | ||
81 | for (auto except : _except) | 87 | for (auto except : _except) |
82 | { | 88 | { |
83 | conditions.push_back("verb_id != @EXCID"); | 89 | conditions.push_back("verb_id != ?"); |
90 | bindings.emplace_back(except._id); | ||
84 | } | 91 | } |
85 | 92 | ||
86 | if (!_has_frames) | 93 | if (!_has_frames) |
@@ -111,21 +118,27 @@ namespace verbly { | |||
111 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | 118 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); |
112 | } | 119 | } |
113 | 120 | ||
114 | if (!_rhymes.empty()) | 121 | int i = 1; |
122 | for (auto& binding : bindings) | ||
115 | { | 123 | { |
116 | int i = 0; | 124 | switch (binding.get_type()) |
117 | for (auto rhyme : _rhymes) | ||
118 | { | 125 | { |
119 | std::string rhymer = "%" + rhyme; | 126 | case binding::type::integer: |
120 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@RHMPRN"), rhymer.c_str(), rhymer.length(), SQLITE_STATIC); | 127 | { |
128 | sqlite3_bind_int(ppstmt, i, binding.get_integer()); | ||
129 | |||
130 | break; | ||
131 | } | ||
121 | 132 | ||
122 | i++; | 133 | case binding::type::string: |
134 | { | ||
135 | sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_STATIC); | ||
136 | |||
137 | break; | ||
138 | } | ||
123 | } | 139 | } |
124 | } | 140 | |
125 | 141 | i++; | |
126 | for (auto except : _except) | ||
127 | { | ||
128 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@EXCID"), except._id); | ||
129 | } | 142 | } |
130 | 143 | ||
131 | std::list<verb> output; | 144 | std::list<verb> output; |