Change return types for 'Bind' methods 61/324361/3
authorjh9216.park <jh9216.park@samsung.com>
Fri, 16 May 2025 02:21:41 +0000 (11:21 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 20 May 2025 06:02:40 +0000 (06:02 +0000)
- It returns r-value reference instead of l-value reference to use move
  constructor

Change-Id: I8ef888cca285bc23cb9cbcf9b9b15f2be11de868
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
src/tizen-database/database.hpp

index ebaa0cad34c51af8ed52bd9011f1bfa3c11fa2c5..cdd30791a5260eeed79597059c4d71dc2e003888 100644 (file)
@@ -35,7 +35,7 @@
 
 namespace tizen_base {
 
-template<std::size_t N>
+template <std::size_t N>
 struct num {
   static const constexpr auto value = N;
 };
@@ -50,27 +50,24 @@ void for_(F func) {
   for_(func, std::make_index_sequence<N>());
 }
 
-using DbType = std::optional<std::variant<int64_t, double, std::string,
-    std::vector<unsigned char>>>;
+using DbType = std::optional<
+    std::variant<int64_t, double, std::string, std::vector<unsigned char>>>;
 
 class DbException : public std::runtime_error {
  public:
   explicit DbException(const std::string& msg, int code = SQLITE_ERROR)
-      : std::runtime_error(msg), code_(code) {
-  }
+      : std::runtime_error(msg), code_(code) {}
 
   DbException(const std::string& msg, int code, const std::string& file,
-      int line) : std::runtime_error(msg), code_(code) {
+              int line)
+      : std::runtime_error(msg), code_(code) {
     msg_ = msg + " at " + file + ":" + std::to_string(line);
   }
 
-  int code() const {
-    return code_;
-  }
+  int code() const { return code_; }
 
   const char* msg() const {
-    if (msg_.empty())
-      return what();
+    if (msg_.empty()) return what();
     return msg_.c_str();
   }
 
@@ -85,11 +82,9 @@ class AutoDbType {
   explicit AutoDbType(DbType db_type, int real_type)
       : db_type_(db_type), real_type_(real_type) {}
 
-  int GetType() const {
-    return real_type_;
-  }
+  int GetType() const { return real_type_; }
 
-  explicit operator int () {
+  explicit operator int() {
     if (!db_type_)
       throw DbException("invalid type conversion from nullopt to int");
     if (real_type_ != SQLITE_INTEGER)
@@ -98,7 +93,7 @@ class AutoDbType {
     return std::get<int64_t>(*db_type_);
   }
 
-  explicit operator int64_t () {
+  explicit operator int64_t() {
     if (!db_type_)
       throw DbException("invalid type conversion from nullopt to int64_t");
     if (real_type_ != SQLITE_INTEGER)
@@ -107,10 +102,9 @@ class AutoDbType {
     return std::get<int64_t>(*db_type_);
   }
 
-  explicit operator std::string () {
+  explicit operator std::string() {
     if (!db_type_) {
-      throw DbException(
-          "invalid type conversion from nullopt to string");
+      throw DbException("invalid type conversion from nullopt to string");
     }
 
     if (real_type_ != SQLITE_TEXT)
@@ -119,10 +113,9 @@ class AutoDbType {
     return std::get<std::string>(*db_type_);
   }
 
-  explicit operator double () {
+  explicit operator double() {
     if (!db_type_) {
-      throw DbException(
-          "invalid type conversion from nullopt to double");
+      throw DbException("invalid type conversion from nullopt to double");
     }
 
     if (real_type_ != SQLITE_FLOAT)
@@ -131,59 +124,56 @@ class AutoDbType {
     return std::get<double>(*db_type_);
   }
 
-  explicit operator std::vector<unsigned char> () {
+  explicit operator std::vector<unsigned char>() {
     if (!db_type_) {
       throw DbException(
           "invalid type conversion from nullopt to std::vector<unsigned char>");
     }
 
     if (real_type_ != SQLITE_BLOB)
-      throw DbException("invalid type conversion to std::vector<unsigned char>");
+      throw DbException(
+          "invalid type conversion to std::vector<unsigned char>");
 
     return std::get<std::vector<unsigned char>>(*db_type_);
   }
 
-  operator std::optional<int> () {
-    if (!db_type_)
-      return std::nullopt;
+  operator std::optional<int>() {
+    if (!db_type_) return std::nullopt;
     if (real_type_ != SQLITE_INTEGER)
       throw DbException("invalid type conversion to int");
 
     return std::get<int64_t>(*db_type_);
   }
 
-  operator std::optional<int64_t> () {
-    if (!db_type_)
-      return std::nullopt;
+  operator std::optional<int64_t>() {
+    if (!db_type_) return std::nullopt;
     if (real_type_ != SQLITE_INTEGER)
       throw DbException("invalid type conversion to int64_t");
 
     return std::get<int64_t>(*db_type_);
   }
 
-  operator std::optional<std::string> () {
-    if (!db_type_)
-      return std::nullopt;
+  operator std::optional<std::string>() {
+    if (!db_type_) return std::nullopt;
     if (real_type_ != SQLITE_TEXT)
       throw DbException("invalid type conversion to string");
 
     return std::get<std::string>(*db_type_);
   }
 
-  operator std::optional<double> () {
-    if (!db_type_)
-      return std::nullopt;
+  operator std::optional<double>() {
+    if (!db_type_) return std::nullopt;
     if (real_type_ != SQLITE_FLOAT)
       throw DbException("invalid type conversion to double");
 
     return std::get<double>(*db_type_);
   }
 
-  operator std::optional<std::vector<unsigned char>> () {
-    if (!db_type_)
-      return std::nullopt;
+  operator std::optional<std::vector<unsigned char>>() {
+    if (!db_type_) return std::nullopt;
     if (real_type_ != SQLITE_BLOB)
-      throw DbException("invalid type conversion to std::vector<unsigned char>");
+      throw DbException(
+          "invalid type conversion to std::vector<unsigned char>");
 
     return std::get<std::vector<unsigned char>>(*db_type_);
   }
@@ -200,13 +190,11 @@ class Database {
   class TransactionGuard {
    public:
     TransactionGuard(const TransactionGuard&) = delete;
-    TransactionGuard& operator = (const TransactionGuard&) = delete;
+    TransactionGuard& operator=(const TransactionGuard&) = delete;
 
-    TransactionGuard(TransactionGuard&& t) noexcept {
-      db_ = std::move(t.db_);
-    }
+    TransactionGuard(TransactionGuard&& t) noexcept { db_ = std::move(t.db_); }
 
-    TransactionGuard& operator = (TransactionGuard&& t) noexcept {
+    TransactionGuard& operator=(TransactionGuard&& t) noexcept {
       if (this != &t) {
         if (!db_.expired())
           sqlite3_exec(db_.lock().get(), "ROLLBACK", nullptr, nullptr, nullptr);
@@ -216,10 +204,9 @@ class Database {
       return *this;
     }
 
-    explicit TransactionGuard(const std::shared_ptr<sqlite3>& db)
-        : db_(db) {
-      int r = sqlite3_exec(db_.lock().get(), "BEGIN DEFERRED",
-          nullptr, nullptr, nullptr);
+    explicit TransactionGuard(const std::shared_ptr<sqlite3>& db) : db_(db) {
+      int r = sqlite3_exec(db_.lock().get(), "BEGIN DEFERRED", nullptr, nullptr,
+                           nullptr);
       if (r != SQLITE_OK) {
         throw DbException("begin transaction failed", r);
       }
@@ -231,8 +218,7 @@ class Database {
     }
 
     int Commit() {
-      if (db_.expired())
-        return SQLITE_OK;
+      if (db_.expired()) return SQLITE_OK;
 
       auto db = db_.lock();
       int ret = sqlite3_exec(db.get(), "COMMIT", nullptr, nullptr, nullptr);
@@ -251,7 +237,13 @@ class Database {
    public:
     Sql(std::string query) : query_(std::move(query)) {}
 
-    Sql& Bind(const char* val) {
+    Sql(const Sql&) = default;
+    Sql& operator=(const Sql& sql) noexcept = default;
+
+    Sql(Sql&& sql) noexcept = default;
+    Sql& operator=(Sql&& sql) noexcept = default;
+
+    Sql&& Bind(const char* val) {
       if (val == nullptr) {
         bindings_.push_back(DbType(std::nullopt));
       } else {
@@ -261,46 +253,46 @@ class Database {
         else
           bindings_.push_back(DbType(std::move(str)));
       }
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string val) {
+    Sql&& Bind(std::string val) {
       if (empty_string_as_null_ && val.empty())
         bindings_.push_back(DbType(std::nullopt));
       else
         bindings_.push_back(DbType(std::move(val)));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int val) {
+    Sql&& Bind(int val) {
       bindings_.push_back(DbType(static_cast<int64_t>(val)));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int64_t val) {
+    Sql&& Bind(int64_t val) {
       bindings_.push_back(DbType(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(double val) {
+    Sql&& Bind(double val) {
       bindings_.push_back(DbType(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::vector<unsigned char> val) {
+    Sql&& Bind(std::vector<unsigned char> val) {
       if (empty_vector_as_null_ && val.empty())
         bindings_.push_back(DbType(std::nullopt));
       else
         bindings_.push_back(DbType(std::move(val)));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(const std::nullopt_t val) {
+    Sql&& Bind(const std::nullopt_t val) {
       bindings_.push_back(DbType(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int pos, const char* val) {
+    Sql&& Bind(int pos, const char* val) {
       if (val == nullptr) {
         binding_map_[pos] = DbType(std::nullopt);
       } else {
@@ -310,46 +302,46 @@ class Database {
         else
           binding_map_[pos] = DbType(std::move(str));
       }
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int pos, std::string val) {
+    Sql&& Bind(int pos, std::string val) {
       if (empty_string_as_null_ && val.empty())
         binding_map_[pos] = DbType(std::nullopt);
       else
         binding_map_[pos] = DbType(std::move(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int pos, int val) {
+    Sql&& Bind(int pos, int val) {
       binding_map_[pos] = DbType(static_cast<int64_t>(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int pos, int64_t val) {
+    Sql&& Bind(int pos, int64_t val) {
       binding_map_[pos] = DbType(val);
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int pos, double val) {
+    Sql&& Bind(int pos, double val) {
       binding_map_[pos] = DbType(val);
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int pos, std::vector<unsigned char> val) {
+    Sql&& Bind(int pos, std::vector<unsigned char> val) {
       if (empty_vector_as_null_ && val.empty())
         binding_map_[pos] = DbType(std::nullopt);
       else
         binding_map_[pos] = DbType(std::move(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(int pos, const std::nullopt_t& val) {
+    Sql&& Bind(int pos, const std::nullopt_t& val) {
       binding_map_[pos] = DbType(val);
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string name, const char* val) {
+    Sql&& Bind(std::string name, const char* val) {
       if (val == nullptr) {
         binding_name_map_[std::move(name)] = DbType(std::nullopt);
       } else {
@@ -359,78 +351,72 @@ class Database {
         else
           binding_name_map_[std::move(name)] = DbType(std::move(str));
       }
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string name, std::string val) {
+    Sql&& Bind(std::string name, std::string val) {
       if (empty_string_as_null_ && val.empty())
         binding_name_map_[std::move(name)] = DbType(std::nullopt);
       else
         binding_name_map_[std::move(name)] = DbType(std::move(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string name, int val) {
+    Sql&& Bind(std::string name, int val) {
       binding_name_map_[std::move(name)] = DbType(static_cast<int64_t>(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string name, int64_t val) {
+    Sql&& Bind(std::string name, int64_t val) {
       binding_name_map_[std::move(name)] = DbType(val);
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string name, double val) {
+    Sql&& Bind(std::string name, double val) {
       binding_name_map_[std::move(name)] = DbType(val);
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string name, std::vector<unsigned char> val) {
+    Sql&& Bind(std::string name, std::vector<unsigned char> val) {
       if (empty_vector_as_null_ && val.empty())
         binding_name_map_[std::move(name)] = DbType(std::nullopt);
       else
         binding_name_map_[std::move(name)] = DbType(std::move(val));
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Bind(std::string name, const std::nullopt_t& val) {
+    Sql&& Bind(std::string name, const std::nullopt_t& val) {
       binding_name_map_[std::move(name)] = DbType(val);
-      return *this;
+      return std::move(*this);
     }
 
-    const std::vector<DbType>& GetBindings() const {
-      return bindings_;
-    }
+    const std::vector<DbType>& GetBindings() const { return bindings_; }
 
-    const std::map<int, DbType>& GetBindingMap() const {
-      return binding_map_;
-    }
+    const std::map<int, DbType>& GetBindingMap() const { return binding_map_; }
 
     const std::map<std::string, DbType>& GetBindingNameMap() const {
       return binding_name_map_;
     }
 
-    const std::string& GetQuery() const {
-      return query_;
-    }
+    const std::string& GetQuery() const { return query_; }
 
-    Sql& SetEmptyStringAsNull(bool as_null) {
+    Sql&& SetEmptyStringAsNull(bool as_null) {
       empty_string_as_null_ = as_null;
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& SetEmptyVectorAsNull(bool as_null) {
+    Sql&& SetEmptyVectorAsNull(bool as_null) {
       empty_vector_as_null_ = as_null;
-      return *this;
+      return std::move(*this);
     }
 
-    Sql& Reset() {
+    Sql&& Reset() {
       bindings_.clear();
       binding_map_.clear();
       binding_name_map_.clear();
       empty_string_as_null_ = false;
       empty_vector_as_null_ = false;
-      return *this;
+      return std::move(*this);
     }
 
    private:
@@ -446,12 +432,11 @@ class Database {
    public:
     Result() = default;
     ~Result() {
-      if (stmt_)
-        sqlite3_finalize(stmt_);
+      if (stmt_) sqlite3_finalize(stmt_);
     }
 
     Result(const Result&) = delete;
-    Result& operator = (const Result&) = delete;
+    Result& operator=(const Result&) = delete;
 
     Result(Result&& r) noexcept {
       stmt_ = r.stmt_;
@@ -460,10 +445,9 @@ class Database {
       is_done_ = r.is_done_;
     }
 
-    Result& operator = (Result&& r) noexcept {
+    Result& operator=(Result&& r) noexcept {
       if (this != &r) {
-        if (stmt_)
-          sqlite3_finalize(stmt_);
+        if (stmt_) sqlite3_finalize(stmt_);
         stmt_ = r.stmt_;
         r.stmt_ = nullptr;
         query_ = std::move(r.query_);
@@ -479,10 +463,9 @@ class Database {
 
       std::optional<std::string> GetString(int pos) const {
         sqlite3_stmt* stmt = const_cast<sqlite3_stmt*>(stmt_);
-        const char* text = reinterpret_cast<const char*>(
-            sqlite3_column_text(stmt, pos));
-        if (!text)
-          return std::nullopt;
+        const char* text =
+            reinterpret_cast<const char*>(sqlite3_column_text(stmt, pos));
+        if (!text) return std::nullopt;
 
         return text;
       }
@@ -498,8 +481,8 @@ class Database {
 
         DbType dbt;
         if (type == SQLITE_TEXT) {
-          dbt = DbType(reinterpret_cast<const char*>(
-              sqlite3_column_text(stmt, pos)));
+          dbt = DbType(
+              reinterpret_cast<const char*>(sqlite3_column_text(stmt, pos)));
         } else if (type == SQLITE_INTEGER) {
           dbt = DbType(static_cast<int64_t>(sqlite3_column_int64(stmt, pos)));
         } else if (type == SQLITE_FLOAT) {
@@ -510,7 +493,8 @@ class Database {
           int len = sqlite3_column_bytes(stmt, pos);
 
           if (!val || len < 0) {
-            throw DbException("invalid blob");;
+            throw DbException("invalid blob");
+            ;
           } else {
             dbt = DbType(std::vector<unsigned char>(val, val + len));
           }
@@ -523,13 +507,12 @@ class Database {
         return AutoDbType(dbt, type);
       }
 
-      template <typename ...Types>
+      template <typename... Types>
       auto Get() const {
         std::tuple<Types...> t;
         int pos = 0;
-        for_<std::tuple_size_v<std::tuple<Types...>>>([&] (auto i) {
-          std::get<i.value>(t) = Get(pos++);
-        });
+        for_<std::tuple_size_v<std::tuple<Types...>>>(
+            [&](auto i) { std::get<i.value>(t) = Get(pos++); });
 
         return t;
       }
@@ -544,14 +527,11 @@ class Database {
 
       Record operator*() { return Record(stmt_); }
 
-      bool operator != (const Iterator& rhs) const {
-        return stmt_ != rhs.stmt_;
-      }
+      bool operator!=(const Iterator& rhs) const { return stmt_ != rhs.stmt_; }
 
-      void operator ++() {
+      void operator++() {
         int r = sqlite3_step(stmt_);
-        if (r != SQLITE_ROW)
-          stmt_ = nullptr;
+        if (r != SQLITE_ROW) stmt_ = nullptr;
       }
 
      private:
@@ -559,39 +539,32 @@ class Database {
     };
 
     Iterator begin() const {
-      if (is_done_)
-        return Iterator(nullptr);
+      if (is_done_) return Iterator(nullptr);
       return Iterator(stmt_);
     }
 
-    Iterator end() const {
-      return Iterator(nullptr);
-    }
+    Iterator end() const { return Iterator(nullptr); }
 
     operator bool() const {
-      if (stmt_ == nullptr)
-        return false;
+      if (stmt_ == nullptr) return false;
       return true;
     }
 
     explicit operator int() const {
       auto db = db_.lock();
-      if (db == nullptr)
-        return SQLITE_ERROR;
+      if (db == nullptr) return SQLITE_ERROR;
       return sqlite3_errcode(db.get());
     }
 
     explicit operator const char*() const {
       auto db = db_.lock();
-      if (db == nullptr)
-        return "";
+      if (db == nullptr) return "";
       return sqlite3_errmsg(db.get());
     }
 
     template <class T>
     std::vector<T> ToVector() {
-      if (stmt_ == nullptr)
-        return {};
+      if (stmt_ == nullptr) return {};
 
       std::vector<T> vec;
       for (const auto& rec : *this) {
@@ -605,8 +578,7 @@ class Database {
 
     template <class T>
     std::list<T> ToList() {
-      if (stmt_ == nullptr)
-        return {};
+      if (stmt_ == nullptr) return {};
 
       std::list<T> l;
       for (const auto& rec : *this) {
@@ -620,8 +592,7 @@ class Database {
 
     template <class T>
     std::optional<T> GetFirst() {
-      if (stmt_ == nullptr)
-        return std::nullopt;
+      if (stmt_ == nullptr) return std::nullopt;
       for (const auto& rec : *this) {
         T t;
         t(rec);
@@ -632,8 +603,7 @@ class Database {
     }
 
     std::optional<Record> GetFirstRecord() {
-      if (stmt_ == nullptr)
-        return std::nullopt;
+      if (stmt_ == nullptr) return std::nullopt;
       for (const auto& rec : *this) {
         return rec;
       }
@@ -641,25 +611,18 @@ class Database {
       return std::nullopt;
     }
 
-    sqlite3_stmt* GetRaw() const {
-      return stmt_;
-    }
+    sqlite3_stmt* GetRaw() const { return stmt_; }
 
-    const std::string& GetQuery() const {
-      return query_;
-    }
+    const std::string& GetQuery() const { return query_; }
 
-    void SetDone(bool is_done) {
-      is_done_ = is_done;
-    }
+    void SetDone(bool is_done) { is_done_ = is_done; }
 
-    size_t GetColumnCount() const {
-      return sqlite3_column_count(stmt_);
-    }
+    size_t GetColumnCount() const { return sqlite3_column_count(stmt_); }
 
    private:
     friend class Database;
-    Result(sqlite3_stmt* stmt, const std::shared_ptr<sqlite3>& db, std::string query, bool is_done)
+    Result(sqlite3_stmt* stmt, const std::shared_ptr<sqlite3>& db,
+           std::string query, bool is_done)
         : stmt_(stmt), db_(db), query_(std::move(query)), is_done_(is_done) {}
 
     sqlite3_stmt* stmt_ = nullptr;
@@ -671,36 +634,35 @@ class Database {
   Database(std::string_view db_path, int flags) {
     sqlite3* raw_db = nullptr;
     int r = sqlite3_open_v2(db_path.data(), &raw_db, flags, nullptr);
-    if (r != SQLITE_OK)
-      throw DbException("open failed", r);
+    if (r != SQLITE_OK) throw DbException("open failed", r);
 
     db_.reset(raw_db, sqlite3_close_v2);
   }
 
   Database(std::string_view db_path, int flags,
-      std::function<bool(int)> busy_handler) {
+           std::function<bool(int)> busy_handler) {
     sqlite3* raw_db = nullptr;
     int r = sqlite3_open_v2(db_path.data(), &raw_db, flags, nullptr);
-    if (r != SQLITE_OK)
-      throw DbException("sqlite3_open_v2() failed", r);
+    if (r != SQLITE_OK) throw DbException("sqlite3_open_v2() failed", r);
 
     db_.reset(raw_db, sqlite3_close_v2);
     busy_handler_ = std::move(busy_handler);
-    r = sqlite3_busy_handler(db_.get(), [](void* data, int count) {
-      Database* pDb = static_cast<Database*>(data);
-      if (pDb->busy_handler_ && pDb->busy_handler_(count))
-        return 1;
-      return 0;
-    }, this);
-
-    if (r != SQLITE_OK)
-      throw DbException("sqlite3_busy_handler() failed", r);
+    r = sqlite3_busy_handler(
+        db_.get(),
+        [](void* data, int count) {
+          Database* pDb = static_cast<Database*>(data);
+          if (pDb->busy_handler_ && pDb->busy_handler_(count)) return 1;
+          return 0;
+        },
+        this);
+
+    if (r != SQLITE_OK) throw DbException("sqlite3_busy_handler() failed", r);
   }
 
   ~Database() = default;
   Database() = default;
   Database(const Database&) = delete;
-  Database& operator = (const Database&) = delete;
+  Database& operator=(const Database&) = delete;
 
   Database(Database&& db) noexcept {
     db_ = std::move(db.db_);
@@ -708,32 +670,35 @@ class Database {
     db.db_ = nullptr;
     db.busy_handler_ = nullptr;
 
-    sqlite3_busy_handler(db_.get(), [](void* data, int count) {
-      Database* pDb = static_cast<Database*>(data);
-      if (pDb->busy_handler_ && pDb->busy_handler_(count))
-        return 1;
-      return 0;
-    }, this);
+    sqlite3_busy_handler(
+        db_.get(),
+        [](void* data, int count) {
+          Database* pDb = static_cast<Database*>(data);
+          if (pDb->busy_handler_ && pDb->busy_handler_(count)) return 1;
+          return 0;
+        },
+        this);
   }
 
   explicit operator bool() const {
-    if (db_ == nullptr)
-      return false;
+    if (db_ == nullptr) return false;
     return true;
   }
 
-  Database& operator = (Database&& db) noexcept {
+  Database& operator=(Database&& db) noexcept {
     if (this != &db) {
       db_ = std::move(db.db_);
       busy_handler_ = std::move(db.busy_handler_);
       db.db_ = nullptr;
       db.busy_handler_ = nullptr;
-      sqlite3_busy_handler(db_.get(), [](void* data, int count) {
-        Database* pDb = static_cast<Database*>(data);
-        if (pDb->busy_handler_ && pDb->busy_handler_(count))
-          return 1;
-        return 0;
-      }, this);
+      sqlite3_busy_handler(
+          db_.get(),
+          [](void* data, int count) {
+            Database* pDb = static_cast<Database*>(data);
+            if (pDb->busy_handler_ && pDb->busy_handler_(count)) return 1;
+            return 0;
+          },
+          this);
     }
 
     return *this;
@@ -744,30 +709,27 @@ class Database {
   }
 
   Result Prepare(const Sql& sql) const {
-    if (!db_)
-      throw DbException("Not opened");
+    if (!db_) throw DbException("Not opened");
 
     sqlite3_stmt* stmt = nullptr;
-    int r = sqlite3_prepare_v2(db_.get(), sql.GetQuery().c_str(),
-        -1, &stmt, nullptr);
-    if (r != SQLITE_OK)
-      return { nullptr, db_, "", true };
-    return { stmt, db_, sql.GetQuery(), false };
+    int r = sqlite3_prepare_v2(db_.get(), sql.GetQuery().c_str(), -1, &stmt,
+                               nullptr);
+    if (r != SQLITE_OK) return {nullptr, db_, "", true};
+    return {stmt, db_, sql.GetQuery(), false};
   }
 
   Result Exec(const Sql& sql) const {
-    if (!db_)
-      throw DbException("Not opened");
+    if (!db_) throw DbException("Not opened");
 
     sqlite3_stmt* stmt = nullptr;
-    int r = sqlite3_prepare_v2(db_.get(), sql.GetQuery().c_str(),
-        -1, &stmt, nullptr);
+    int r = sqlite3_prepare_v2(db_.get(), sql.GetQuery().c_str(), -1, &stmt,
+                               nullptr);
     if (r != SQLITE_OK) {
-      return { nullptr, db_, "", true };
+      return {nullptr, db_, "", true};
     }
 
-    std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_auto(stmt,
-        sqlite3_finalize);
+    std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_auto(
+        stmt, sqlite3_finalize);
     int pos = 1;
     for (const auto& i : sql.GetBindings()) {
       Bind(pos++, i, stmt);
@@ -779,18 +741,17 @@ class Database {
 
     for (const auto& i : sql.GetBindingNameMap()) {
       pos = sqlite3_bind_parameter_index(stmt, i.first.c_str());
-      if (pos == 0)
-        throw DbException("Invalid binding");
+      if (pos == 0) throw DbException("Invalid binding");
       Bind(pos, i.second, stmt);
     }
 
     r = sqlite3_step(stmt);
     if (r != SQLITE_ROW && r != SQLITE_DONE) {
-      return { nullptr, db_, "", true };
+      return {nullptr, db_, "", true};
     }
 
-    return { stmt_auto.release(), db_, sql.GetQuery(),
-        r == SQLITE_DONE ? true : false };
+    return {stmt_auto.release(), db_, sql.GetQuery(),
+            r == SQLITE_DONE ? true : false};
   }
 
   bool Exec(const Sql& sql, Result& previous_stmt) const {
@@ -798,12 +759,10 @@ class Database {
       throw DbException("Query is different");
 
     sqlite3_stmt* stmt = previous_stmt.GetRaw();
-    if (!stmt)
-      return false;
+    if (!stmt) return false;
 
     int r = sqlite3_reset(stmt);
-    if (r != SQLITE_ROW && r != SQLITE_DONE && r != SQLITE_OK)
-      return false;
+    if (r != SQLITE_ROW && r != SQLITE_DONE && r != SQLITE_OK) return false;
 
     int pos = 1;
     for (const auto& i : sql.GetBindings()) {
@@ -816,39 +775,34 @@ class Database {
 
     for (const auto& i : sql.GetBindingNameMap()) {
       pos = sqlite3_bind_parameter_index(stmt, i.first.c_str());
-      if (pos == 0)
-        throw DbException("Invalid binding");
+      if (pos == 0) throw DbException("Invalid binding");
       Bind(pos, i.second, stmt);
     }
 
     r = sqlite3_step(stmt);
-    if (r != SQLITE_ROW && r != SQLITE_DONE)
-      return false;
+    if (r != SQLITE_ROW && r != SQLITE_DONE) return false;
 
     previous_stmt.SetDone(r == SQLITE_DONE ? true : false);
     return true;
   }
 
   std::future<Result> ExecAsync(const Sql& sql) const {
-    return std::async(std::launch::async, [=]() {
-      return Exec(sql);
-    });
+    return std::async(std::launch::async, [=]() { return Exec(sql); });
   }
 
   void OneStepExec(const Sql& sql) const {
     char* errmsg = nullptr;
     int ret = sqlite3_exec(db_.get(), sql.GetQuery().c_str(), nullptr, nullptr,
-        &errmsg);
+                           &errmsg);
     if (ret != SQLITE_OK) {
-      std::unique_ptr<char, decltype(sqlite3_free)*> errmsg_auto(
-          errmsg, sqlite3_free);
+      std::unique_ptr<char, decltype(sqlite3_free)*> errmsg_auto(errmsg,
+                                                                 sqlite3_free);
       throw DbException(errmsg);
     }
   }
 
   sqlite3* GetRaw() const {
-    if (!db_)
-      throw DbException("Not opened");
+    if (!db_) throw DbException("Not opened");
     return db_.get();
   }
 
@@ -865,16 +819,15 @@ class Database {
     }
 
     if (const std::string* pstr = std::get_if<std::string>(&(*type))) {
-      r = sqlite3_bind_text(stmt, pos, (*pstr).c_str(), -1,
-          SQLITE_TRANSIENT);
+      r = sqlite3_bind_text(stmt, pos, (*pstr).c_str(), -1, SQLITE_TRANSIENT);
     } else if (const int64_t* pint = std::get_if<int64_t>(&(*type))) {
       r = sqlite3_bind_int64(stmt, pos, (*pint));
     } else if (const double* pdouble = std::get_if<double>(&(*type))) {
       r = sqlite3_bind_double(stmt, pos, (*pdouble));
     } else if (const std::vector<unsigned char>* pvector =
-        std::get_if<std::vector<unsigned char>>(&(*type))) {
-      r = sqlite3_bind_blob(stmt, pos, (*pvector).data(),
-          (*pvector).size(), nullptr);
+                   std::get_if<std::vector<unsigned char>>(&(*type))) {
+      r = sqlite3_bind_blob(stmt, pos, (*pvector).data(), (*pvector).size(),
+                            nullptr);
     } else {
       r = -1;
     }