return true;
}
-bool SQLiteConnection::BeginTransaction() {
- return Execute("BEGIN EXCLUSIVE");
-}
-
-bool SQLiteConnection::CommitTransaction() {
- return Execute("COMMIT");
-}
-
-bool SQLiteConnection::RollbackTransaction() {
- SetErrorCode(0);
- return Execute("ROLLBACK");
-}
-
std::string SQLiteConnection::GetErrorMessage() const {
return sqlite3_errmsg(db_);
}
bool Disconnect();
std::string GetErrorMessage() const;
- bool BeginTransaction();
- bool CommitTransaction();
- bool RollbackTransaction();
-
std::string path_;
sqlite3* db_;
int error_code_;
return res;
}
-bool SQLiteStatement::BindInt(int pos, int val) {
- int r = sqlite3_bind_int(stmt_, pos, val);
- if (r != SQLITE_OK) {
- LOG(ERROR) << "sqlite3_bind_int() failed: " << GetErrorMessage();
- sql_conn_->SetErrorCode(r);
- return false;
- }
- return true;
-}
-
bool SQLiteStatement::BindString(int pos, const std::string& val) {
int r = sqlite3_bind_text(stmt_, pos, val.c_str(), -1, SQLITE_TRANSIENT);
if (r != SQLITE_OK) {
return true;
}
-int SQLiteStatement::GetColumnInt(int pos) const {
- int val = sqlite3_column_int(stmt_, pos);
- return val;
-}
-
std::string SQLiteStatement::GetColumnString(int pos) const {
const char* val = reinterpret_cast<const char*>(
sqlite3_column_text(stmt_, pos));
return std::vector<unsigned char>(val, val + len);
}
-bool SQLiteStatement::Reset() {
- int r = sqlite3_reset(stmt_);
- if (r != SQLITE_OK) {
- LOG(ERROR) << "sqlite3_reset failed: " << GetErrorMessage();
- return false;
- }
- return true;
-}
-
-void SQLiteStatement::Clear() {
- sqlite3_clear_bindings(stmt_);
-}
-
std::string SQLiteStatement::GetErrorMessage() const {
return sqlite3_errmsg(sqlite3_db_handle(stmt_));
}
enum class StepResult : int { DONE, ROW, ERROR, };
StepResult Step();
- bool BindInt(int pos, int val);
bool BindString(int pos, const std::string& val);
bool BindBlob(int pos, const std::vector<unsigned char>& val);
- int GetColumnInt(int pos) const;
std::string GetColumnString(int pos) const;
std::vector<unsigned char> GetColumnBlob(int pos) const;
- bool Reset();
- void Clear();
-
private:
std::string GetErrorMessage() const;
+++ /dev/null
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include "theme_provider/sqlite_transaction.h"
-
-#include "theme_provider/sqlite_connection.h"
-
-namespace ttm {
-namespace provider {
-
-void SQLiteTransaction::lock() const {
- sql_conn_->BeginTransaction();
-}
-
-void SQLiteTransaction::unlock() const {
- if (!sql_conn_->GetErrorCode())
- sql_conn_->CommitTransaction();
- else
- sql_conn_->RollbackTransaction();
-}
-
-} // namespace provider
-} // namespace ttm
+++ /dev/null
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef THEME_PROVIDER_SQLITE_TRANSACTION_H_
-#define THEME_PROVIDER_SQLITE_TRANSACTION_H_
-
-namespace ttm {
-namespace provider {
-
-class SQLiteConnection;
-
-// BasicLockableClass.
-// usage:
-// SQLiteTransaction t;
-// std::lock_guard<SQLiteTransaction> guard(t);
-class SQLiteTransaction {
- public:
- explicit SQLiteTransaction(SQLiteConnection* sql_conn)
- : sql_conn_(sql_conn) { }
- void lock() const;
- void unlock() const;
-
- private:
- SQLiteConnection* sql_conn_;
-};
-
-} // namespace provider
-} // namespace ttm
-
-#endif // THEME_PROVIDER_SQLITE_TRANSACTION_H_