include/simdb/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
384 / 399
96.2%
Branches:
248 / 463
53.6%
Functions:
97 / 99
98.0%

sqlite/Table.hpp
Line Branch Exec Source
1 // <Table.hpp> -*- C++ -*-
2
3 #pragma once
4
5 #include "simdb/Assert.hpp"
6 #include "simdb/sqlite/Query.hpp"
7 #include "simdb/sqlite/Transaction.hpp"
8 #include "simdb/sqlite/ValueContainer.hpp"
9 #include "simdb/utils/utf16.hpp"
10
11 #include <algorithm>
12 #include <list>
13 #include <sqlite3.h>
14
15 namespace simdb {
16
17 /*!
18 * \class SqlTable
19 *
20 * \brief Helper class that is used under the hood for
21 * db_mgr.INSERT(SQL_TABLE("MyTable"), ...)
22 */
23 class SqlTable
24 {
25 public:
26 210591 SqlTable(const std::string_view table_name) :
27
1/1
✓ Branch 4 → 5 taken 210591 times.
421182 table_name_(table_name)
28 {
29 210591 }
30
31 641956 const std::string& getName() const { return table_name_; }
32
33 private:
34 std::string table_name_;
35 };
36
37 /*!
38 * \class SqlColumns
39 *
40 * \brief Helper class that is used under the hood for db_mgr.INSERT(...,
41 * SQL_COLUMNS("ColA", "ColB"), ...)
42 */
43 class SqlColumns
44 {
45 public:
46 template <typename... Rest>
47 400404 SqlColumns(const char* col_name, Rest... rest) :
48 400404 SqlColumns(std::forward<Rest>(rest)...)
49 {
50
6/6
simdb::SqlColumns::SqlColumns<char const*>(char const*, char const*):
✓ Branch 4 → 5 taken 200185 times.
simdb::SqlColumns::SqlColumns<char const*, char const*>(char const*, char const*, char const*):
✓ Branch 5 → 6 taken 200143 times.
simdb::SqlColumns::SqlColumns<char const*, char const*, char const*>(char const*, char const*, char const*, char const*):
✓ Branch 6 → 7 taken 65 times.
simdb::SqlColumns::SqlColumns<char const*, char const*, char const*, char const*>(char const*, char const*, char const*, char const*, char const*):
✓ Branch 7 → 8 taken 5 times.
simdb::SqlColumns::SqlColumns<char const*, char const*, char const*, char const*, char const*>(char const*, char const*, char const*, char const*, char const*, char const*):
✓ Branch 8 → 9 taken 4 times.
simdb::SqlColumns::SqlColumns<char const*, char const*, char const*, char const*, char const*, char const*>(char const*, char const*, char const*, char const*, char const*, char const*, char const*):
✓ Branch 9 → 10 taken 2 times.
400404 col_names_.emplace_front(col_name);
51 400404 }
52
53 200215 SqlColumns(const char* col_name)
54 200215 {
55 // It is important that this is emplace_front()
56 // since this constructor might be called last
57 // in a chain of constructors (parameter pack
58 // unrolling).
59
1/1
✓ Branch 3 → 4 taken 200215 times.
200215 col_names_.emplace_front(col_name);
60 200215 }
61
62 10372 SqlColumns(const std::vector<std::string>& col_names)
63 10372 {
64
2/2
✓ Branch 9 → 5 taken 17794 times.
✓ Branch 9 → 10 taken 10372 times.
28166 for (const auto& col_name : col_names)
65 {
66
1/1
✓ Branch 6 → 7 taken 17794 times.
17794 col_names_.emplace_back(col_name);
67 }
68 10372 }
69
70 210367 void writeColsForINSERT(std::ostringstream& oss) const
71 {
72
1/1
✓ Branch 2 → 3 taken 210367 times.
210367 oss << " (";
73 210367 auto iter = col_names_.begin();
74 210367 size_t idx = 0;
75
2/2
✓ Branch 13 → 5 taken 617731 times.
✓ Branch 13 → 14 taken 210367 times.
828098 while (iter != col_names_.end())
76 {
77
1/1
✓ Branch 6 → 7 taken 617731 times.
617731 oss << *iter;
78
2/2
✓ Branch 8 → 9 taken 407364 times.
✓ Branch 8 → 10 taken 210367 times.
617731 if (idx != col_names_.size() - 1)
79 {
80
1/1
✓ Branch 9 → 10 taken 407364 times.
407364 oss << ",";
81 }
82 617731 ++idx;
83 617731 ++iter;
84 }
85
1/1
✓ Branch 14 → 15 taken 210367 times.
210367 oss << ") ";
86 210367 }
87
88 1334 const std::list<std::string>& getColNames() const { return col_names_; }
89
90 private:
91 std::list<std::string> col_names_;
92 };
93
94 /*!
95 * \class SqlValues
96 *
97 * \brief Helper class that is used together with SQL_VALUES() in order to bind
98 * data values to a prepared statement for INSERT's.
99 */
100 class SqlValues
101 {
102 public:
103 template <typename T, typename... Rest>
104 407365 SqlValues(T val, Rest... rest) :
105
10/10
simdb::SqlValues::SqlValues<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):
✓ Branch 4 → 5 taken 1 time.
simdb::SqlValues::SqlValues<double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):
✓ Branch 4 → 5 taken 200000 times.
simdb::SqlValues::SqlValues<double, char const*, std::vector<int, std::allocator<int> > >(double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 5 → 6 taken 1 time.
simdb::SqlValues::SqlValues<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> > >(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> >):
✓ Branch 6 → 7 taken 4 times.
simdb::SqlValues::SqlValues<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):
✓ Branch 5 → 6 taken 200000 times.
simdb::SqlValues::SqlValues<int, unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(int, unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 9 → 10 taken 1 time.
simdb::SqlValues::SqlValues<unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 8 → 9 taken 1 time.
simdb::SqlValues::SqlValues<long, unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(long, unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 7 → 8 taken 1 time.
simdb::SqlValues::SqlValues<unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 6 → 7 taken 1 time.
simdb::SqlValues::SqlValues<unsigned long, unsigned long, std::vector<int, std::allocator<int> > >(unsigned long, unsigned long, std::vector<int, std::allocator<int> >):
✓ Branch 5 → 6 taken 5 times.
407365 SqlValues(std::forward<Rest>(rest)...)
106 {
107
76/78
simdb::SqlValues::SqlValues<simdb::SqlBlob, char const*>(simdb::SqlBlob, char const*):
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
simdb::SqlValues::SqlValues<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, simdb::SqlBlob>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, simdb::SqlBlob):
✓ Branch 4 → 5 taken 7258 times.
✓ Branch 5 → 6 taken 7258 times.
simdb::SqlValues::SqlValues<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):
✓ Branch 6 → 7 taken 1 time.
✓ Branch 7 → 8 taken 1 time.
simdb::SqlValues::SqlValues<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> >):
✓ Branch 4 → 5 taken 4 times.
✓ Branch 5 → 6 taken 4 times.
simdb::SqlValues::SqlValues<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int):
✓ Branch 4 → 5 taken 26 times.
✓ Branch 5 → 6 taken 26 times.
simdb::SqlValues::SqlValues<char const*, char const*>(char const*, char const*):
✓ Branch 4 → 5 taken 4 times.
✓ Branch 5 → 6 taken 4 times.
simdb::SqlValues::SqlValues<char const*, char const*, char const*>(char const*, char const*, char const*):
✓ Branch 5 → 6 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
simdb::SqlValues::SqlValues<char const*, char const*, int>(char const*, char const*, int):
✓ Branch 5 → 6 taken 4 times.
✓ Branch 6 → 7 taken 4 times.
simdb::SqlValues::SqlValues<char const*, std::vector<int, std::allocator<int> > >(char const*, std::vector<int, std::allocator<int> >):
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
simdb::SqlValues::SqlValues<char const*, int>(char const*, int):
✓ Branch 4 → 5 taken 4 times.
✓ Branch 5 → 6 taken 4 times.
simdb::SqlValues::SqlValues<double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):
✓ Branch 6 → 7 taken 200000 times.
✓ Branch 7 → 8 taken 200000 times.
simdb::SqlValues::SqlValues<double, char const*, std::vector<int, std::allocator<int> > >(double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 7 → 8 taken 1 time.
✓ Branch 8 → 9 taken 1 time.
simdb::SqlValues::SqlValues<double, double>(double, double):
✓ Branch 4 → 5 taken 2 times.
✓ Branch 5 → 6 taken 2 times.
simdb::SqlValues::SqlValues<double, double, double>(double, double, double):
✓ Branch 5 → 6 taken 2 times.
✓ Branch 6 → 7 taken 2 times.
simdb::SqlValues::SqlValues<double, double, double, double>(double, double, double, double):
✓ Branch 6 → 7 taken 2 times.
✓ Branch 7 → 8 taken 2 times.
simdb::SqlValues::SqlValues<double, double, double, double, double>(double, double, double, double, double):
✓ Branch 7 → 8 taken 2 times.
✓ Branch 8 → 9 taken 2 times.
simdb::SqlValues::SqlValues<double, double, double, double, double, double>(double, double, double, double, double, double):
✓ Branch 8 → 9 taken 2 times.
✓ Branch 9 → 10 taken 2 times.
simdb::SqlValues::SqlValues<int, simdb::SqlBlob, char const*>(int, simdb::SqlBlob, char const*):
✓ Branch 5 → 6 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
simdb::SqlValues::SqlValues<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> > >(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> >):
✓ Branch 9 → 10 taken 4 times.
✓ Branch 10 → 11 taken 4 times.
simdb::SqlValues::SqlValues<int, char const*>(int, char const*):
✓ Branch 4 → 5 taken 2 times.
✓ Branch 5 → 6 taken 2 times.
simdb::SqlValues::SqlValues<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):
✓ Branch 7 → 8 taken 200000 times.
✓ Branch 8 → 9 taken 200000 times.
simdb::SqlValues::SqlValues<int, int>(int, int):
✗ Branch 4 → 5 not taken.
✗ Branch 5 → 6 not taken.
simdb::SqlValues::SqlValues<int, unsigned int, long, unsigned long, double>(int, unsigned int, long, unsigned long, double):
✓ Branch 7 → 8 taken 1 time.
✓ Branch 8 → 9 taken 1 time.
simdb::SqlValues::SqlValues<int, unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(int, unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 11 → 12 taken 1 time.
✓ Branch 12 → 13 taken 1 time.
simdb::SqlValues::SqlValues<int, long>(int, long):
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
simdb::SqlValues::SqlValues<int, long, unsigned int>(int, long, unsigned int):
✓ Branch 5 → 6 taken 6 times.
✓ Branch 6 → 7 taken 6 times.
simdb::SqlValues::SqlValues<int, long, unsigned int, unsigned long>(int, long, unsigned int, unsigned long):
✓ Branch 6 → 7 taken 1 time.
✓ Branch 7 → 8 taken 1 time.
simdb::SqlValues::SqlValues<unsigned int, long, unsigned long, double>(unsigned int, long, unsigned long, double):
✓ Branch 6 → 7 taken 1 time.
✓ Branch 7 → 8 taken 1 time.
simdb::SqlValues::SqlValues<unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(unsigned int, long, unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 10 → 11 taken 1 time.
✓ Branch 11 → 12 taken 1 time.
simdb::SqlValues::SqlValues<unsigned int, unsigned long>(unsigned int, unsigned long):
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
simdb::SqlValues::SqlValues<long, unsigned int>(long, unsigned int):
✓ Branch 4 → 5 taken 6 times.
✓ Branch 5 → 6 taken 6 times.
simdb::SqlValues::SqlValues<long, unsigned int, unsigned long>(long, unsigned int, unsigned long):
✓ Branch 5 → 6 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
simdb::SqlValues::SqlValues<long, unsigned long, double>(long, unsigned long, double):
✓ Branch 5 → 6 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
simdb::SqlValues::SqlValues<long, unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(long, unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 9 → 10 taken 1 time.
✓ Branch 10 → 11 taken 1 time.
simdb::SqlValues::SqlValues<unsigned long, std::vector<int, std::allocator<int> > >(unsigned long, std::vector<int, std::allocator<int> >):
✓ Branch 4 → 5 taken 5 times.
✓ Branch 5 → 6 taken 5 times.
simdb::SqlValues::SqlValues<unsigned long, double>(unsigned long, double):
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
simdb::SqlValues::SqlValues<unsigned long, double, char const*, std::vector<int, std::allocator<int> > >(unsigned long, double, char const*, std::vector<int, std::allocator<int> >):
✓ Branch 8 → 9 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
simdb::SqlValues::SqlValues<unsigned long, unsigned long>(unsigned long, unsigned long):
✓ Branch 4 → 5 taken 9 times.
✓ Branch 5 → 6 taken 9 times.
simdb::SqlValues::SqlValues<unsigned long, unsigned long, std::vector<int, std::allocator<int> > >(unsigned long, unsigned long, std::vector<int, std::allocator<int> >):
✓ Branch 7 → 8 taken 5 times.
✓ Branch 8 → 9 taken 5 times.
407365 col_vals_.emplace_front(createValueContainer<T>(val));
108 407365 }
109
110 template <typename T, typename... Rest>
111 1 SqlValues(const std::vector<T>& val, Rest... rest) :
112 1 SqlValues(std::forward<Rest>(rest)...)
113 {
114
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
1 col_vals_.emplace_front(createValueContainer(val));
115 1 }
116
117 template <typename T, typename... Rest>
118 SqlValues(std::vector<T>&& val, Rest... rest) :
119 SqlValues(std::forward<Rest>(rest)...)
120 {
121 col_vals_.emplace_front(createValueContainer(std::move(val)));
122 }
123
124
16/16
simdb::SqlValues::SqlValues<simdb::SqlBlob>(simdb::SqlBlob):
✓ Branch 3 → 4 taken 7260 times.
✓ Branch 4 → 5 taken 7260 times.
simdb::SqlValues::SqlValues<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):
✓ Branch 3 → 4 taken 200006 times.
✓ Branch 4 → 5 taken 200006 times.
simdb::SqlValues::SqlValues<char const*>(char const*):
✓ Branch 3 → 4 taken 12 times.
✓ Branch 4 → 5 taken 12 times.
simdb::SqlValues::SqlValues<double>(double):
✓ Branch 3 → 4 taken 16 times.
✓ Branch 4 → 5 taken 16 times.
simdb::SqlValues::SqlValues<int>(int):
✓ Branch 3 → 4 taken 35 times.
✓ Branch 4 → 5 taken 35 times.
simdb::SqlValues::SqlValues<unsigned int>(unsigned int):
✓ Branch 3 → 4 taken 6 times.
✓ Branch 4 → 5 taken 6 times.
simdb::SqlValues::SqlValues<long>(long):
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
simdb::SqlValues::SqlValues<unsigned long>(unsigned long):
✓ Branch 3 → 4 taken 3021 times.
✓ Branch 4 → 5 taken 3021 times.
210357 template <typename T> SqlValues(T val) { col_vals_.emplace_front(createValueContainer<T>(val)); }
125
126
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
1 template <typename T> SqlValues(const std::vector<T>& val) { col_vals_.emplace_front(createValueContainer(val)); }
127
128 11 template <typename T> SqlValues(std::vector<T>&& val)
129 11 {
130
2/2
✓ Branch 4 → 5 taken 11 times.
✓ Branch 5 → 6 taken 11 times.
11 col_vals_.emplace_front(createValueContainer(std::move(val)));
131 11 }
132
133 210367 void writeValsForINSERT(std::ostringstream& oss) const
134 {
135 210367 oss << " VALUES(";
136 210367 size_t count = col_vals_.size();
137
2/2
✓ Branch 9 → 5 taken 617731 times.
✓ Branch 9 → 10 taken 210367 times.
828098 for (size_t idx = 0; idx < count; ++idx)
138 {
139 617731 oss << "?";
140
2/2
✓ Branch 6 → 7 taken 407364 times.
✓ Branch 6 → 8 taken 210367 times.
617731 if (idx != count - 1)
141 {
142 407364 oss << ",";
143 }
144 }
145 210367 oss << ") ";
146 210367 }
147
148 210365 void bindValsForINSERT(sqlite3_stmt* stmt) const
149 {
150 210365 int32_t idx = 1;
151
2/2
✓ Branch 32 → 4 taken 617726 times.
✓ Branch 32 → 33 taken 210365 times.
828091 for (auto& val : col_vals_)
152 {
153
2/2
✓ Branch 6 → 7 taken 617726 times.
✓ Branch 7 → 8 taken 617726 times.
617726 auto rc = SQLiteReturnCode(val->bind(stmt, idx++));
154
1/14
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 30 taken 617726 times.
✗ Branch 12 → 13 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 28 → 29 not taken.
617726 simdb_assert(!rc, sqlite3_errmsg(sqlite3_db_handle(stmt)));
155 }
156 210365 }
157
158 private:
159 std::list<std::shared_ptr<ValueContainerBase>> col_vals_;
160 };
161
162 /*!
163 * \class SqlRecord
164 *
165 * \brief This class wraps one table record by its table name and database ID.
166 */
167 class SqlRecord
168 {
169 public:
170 210379 SqlRecord(const std::string& table_name, const int32_t db_id, sqlite3* db_conn, Transaction* transaction) :
171 210379 table_name_(table_name),
172 210379 db_id_(db_id),
173 210379 db_conn_(db_conn),
174 210379 transaction_(transaction)
175 {
176 210379 }
177
178 /// Get the database ID (primary key) for this record.
179 3020 int32_t getId() const { return db_id_; }
180
181 /// SELECT the given column value (int32_t)
182 int32_t getPropertyInt32(const char* col_name) const;
183
184 /// SELECT the given column value (uint32_t)
185 uint32_t getPropertyUInt32(const char* col_name) const;
186
187 /// SELECT the given column value (int64_t)
188 int64_t getPropertyInt64(const char* col_name) const;
189
190 /// SELECT the given column value (uint64_t)
191 uint64_t getPropertyUInt64(const char* col_name) const;
192
193 /// SELECT the given column value (double)
194 double getPropertyDouble(const char* col_name) const;
195
196 /// SELECT the given column value (string)
197 std::string getPropertyString(const char* col_name) const;
198
199 /// SELECT the given column value (blob)
200 template <typename T> std::vector<T> getPropertyBlob(const char* col_name) const;
201
202 /// UPDATE the given column value (int32_t)
203 void setPropertyInt32(const char* col_name, const int32_t val) const;
204
205 /// UPDATE the given column value (uint32_t)
206 void setPropertyUInt32(const char* col_name, const uint32_t val) const;
207
208 /// UPDATE the given column value (int64_t)
209 void setPropertyInt64(const char* col_name, const int64_t val) const;
210
211 /// UPDATE the given column value (uint64_t)
212 void setPropertyUInt64(const char* col_name, const uint64_t val) const;
213
214 /// UPDATE the given column value (double)
215 void setPropertyDouble(const char* col_name, const double val) const;
216
217 /// UPDATE the given column value (string)
218 void setPropertyString(const char* col_name, const std::string& val) const;
219
220 /// UPDATE the given column value (blob)
221 template <typename T> void setPropertyBlob(const char* col_name, const std::vector<T>& val) const;
222
223 /// UPDATE the given column value (blob)
224 void setPropertyBlob(const char* col_name, const void* data, const size_t bytes) const;
225
226 /// DELETE this record from its table. Returns TRUE if successful,
227 /// FALSE otherwise. Should return FALSE on subsequent calls to this method.
228 bool removeFromTable();
229
230 private:
231 /// Create a prepared statement: UPDATE <table_name_> SET <col_name>=? WHERE
232 /// Id=<db_id_>
233 8 SQLitePreparedStatement createSetPropertyStmt_(const char* col_name) const
234 {
235
1/1
✓ Branch 2 → 3 taken 8 times.
8 std::string cmd = "UPDATE " + table_name_;
236
1/1
✓ Branch 3 → 4 taken 8 times.
8 cmd += " SET ";
237
1/1
✓ Branch 4 → 5 taken 8 times.
8 cmd += col_name;
238
2/2
✓ Branch 6 → 7 taken 8 times.
✓ Branch 7 → 8 taken 8 times.
8 cmd += "=? WHERE Id=" + std::to_string(db_id_);
239
240
1/1
✓ Branch 11 → 12 taken 8 times.
16 return SQLitePreparedStatement(db_conn_, cmd);
241 8 }
242
243 /// \brief Step a prepared statement forward
244 /// \param stmt Prepared statement
245 /// \param ret_codes List of expected return codes from sqlite3_step()
246 /// \throws Throws an exception if sqlite3_step() returned a code that was
247 /// not in <ret_codes>
248 8 void stepStatement_(sqlite3_stmt* stmt, const std::initializer_list<int>& ret_codes) const
249 {
250
2/2
✓ Branch 2 → 3 taken 8 times.
✓ Branch 3 → 4 taken 8 times.
8 auto rc = SQLiteReturnCode(sqlite3_step(stmt));
251
2/3
✓ Branch 6 → 7 taken 8 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 36 taken 8 times.
8 if (std::find(ret_codes.begin(), ret_codes.end(), rc) == ret_codes.end())
252 {
253 ✗ auto stringify_ret_codes = [&]() {
254
0/1
✗ Branch 2 → 3 not taken.
✗ std::ostringstream oss;
255 ✗ auto iter = ret_codes.begin();
256
0/2
✗ Branch 11 → 5 not taken.
✗ Branch 11 → 12 not taken.
✗ for (size_t idx = 0; idx < ret_codes.size(); ++idx)
257 {
258
0/1
✗ Branch 5 → 6 not taken.
✗ oss << *iter;
259
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (idx != ret_codes.size() - 1)
260 {
261
0/1
✗ Branch 8 → 9 not taken.
✗ oss << ",";
262 }
263 ✗ ++iter;
264 }
265
0/1
✗ Branch 12 → 13 not taken.
✗ return oss.str();
266 ✗ };
267
268
0/18
✗ Branch 11 → 12 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 31 → 32 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 34 → 35 not taken.
✗ simdb_assert(false, "Unexpected sqlite3_step() return code:\n"
269 << "\tActual: " << rc << "\tExpected: " << stringify_ret_codes()
270 << "\tError: " << sqlite3_errmsg(db_conn_));
271 }
272 8 }
273
274 // SELECT ColA FROM <table_name_> WHERE Id=<db_id_>
275 const std::string table_name_;
276
277 // SELECT ColA FROM <table_name_> WHERE Id=<db_id_>
278 const int32_t db_id_;
279
280 // Underlying sqlite3 database
281 sqlite3* const db_conn_;
282
283 // Used for safeTransaction()
284 Transaction* const transaction_;
285 };
286
287 /// Run a query on the given table, column, and database ID, and return the
288 /// property value. SELECT <col_name> FROM <table_name> WHERE Id=<db_id>
289 template <typename T>
290 55 inline T queryPropertyValue(const char* table_name, const char* col_name, const int db_id, sqlite3* db_conn)
291 {
292
7/7
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > simdb::queryPropertyValue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, int, sqlite3*):
✓ Branch 2 → 3 taken 8 times.
std::vector<int, std::allocator<int> > simdb::queryPropertyValue<std::vector<int, std::allocator<int> > >(char const*, char const*, int, sqlite3*):
✓ Branch 2 → 3 taken 12 times.
double simdb::queryPropertyValue<double>(char const*, char const*, int, sqlite3*):
✓ Branch 2 → 3 taken 5 times.
int simdb::queryPropertyValue<int>(char const*, char const*, int, sqlite3*):
✓ Branch 2 → 3 taken 9 times.
unsigned int simdb::queryPropertyValue<unsigned int>(char const*, char const*, int, sqlite3*):
✓ Branch 2 → 3 taken 7 times.
long simdb::queryPropertyValue<long>(char const*, char const*, int, sqlite3*):
✓ Branch 2 → 3 taken 8 times.
unsigned long simdb::queryPropertyValue<unsigned long>(char const*, char const*, int, sqlite3*):
✓ Branch 2 → 3 taken 6 times.
55 SqlQuery query(table_name, db_conn);
293
294 // SELECT <col_name> FROM <table_name> WHERE Id=<db_id>
295 20 T val;
296
7/7
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > simdb::queryPropertyValue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, int, sqlite3*):
✓ Branch 4 → 5 taken 8 times.
std::vector<int, std::allocator<int> > simdb::queryPropertyValue<std::vector<int, std::allocator<int> > >(char const*, char const*, int, sqlite3*):
✓ Branch 4 → 5 taken 12 times.
double simdb::queryPropertyValue<double>(char const*, char const*, int, sqlite3*):
✓ Branch 3 → 4 taken 5 times.
int simdb::queryPropertyValue<int>(char const*, char const*, int, sqlite3*):
✓ Branch 3 → 4 taken 9 times.
unsigned int simdb::queryPropertyValue<unsigned int>(char const*, char const*, int, sqlite3*):
✓ Branch 3 → 4 taken 7 times.
long simdb::queryPropertyValue<long>(char const*, char const*, int, sqlite3*):
✓ Branch 3 → 4 taken 8 times.
unsigned long simdb::queryPropertyValue<unsigned long>(char const*, char const*, int, sqlite3*):
✓ Branch 3 → 4 taken 6 times.
55 query.select(col_name, val);
297
7/7
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > simdb::queryPropertyValue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, int, sqlite3*):
✓ Branch 5 → 6 taken 8 times.
std::vector<int, std::allocator<int> > simdb::queryPropertyValue<std::vector<int, std::allocator<int> > >(char const*, char const*, int, sqlite3*):
✓ Branch 5 → 6 taken 12 times.
double simdb::queryPropertyValue<double>(char const*, char const*, int, sqlite3*):
✓ Branch 4 → 5 taken 5 times.
int simdb::queryPropertyValue<int>(char const*, char const*, int, sqlite3*):
✓ Branch 4 → 5 taken 9 times.
unsigned int simdb::queryPropertyValue<unsigned int>(char const*, char const*, int, sqlite3*):
✓ Branch 4 → 5 taken 7 times.
long simdb::queryPropertyValue<long>(char const*, char const*, int, sqlite3*):
✓ Branch 4 → 5 taken 8 times.
unsigned long simdb::queryPropertyValue<unsigned long>(char const*, char const*, int, sqlite3*):
✓ Branch 4 → 5 taken 6 times.
55 query.addConstraintForInt("Id", Constraints::EQUAL, db_id);
298
299
7/7
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > simdb::queryPropertyValue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, int, sqlite3*):
✓ Branch 6 → 7 taken 8 times.
std::vector<int, std::allocator<int> > simdb::queryPropertyValue<std::vector<int, std::allocator<int> > >(char const*, char const*, int, sqlite3*):
✓ Branch 6 → 7 taken 12 times.
double simdb::queryPropertyValue<double>(char const*, char const*, int, sqlite3*):
✓ Branch 5 → 6 taken 5 times.
int simdb::queryPropertyValue<int>(char const*, char const*, int, sqlite3*):
✓ Branch 5 → 6 taken 9 times.
unsigned int simdb::queryPropertyValue<unsigned int>(char const*, char const*, int, sqlite3*):
✓ Branch 5 → 6 taken 7 times.
long simdb::queryPropertyValue<long>(char const*, char const*, int, sqlite3*):
✓ Branch 5 → 6 taken 8 times.
unsigned long simdb::queryPropertyValue<unsigned long>(char const*, char const*, int, sqlite3*):
✓ Branch 5 → 6 taken 6 times.
55 auto result_set = query.getResultSet();
300
14/91
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > simdb::queryPropertyValue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, int, sqlite3*):
✓ Branch 7 → 8 taken 8 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 27 taken 8 times.
✗ Branch 11 → 12 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 25 → 26 not taken.
std::vector<int, std::allocator<int> > simdb::queryPropertyValue<std::vector<int, std::allocator<int> > >(char const*, char const*, int, sqlite3*):
✓ Branch 7 → 8 taken 12 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 27 taken 12 times.
✗ Branch 11 → 12 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 25 → 26 not taken.
double simdb::queryPropertyValue<double>(char const*, char const*, int, sqlite3*):
✓ Branch 6 → 7 taken 5 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 26 taken 5 times.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 24 → 25 not taken.
int simdb::queryPropertyValue<int>(char const*, char const*, int, sqlite3*):
✓ Branch 6 → 7 taken 9 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 26 taken 9 times.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 24 → 25 not taken.
unsigned int simdb::queryPropertyValue<unsigned int>(char const*, char const*, int, sqlite3*):
✓ Branch 6 → 7 taken 7 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 26 taken 7 times.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 24 → 25 not taken.
long simdb::queryPropertyValue<long>(char const*, char const*, int, sqlite3*):
✓ Branch 6 → 7 taken 8 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 26 taken 8 times.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 24 → 25 not taken.
unsigned long simdb::queryPropertyValue<unsigned long>(char const*, char const*, int, sqlite3*):
✓ Branch 6 → 7 taken 6 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 26 taken 6 times.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 24 → 25 not taken.
55 simdb_assert(result_set.getNextRecord(), "Record not found");
301
302 55 return val;
303 55 }
304
305 9 inline int32_t SqlRecord::getPropertyInt32(const char* col_name) const
306 {
307 9 return queryPropertyValue<int32_t>(table_name_.c_str(), col_name, db_id_, db_conn_);
308 }
309
310 7 inline uint32_t SqlRecord::getPropertyUInt32(const char* col_name) const
311 {
312 7 return queryPropertyValue<uint32_t>(table_name_.c_str(), col_name, db_id_, db_conn_);
313 }
314
315 8 inline int64_t SqlRecord::getPropertyInt64(const char* col_name) const
316 {
317 8 return queryPropertyValue<int64_t>(table_name_.c_str(), col_name, db_id_, db_conn_);
318 }
319
320 6 inline uint64_t SqlRecord::getPropertyUInt64(const char* col_name) const
321 {
322 6 return queryPropertyValue<uint64_t>(table_name_.c_str(), col_name, db_id_, db_conn_);
323 }
324
325 5 inline double SqlRecord::getPropertyDouble(const char* col_name) const
326 {
327 5 return queryPropertyValue<double>(table_name_.c_str(), col_name, db_id_, db_conn_);
328 }
329
330 8 inline std::string SqlRecord::getPropertyString(const char* col_name) const
331 {
332 8 return queryPropertyValue<std::string>(table_name_.c_str(), col_name, db_id_, db_conn_);
333 }
334
335 12 template <typename T> inline std::vector<T> SqlRecord::getPropertyBlob(const char* col_name) const
336 {
337 12 return queryPropertyValue<std::vector<T>>(table_name_.c_str(), col_name, db_id_, db_conn_);
338 }
339
340 1 inline void SqlRecord::setPropertyInt32(const char* col_name, const int32_t val) const
341 {
342
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
1 transaction_->safeTransaction([&]() {
343
1/1
✓ Branch 2 → 3 taken 1 time.
1 auto stmt = createSetPropertyStmt_(col_name);
344
3/15
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 27 taken 1 time.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 25 → 26 not taken.
1 simdb_assert(!SQLiteReturnCode(sqlite3_bind_int(stmt, 1, val)), sqlite3_errmsg(db_conn_));
345
1/1
✓ Branch 28 → 29 taken 1 time.
1 stepStatement_(stmt, {SQLITE_DONE});
346 1 });
347 1 }
348
349 inline void SqlRecord::setPropertyUInt32(const char* col_name, const uint32_t val) const
350 {
351 transaction_->safeTransaction([&]() {
352 auto stmt = createSetPropertyStmt_(col_name);
353 simdb_assert(!SQLiteReturnCode(sqlite3_bind_int64(stmt, 1, static_cast<sqlite3_int64>(val))),
354 sqlite3_errmsg(db_conn_));
355 stepStatement_(stmt, {SQLITE_DONE});
356 });
357 }
358
359 1 inline void SqlRecord::setPropertyInt64(const char* col_name, const int64_t val) const
360 {
361
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
1 transaction_->safeTransaction([&]() {
362
1/1
✓ Branch 2 → 3 taken 1 time.
1 auto stmt = createSetPropertyStmt_(col_name);
363
3/15
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 27 taken 1 time.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 25 → 26 not taken.
1 simdb_assert(!SQLiteReturnCode(sqlite3_bind_int64(stmt, 1, val)), sqlite3_errmsg(db_conn_));
364
1/1
✓ Branch 28 → 29 taken 1 time.
1 stepStatement_(stmt, {SQLITE_DONE});
365 1 });
366 1 }
367
368 2 inline void SqlRecord::setPropertyUInt64(const char* col_name, const uint64_t val) const
369 {
370
2/2
✓ Branch 3 → 4 taken 2 times.
✓ Branch 4 → 5 taken 2 times.
2 transaction_->safeTransaction([&]() {
371
1/1
✓ Branch 2 → 3 taken 2 times.
2 auto utf16 = utils::uint64_to_utf16(val);
372
1/1
✓ Branch 3 → 4 taken 2 times.
2 auto stmt = createSetPropertyStmt_(col_name);
373
3/15
✓ Branch 6 → 7 taken 2 times.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 29 taken 2 times.
✗ Branch 12 → 13 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 27 → 28 not taken.
2 simdb_assert(!SQLiteReturnCode(sqlite3_bind_text16(stmt, 1, utf16.data(), 40, 0)), sqlite3_errmsg(db_conn_));
374
1/1
✓ Branch 30 → 31 taken 2 times.
2 stepStatement_(stmt, {SQLITE_DONE});
375 2 });
376 2 }
377
378 1 inline void SqlRecord::setPropertyDouble(const char* col_name, const double val) const
379 {
380
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
1 transaction_->safeTransaction([&]() {
381
1/1
✓ Branch 2 → 3 taken 1 time.
1 auto stmt = createSetPropertyStmt_(col_name);
382
3/15
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 27 taken 1 time.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 25 → 26 not taken.
1 simdb_assert(!SQLiteReturnCode(sqlite3_bind_double(stmt, 1, val)), sqlite3_errmsg(db_conn_));
383
1/1
✓ Branch 28 → 29 taken 1 time.
1 stepStatement_(stmt, {SQLITE_DONE});
384
385 1 return true;
386 1 });
387 1 }
388
389 1 inline void SqlRecord::setPropertyString(const char* col_name, const std::string& val) const
390 {
391
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
1 transaction_->safeTransaction([&]() {
392
1/1
✓ Branch 2 → 3 taken 1 time.
1 auto stmt = createSetPropertyStmt_(col_name);
393
3/15
✓ Branch 5 → 6 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 28 taken 1 time.
✗ Branch 11 → 12 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 26 → 27 not taken.
1 simdb_assert(!SQLiteReturnCode(sqlite3_bind_text(stmt, 1, val.c_str(), -1, 0)), sqlite3_errmsg(db_conn_));
394
1/1
✓ Branch 29 → 30 taken 1 time.
1 stepStatement_(stmt, {SQLITE_DONE});
395 1 });
396 1 }
397
398 1 template <typename T> inline void SqlRecord::setPropertyBlob(const char* col_name, const std::vector<T>& val) const
399 {
400
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
2 transaction_->safeTransaction([&]() {
401
1/1
✓ Branch 2 → 3 taken 1 time.
1 auto stmt = createSetPropertyStmt_(col_name);
402
3/15
✓ Branch 6 → 7 taken 1 time.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 29 taken 1 time.
✗ Branch 12 → 13 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 27 → 28 not taken.
1 simdb_assert(!SQLiteReturnCode(sqlite3_bind_blob(stmt, 1, val.data(), val.size() * sizeof(T), 0)),
403 sqlite3_errmsg(db_conn_));
404
1/1
✓ Branch 30 → 31 taken 1 time.
1 stepStatement_(stmt, {SQLITE_DONE});
405 1 });
406 1 }
407
408 1 inline void SqlRecord::setPropertyBlob(const char* col_name, const void* data, const size_t bytes) const
409 {
410
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 4 → 5 taken 1 time.
1 transaction_->safeTransaction([&]() {
411
1/1
✓ Branch 2 → 3 taken 1 time.
1 auto stmt = createSetPropertyStmt_(col_name);
412
3/15
✓ Branch 4 → 5 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 27 taken 1 time.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 25 → 26 not taken.
1 simdb_assert(!SQLiteReturnCode(sqlite3_bind_blob(stmt, 1, data, bytes, 0)), sqlite3_errmsg(db_conn_));
413
1/1
✓ Branch 28 → 29 taken 1 time.
1 stepStatement_(stmt, {SQLITE_DONE});
414 1 });
415 1 }
416
417 2 inline bool SqlRecord::removeFromTable()
418 {
419
1/1
✓ Branch 4 → 5 taken 2 times.
2 transaction_->safeTransaction([&]() {
420
1/1
✓ Branch 2 → 3 taken 2 times.
2 std::ostringstream oss;
421
4/4
✓ Branch 3 → 4 taken 2 times.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 6 → 7 taken 2 times.
2 oss << "DELETE FROM " << table_name_ << " WHERE Id=" << db_id_;
422
1/1
✓ Branch 7 → 8 taken 2 times.
2 const auto cmd = oss.str();
423
424
2/2
✓ Branch 9 → 10 taken 2 times.
✓ Branch 10 → 11 taken 2 times.
2 auto rc = SQLiteReturnCode(sqlite3_exec(db_conn_, cmd.c_str(), nullptr, nullptr, nullptr));
425
1/13
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 32 taken 2 times.
✗ Branch 15 → 16 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 27 → 28 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 30 → 31 not taken.
2 simdb_assert(!rc, sqlite3_errmsg(db_conn_));
426 2 });
427
428 2 return sqlite3_changes(db_conn_) == 1;
429 }
430
431 } // namespace simdb
432
433 #define SQL_TABLE(name) simdb::SqlTable(name)
434 #define SQL_COLUMNS(...) simdb::SqlColumns(__VA_ARGS__)
435 #define SQL_VALUES(...) simdb::SqlValues(__VA_ARGS__)
436