Skip to content

Commit e94d56c

Browse files
committed
type fixes
1 parent bbcf8f1 commit e94d56c

File tree

6 files changed

+88
-98
lines changed

6 files changed

+88
-98
lines changed

dev/implementations/storage_definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace sqlite_orm {
158158
<< streaming_identifier(sourceTableName) << std::flush;
159159
sql = ss.str();
160160
}
161-
this->executor.perform_void_exec(db, sql);
161+
this->executor.perform_void_exec(db, sql.data());
162162
}
163163
}
164164
}

dev/pragma.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ namespace sqlite_orm {
271271

272272
void set_pragma_impl(const std::string& sql, sqlite3* db = nullptr) {
273273
if (db) {
274-
this->executor.perform_void_exec(db, sql);
274+
this->executor.perform_void_exec(db, sql.data());
275275
} else {
276-
auto con = this->get_connection();
277-
this->executor.perform_void_exec(con.get(), sql);
276+
auto connection = this->get_connection();
277+
this->executor.perform_void_exec(connection.get(), sql.data());
278278
}
279279
}
280280
};

dev/storage.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ namespace sqlite_orm {
194194
context_t context{this->db_objects};
195195
statement_serializer<Table, void> serializer;
196196
const std::string sql = serializer.serialize(table, context, tableName);
197-
this->executor.perform_void_exec(db, sql);
197+
this->executor.perform_void_exec(db, sql.data());
198198
}
199199

