Skip to content

Commit c61c972

Browse files
authored
Merge pull request #1411 from fnc12/feature/logger
Logger
2 parents 564afba + 047762f commit c61c972

17 files changed

+2413
-440
lines changed

.vscode/settings.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@
7676
"__config": "cpp",
7777
"any": "cpp",
7878
"__threading_support": "cpp",
79-
"complex": "cpp",
8079
"condition_variable": "cpp",
81-
"execution": "cpp",
82-
"fstream": "cpp",
80+
"complex": "cpp",
81+
"thread": "cpp",
8382
"future": "cpp",
83+
"fstream": "cpp",
84+
"execution": "cpp",
8485
"iostream": "cpp",
8586
"numbers": "cpp",
8687
"queue": "cpp",

dev/connection_holder.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ namespace sqlite_orm {
3434
// therefore we can just use an atomic increment but don't need sequencing due to `prevCount > 0`.
3535
if (_retainCount.fetch_add(1, std::memory_order_relaxed) == 0) {
3636
int open_flags = internal::db_open_mode_to_int_flags(this->open_mode);
37-
#if SQLITE_VERSION_NUMBER >= 3008008
37+
#if SQLITE_VERSION_NUMBER >= 3037002
3838
open_flags |= SQLITE_OPEN_EXRESCODE;
3939
#endif
4040

41-
int rc = sqlite3_open_v2(this->filename.c_str(), &this->db, open_flags, this->vfs_name.c_str());
41+
const int rc =
42+
sqlite3_open_v2(this->filename.c_str(), &this->db, open_flags, this->vfs_name.c_str());
4243

4344
if (rc != SQLITE_OK) SQLITE_ORM_CPP_UNLIKELY /*possible, but unexpected*/ {
4445
throw_translated_sqlite_error(rc);

dev/implementations/storage_definitions.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ namespace sqlite_orm {
149149
}
150150
});
151151

152-
std::stringstream ss;
153-
ss << "INSERT INTO " << streaming_identifier(destinationTableName) << " ("
154-
<< streaming_identifiers(columnNames) << ") "
155-
<< "SELECT " << streaming_identifiers(columnNames) << " FROM " << streaming_identifier(sourceTableName)
156-
<< std::flush;
157-
perform_void_exec(db, ss.str());
152+
std::string sql;
153+
{
154+
std::stringstream ss;
155+
ss << "INSERT INTO " << streaming_identifier(destinationTableName) << " ("
156+
<< streaming_identifiers(columnNames) << ") "
157+
<< "SELECT " << streaming_identifiers(columnNames) << " FROM "
158+
<< streaming_identifier(sourceTableName) << std::flush;
159+
sql = ss.str();
160+
}
161+
this->executor.perform_void_exec(db, sql.data());
158162
}
159163
}
160164
}

