summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordohyunglim <delight.lim@samsung.com>2017-08-16 03:28:43 +0000
committerdohyunglim <delight.lim@samsung.com>2017-08-16 05:07:23 +0000
commit878e6ad4deeef96416c0f1535f4d6ed066f8b183 (patch)
tree53596cd881bbcb2d5e079e826c4cbbd82158414d
parent6ce653d0fe3846e7b13d4c73e47a2f63f6597b1f (diff)
downloadbrowser-878e6ad4deeef96416c0f1535f4d6ed066f8b183.tar.gz
browser-878e6ad4deeef96416c0f1535f4d6ed066f8b183.tar.bz2
browser-878e6ad4deeef96416c0f1535f4d6ed066f8b183.zip
PVS V690 issue fixed.
Change-Id: I8c560352a23a13c854937d80a3339234f0969f42 Signed-off-by: dohyunglim <delight.lim@samsung.com>
-rwxr-xr-xservices/StorageService/SQLDatabase.cpp86
-rwxr-xr-xservices/StorageService/SQLDatabaseImpl.h5
2 files changed, 49 insertions, 42 deletions
diff --git a/services/StorageService/SQLDatabase.cpp b/services/StorageService/SQLDatabase.cpp
index f614239..6fd0255 100755
--- a/services/StorageService/SQLDatabase.cpp
+++ b/services/StorageService/SQLDatabase.cpp
@@ -42,13 +42,13 @@ static inline int sql_prepare(sqlite3 * db, sqlite3_stmt ** stmt, const char * q
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,
@@ -68,21 +68,21 @@ static inline int sql_step(sqlite3_stmt * stmt)
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");
}
@@ -92,7 +92,7 @@ static inline int sql_step(sqlite3_stmt * stmt)
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;
}
@@ -100,7 +100,7 @@ static inline bool sql_begin(sqlite3 * db)
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;
}
@@ -111,7 +111,7 @@ static inline bool sql_begin(sqlite3 * db)
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;
}
@@ -119,7 +119,7 @@ static inline bool sql_commit(sqlite3 * db)
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;
}
@@ -130,7 +130,7 @@ static inline bool sql_commit(sqlite3 * db)
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;
}
@@ -138,7 +138,7 @@ static inline bool sql_rollback(sqlite3 * db)
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;
}
@@ -168,9 +168,15 @@ SQLQueryPrivate::SQLQueryPrivate(const SQLQueryPrivate& other) :
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);
}
@@ -186,7 +192,7 @@ SQLDatabasePrivate::~SQLDatabasePrivate()
void SQLDatabasePrivate::close()
{
- if(_db) {
+ if (_db) {
sqlite3_close(_db);
_db = NULL;
}
@@ -199,7 +205,7 @@ SQLQuery::SQLQuery() :
SQLQuery::SQLQuery(const SQLQuery& other)
{
- if(other.d)
+ if (other.d)
d = new SQLQueryPrivate(*other.d);
else
d = NULL;
@@ -352,7 +358,7 @@ std::string SQLQuery::getString(int column) const
const char * str = (const char *)sqlite3_column_text(d->_stmt, column);
- if(!str)
+ if (!str)
return std::string();
return str;
@@ -393,7 +399,7 @@ std::shared_ptr<tizen_browser::tools::Blob> SQLQuery::getBlob(int column) const
const void * blob = sqlite3_column_blob(d->_stmt, column);
- if(blob == NULL) {
+ if (blob == NULL) {
return std::shared_ptr<tizen_browser::tools::Blob>();
}
@@ -410,8 +416,8 @@ size_t SQLQuery::getDataLength(int column) const
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));
}
}
@@ -436,10 +442,10 @@ FieldPtr SQLQuery::getField(int column) const
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));
@@ -477,7 +483,7 @@ bool SQLQuery::next()
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) {
@@ -500,7 +506,7 @@ void SQLQuery::reset()
{
M_ASSERT(d);
- if(d->_stmt) {
+ if (d->_stmt) {
M_ASSERT(!d->_db_ref.expired());
sqlite3_reset(d->_stmt);
}
@@ -510,7 +516,7 @@ void SQLQuery::clearBindings()
{
M_ASSERT(d);
- if(d->_stmt) {
+ if (d->_stmt) {
M_ASSERT(!d->_db_ref.expired());
sqlite3_clear_bindings(d->_stmt);
}
@@ -521,7 +527,7 @@ void SQLQuery::exec()
M_ASSERT(d);
M_ASSERT(!d->_db_ref.expired());
- if(!d->_stmt) {
+ if (!d->_stmt) {
throw StorageException("[SQLQuery] Statement not active", 0);
}
@@ -529,7 +535,7 @@ void SQLQuery::exec()
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;
@@ -554,7 +560,7 @@ std::vector<std::string> SQLQuery::columnNames() const
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)));
}
@@ -589,7 +595,7 @@ void SQLDatabase::open(const std::string& path)
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);
@@ -613,7 +619,7 @@ SQLQuery SQLDatabase::prepare(const std::string& query) const
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,
@@ -636,7 +642,7 @@ SQLQuery SQLDatabase::prepare(const std::string& query) const
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=?"));
@@ -649,7 +655,7 @@ bool SQLDatabase::tableExists(const std::string& name) const
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);
@@ -660,16 +666,16 @@ long long SQLDatabase::lastInsertId() const
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,
@@ -681,7 +687,7 @@ bool SQLDatabase::exec(const std::string& command) const
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,
@@ -703,7 +709,7 @@ std::vector<std::string> SQLDatabase::tableColumnNames(const std::string& table)
SQLQuery query(prepare(query_str));
query.exec();
- while(query.hasNext()) {
+ while (query.hasNext()) {
result.push_back(query.getString(1));
query.next();
}
@@ -713,14 +719,14 @@ std::vector<std::string> SQLDatabase::tableColumnNames(const std::string& table)
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));
}
}
diff --git a/services/StorageService/SQLDatabaseImpl.h b/services/StorageService/SQLDatabaseImpl.h
index 088793a..41bcaf9 100755
--- a/services/StorageService/SQLDatabaseImpl.h
+++ b/services/StorageService/SQLDatabaseImpl.h
@@ -33,8 +33,9 @@ public:
std::string _query;
SQLQueryPrivate(const std::shared_ptr<SQLDatabase>& db_ref, sqlite3 * db, sqlite3_stmt * stmt, const std::string& query);
- SQLQueryPrivate(const SQLQueryPrivate& other);
- ~SQLQueryPrivate();
+ SQLQueryPrivate(const SQLQueryPrivate& other);
+ SQLQueryPrivate& operator=(const SQLQueryPrivate&);
+ ~SQLQueryPrivate();
};
class SQLDatabasePrivate