diff options
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..8df13aa 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_STATIC); | ||
87 | |||
88 | break; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | i++; | ||
69 | } | 93 | } |
70 | 94 | ||
71 | std::list<preposition> output; | 95 | std::list<preposition> output; |