200200
/**
@@ -217,7 +217,7 @@ namespace sqlite_orm {
217217
<< streaming_identifier(columnName) << std::flush;
218218
sql = ss.str();
219219
}
220-
this->executor.perform_void_exec(db, sql);
220+
this->executor.perform_void_exec(db, sql.data());
221221
}
222222
#endif
223223

@@ -1186,7 +1186,7 @@ namespace sqlite_orm {
11861186
const auto res = sync_schema_result::already_in_sync;
11871187
context_t context{this->db_objects};
11881188
const auto sql = serialize(virtualTable, context);
1189-
this->executor.perform_void_exec(db, sql);
1189+
this->executor.perform_void_exec(db, sql.data());
11901190
return res;
11911191
}
11921192

@@ -1197,7 +1197,7 @@ namespace sqlite_orm {
11971197
const auto res = sync_schema_result::already_in_sync;
11981198
context_t context{this->db_objects};
11991199
const auto sql = serialize(index, context);
1200-
this->executor.perform_void_exec(db, sql);
1200+
this->executor.perform_void_exec(db, sql.data());
12011201
return res;
12021202
}
12031203

@@ -1208,7 +1208,7 @@ namespace sqlite_orm {
12081208
const auto res = sync_schema_result::already_in_sync; // TODO Change accordingly
12091209
context_t context{this->db_objects};
12101210
const auto sql = serialize(trigger, context);
1211-
this->executor.perform_void_exec(db, sql);
1211+
this->executor.perform_void_exec(db, sql.data());
12121212
return res;
12131213
}
12141214

@@ -1230,7 +1230,7 @@ namespace sqlite_orm {
12301230
<< serialize(column, context) << std::flush;
12311231
sql = ss.str();
12321232
}
1233-
this->executor.perform_void_exec(db, sql);
1233+
this->executor.perform_void_exec(db, sql.data());
12341234
}
12351235

12361236
template<class ColResult, class S>

dev/storage_base.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace sqlite_orm {
156156
<< streaming_identifier(newName) << std::flush;
157157
sql = ss.str();
158158
}
159-
this->executor.perform_void_exec(db, sql);
159+
this->executor.perform_void_exec(db, sql.data());
160160
}
161161

162162
/**
@@ -732,7 +732,7 @@ namespace sqlite_orm {
732732
void begin_transaction_internal(const std::string& sql) {
733733
this->connection->retain();
734734
sqlite3* db = this->connection->get();
735-
this->executor.perform_void_exec(db, sql);
735+
this->executor.perform_void_exec(db, sql.data());
736736
}
737737

738738
connection_ref get_connection() {
@@ -748,7 +748,7 @@ namespace sqlite_orm {
748748
ss << "PRAGMA foreign_keys = " << value << std::flush;
749749
sql = ss.str();
750750
}
751-
this->executor.perform_void_exec(db, sql);
751+
this->executor.perform_void_exec(db, sql.data());
752752
}
753753

754754
bool foreign_keys(sqlite3* db) {
@@ -970,7 +970,7 @@ namespace sqlite_orm {
970970
ss << ' ' << streaming_identifier(tableName) << std::flush;
971971
sql = ss.str();
972972
}
973-
this->executor.perform_void_exec(db, sql);
973+
this->executor.perform_void_exec(db, sql.data());
974974
}
975975

976976
void drop_index_internal(const std::string& indexName, bool ifExists) {
@@ -985,7 +985,7 @@ namespace sqlite_orm {
985985
sql = ss.str();
986986
}
987987
auto connection = this->get_connection();
988-
this->executor.perform_void_exec(connection.get(), sql);
988+
this->executor.perform_void_exec(connection.get(), sql.data());
989989
}
990990

991991
void drop_trigger_internal(const std::string& triggerName, bool ifExists) {
@@ -1000,7 +1000,7 @@ namespace sqlite_orm {
10001000
sql = ss.str();
10011001
}
10021002
auto connection = this->get_connection();
1003-
this->executor.perform_void_exec(connection.get(), sql);
1003+
this->executor.perform_void_exec(connection.get(), sql.data());
10041004
}
10051005

10061006
static int
@@ -1069,7 +1069,7 @@ namespace sqlite_orm {
10691069
std::function<int(int)> _busy_handler;
10701070
std::list<udf_proxy> scalarFunctions;
10711071
std::list<udf_proxy> aggregateFunctions;
1072-
sqlite_executor executor;
1072+
const sqlite_executor executor;
10731073
};
10741074
}
10751075
}

dev/util.h

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,31 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
5959
namespace sqlite_orm {
6060
namespace internal {
6161

62+
template<class L>
63+
int perform_step(sqlite3_stmt* stmt, L&& lambda) {
64+
const int rc = sqlite3_step(stmt);
65+
switch (rc) {
66+
case SQLITE_ROW: {
67+
lambda(stmt);
68+
} break;
69+
case SQLITE_DONE:
70+
break;
71+
default: {
72+
throw_translated_sqlite_error(rc);
73+
}
74+
}
75+
return rc;
76+
}
77+
6278
struct sqlite_executor {
6379
std::function<void(serialize_arg_type sql)> will_run_query;
6480
std::function<void(serialize_arg_type sql)> did_run_query;
6581

66-
inline void perform_void_exec(sqlite3* db, serialize_arg_type sql) const {
82+
inline void perform_void_exec(sqlite3* db, const char* sql) const {
6783
if (this->will_run_query) {
6884
this->will_run_query(sql);
6985
}
70-
const int rc = sqlite3_exec(db, sql.data(), nullptr, nullptr, nullptr);
86+
const int rc = sqlite3_exec(db, sql, nullptr, nullptr, nullptr);
7187
if (rc != SQLITE_OK) {
7288
throw_translated_sqlite_error(rc);
7389
}
@@ -93,30 +109,24 @@ namespace sqlite_orm {
93109
}
94110

95111
inline void perform_exec(sqlite3* db,
96-
const serialize_result_type& query,
112+
const std::string& query,
97113
int (*callback)(void* data, int argc, char** argv, char**),
98114
void* user_data) const {
99115
return perform_exec(db, query.data(), callback, user_data);
100116
}
101117

102118
template<class L>
103-
void perform_steps(sqlite3_stmt* stmt, L&& lambda) {
104-
const auto sql = sqlite3_sql(stmt);
119+
void perform_steps(sqlite3_stmt* stmt, L&& lambda) const {
120+
const char* sql = nullptr;
121+
if (this->will_run_query || this->did_run_query) {
122+
sql = sqlite3_sql(stmt);
123+
}
105124
if (this->will_run_query) {
106125
this->will_run_query(sql);
107126
}
108-
int rc;
127+
int rc = 0;
109128
do {
110-
switch (rc = sqlite3_step(stmt)) {
111-
case SQLITE_ROW: {
112-
lambda(stmt);
113-
} break;
114-
case SQLITE_DONE:
115-
break;
116-
default: {
117-
throw_translated_sqlite_error(rc);
118-
}
119-
}
129+
rc = internal::perform_step(stmt, lambda);
120130
} while (rc != SQLITE_DONE);
121131
if (this->did_run_query) {
122132
this->did_run_query(sql);
@@ -130,10 +140,9 @@ namespace sqlite_orm {
130140
return stmt;
131141
}
132142

133-
// note: query is deliberately taken by value, such that it is thrown away early
134143
inline sqlite3_stmt* prepare_stmt(sqlite3* db, serialize_arg_type query) {
135144
sqlite3_stmt* stmt;
136-
const int rc = sqlite3_prepare_v2(db, query.data(), -1, &stmt, nullptr);
145+
const int rc = sqlite3_prepare_v2(db, query.data(), query.size(), &stmt, nullptr);
137146
if (rc != SQLITE_OK) SQLITE_ORM_CPP_UNLIKELY /*possible but unexpected*/ {
138147
throw_translated_sqlite_error(rc);
139148
}
@@ -147,19 +156,5 @@ namespace sqlite_orm {
147156
throw_translated_sqlite_error(rc);
148157
}
149158
}
150-
151-
template<class L>
152-
void perform_step(sqlite3_stmt* stmt, L&& lambda) {
153-
switch (int rc = sqlite3_step(stmt)) {
154-
case SQLITE_ROW: {
155-
lambda(stmt);
156-
} break;
157-
case SQLITE_DONE:
158-
return;
159-
default: {
160-
throw_translated_sqlite_error(rc);
161-
}
162-
}
163-
}
164159
}
165160
}

0 commit comments

Comments
 (0)