diff options
Diffstat (limited to 'lib/adverb_query.cpp')
-rw-r--r-- | lib/adverb_query.cpp | 103 |
1 files changed, 48 insertions, 55 deletions
diff --git a/lib/adverb_query.cpp b/lib/adverb_query.cpp index c9d0d09..30ba92b 100644 --- a/lib/adverb_query.cpp +++ b/lib/adverb_query.cpp | |||
@@ -172,6 +172,7 @@ namespace verbly { | |||
172 | std::stringstream construct; | 172 | std::stringstream construct; |
173 | construct << "SELECT adverb_id, base_form, comparative, superlative FROM adverbs"; | 173 | construct << "SELECT adverb_id, base_form, comparative, superlative FROM adverbs"; |
174 | std::list<std::string> conditions; | 174 | std::list<std::string> conditions; |
175 | std::list<binding> bindings; | ||
175 | 176 | ||
176 | if (_has_prn) | 177 | if (_has_prn) |
177 | { | 178 | { |
@@ -180,14 +181,20 @@ namespace verbly { | |||
180 | 181 | ||
181 | if (!_rhymes.empty()) | 182 | if (!_rhymes.empty()) |
182 | { | 183 | { |
183 | std::list<std::string> clauses(_rhymes.size(), "pronunciation LIKE @RHMPRN"); | 184 | std::list<std::string> clauses(_rhymes.size(), "pronunciation LIKE ?"); |
184 | std::string cond = "adverb_id IN (SELECT adverb_id FROM adverb_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | 185 | std::string cond = "adverb_id IN (SELECT adverb_id FROM adverb_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; |
185 | conditions.push_back(cond); | 186 | conditions.push_back(cond); |
187 | |||
188 | for (auto rhyme : _rhymes) | ||
189 | { | ||
190 | bindings.emplace_back("%" + rhyme); | ||
191 | } | ||
186 | } | 192 | } |
187 | 193 | ||
188 | for (auto except : _except) | 194 | for (auto except : _except) |
189 | { | 195 | { |
190 | conditions.push_back("adverb_id != @EXCID"); | 196 | conditions.push_back("adverb_id != ?"); |
197 | bindings.emplace_back(except._id); | ||
191 | } | 198 | } |
192 | 199 | ||
193 | if (_requires_comparative_form) | 200 | if (_requires_comparative_form) |
@@ -207,11 +214,13 @@ namespace verbly { | |||
207 | { | 214 | { |
208 | case filter<std::string>::type::singleton: | 215 | case filter<std::string>::type::singleton: |
209 | { | 216 | { |
217 | bindings.emplace_back(f.get_elem() + "%"); | ||
218 | |||
210 | if (notlogic == f.get_notlogic()) | 219 | if (notlogic == f.get_notlogic()) |
211 | { | 220 | { |
212 | return "base_form LIKE @PREFIX"; | 221 | return "base_form LIKE ?"; |
213 | } else { | 222 | } else { |
214 | return "base_form NOT LIKE @PREFIX"; | 223 | return "base_form NOT LIKE ?"; |
215 | } | 224 | } |
216 | } | 225 | } |
217 | 226 | ||
@@ -244,11 +253,13 @@ namespace verbly { | |||
244 | { | 253 | { |
245 | case filter<std::string>::type::singleton: | 254 | case filter<std::string>::type::singleton: |
246 | { | 255 | { |
256 | bindings.emplace_back("%" + f.get_elem()); | ||
257 | |||
247 | if (notlogic == f.get_notlogic()) | 258 | if (notlogic == f.get_notlogic()) |
248 | { | 259 | { |
249 | return "base_form LIKE @SUFFIX"; | 260 | return "base_form LIKE ?"; |
250 | } else { | 261 | } else { |
251 | return "base_form NOT LIKE @SUFFIX"; | 262 | return "base_form NOT LIKE ?"; |
252 | } | 263 | } |
253 | } | 264 | } |
254 | 265 | ||
@@ -276,7 +287,8 @@ namespace verbly { | |||
276 | 287 | ||
277 | if (_with_complexity != unlimited) | 288 | if (_with_complexity != unlimited) |
278 | { | 289 | { |
279 | conditions.push_back("complexity = @COMPLEX"); | 290 | conditions.push_back("complexity = ?"); |
291 | bindings.emplace_back(_with_complexity); | ||
280 | } | 292 | } |
281 | 293 | ||
282 | if (_has_antonyms) | 294 | if (_has_antonyms) |
@@ -301,11 +313,13 @@ namespace verbly { | |||
301 | { | 313 | { |
302 | case filter<adverb>::type::singleton: | 314 | case filter<adverb>::type::singleton: |
303 | { | 315 | { |
316 | bindings.emplace_back(f.get_elem()._id); | ||
317 | |||
304 | if (notlogic == f.get_notlogic()) | 318 | if (notlogic == f.get_notlogic()) |
305 | { | 319 | { |
306 | return "adverb_1_id = @ANTID"; | 320 | return "adverb_1_id = ?"; |
307 | } else { | 321 | } else { |
308 | return "adverb_1_id != @ANTID"; | 322 | return "adverb_1_id != ?"; |
309 | } | 323 | } |
310 | } | 324 | } |
311 | 325 | ||
@@ -355,11 +369,13 @@ namespace verbly { | |||
355 | { | 369 | { |
356 | case filter<adverb>::type::singleton: | 370 | case filter<adverb>::type::singleton: |
357 | { | 371 | { |
372 | bindings.emplace_back(f.get_elem()._id); | ||
373 | |||
358 | if (notlogic == f.get_notlogic()) | 374 | if (notlogic == f.get_notlogic()) |
359 | { | 375 | { |
360 | return "adverb_1_id = @SYNID"; | 376 | return "adverb_1_id = ?"; |
361 | } else { | 377 | } else { |
362 | return "adverb_1_id != @SYNID"; | 378 | return "adverb_1_id != ?"; |
363 | } | 379 | } |
364 | } | 380 | } |
365 | 381 | ||
@@ -409,11 +425,13 @@ namespace verbly { | |||
409 | { | 425 | { |
410 | case filter<adjective>::type::singleton: | 426 | case filter<adjective>::type::singleton: |
411 | { | 427 | { |
428 | bindings.emplace_back(f.get_elem()._id); | ||
429 | |||
412 | if (notlogic == f.get_notlogic()) | 430 | if (notlogic == f.get_notlogic()) |
413 | { | 431 | { |
414 | return "adjective_id = @AMANID"; | 432 | return "adjective_id = ?"; |
415 | } else { | 433 | } else { |
416 | return "adjective_id != @AMANID"; | 434 | return "adjective_id != ?"; |
417 | } | 435 | } |
418 | } | 436 | } |
419 | 437 | ||
@@ -506,54 +524,29 @@ namespace verbly { | |||
506 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | 524 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); |
507 | } | 525 | } |
508 | 526 | ||
509 | if (!_rhymes.empty()) | 527 | int i = 1; |
528 | for (auto& binding : bindings) | ||
510 | { | 529 | { |
511 | int i = 0; | 530 | switch (binding.get_type()) |
512 | for (auto rhyme : _rhymes) | ||
513 | { | 531 | { |
514 | std::string rhymer = "%" + rhyme; | 532 | case binding::type::integer: |
515 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@RHMPRN"), rhymer.c_str(), rhymer.length(), SQLITE_STATIC); | 533 | { |
534 | sqlite3_bind_int(ppstmt, i, binding.get_integer()); | ||
535 | |||
536 | break; | ||
537 | } | ||
516 | 538 | ||
517 | i++; | 539 | case binding::type::string: |
540 | { | ||
541 | sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_STATIC); | ||
542 | |||
543 | break; | ||
544 | } | ||
518 | } | 545 | } |
546 | |||
547 | i++; | ||
519 | } | 548 | } |
520 | 549 | ||
521 | for (auto except : _except) | ||
522 | { | ||
523 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@EXCID"), except._id); | ||
524 | } | ||
525 | |||
526 | for (auto prefix : _with_prefix.inorder_flatten()) | ||
527 | { | ||
528 | std::string pfat = prefix + "%"; | ||
529 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@PREFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC); | ||
530 | } | ||
531 | |||
532 | for (auto suffix : _with_suffix.inorder_flatten()) | ||
533 | { | ||
534 | std::string pfat = "%" + suffix; | ||
535 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SUFFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC); | ||
536 | } | ||
537 | |||
538 | if (_with_complexity != unlimited) | ||
539 | { | ||
540 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@COMPLEX"), _with_complexity); | ||
541 | } | ||
542 | |||
543 | for (auto antonym : _antonym_of.inorder_flatten()) | ||
544 | { | ||
545 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@ANTID"), antonym._id); | ||
546 | } | ||
547 | |||
548 | for (auto synonym : _synonym_of.inorder_flatten()) | ||
549 | { | ||
550 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SYNID"), synonym._id); | ||
551 | } | ||
552 | |||
553 | for (auto adj : _mannernym_of.inorder_flatten()) | ||
554 | { | ||
555 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@AMANID"), adj._id); | ||
556 | } | ||
557 | /* | 550 | /* |
558 | for (auto adj : _derived_from_adjective) | 551 | for (auto adj : _derived_from_adjective) |
559 | { | 552 | { |