dev/mapped_view.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ namespace sqlite_orm {
5151

5252
mapped_iterator<T, db_objects_type> begin() {
5353
using context_t = serializer_context<db_objects_type>;
54+
5455
auto& dbObjects = obtain_db_objects(this->storage);
5556
context_t context{dbObjects};
5657
context.skip_table_name = false;
5758
context.replace_bindable_with_question = true;
5859

59-
statement_finalizer stmt{prepare_stmt(this->connection.get(), serialize(this->expression, context))};
60+
const std::string sql = serialize(this->expression, context);
61+
statement_finalizer stmt{prepare_stmt(this->connection.get(), sql)};
6062
iterate_ast(this->expression.conditions, conditional_binder{stmt.get()});
6163
return {dbObjects, std::move(stmt)};
6264
}

dev/pragma.h

+30-18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace sqlite_orm {
2222

2323
namespace internal {
2424
struct storage_base;
25+
struct sqlite_executor;
2526

2627
template<class T>
2728
int getPragmaCallback(void* data, int argc, char** argv, char** x) {
@@ -42,7 +43,8 @@ namespace sqlite_orm {
4243
struct pragma_t {
4344
using get_connection_t = std::function<internal::connection_ref()>;
4445

45-
pragma_t(get_connection_t get_connection_) : get_connection(std::move(get_connection_)) {}
46+
pragma_t(get_connection_t get_connection_, const sqlite_executor& executor) :
47+
get_connection(std::move(get_connection_)), executor(executor) {}
4648

4749
std::vector<std::string> module_list() {
4850
return this->get_pragma<std::vector<std::string>>("module_list");
@@ -156,13 +158,17 @@ namespace sqlite_orm {
156158
auto connection = this->get_connection();
157159

158160
std::vector<sqlite_orm::table_xinfo> result;
159-
std::ostringstream ss;
160-
ss << "PRAGMA "
161-
"table_xinfo("
162-
<< streaming_identifier(tableName) << ")" << std::flush;
163-
perform_exec(
161+
std::string sql;
162+
{
163+
std::ostringstream ss;
164+
ss << "PRAGMA "
165+
"table_xinfo("
166+
<< streaming_identifier(tableName) << ")" << std::flush;
167+
sql = ss.str();
168+
}
169+
this->executor.perform_exec(
164170
connection.get(),
165-
ss.str(),
171+
sql,
166172
[](void* data, int argc, char** argv, char**) -> int {
167173
auto& res = *(std::vector<sqlite_orm::table_xinfo>*)data;
168174
if (argc) {
@@ -192,14 +198,18 @@ namespace sqlite_orm {
192198
std::vector<sqlite_orm::table_info> table_info(const std::string& tableName) const {
193199
auto connection = this->get_connection();
194200

195-
std::ostringstream ss;
196-
ss << "PRAGMA "
197-
"table_info("
198-
<< streaming_identifier(tableName) << ")" << std::flush;
201+
std::string sql;
202+
{
203+
std::ostringstream ss;
204+
ss << "PRAGMA "
205+
"table_info("
206+
<< streaming_identifier(tableName) << ")" << std::flush;
207+
sql = ss.str();
208+
}
199209
std::vector<sqlite_orm::table_info> result;
200-
perform_exec(
210+
this->executor.perform_exec(
201211
connection.get(),
202-
ss.str(),
212+
sql,
203213
[](void* data, int argc, char** argv, char**) -> int {
204214
auto& res = *(std::vector<sqlite_orm::table_info>*)data;
205215
if (argc) {
@@ -225,12 +235,14 @@ namespace sqlite_orm {
225235
int synchronous_ = -1;
226236
signed char journal_mode_ = -1; // if != -1 stores static_cast<sqlite_orm::journal_mode>(journal_mode)
227237
get_connection_t get_connection;
238+
const sqlite_executor& executor;
228239

229240
template<class T>
230241
T get_pragma(const std::string& name) {
231242
auto connection = this->get_connection();
232243
T result;
233-
perform_exec(connection.get(), "PRAGMA " + name, getPragmaCallback<T>, &result);
244+
const std::string sql = "PRAGMA " + name;
245+
this->executor.perform_exec(connection.get(), sql, getPragmaCallback<T>, &result);
234246
return result;
235247
}
236248

@@ -257,12 +269,12 @@ namespace sqlite_orm {
257269
this->set_pragma_impl(ss.str(), db);
258270
}
259271

260-
void set_pragma_impl(const std::string& query, sqlite3* db = nullptr) {
272+
void set_pragma_impl(const std::string& sql, sqlite3* db = nullptr) {
261273
if (db) {
262-
perform_void_exec(db, query);
274+
this->executor.perform_void_exec(db, sql.data());
263275
} else {
264-
auto con = this->get_connection();
265-
perform_void_exec(con.get(), query);
276+
auto connection = this->get_connection();
277+
this->executor.perform_void_exec(connection.get(), sql.data());
266278
}
267279
}
268280
};

dev/result_set_view.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ namespace sqlite_orm::internal {
5151
using select_type = polyfill::detected_or_t<expression_type, expression_type_t, expression_type>;
5252
using column_result_type = column_result_of_t<ExprDBOs, select_type>;
5353
using context_t = serializer_context<ExprDBOs>;
54+
5455
context_t context{exprDBOs};
5556
context.skip_table_name = false;
5657
context.replace_bindable_with_question = true;
5758

58-
statement_finalizer stmt{prepare_stmt(this->connection.get(), serialize(this->expression, context))};
59+
const std::string sql = serialize(this->expression, context);
60+
statement_finalizer stmt{prepare_stmt(this->connection.get(), sql)};
5961
iterate_ast(this->expression, conditional_binder{stmt.get()});
6062

6163
// note: it is enough to only use the 'expression DBOs' at compile-time to determine the column results;

0 commit comments

Comments
 (0)