@@ -22,6 +22,7 @@ namespace sqlite_orm {
22
22
23
23
namespace internal {
24
24
struct storage_base ;
25
+ struct sqlite_executor ;
25
26
26
27
template <class T >
27
28
int getPragmaCallback (void * data, int argc, char ** argv, char ** x) {
@@ -42,7 +43,8 @@ namespace sqlite_orm {
42
43
struct pragma_t {
43
44
using get_connection_t = std::function<internal::connection_ref()>;
44
45
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) {}
46
48
47
49
std::vector<std::string> module_list () {
48
50
return this ->get_pragma <std::vector<std::string>>(" module_list" );
@@ -156,13 +158,17 @@ namespace sqlite_orm {
156
158
auto connection = this ->get_connection ();
157
159
158
160
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 (
164
170
connection.get (),
165
- ss. str () ,
171
+ sql ,
166
172
[](void * data, int argc, char ** argv, char **) -> int {
167
173
auto & res = *(std::vector<sqlite_orm::table_xinfo>*)data;
168
174
if (argc) {
@@ -192,14 +198,18 @@ namespace sqlite_orm {
192
198
std::vector<sqlite_orm::table_info> table_info (const std::string& tableName) const {
193
199
auto connection = this ->get_connection ();
194
200
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
+ }
199
209
std::vector<sqlite_orm::table_info> result;
200
- perform_exec (
210
+ this -> executor . perform_exec (
201
211
connection.get (),
202
- ss. str () ,
212
+ sql ,
203
213
[](void * data, int argc, char ** argv, char **) -> int {
204
214
auto & res = *(std::vector<sqlite_orm::table_info>*)data;
205
215
if (argc) {
@@ -225,12 +235,14 @@ namespace sqlite_orm {
225
235
int synchronous_ = -1 ;
226
236
signed char journal_mode_ = -1 ; // if != -1 stores static_cast<sqlite_orm::journal_mode>(journal_mode)
227
237
get_connection_t get_connection;
238
+ const sqlite_executor& executor;
228
239
229
240
template <class T >
230
241
T get_pragma (const std::string& name) {
231
242
auto connection = this ->get_connection ();
232
243
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);
234
246
return result;
235
247
}
236
248
@@ -257,12 +269,12 @@ namespace sqlite_orm {
257
269
this ->set_pragma_impl (ss.str (), db);
258
270
}
259
271
260
- void set_pragma_impl (const std::string& query , sqlite3* db = nullptr ) {
272
+ void set_pragma_impl (const std::string& sql , sqlite3* db = nullptr ) {
261
273
if (db) {
262
- perform_void_exec (db, query );
274
+ this -> executor . perform_void_exec (db, sql. data () );
263
275
} 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 () );
266
278
}
267
279
}
268
280
};
0 commit comments