Skip to content

Commit fdbfbc3

Browse files
MeanSquaredErrorrbock
authored andcommitted
Replace ()-initialization with {}-initialization in the SQLite3 connector code.
1 parent f7ad116 commit fdbfbc3

File tree

6 files changed

+46
-46
lines changed

6 files changed

+46
-46
lines changed

include/sqlpp11/sqlite3/bind_result.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace sqlpp
104104

105105
public:
106106
bind_result_t() = default;
107-
bind_result_t(const std::shared_ptr<detail::prepared_statement_handle_t>& handle) : _handle(handle)
107+
bind_result_t(const std::shared_ptr<detail::prepared_statement_handle_t>& handle) : _handle{handle}
108108
{
109109
if (_handle and _handle->debug)
110110
std::cerr << "Sqlite3 debug: Constructing bind result, using handle at " << _handle.get() << std::endl;
@@ -230,7 +230,7 @@ namespace sqlpp
230230
if (detail::check_date_digits(date_string))
231231
{
232232
const auto ymd = ::date::year(std::atoi(date_string)) / atoi(date_string + 5) / atoi(date_string + 8);
233-
*value = ::sqlpp::chrono::day_point(ymd);
233+
*value = ::sqlpp::chrono::day_point{ymd};
234234
}
235235
else
236236
{
@@ -261,7 +261,7 @@ namespace sqlpp
261261
{
262262
const auto ymd =
263263
::date::year(std::atoi(date_time_string)) / atoi(date_time_string + 5) / atoi(date_time_string + 8);
264-
*value = ::sqlpp::chrono::day_point(ymd);
264+
*value = ::sqlpp::chrono::day_point{ymd};
265265
}
266266
else
267267
{
@@ -275,8 +275,8 @@ namespace sqlpp
275275
const auto time_string = date_time_string + 11; // YYYY-MM-DDT
276276
if (detail::check_time_digits(time_string))
277277
{
278-
*value += ::std::chrono::hours(std::atoi(time_string + 0)) +
279-
std::chrono::minutes(std::atoi(time_string + 3)) + std::chrono::seconds(std::atoi(time_string + 6));
278+
*value += ::std::chrono::hours{std::atoi(time_string + 0)} +
279+
std::chrono::minutes{std::atoi(time_string + 3)} + std::chrono::seconds{std::atoi(time_string + 6)};
280280
}
281281
else
282282
{
@@ -285,7 +285,7 @@ namespace sqlpp
285285
const auto ms_string = time_string + 9; // hh:mm:ss.
286286
if (detail::check_ms_digits(ms_string) and ms_string[4] == '\0')
287287
{
288-
*value += ::std::chrono::milliseconds(std::atoi(ms_string));
288+
*value += ::std::chrono::milliseconds{std::atoi(ms_string)};
289289
}
290290
else
291291
{
@@ -308,7 +308,7 @@ namespace sqlpp
308308
case SQLITE_DONE:
309309
return false;
310310
default:
311-
throw sqlpp::exception("Sqlite3 error: Unexpected return value for sqlite3_step()");
311+
throw sqlpp::exception{"Sqlite3 error: Unexpected return value for sqlite3_step()"};
312312
}
313313
}
314314
};

include/sqlpp11/sqlite3/connection.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ namespace sqlpp
7272
if (handle->config->debug)
7373
std::cerr << "Sqlite3 debug: Preparing: '" << statement << "'" << std::endl;
7474

75-
detail::prepared_statement_handle_t result(nullptr, handle->config->debug);
75+
detail::prepared_statement_handle_t result{nullptr, handle->config->debug};
7676

7777
auto rc = sqlite3_prepare_v2(handle->native_handle(), statement.c_str(), static_cast<int>(statement.size()),
7878
&result.sqlite_statement, nullptr);
7979

8080
if (rc != SQLITE_OK)
8181
{
82-
throw sqlpp::exception(
82+
throw sqlpp::exception{
8383
"Sqlite3 error: Could not prepare statement: " + std::string(sqlite3_errmsg(handle->native_handle())) +
84-
" (statement was >>" + (rc == SQLITE_TOOBIG ? statement.substr(0, 128) + "..." : statement) + "<<\n");
84+
" (statement was >>" + (rc == SQLITE_TOOBIG ? statement.substr(0, 128) + "..." : statement) + "<<\n"};
8585
}
8686

8787
return result;
@@ -99,8 +99,8 @@ namespace sqlpp
9999
default:
100100
if (handle->config->debug)
101101
std::cerr << "Sqlite3 debug: sqlite3_step return code: " << rc << std::endl;
102-
throw sqlpp::exception("Sqlite3 error: Could not execute statement: " +
103-
std::string(sqlite3_errmsg(handle->native_handle())));
102+
throw sqlpp::exception{"Sqlite3 error: Could not execute statement: " +
103+
std::string(sqlite3_errmsg(handle->native_handle()))};
104104
}
105105
}
106106
} // namespace detail
@@ -110,7 +110,7 @@ namespace sqlpp
110110

