summary refs log tree commit diff stats
path: root/lib/frame_query.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/frame_query.cpp')
-rw-r--r--lib/frame_query.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/frame_query.cpp b/lib/frame_query.cpp index 6583da4..3c4a3e8 100644 --- a/lib/frame_query.cpp +++ b/lib/frame_query.cpp
@@ -37,13 +37,19 @@ namespace verbly {
37 { 37 {
38 std::stringstream construct; 38 std::stringstream construct;
39 construct << "SELECT frames.data, groups.data FROM frames INNER JOIN groups ON frames.group_id = groups.group_id"; 39 construct << "SELECT frames.data, groups.data FROM frames INNER JOIN groups ON frames.group_id = groups.group_id";
40 std::list<binding> bindings;
40 41
41 if (!_for_verb.empty()) 42 if (!_for_verb.empty())
42 { 43 {
43 std::list<std::string> clauses(_for_verb.size(), "verb_id = @VERID"); 44 std::list<std::string> clauses(_for_verb.size(), "verb_id = ?");
44 construct << " WHERE frames.group_id IN (SELECT group_id FROM verb_groups WHERE "; 45 construct << " WHERE frames.group_id IN (SELECT group_id FROM verb_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 v : _for_verb)
50 {
51 bindings.emplace_back(v._id);
52 }
47 } 53 }
48 54
49 sqlite3_stmt* ppstmt; 55 sqlite3_stmt* ppstmt;
@@ -53,9 +59,27 @@ namespace verbly {
53 throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); 59 throw std::runtime_error(sqlite3_errmsg(_data.ppdb));
54 } 60 }
55 61
56 for (auto verb : _for_verb) 62 int i = 1;
63 for (auto& binding : bindings)
57 { 64 {
58 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@VERID"), verb._id); 65 switch (binding.get_type())
66 {
67 case binding::type::integer:
68 {
69 sqlite3_bind_int(ppstmt, i, binding.get_integer());
70
71 break;
72 }
73
74 case binding::type::string:
75 {
76 sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_STATIC);
77
78 break;
79 }
80 }
81
82 i++;
59 } 83 }
60 84
61 std::list<frame> output; 85 std::list<frame> output;