do {
rc = sqlite3_prepare_v2(db, query, -1, stmt, NULL);
- if(rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
+ if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
++retry;
std::this_thread::sleep_for(std::chrono::milliseconds(SQL_RETRY_TIME_US));
}
- } while(retry < SQL_RETRY_COUNT && (rc == SQLITE_BUSY || rc == SQLITE_LOCKED));
+ } while (retry < SQL_RETRY_COUNT && (rc == SQLITE_BUSY || rc == SQLITE_LOCKED));
- if(rc != SQLITE_OK) {
+ if (rc != SQLITE_OK) {
BROWSER_LOGE("[sql_db] Can't prepare query from string '%s' with result %d (%s)",
query,
rc,
do {
rc = sqlite3_step(stmt);
- if(rc == SQLITE_LOCKED) {
+ if (rc == SQLITE_LOCKED) {
rc = sqlite3_reset(stmt);
++retry;
std::this_thread::sleep_for(std::chrono::milliseconds(SQL_RETRY_TIME_US));
- } else if(rc == SQLITE_BUSY) {
+ } else if (rc == SQLITE_BUSY) {
++retry;
std::this_thread::sleep_for(std::chrono::milliseconds(SQL_RETRY_TIME_US));
}
- } while(retry < SQL_RETRY_COUNT && (rc == SQLITE_BUSY || rc == SQLITE_LOCKED));
+ } while (retry < SQL_RETRY_COUNT && (rc == SQLITE_BUSY || rc == SQLITE_LOCKED));
- if(retry == SQL_RETRY_COUNT) {
+ if (retry == SQL_RETRY_COUNT) {
BROWSER_LOGE("[sql_db] Database timeout");
}
- if(rc == SQLITE_MISUSE) {
+ if (rc == SQLITE_MISUSE) {
BROWSER_LOGE("[sql_db] Sqlite misuse");
}
static inline bool sql_begin(sqlite3 * db)
{
sqlite3_stmt * stmt = 0;
- if(sql_prepare(db, &stmt, "BEGIN EXCLUSIVE TRANSACTION")) {
+ if (sql_prepare(db, &stmt, "BEGIN EXCLUSIVE TRANSACTION")) {
BROWSER_LOGE("[sql_db] Can't begin SQL transaction");
return false;
}
int result = sql_step(stmt);
sqlite3_finalize(stmt);
- if(result && result != SQLITE_DONE) {
+ if (result && result != SQLITE_DONE) {
BROWSER_LOGE("[sql_db] Error while starting transaction");
return false;
}
static inline bool sql_commit(sqlite3 * db)
{
sqlite3_stmt * stmt = 0;
- if(sql_prepare(db, &stmt, "COMMIT")) {
+ if (sql_prepare(db, &stmt, "COMMIT")) {
BROWSER_LOGE("[sql_db] Can't commit SQL transaction");
return false;
}
int result = sql_step(stmt);
sqlite3_finalize(stmt);
- if(result && result != SQLITE_DONE) {
+ if (result && result != SQLITE_DONE) {
BROWSER_LOGD("[sql_db] Error while commiting transaction");
return false;
}
static inline bool sql_rollback(sqlite3 * db)
{
sqlite3_stmt * stmt = 0;
- if(sql_prepare(db, &stmt, "ROLLBACK")) {
+ if (sql_prepare(db, &stmt, "ROLLBACK")) {
BROWSER_LOGE("[sql_db] Can't rollback SQL transaction");
return false;
}
int result = sql_step(stmt);
sqlite3_finalize(stmt);
- if(result && result != SQLITE_DONE) {
+ if (result && result != SQLITE_DONE) {
BROWSER_LOGD("[sql_db] Error while rolling transaction back");
return false;
}
const_cast<SQLQueryPrivate &>(other)._stmt = NULL;
}
+SQLQueryPrivate& SQLQueryPrivate::operator=(const SQLQueryPrivate& other)
+{
+ const_cast<SQLQueryPrivate &>(other)._stmt = NULL;
+ return *this;
+}
+
SQLQueryPrivate::~SQLQueryPrivate()
{
- if(_stmt)
+ if (_stmt)
sqlite3_finalize(_stmt);
}
void SQLDatabasePrivate::close()
{
- if(_db) {
+ if (_db) {
sqlite3_close(_db);
_db = NULL;
}
SQLQuery::SQLQuery(const SQLQuery& other)
{
- if(other.d)
+ if (other.d)
d = new SQLQueryPrivate(*other.d);
else
d = NULL;
const char * str = (const char *)sqlite3_column_text(d->_stmt, column);
- if(!str)
+ if (!str)
return std::string();
return str;
const void * blob = sqlite3_column_blob(d->_stmt, column);
- if(blob == NULL) {
+ if (blob == NULL) {
return std::shared_ptr<tizen_browser::tools::Blob>();
}
int result = sqlite3_column_bytes(d->_stmt, column);
- if(result <= 0) {
- if(sqlite3_errcode(d->_db) != SQLITE_OK) {
+ if (result <= 0) {
+ if (sqlite3_errcode(d->_db) != SQLITE_OK) {
throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db));
}
}
int col_type = sqlite3_column_type(d->_stmt, column);
- if(col_type == 0)
+ if (col_type == 0)
throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db));
- switch(col_type)
+ switch (col_type)
{
case SQLITE_INTEGER:
return std::make_shared<Field>(sqlite3_column_int(d->_stmt, column));
M_ASSERT(d);
M_ASSERT(!d->_db_ref.expired());
- if(d->_hasNext) {
+ if (d->_hasNext) {
int error = sql_step(d->_stmt);
if (error == SQLITE_DONE) {
{
M_ASSERT(d);
- if(d->_stmt) {
+ if (d->_stmt) {
M_ASSERT(!d->_db_ref.expired());
sqlite3_reset(d->_stmt);
}
{
M_ASSERT(d);
- if(d->_stmt) {
+ if (d->_stmt) {
M_ASSERT(!d->_db_ref.expired());
sqlite3_clear_bindings(d->_stmt);
}
M_ASSERT(d);
M_ASSERT(!d->_db_ref.expired());
- if(!d->_stmt) {
+ if (!d->_stmt) {
throw StorageException("[SQLQuery] Statement not active", 0);
}
if (error == SQLITE_DONE) {
// No more data available
- d->_hasNext= false;
+ d->_hasNext = false;
} else if (error == SQLITE_ROW) {
// Data is available
d->_hasNext = true;
int cols = sqlite3_column_count(d->_stmt);
result.reserve(cols);
- for(int i = 0 ; i < cols ; ++i) {
+ for (int i = 0 ; i < cols ; ++i) {
result.push_back(std::string(sqlite3_column_name(d->_stmt, i)));
}
int error = sqlite3_open_v2(path.c_str(), &d->_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
- if(error != SQLITE_OK) {
+ if (error != SQLITE_OK) {
BROWSER_LOGE("[SQLDatabase] Can't open sqlite database from file '%s' with error %d",
path.c_str(),
error);
sqlite3_stmt * stmt = NULL;
int rc = sql_prepare(d->_db, &stmt, query.c_str());
- if(rc != SQLITE_OK) {
+ if (rc != SQLITE_OK) {
BROWSER_LOGE("[SQLDatabase] Can't prepare query from string '%s' with result %d (%s)",
query.c_str(),
rc,
bool SQLDatabase::tableExists(const std::string& name) const
{
- if(!d->_db)
+ if (!d->_db)
return false;
SQLQuery query(prepare("select count(*) from sqlite_master where type='table' and name=?"));
long long SQLDatabase::lastInsertId() const
{
BROWSER_LOGD("lastInsertId");
- if(!d->_db)
+ if (!d->_db)
return -1;
long long id = sqlite3_last_insert_rowid(d->_db);
bool SQLDatabase::exec(const std::string& command) const
{
- if(!d->_db)
+ if (!d->_db)
return false;
sqlite3_stmt * stmt = NULL;
int rc = sql_prepare(d->_db, &stmt, command.c_str());
- if(rc != SQLITE_OK) {
+ if (rc != SQLITE_OK) {
const char * errorMessage = sqlite3_errmsg(d->_db);
int errorCode = sqlite3_errcode(d->_db);
- std::string error( errorMessage ? errorMessage : "" );
+ std::string error(errorMessage ? errorMessage : "");
BROWSER_LOGE("[SQLDatabase] Can't prepare query from string '%s' with result %d (%s)",
command.c_str(),
rc,
rc = sql_step(stmt);
sqlite3_finalize(stmt);
- if(rc != SQLITE_DONE && rc != SQLITE_ROW) {
+ if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
BROWSER_LOGE("[SQLDatabase] Can't execute query from string '%s' with result %d (%s)",
command.c_str(),
rc,
SQLQuery query(prepare(query_str));
query.exec();
- while(query.hasNext()) {
+ while (query.hasNext()) {
result.push_back(query.getString(1));
query.next();
}
void SQLDatabase::begin()
{
- if(!sql_begin(d->_db)) {
+ if (!sql_begin(d->_db)) {
throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db));
}
}
void SQLDatabase::commit()
{
- if(!sql_commit(d->_db)) {
+ if (!sql_commit(d->_db)) {
throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db));
}
}