diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-02 22:45:11 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-02 22:45:11 -0400 |
| commit | bd398509575af0362e53ce6b805eaa210406b9fd (patch) | |
| tree | e699624ca6934f591241d5dfa95a91b839ce6bc7 /lib/preposition.cpp | |
| parent | 499dbc410174602a5985bd75b600fbec5cd086f1 (diff) | |
| parent | 965a3206df834f846f2c560438c80a707dcee4cb (diff) | |
| download | verbly-bd398509575af0362e53ce6b805eaa210406b9fd.tar.gz verbly-bd398509575af0362e53ce6b805eaa210406b9fd.tar.bz2 verbly-bd398509575af0362e53ce6b805eaa210406b9fd.zip | |
Merge branch 'master' of https://github.com/hatkirby/verbly
Diffstat (limited to 'lib/preposition.cpp')
| -rw-r--r-- | lib/preposition.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
| diff --git a/lib/preposition.cpp b/lib/preposition.cpp index c619bbf..cea9165 100644 --- a/lib/preposition.cpp +++ b/lib/preposition.cpp | |||
| @@ -37,13 +37,19 @@ namespace verbly { | |||
| 37 | { | 37 | { |
| 38 | std::stringstream construct; | 38 | std::stringstream construct; |
| 39 | construct << "SELECT form FROM prepositions"; | 39 | construct << "SELECT form FROM prepositions"; |
| 40 | std::list<binding> bindings; | ||
| 40 | 41 | ||
| 41 | if (!_in_group.empty()) | 42 | if (!_in_group.empty()) |
| 42 | { | 43 | { |
| 43 | std::list<std::string> clauses(_in_group.size(), "groupname = @GNAME"); | 44 | std::list<std::string> clauses(_in_group.size(), "groupname = ?"); |
| 44 | construct << " WHERE preposition_id IN (SELECT preposition_id FROM preposition_groups WHERE "; | 45 | construct << " WHERE preposition_id IN (SELECT preposition_id FROM preposition_groups WHERE "; |
| 45 | construct << verbly::implode(std::begin(clauses), std::end(clauses), " OR "); | 46 | construct << verbly::implode(std::begin(clauses), std::end(clauses), " OR "); |
| 46 | construct << ")"; | 47 | construct << ")"; |
| 48 | |||
| 49 | for (auto g : _in_group) | ||
| 50 | { | ||
| 51 | bindings.emplace_back(g); | ||
| 52 | } | ||
| 47 | } | 53 | } |
| 48 | 54 | ||
| 49 | if (_random) | 55 | if (_random) |
| @@ -63,9 +69,27 @@ namespace verbly { | |||
| 63 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | 69 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); |
| 64 | } | 70 | } |
| 65 | 71 | ||
| 66 | for (auto& group : _in_group) | 72 | int i = 1; |
| 73 | for (auto& binding : bindings) | ||
| 67 | { | 74 | { |
| 68 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@GNAME"), group.c_str(), group.length(), SQLITE_STATIC); | 75 | switch (binding.get_type()) |
| 76 | { | ||
| 77 | case binding::type::integer: | ||
| 78 | { | ||
| 79 | sqlite3_bind_int(ppstmt, i, binding.get_integer()); | ||
| 80 | |||
| 81 | break; | ||
| 82 | } | ||
| 83 | |||
| 84 | case binding::type::string: | ||
| 85 | { | ||
| 86 | sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_TRANSIENT); | ||
| 87 | |||
| 88 | break; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | i++; | ||
| 69 | } | 93 | } |
| 70 | 94 | ||
| 71 | std::list<preposition> output; | 95 | std::list<preposition> output; |
