0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Replace ()-initialization with {}-initialization in the SQLite3 connector code.

This commit is contained in:
MeanSquaredError 2023-08-18 15:27:31 +03:00 committed by Roland Bock
parent f7ad116ced
commit fdbfbc345e
6 changed files with 46 additions and 46 deletions

View File

@ -104,7 +104,7 @@ namespace sqlpp
public: public:
bind_result_t() = default; bind_result_t() = default;
bind_result_t(const std::shared_ptr<detail::prepared_statement_handle_t>& handle) : _handle(handle) bind_result_t(const std::shared_ptr<detail::prepared_statement_handle_t>& handle) : _handle{handle}
{ {
if (_handle and _handle->debug) if (_handle and _handle->debug)
std::cerr << "Sqlite3 debug: Constructing bind result, using handle at " << _handle.get() << std::endl; std::cerr << "Sqlite3 debug: Constructing bind result, using handle at " << _handle.get() << std::endl;
@ -230,7 +230,7 @@ namespace sqlpp
if (detail::check_date_digits(date_string)) if (detail::check_date_digits(date_string))
{ {
const auto ymd = ::date::year(std::atoi(date_string)) / atoi(date_string + 5) / atoi(date_string + 8); const auto ymd = ::date::year(std::atoi(date_string)) / atoi(date_string + 5) / atoi(date_string + 8);
*value = ::sqlpp::chrono::day_point(ymd); *value = ::sqlpp::chrono::day_point{ymd};
} }
else else
{ {
@ -261,7 +261,7 @@ namespace sqlpp
{ {
const auto ymd = const auto ymd =
::date::year(std::atoi(date_time_string)) / atoi(date_time_string + 5) / atoi(date_time_string + 8); ::date::year(std::atoi(date_time_string)) / atoi(date_time_string + 5) / atoi(date_time_string + 8);
*value = ::sqlpp::chrono::day_point(ymd); *value = ::sqlpp::chrono::day_point{ymd};
} }
else else
{ {
@ -275,8 +275,8 @@ namespace sqlpp
const auto time_string = date_time_string + 11; // YYYY-MM-DDT const auto time_string = date_time_string + 11; // YYYY-MM-DDT
if (detail::check_time_digits(time_string)) if (detail::check_time_digits(time_string))
{ {
*value += ::std::chrono::hours(std::atoi(time_string + 0)) + *value += ::std::chrono::hours{std::atoi(time_string + 0)} +
std::chrono::minutes(std::atoi(time_string + 3)) + std::chrono::seconds(std::atoi(time_string + 6)); std::chrono::minutes{std::atoi(time_string + 3)} + std::chrono::seconds{std::atoi(time_string + 6)};
} }
else else
{ {
@ -285,7 +285,7 @@ namespace sqlpp
const auto ms_string = time_string + 9; // hh:mm:ss. const auto ms_string = time_string + 9; // hh:mm:ss.
if (detail::check_ms_digits(ms_string) and ms_string[4] == '\0') if (detail::check_ms_digits(ms_string) and ms_string[4] == '\0')
{ {
*value += ::std::chrono::milliseconds(std::atoi(ms_string)); *value += ::std::chrono::milliseconds{std::atoi(ms_string)};
} }
else else
{ {
@ -308,7 +308,7 @@ namespace sqlpp
case SQLITE_DONE: case SQLITE_DONE:
return false; return false;
default: default:
throw sqlpp::exception("Sqlite3 error: Unexpected return value for sqlite3_step()"); throw sqlpp::exception{"Sqlite3 error: Unexpected return value for sqlite3_step()"};
} }
} }
}; };

View File

@ -72,16 +72,16 @@ namespace sqlpp
if (handle->config->debug) if (handle->config->debug)
std::cerr << "Sqlite3 debug: Preparing: '" << statement << "'" << std::endl; std::cerr << "Sqlite3 debug: Preparing: '" << statement << "'" << std::endl;
detail::prepared_statement_handle_t result(nullptr, handle->config->debug); detail::prepared_statement_handle_t result{nullptr, handle->config->debug};
auto rc = sqlite3_prepare_v2(handle->native_handle(), statement.c_str(), static_cast<int>(statement.size()), auto rc = sqlite3_prepare_v2(handle->native_handle(), statement.c_str(), static_cast<int>(statement.size()),
&result.sqlite_statement, nullptr); &result.sqlite_statement, nullptr);
if (rc != SQLITE_OK) if (rc != SQLITE_OK)
{ {
throw sqlpp::exception( throw sqlpp::exception{
"Sqlite3 error: Could not prepare statement: " + std::string(sqlite3_errmsg(handle->native_handle())) + "Sqlite3 error: Could not prepare statement: " + std::string(sqlite3_errmsg(handle->native_handle())) +
" (statement was >>" + (rc == SQLITE_TOOBIG ? statement.substr(0, 128) + "..." : statement) + "<<\n"); " (statement was >>" + (rc == SQLITE_TOOBIG ? statement.substr(0, 128) + "..." : statement) + "<<\n"};
} }
return result; return result;
@ -99,8 +99,8 @@ namespace sqlpp
default: default:
if (handle->config->debug) if (handle->config->debug)
std::cerr << "Sqlite3 debug: sqlite3_step return code: " << rc << std::endl; std::cerr << "Sqlite3 debug: sqlite3_step return code: " << rc << std::endl;
throw sqlpp::exception("Sqlite3 error: Could not execute statement: " + throw sqlpp::exception{"Sqlite3 error: Could not execute statement: " +
std::string(sqlite3_errmsg(handle->native_handle()))); std::string(sqlite3_errmsg(handle->native_handle()))};
} }
} }
} // namespace detail } // namespace detail
@ -110,7 +110,7 @@ namespace sqlpp
struct context_t struct context_t
{ {
context_t(const connection_base& db) : _db(db), _count(1) context_t(const connection_base& db) : _db{db}, _count{1}
{ {
} }
@ -153,16 +153,16 @@ namespace sqlpp
active active
}; };
transaction_status_type _transaction_status = transaction_status_type::none; transaction_status_type _transaction_status{transaction_status_type::none};
// direct execution // direct execution
bind_result_t select_impl(const std::string& statement) bind_result_t select_impl(const std::string& statement)
{ {
std::unique_ptr<detail::prepared_statement_handle_t> prepared( std::unique_ptr<detail::prepared_statement_handle_t> prepared{
new detail::prepared_statement_handle_t(prepare_statement(_handle, statement))); new detail::prepared_statement_handle_t(prepare_statement(_handle, statement))};
if (!prepared) if (!prepared)
{ {
throw sqlpp::exception("Sqlite3 error: Could not store result set"); throw sqlpp::exception{"Sqlite3 error: Could not store result set"};
} }
return {std::move(prepared)}; return {std::move(prepared)};
@ -193,8 +193,8 @@ namespace sqlpp
// prepared execution // prepared execution
prepared_statement_t prepare_impl(const std::string& statement) prepared_statement_t prepare_impl(const std::string& statement)
{ {
return {std::unique_ptr<detail::prepared_statement_handle_t>( return {std::unique_ptr<detail::prepared_statement_handle_t>{
new detail::prepared_statement_handle_t(prepare_statement(_handle, statement)))}; new detail::prepared_statement_handle_t(prepare_statement(_handle, statement))}};
} }
bind_result_t run_prepared_select_impl(prepared_statement_t& prepared_statement) bind_result_t run_prepared_select_impl(prepared_statement_t& prepared_statement)
@ -263,7 +263,7 @@ namespace sqlpp
template <typename Select> template <typename Select>
bind_result_t select(const Select& s) bind_result_t select(const Select& s)
{ {
_context_t context(*this); _context_t context{*this};
serialize(s, context); serialize(s, context);
return select_impl(context.str()); return select_impl(context.str());
} }
@ -271,7 +271,7 @@ namespace sqlpp
template <typename Select> template <typename Select>
_prepared_statement_t prepare_select(Select& s) _prepared_statement_t prepare_select(Select& s)
{ {
_context_t context(*this); _context_t context{*this};
serialize(s, context); serialize(s, context);
return prepare_impl(context.str()); return prepare_impl(context.str());
} }
@ -288,7 +288,7 @@ namespace sqlpp
template <typename Insert> template <typename Insert>
size_t insert(const Insert& i) size_t insert(const Insert& i)
{ {
_context_t context(*this); _context_t context{*this};
serialize(i, context); serialize(i, context);
return insert_impl(context.str()); return insert_impl(context.str());
} }
@ -296,7 +296,7 @@ namespace sqlpp
template <typename Insert> template <typename Insert>
_prepared_statement_t prepare_insert(Insert& i) _prepared_statement_t prepare_insert(Insert& i)
{ {
_context_t context(*this); _context_t context{*this};
serialize(i, context); serialize(i, context);
return prepare_impl(context.str()); return prepare_impl(context.str());
} }
@ -313,7 +313,7 @@ namespace sqlpp
template <typename Update> template <typename Update>
size_t update(const Update& u) size_t update(const Update& u)
{ {
_context_t context(*this); _context_t context{*this};
serialize(u, context); serialize(u, context);
return update_impl(context.str()); return update_impl(context.str());
} }
@ -321,7 +321,7 @@ namespace sqlpp
template <typename Update> template <typename Update>
_prepared_statement_t prepare_update(Update& u) _prepared_statement_t prepare_update(Update& u)
{ {
_context_t context(*this); _context_t context{*this};
serialize(u, context); serialize(u, context);
return prepare_impl(context.str()); return prepare_impl(context.str());
} }
@ -338,7 +338,7 @@ namespace sqlpp
template <typename Remove> template <typename Remove>
size_t remove(const Remove& r) size_t remove(const Remove& r)
{ {
_context_t context(*this); _context_t context{*this};
serialize(r, context); serialize(r, context);
return remove_impl(context.str()); return remove_impl(context.str());
} }
@ -346,7 +346,7 @@ namespace sqlpp
template <typename Remove> template <typename Remove>
_prepared_statement_t prepare_remove(Remove& r) _prepared_statement_t prepare_remove(Remove& r)
{ {
_context_t context(*this); _context_t context{*this};
serialize(r, context); serialize(r, context);
return prepare_impl(context.str()); return prepare_impl(context.str());
} }
@ -372,7 +372,7 @@ namespace sqlpp
typename Enable = typename std::enable_if<not std::is_convertible<Execute, std::string>::value, void>::type> typename Enable = typename std::enable_if<not std::is_convertible<Execute, std::string>::value, void>::type>
size_t execute(const Execute& x) size_t execute(const Execute& x)
{ {
_context_t context(*this); _context_t context{*this};
serialize(x, context); serialize(x, context);
return execute(context.str()); return execute(context.str());
} }
@ -380,7 +380,7 @@ namespace sqlpp
template <typename Execute> template <typename Execute>
_prepared_statement_t prepare_execute(Execute& x) _prepared_statement_t prepare_execute(Execute& x)
{ {
_context_t context(*this); _context_t context{*this};
serialize(x, context); serialize(x, context);
return prepare_impl(context.str()); return prepare_impl(context.str());
} }
@ -472,7 +472,7 @@ namespace sqlpp
{ {
if (_transaction_status == transaction_status_type::active) if (_transaction_status == transaction_status_type::active)
{ {
throw sqlpp::exception("Sqlite3 error: Cannot have more than one open transaction per connection"); throw sqlpp::exception{"Sqlite3 error: Cannot have more than one open transaction per connection"};
} }
_transaction_status = transaction_status_type::maybe; _transaction_status = transaction_status_type::maybe;
@ -486,7 +486,7 @@ namespace sqlpp
{ {
if (_transaction_status == transaction_status_type::none) if (_transaction_status == transaction_status_type::none)
{ {
throw sqlpp::exception("Sqlite3 error: Cannot commit a finished or failed transaction"); throw sqlpp::exception{"Sqlite3 error: Cannot commit a finished or failed transaction"};
} }
_transaction_status = transaction_status_type::maybe; _transaction_status = transaction_status_type::maybe;
auto prepared = prepare_statement(_handle, "COMMIT"); auto prepared = prepare_statement(_handle, "COMMIT");
@ -500,7 +500,7 @@ namespace sqlpp
{ {
if (_transaction_status == transaction_status_type::none) if (_transaction_status == transaction_status_type::none)
{ {
throw sqlpp::exception("Sqlite3 error: Cannot rollback a finished or failed transaction"); throw sqlpp::exception{"Sqlite3 error: Cannot rollback a finished or failed transaction"};
} }
if (report) if (report)
{ {

View File

@ -35,7 +35,7 @@ namespace sqlpp
{ {
struct connection_config struct connection_config
{ {
connection_config() : path_to_database(), flags(0), vfs(), debug(false),password("") connection_config() : path_to_database{}, flags{0}, vfs{}, debug{false},password{}
{ {
} }
connection_config(const connection_config&) = default; connection_config(const connection_config&) = default;
@ -44,7 +44,7 @@ namespace sqlpp
connection_config& operator=(connection_config&&) = default; connection_config& operator=(connection_config&&) = default;
connection_config(std::string path, int fl = 0, std::string vf = "", bool dbg = false,std::string password="") connection_config(std::string path, int fl = 0, std::string vf = "", bool dbg = false,std::string password="")
: path_to_database(std::move(path)), flags(fl), vfs(std::move(vf)), debug(dbg),password(password) : path_to_database{std::move(path)}, flags{fl}, vfs{std::move(vf)}, debug{dbg},password{password}
{ {
} }

View File

@ -53,8 +53,8 @@ namespace sqlpp
std::unique_ptr<::sqlite3, int (*)(::sqlite3*)> sqlite; std::unique_ptr<::sqlite3, int (*)(::sqlite3*)> sqlite;
connection_handle(const std::shared_ptr<const connection_config>& conf) : connection_handle(const std::shared_ptr<const connection_config>& conf) :
config(conf), config{conf},
sqlite(nullptr, sqlite3_close) sqlite{nullptr, sqlite3_close}
{ {
#ifdef SQLPP_DYNAMIC_LOADING #ifdef SQLPP_DYNAMIC_LOADING
init_sqlite(""); init_sqlite("");
@ -67,7 +67,7 @@ namespace sqlpp
{ {
const std::string msg = sqlite3_errmsg(sqlite_ptr); const std::string msg = sqlite3_errmsg(sqlite_ptr);
sqlite3_close(sqlite_ptr); sqlite3_close(sqlite_ptr);
throw sqlpp::exception("Sqlite3 error: Can't open database: " + msg); throw sqlpp::exception{"Sqlite3 error: Can't open database: " + msg};
} }
sqlite.reset(sqlite_ptr); sqlite.reset(sqlite_ptr);
@ -80,7 +80,7 @@ namespace sqlpp
{ {
const std::string msg = sqlite3_errmsg(native_handle()); const std::string msg = sqlite3_errmsg(native_handle());
sqlite3_close(native_handle()); sqlite3_close(native_handle());
throw sqlpp::exception("Sqlite3 error: Can't set password to database: " + msg); throw sqlpp::exception{"Sqlite3 error: Can't set password to database: " + msg};
} }
} }
#endif #endif

View File

@ -48,14 +48,14 @@ namespace sqlpp
sqlite3_stmt* sqlite_statement; sqlite3_stmt* sqlite_statement;
bool debug; bool debug;
prepared_statement_handle_t(sqlite3_stmt* statement, bool debug_) : sqlite_statement(statement), debug(debug_) prepared_statement_handle_t(sqlite3_stmt* statement, bool debug_) : sqlite_statement{statement}, debug{debug_}
{ {
} }
prepared_statement_handle_t(const prepared_statement_handle_t&) = delete; prepared_statement_handle_t(const prepared_statement_handle_t&) = delete;
prepared_statement_handle_t(prepared_statement_handle_t&& rhs) : prepared_statement_handle_t(prepared_statement_handle_t&& rhs) :
sqlite_statement(rhs.sqlite_statement), sqlite_statement{rhs.sqlite_statement},
debug(rhs.debug) debug{rhs.debug}
{ {
rhs.sqlite_statement = nullptr; rhs.sqlite_statement = nullptr;
} }

View File

@ -60,14 +60,14 @@ namespace sqlpp
case SQLITE_OK: case SQLITE_OK:
return; return;
case SQLITE_RANGE: case SQLITE_RANGE:
throw sqlpp::exception("Sqlite3 error: " + std::string(type) + " bind value out of range"); throw sqlpp::exception{"Sqlite3 error: " + std::string(type) + " bind value out of range"};
case SQLITE_NOMEM: case SQLITE_NOMEM:
throw sqlpp::exception("Sqlite3 error: " + std::string(type) + " bind out of memory"); throw sqlpp::exception{"Sqlite3 error: " + std::string(type) + " bind out of memory"};
case SQLITE_TOOBIG: case SQLITE_TOOBIG:
throw sqlpp::exception("Sqlite3 error: " + std::string(type) + " bind too big"); throw sqlpp::exception{"Sqlite3 error: " + std::string(type) + " bind too big"};
default: default:
throw sqlpp::exception("Sqlite3 error: " + std::string(type) + throw sqlpp::exception{"Sqlite3 error: " + std::string(type) +
" bind returned unexpected value: " + std::to_string(result)); " bind returned unexpected value: " + std::to_string(result)};
} }
} }
} // namespace detail } // namespace detail