Classes | Functions
cet::sqlite::detail Namespace Reference

Classes

struct  bind_parameters
 
struct  bind_parameters< TUP, 1 >
 
class  DefaultDatabaseOpenPolicy
 

Functions

template<typename T , typename... Constraints>
std::string column_info (column< T, Constraints... > const &col)
 
template<typename H , typename... T>
std::string columns (H const &h, T const &...t)
 
std::string create_table (std::string const &tablename)
 
template<typename... Cols>
std::string create_table_ddl (std::string const &tablename, Cols const &...cols)
 
std::string create_table_as_ddl (std::string const &tablename, SelectStmt const &stmt)
 
void bind_one_parameter (sqlite3_stmt *s, std::size_t const idx, double const v)
 
void bind_one_parameter (sqlite3_stmt *s, std::size_t const idx, int const v)
 
void bind_one_parameter (sqlite3_stmt *s, std::size_t const idx, std::uint32_t const v)
 
void bind_one_parameter (sqlite3_stmt *s, std::size_t const idx, sqlite_int64 const v)
 
void bind_one_parameter (sqlite3_stmt *s, std::size_t const idx, std::string const &v)
 
void bind_one_null (sqlite3_stmt *s, std::size_t const idx)
 
template<typename T >
auto convertTo (std::string const &arg)
 
template<>
auto convertTo< int > (std::string const &arg)
 
template<>
auto convertTo< long > (std::string const &arg)
 
template<>
auto convertTo< long long > (std::string const &arg)
 
template<>
auto convertTo< unsigned > (std::string const &arg)
 
template<>
auto convertTo< unsigned long > (std::string const &arg)
 
template<>
auto convertTo< unsigned long long > (std::string const &arg)
 
template<>
auto convertTo< float > (std::string const &arg)
 
template<>
auto convertTo< double > (std::string const &arg)
 
template<>
auto convertTo< long double > (std::string const &arg)
 
template<std::size_t I, typename Tuple >
std::enable_if_t<(I==std::tuple_size_v< Tuple >)> fillData (Tuple &, int const ncols[[maybe_unused]], int const currentcol[[maybe_unused]], char **)
 
template<std::size_t I, typename Tuple >
std::enable_if_t<(I< std::tuple_size_v< Tuple >)> fillData (Tuple &data, int const ncols, int currentcol, char **results)
 
template<typename... Args>
int get_result (void *data, int ncols, char **results, char **cnames)
 
void normalize_statement (std::string &to_replace)
 
std::string normalized_statement (std::string to_replace)
 
std::string maybe_quote (std::string const &s)
 
std::string maybe_quote (char const *s)
 
template<typename T >
maybe_quote (T const &t)
 
void values_str_impl (std::ostream &)
 
template<typename H , typename... T>
void values_str_impl (std::ostream &os, H const &h, T const &...t)
 
template<typename... Args>
std::string values_str (Args const &...args)
 
template<typename H , typename... T>
std::string concatenate (H const &h, T const &...t)
 

Function Documentation

void cet::sqlite::detail::bind_one_null ( sqlite3_stmt s,
std::size_t const  idx 
)

Definition at line 69 of file bind_parameters.cc.

70 {
71  int const rc{sqlite3_bind_null(s, idx)};
72  if (rc != SQLITE_OK)
73  throw_bind_failure("null", rc);
74 }
static QCString * s
Definition: config.cpp:1042
void cet::sqlite::detail::bind_one_parameter ( sqlite3_stmt s,
std::size_t const  idx,
double const  v 
)

Definition at line 19 of file bind_parameters.cc.

22 {
23  int const rc{sqlite3_bind_double(s, idx, v)};
24  if (rc != SQLITE_OK)
25  throw_bind_failure("double", rc);
26 }
static QCString * s
Definition: config.cpp:1042
void cet::sqlite::detail::bind_one_parameter ( sqlite3_stmt s,
std::size_t const  idx,
int const  v 
)

Definition at line 29 of file bind_parameters.cc.

32 {
33  int const rc{sqlite3_bind_int(s, idx, v)};
34  if (rc != SQLITE_OK)
35  throw_bind_failure("int", rc);
36 }
static QCString * s
Definition: config.cpp:1042
void cet::sqlite::detail::bind_one_parameter ( sqlite3_stmt s,
std::size_t const  idx,
std::uint32_t const  v 
)

Definition at line 39 of file bind_parameters.cc.

42 {
43  int const rc{sqlite3_bind_int64(s, idx, v)};
44  if (rc != SQLITE_OK)
45  throw_bind_failure("int64", rc);
46 }
static QCString * s
Definition: config.cpp:1042
void cet::sqlite::detail::bind_one_parameter ( sqlite3_stmt s,
std::size_t const  idx,
sqlite_int64 const  v 
)