111111
struct context_t
112112
{
113-
context_t(const connection_base& db) : _db(db), _count(1)
113+
context_t(const connection_base& db) : _db{db}, _count{1}
114114
{
115115
}
116116

@@ -153,16 +153,16 @@ namespace sqlpp
153153
active
154154
};
155155

156-
transaction_status_type _transaction_status = transaction_status_type::none;
156+
transaction_status_type _transaction_status{transaction_status_type::none};
157157

158158
// direct execution
159159
bind_result_t select_impl(const std::string& statement)
160160
{
161-
std::unique_ptr<detail::prepared_statement_handle_t> prepared(
162-
new detail::prepared_statement_handle_t(prepare_statement(_handle, statement)));
161+
std::unique_ptr<detail::prepared_statement_handle_t> prepared{
162+
new detail::prepared_statement_handle_t(prepare_statement(_handle, statement))};
163163
if (!prepared)
164164
{
165-
throw sqlpp::exception("Sqlite3 error: Could not store result set");
165+
throw sqlpp::exception{"Sqlite3 error: Could not store result set"};
166166
}
167167

168168
return {std::move(prepared)};
@@ -193,8 +193,8 @@ namespace sqlpp
193193
// prepared execution
194194
prepared_statement_t prepare_impl(const std::string& statement)
195195
{
196-
return {std::unique_ptr<detail::prepared_statement_handle_t>(
197-
new detail::prepared_statement_handle_t(prepare_statement(_handle, statement)))};
196+
return {std::unique_ptr<detail::prepared_statement_handle_t>{
197+
new detail::prepared_statement_handle_t(prepare_statement(_handle, statement))}};
198198
}
199199

200200
bind_result_t run_prepared_select_impl(prepared_statement_t& prepared_statement)
@@ -263,15 +263,15 @@ namespace sqlpp
263263
template <typename Select>
264264
bind_result_t select(const Select& s)
265265
{
266-
_context_t context(*this);
266+
_context_t context{*this};
267267
serialize(s, context);
268268
return select_impl(context.str());
269269
}
270270

271271
template <typename Select>
272272
_prepared_statement_t prepare_select(Select& s)
273273
{
274-
_context_t context(*this);
274+
_context_t context{*this};
275275
serialize(s, context);
276276
return prepare_impl(context.str());
277277
}
@@ -288,15 +288,15 @@ namespace sqlpp
288288
template <typename Insert>
289289
size_t insert(const Insert& i)
290290
{
291-
_context_t context(*this);
291+
_context_t context{*this};
292292
serialize(i, context);
293293
return insert_impl(context.str());
294294
}
295295

296296
template <typename Insert>
297297
_prepared_statement_t prepare_insert(Insert& i)
298298
{
299-
_context_t context(*this);
299+
_context_t context{*this};
300300
serialize(i, context);
301301
return prepare_impl(context.str());
302302
}
@@ -313,15 +313,15 @@ namespace sqlpp
313313
template <typename Update>
314314
size_t update(const Update& u)
315315
{
316-
_context_t context(*this);
316+
_context_t context{*this};
317317
serialize(u, context);
318318
return update_impl(context.str());
319319
}
320320

321321
template <typename Update>
322322
_prepared_statement_t prepare_update(Update& u)
323323
{
324-
_context_t context(*this);
324+
_context_t context{*this};
325325
serialize(u, context);
326326
return prepare_impl(context.str());
327327
}
@@ -338,15 +338,15 @@ namespace sqlpp
338338
template <typename Remove>
339339
size_t remove(const Remove& r)
340340
{
341-
_context_t context(*this);
341+
_context_t context{*this};
342342
serialize(r, context);
343343
return remove_impl(context.str());
344344
}
345345

346346
template <typename Remove>
347347
_prepared_statement_t prepare_remove(Remove& r)
348348
{
349-
_context_t context(*this);
349+
_context_t context{*this};
350350
serialize(r, context);
351351
return prepare_impl(context.str());
352352
}
@@ -372,15 +372,15 @@ namespace sqlpp
372372
typename Enable = typename std::enable_if<not std::is_convertible<Execute, std::string>::value, void>::type>
373373
size_t execute(const Execute& x)
374374
{
375-
_context_t context(*this);
375+
_context_t context{*this};
376376
serialize(x, context);
377377
return execute(context.str());
378378
}
379379

380380
template <typename Execute>
381381
_prepared_statement_t prepare_execute(Execute& x)
382382
{
383-
_context_t context(*this);
383+
_context_t context{*this};
384384
serialize(x, context);
385385
return prepare_impl(context.str());
386386
}
@@ -472,7 +472,7 @@ namespace sqlpp
472472
{
473473
if (_transaction_status == transaction_status_type::active)
474474
{
475-
throw sqlpp::exception("Sqlite3 error: Cannot have more than one open transaction per connection");
475+
throw sqlpp::exception{"Sqlite3 error: Cannot have more than one open transaction per connection"};
476476
}
477477

478478
_transaction_status = transaction_status_type::maybe;
@@ -486,7 +486,7 @@ namespace sqlpp
486486
{
487487
if (_transaction_status == transaction_status_type::none)
488488
{
489-
throw sqlpp::exception("Sqlite3 error: Cannot commit a finished or failed transaction");
489+
throw sqlpp::exception{"Sqlite3 error: Cannot commit a finished or failed transaction"};
490490
}
491491
_transaction_status = transaction_status_type::maybe;
492492
auto prepared = prepare_statement(_handle, "COMMIT");
@@ -500,7 +500,7 @@ namespace sqlpp
500500
{
501501
if (_transaction_status == transaction_status_type::none)
502502
{
503-
throw sqlpp::exception("Sqlite3 error: Cannot rollback a finished or failed transaction");
503+
throw sqlpp::exception{"Sqlite3 error: Cannot rollback a finished or failed transaction"};
504504
}
505505
if (report)
506506
{

include/sqlpp11/sqlite3/connection_config.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace sqlpp
3535
{
3636
struct connection_config
3737
{
38-
connection_config() : path_to_database(), flags(0), vfs(), debug(false),password("")
38+
connection_config() : path_to_database{}, flags{0}, vfs{}, debug{false},password{}
3939
{
4040
}
4141
connection_config(const connection_config&) = default;
@@ -44,7 +44,7 @@ namespace sqlpp
4444
connection_config& operator=(connection_config&&) = default;
4545

4646
connection_config(std::string path, int fl = 0, std::string vf = "", bool dbg = false,std::string password="")
47-
: path_to_database(std::move(path)), flags(fl), vfs(std::move(vf)), debug(dbg),password(password)
47+
: path_to_database{std::move(path)}, flags{fl}, vfs{std::move(vf)}, debug{dbg},password{password}
4848
{
4949
}
5050

include/sqlpp11/sqlite3/detail/connection_handle.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ namespace sqlpp
5353
std::unique_ptr<::sqlite3, int (*)(::sqlite3*)> sqlite;
5454

5555
connection_handle(const std::shared_ptr<const connection_config>& conf) :
56-
config(conf),
57-
sqlite(nullptr, sqlite3_close)
56+
config{conf},
57+
sqlite{nullptr, sqlite3_close}
5858
{
5959
#ifdef SQLPP_DYNAMIC_LOADING
6060
init_sqlite("");
@@ -67,7 +67,7 @@ namespace sqlpp
6767
{
6868
const std::string msg = sqlite3_errmsg(sqlite_ptr);
6969
sqlite3_close(sqlite_ptr);
70-
throw sqlpp::exception("Sqlite3 error: Can't open database: " + msg);
70+
throw sqlpp::exception{"Sqlite3 error: Can't open database: " + msg};
7171
}
7272

7373
sqlite.reset(sqlite_ptr);
@@ -80,7 +80,7 @@ namespace sqlpp
8080
{
8181
const std::string msg = sqlite3_errmsg(native_handle());
8282
sqlite3_close(native_handle());
83-
throw sqlpp::exception("Sqlite3 error: Can't set password to database: " + msg);
83+
throw sqlpp::exception{"Sqlite3 error: Can't set password to database: " + msg};
8484
}
8585
}
8686
#endif

include/sqlpp11/sqlite3/detail/prepared_statement_handle.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ namespace sqlpp
4848
sqlite3_stmt* sqlite_statement;
4949
bool debug;
5050

51-
prepared_statement_handle_t(sqlite3_stmt* statement, bool debug_) : sqlite_statement(statement), debug(debug_)
51+
prepared_statement_handle_t(sqlite3_stmt* statement, bool debug_) : sqlite_statement{statement}, debug{debug_}
5252
{
5353
}
5454

5555
prepared_statement_handle_t(const prepared_statement_handle_t&) = delete;
5656
prepared_statement_handle_t(prepared_statement_handle_t&& rhs) :
57-
sqlite_statement(rhs.sqlite_statement),
58-
debug(rhs.debug)
57+
sqlite_statement{rhs.sqlite_statement},
58+
debug{rhs.debug}
5959
{
6060
rhs.sqlite_statement = nullptr;
6161
}

include/sqlpp11/sqlite3/prepared_statement.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ namespace sqlpp
6060
case SQLITE_OK:
6161
return;
6262
case SQLITE_RANGE:
63-
throw sqlpp::exception("Sqlite3 error: " + std::string(type) + " bind value out of range");
63+
throw sqlpp::exception{"Sqlite3 error: " + std::string(type) + " bind value out of range"};
6464
case SQLITE_NOMEM:
65-
throw sqlpp::exception("Sqlite3 error: " + std::string(type) + " bind out of memory");
65+
throw sqlpp::exception{"Sqlite3 error: " + std::string(type) + " bind out of memory"};
6666
case SQLITE_TOOBIG:
67-
throw sqlpp::exception("Sqlite3 error: " + std::string(type) + " bind too big");
67+
throw sqlpp::exception{"Sqlite3 error: " + std::string(type) + " bind too big"};
6868
default:
69-
throw sqlpp::exception("Sqlite3 error: " + std::string(type) +
70-
" bind returned unexpected value: " + std::to_string(result));
69+
throw sqlpp::exception{"Sqlite3 error: " + std::string(type) +
70+
" bind returned unexpected value: " + std::to_string(result)};
7171
}
7272
}
7373
} // namespace detail

0 commit comments

Comments
 (0)