~singpolyma/biboumi

ref: b4b9828de50c09fea5503b3b3ead2ae9d5144404 biboumi/src/database/query.cpp -rw-r--r-- 1.3 KiB
b4b9828d — louiz’ Follow log_level even when using journald output 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <database/query.hpp>
#include <database/column.hpp>

void actual_bind(Statement& statement, const std::string& value, int index)
{
  log_debug("binding string:", value, " to col ", index);
  statement.bind_text(index, value);
}

void actual_bind(Statement& statement, const std::size_t value, int index)
{
  log_debug("binding size_t:", value);
  statement.bind_int64(index, value);
}

void actual_bind(Statement& statement, const OptionalBool& value, int index)
{
  log_debug("binding optional_t:", value.to_string());
  if (!value.is_set)
    statement.bind_int64(index, 0);
  else if (value.value)
    statement.bind_int64(index, 1);
  else
    statement.bind_int64(index, -1);
}


void actual_add_param(Query& query, const std::string& val)
{
  query.params.push_back(val);
}

void actual_add_param(Query& query, const OptionalBool& val)
{
  if (!val.is_set)
    query.params.push_back("0");
  else if (val.value)
    query.params.push_back("1");
  else
    query.params.push_back("-1");
}

Query& operator<<(Query& query, const char* str)
{
  query.body += str;
  return query;
}

Query& operator<<(Query& query, const std::string& str)
{
  query.body += "$" + std::to_string(query.current_param);
  query.current_param++;
  actual_add_param(query, str);
  return query;
}