Definition at line 49 of file bind_parameters.cc.

52 {
53  int const rc{sqlite3_bind_int64(s, idx, v)};
54  if (rc != SQLITE_OK)
55  throw_bind_failure("int64", rc);
56 }
static QCString * s
Definition: config.cpp:1042
void cet::sqlite::detail::bind_one_parameter ( sqlite3_stmt s,
std::size_t const  idx,
std::string const &  v 
)

Definition at line 59 of file bind_parameters.cc.

62 {
63  int const rc{sqlite3_bind_text(s, idx, v.c_str(), v.size(), nullptr)};
64  if (rc != SQLITE_OK)
65  throw_bind_failure("text", rc);
66 }
uint size() const
Definition: qcstring.h:201
static QCString * s
Definition: config.cpp:1042
template<typename T , typename... Constraints>
std::string cet::sqlite::detail::column_info ( column< T, Constraints... > const &  col)

Definition at line 74 of file create_table.h.

75  {
76  std::string info{col.name() + col.sqlite_type()};
77  info += (Constraints::snippet() + ... + ""s);
78  return info;
79  }
std::string string
Definition: nybbler.cc:12
static QCString * s
Definition: config.cpp:1042
template<typename H , typename... T>
std::string cet::sqlite::detail::columns ( H const &  h,
T const &...  t 
)
inline

Definition at line 83 of file create_table.h.

84  {
85  return (column_info(h) + ... + (", " + column_info(t)));
86  }
std::string column_info(column< T, Constraints... > const &col)
Definition: create_table.h:74
template<typename H , typename... T>
std::string cet::sqlite::detail::concatenate ( H const &  h,
T const &...  t 
)

Definition at line 138 of file select.h.

139  {
140  return (std::string{h} + ... + ("," + std::string{t}));
141  }
std::string string
Definition: nybbler.cc:12
template<typename T >
auto cet::sqlite::detail::convertTo ( std::string const &  arg)
inline

Definition at line 30 of file convert.h.

31  {
32  return arg;
33  }
template<>
auto cet::sqlite::detail::convertTo< double > ( std::string const &  arg)
inline

Definition at line 79 of file convert.h.

80  {
81  return std::stod(arg);
82  }
template<>
auto cet::sqlite::detail::convertTo< float > ( std::string const &  arg)
inline

Definition at line 73 of file convert.h.

74  {
75  return std::stof(arg);
76  }
template<>
auto cet::sqlite::detail::convertTo< int > ( std::string const &  arg)
inline

Definition at line 37 of file convert.h.

38  {
39  return std::stoi(arg);
40  }
template<>
auto cet::sqlite::detail::convertTo< long > ( std::string const &  arg)
inline

Definition at line 43 of file convert.h.

44  {
45  return std::stol(arg);
46  }
template<>
auto cet::sqlite::detail::convertTo< long double > ( std::string const &  arg)
inline

Definition at line 85 of file convert.h.

86  {
87  return std::stold(arg);
88  }
template<>
auto cet::sqlite::detail::convertTo< long long > ( std::string const &  arg)
inline

Definition at line 49 of file convert.h.

50  {
51  return std::stoll(arg);
52  }
template<>
auto cet::sqlite::detail::convertTo< unsigned > ( std::string const &  arg)
inline

Definition at line 55 of file convert.h.

56  {
57  return std::stoul(arg);
58  }
template<>
auto cet::sqlite::detail::convertTo< unsigned long > ( std::string const &  arg)
inline

Definition at line 61 of file convert.h.

62  {
63  return std::stoul(arg);
64  }
template<>
auto cet::sqlite::detail::convertTo< unsigned long long > ( std::string const &  arg)
inline

Definition at line 67 of file convert.h.

68  {
69  return std::stoull(arg);
70  }
std::string cet::sqlite::detail::create_table ( std::string const &  tablename)
inline

Definition at line 89 of file create_table.h.

90  {
91  return "CREATE TABLE "s + tablename;
92  }
static QCString * s
Definition: config.cpp:1042
std::string cet::sqlite::detail::create_table_as_ddl ( std::string const &  tablename,
SelectStmt const &  stmt 
)
inline

Definition at line 106 of file create_table.h.

107  {
108  std::string ddl{create_table(tablename)};
109  ddl += " AS ";
110  ddl += stmt.ddl_;
111  return ddl;
112  }
std::string string
Definition: nybbler.cc:12
std::string create_table(std::string const &tablename)
Definition: create_table.h:89
template<typename... Cols>
std::string cet::sqlite::detail::create_table_ddl ( std::string const &  tablename,
Cols const &...  cols 
)

Definition at line 96 of file create_table.h.

