query_result_t.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
5 #include "cetlib/sqlite/column.h"
7 #include "cetlib/sqlite/insert.h"
9 #include "cetlib/sqlite/select.h"
10 
11 #include <cassert>
12 #include <memory>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 using namespace std;
18 using namespace cet::sqlite;
19 
20 int
22 {
24  unique_ptr<Connection> c{cf.make_connection(":memory:")};
25  string const name{"numbers"};
26  vector<pair<string, int>> const pairs{{"one", 1}, {"five", 5}, {"ten", 10}};
27  create_table(*c, name, column<string>("key"), column<int>("value"));
28  for (auto const& pr : pairs) {
29  insert_into(*c, name).values(pr.first, pr.second);
30  }
31  query_result<string, int> allEntries;
32  allEntries << select("*").from(*c, name);
33  cet::for_all_with_index(allEntries,
34  [&pairs](size_t const i, auto const& row) {
35  auto const [key, value] = row;
36  assert(key == pairs[i].first);
37  assert(value == pairs[i].second);
38  });
40  create_table_as("onlyValues", select("value").from(*c, name));
41  cet::for_all_with_index(values, [&pairs](size_t const i, auto const& row) {
42  auto const& v = get<0>(row);
43  assert(v == pairs[i].second);
44  });
45 }
static QCString name
Definition: declinfo.cpp:673
auto insert_into(sqlite3 *const db, std::string const &tablename)
Definition: insert.h:110
void for_all_with_index(FwdCont &, Func)
STL namespace.
auto make_connection(std::string const &file_name, PolicyArgs &&...) -> Connection *
void create_table_as(std::string const &tablename, SelectStmt const &stmt)
Definition: create_table.h:127
def key(type, name=None)
Definition: graph.py:13
void create_table(sqlite3 *const db, std::string const &tablename, Cols const &...cols)
Definition: create_table.h:118
Q_UINT16 values[128]
int main()
auto select(T const &...t)
Definition: select.h:146
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85