97  {
98  std::string ddl{create_table(tablename)};
99  ddl += "( ";
100  ddl += columns(cols...);
101  ddl += " )";
102  return ddl;
103  }
std::string string
Definition: nybbler.cc:12
std::string create_table(std::string const &tablename)
Definition: create_table.h:89
std::string columns(H const &h, T const &...t)
Definition: create_table.h:83
template<std::size_t I, typename Tuple >
std::enable_if_t<(I == std::tuple_size_v<Tuple>)> cet::sqlite::detail::fillData ( Tuple &  ,
int const ncols]  [[maybe_unused],
int const currentcol]  [[maybe_unused],
char **   
)

Definition at line 14 of file get_result.h.

18  {
19  assert(currentcol == ncols);
20  }
template<std::size_t I, typename Tuple >
std::enable_if_t<(I < std::tuple_size_v<Tuple>)> cet::sqlite::detail::fillData ( Tuple &  data,
int const  ncols,
int  currentcol,
char **  results 
)

Definition at line 24 of file get_result.h.

25  {
26  assert(currentcol != ncols);
27  using ET = std::tuple_element_t<I, Tuple>;
28  std::get<I>(data) = detail::convertTo<ET>(results[currentcol]);
29  fillData<I + 1>(data, ncols, ++currentcol, results);
30  }
template<typename... Args>
int cet::sqlite::detail::get_result ( void *  data,
int  ncols,
char **  results,
char **  cnames 
)

Definition at line 34 of file get_result.h.

35  {
36  assert(ncols >= 1);
37  auto j = static_cast<cet::sqlite::query_result<Args...>*>(data);
38  if (j->columns.empty()) {
39  for (int i{}; i < ncols; ++i)
40  j->columns.push_back(cnames[i]);
41  }
42 
43  assert(sizeof...(Args) == ncols);
44  std::tuple<Args...> rowdata;
45  int currentCol{};
46  fillData<0u>(rowdata, ncols, currentCol, results);
47  j->data.emplace_back(rowdata);
48  return 0;
49  }
std::vector< std::string > columns
Definition: query_result.h:88
std::string cet::sqlite::detail::maybe_quote ( std::string const &  s)
inline

Definition at line 47 of file insert.h.

48  {
49  return "\"" + s + "\"";
50  }
static QCString * s
Definition: config.cpp:1042
std::string cet::sqlite::detail::maybe_quote ( char const *  s)
inline

Definition at line 53 of file insert.h.

54  {
55  return maybe_quote(std::string{s});
56  }
std::string string
Definition: nybbler.cc:12
T maybe_quote(T const &t)
Definition: insert.h:60
static QCString * s
Definition: config.cpp:1042
template<typename T >
T cet::sqlite::detail::maybe_quote ( T const &  t)

Definition at line 60 of file insert.h.

61  {
62  return t;
63  }
void cet::sqlite::detail::normalize_statement ( std::string to_replace)

Definition at line 6 of file normalize_statement.cc.

7 {
8  // Remove spaces around commas
9  {
10  std::regex const r{"\\s*,\\s*"};
11  to_replace = std::regex_replace(to_replace, r, ",");
12  }
13  // Remove spaces around parentheses
14  {
15  std::regex const r{R"(\s*([\(\)])\s*)"};
16  to_replace = std::regex_replace(to_replace, r, "$1");
17  }
18  // Replace multiple spaces with 1 space.
19  {
20  std::regex const r{"\\s+"};
21  to_replace = std::regex_replace(to_replace, r, " ");
22  }
23 }
std::string cet::sqlite::detail::normalized_statement ( std::string  to_replace)

Definition at line 25 of file normalize_statement.cc.

27 {
28  normalize_statement(to_replace);
29  return to_replace;
30 }
void normalize_statement(std::string &to_replace)
template<typename... Args>
std::string cet::sqlite::detail::values_str ( Args const &...  args)

Definition at line 82 of file insert.h.

83  {
84  std::ostringstream oss;
85  values_str_impl(oss, args...);
86  return oss.str();
87  }
static QCString args
Definition: declinfo.cpp:674
void values_str_impl(std::ostream &os, H const &h, T const &...t)
Definition: insert.h:71
void cet::sqlite::detail::values_str_impl ( std::ostream &  )
inline

Definition at line 66 of file insert.h.

67  {}
template<typename H , typename... T>
void cet::sqlite::detail::values_str_impl ( std::ostream &  os,
H const &  h,
T const &...  t 
)

Definition at line 71 of file insert.h.

72  {
73  if (sizeof...(T) != 0u) {
74  os << maybe_quote(h) << ',';
75  values_str_impl(os, t...);
76  } else
77  os << maybe_quote(h);
78  }
T maybe_quote(T const &t)
Definition: insert.h:60
void values_str_impl(std::ostream &os, H const &h, T const &...t)
Definition: insert.h:71