diff options
Diffstat (limited to 'services/StorageService')
24 files changed, 1051 insertions, 934 deletions
diff --git a/services/StorageService/CMakeLists.txt b/services/StorageService/CMakeLists.txt index 9d511975..9d511975 100644..100755 --- a/services/StorageService/CMakeLists.txt +++ b/services/StorageService/CMakeLists.txt diff --git a/services/StorageService/CertificateStorage.cpp b/services/StorageService/CertificateStorage.cpp index 8f45f7ff..8f45f7ff 100644..100755 --- a/services/StorageService/CertificateStorage.cpp +++ b/services/StorageService/CertificateStorage.cpp diff --git a/services/StorageService/CertificateStorage.h b/services/StorageService/CertificateStorage.h index 54c4cd27..54c4cd27 100644..100755 --- a/services/StorageService/CertificateStorage.h +++ b/services/StorageService/CertificateStorage.h diff --git a/services/StorageService/DBTools.cpp b/services/StorageService/DBTools.cpp index 453181d5..453181d5 100644..100755 --- a/services/StorageService/DBTools.cpp +++ b/services/StorageService/DBTools.cpp diff --git a/services/StorageService/DBTools.h b/services/StorageService/DBTools.h index 9e2278a4..9e2278a4 100644..100755 --- a/services/StorageService/DBTools.h +++ b/services/StorageService/DBTools.h diff --git a/services/StorageService/DriverManager.cpp b/services/StorageService/DriverManager.cpp index 9231532e..aef08e6f 100644..100755 --- a/services/StorageService/DriverManager.cpp +++ b/services/StorageService/DriverManager.cpp @@ -46,7 +46,6 @@ std::shared_ptr<SQLDatabase> DriverManagerInstance::getDatabase(const std::strin DriverManager::DriverManager() { - } DriverManager::~DriverManager() diff --git a/services/StorageService/DriverManager.h b/services/StorageService/DriverManager.h index 63127154..63127154 100644..100755 --- a/services/StorageService/DriverManager.h +++ b/services/StorageService/DriverManager.h diff --git a/services/StorageService/Field.cpp b/services/StorageService/Field.cpp index 912235c0..912235c0 100644..100755 --- a/services/StorageService/Field.cpp +++ b/services/StorageService/Field.cpp diff --git a/services/StorageService/Field.h b/services/StorageService/Field.h index 81b73ac0..81b73ac0 100644..100755 --- a/services/StorageService/Field.h +++ b/services/StorageService/Field.h diff --git a/services/StorageService/FoldersStorage.cpp b/services/StorageService/FoldersStorage.cpp index e84ec7b4..411bbb6f 100644..100755 --- a/services/StorageService/FoldersStorage.cpp +++ b/services/StorageService/FoldersStorage.cpp @@ -38,350 +38,443 @@ #include "StorageExceptionInitialization.h" namespace { - const std::string TABLE_FOLDER = "FOLDER_TABLE"; - const std::string COL_FOLDER_ID = "folder_id"; - const std::string COL_FOLDER_NAME = "name"; - const std::string COL_FOLDER_NUMBER = "number"; - const std::string CONSTRAINT_TABLE_PK = TABLE_FOLDER + "_PK"; - const std::string DDL_CREATE_TABLE_FOLDER - = " CREATE TABLE " + TABLE_FOLDER - + " ( " + COL_FOLDER_ID + " INTEGER, " - + " " + COL_FOLDER_NAME + " TEXT," - + " " + COL_FOLDER_NUMBER + " INTEGER," - + " CONSTRAINT " + CONSTRAINT_TABLE_PK - + " PRIMARY KEY ( " + COL_FOLDER_ID + " ) " - + " ON CONFLICT REPLACE " - + " ); "; + const std::string TABLE_FOLDER = "FOLDER_TABLE"; + const std::string COL_FOLDER_ID = "folder_id"; + const std::string COL_FOLDER_NAME = "name"; + const std::string COL_FOLDER_NUMBER = "number"; + const std::string CONSTRAINT_TABLE_PK = TABLE_FOLDER + "_PK"; + const std::string DDL_CREATE_TABLE_FOLDER + = " CREATE TABLE " + TABLE_FOLDER + + " ( " + COL_FOLDER_ID + " INTEGER, " + + " " + COL_FOLDER_NAME + " TEXT," + + " " + COL_FOLDER_NUMBER + " INTEGER," + + " CONSTRAINT " + CONSTRAINT_TABLE_PK + + " PRIMARY KEY ( " + COL_FOLDER_ID + " ) " + + " ON CONFLICT REPLACE " + " ); "; } -namespace tizen_browser { -namespace storage { +namespace tizen_browser +{ + namespace storage + { -FoldersStorage::FoldersStorage() - : m_isInitialized(false) + FoldersStorage::FoldersStorage() + :m_isInitialized(false) , m_dbFoldersInitialised(false) -{ - init(); -} + { + init(); + } -FoldersStorage::~FoldersStorage() -{ -} + FoldersStorage::~FoldersStorage() + { + } -void FoldersStorage::init() -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - if(m_isInitialized) - return; + void FoldersStorage::init() + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + if (m_isInitialized) + return; + + std::string resourceDbDir(boost::any_cast < std::string > + (tizen_browser::config::Config::getInstance(). + get("resourcedb/dir"))); + std::string sessionDb(boost::any_cast < std::string > + (tizen_browser::config::Config::getInstance(). + get("DB_FOLDERS"))); - std::string resourceDbDir(boost::any_cast < std::string > (tizen_browser::config::Config::getInstance().get("resourcedb/dir"))); - std::string sessionDb(boost::any_cast < std::string > (tizen_browser::config::Config::getInstance().get("DB_FOLDERS"))); + DB_FOLDERS = resourceDbDir + sessionDb; - DB_FOLDERS = resourceDbDir + sessionDb; + BROWSER_LOGD("[%s:%d] DB_FOLDERS=%s", __PRETTY_FUNCTION__, __LINE__, + DB_FOLDERS.c_str()); - BROWSER_LOGD("[%s:%d] DB_FOLDERS=%s", __PRETTY_FUNCTION__, __LINE__, DB_FOLDERS.c_str()); + try { + initDatabaseFolders(DB_FOLDERS); + } + catch(storage::StorageExceptionInitialization & e) { + BROWSER_LOGE("[%s:%d] Cannot initialize database %s!", + __PRETTY_FUNCTION__, __LINE__, DB_FOLDERS.c_str()); + } - try { - initDatabaseFolders(DB_FOLDERS); - } catch (storage::StorageExceptionInitialization & e) { - BROWSER_LOGE("[%s:%d] Cannot initialize database %s!", __PRETTY_FUNCTION__, __LINE__, DB_FOLDERS.c_str()); + m_isInitialized = true; } - m_isInitialized = true; -} + void FoldersStorage::initDatabaseFolders(const std::string & db_str) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); -void FoldersStorage::initDatabaseFolders(const std::string& db_str) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - - if (!m_dbFoldersInitialised) { - try { - dbtools::checkAndCreateTable(db_str, TABLE_FOLDER, DDL_CREATE_TABLE_FOLDER); - const std::string all = "All"; - if (ifFolderExists(all)) - AllFolder = getFolderId(all); - else - AllFolder = addFolder(all); + if (!m_dbFoldersInitialised) { + try { + dbtools::checkAndCreateTable(db_str, TABLE_FOLDER, + DDL_CREATE_TABLE_FOLDER); + const std::string all = "All"; + if (ifFolderExists(all)) + AllFolder = getFolderId(all); + else + AllFolder = addFolder(all); #if PROFILE_MOBILE - const std::string special = "Mobile"; //TODO: missing translation + const std::string special = "Mobile"; //TODO: missing translation #else - const std::string special = "Bookmark Bar"; //TODO: missing translation + const std::string special = "Bookmark Bar"; //TODO: missing translation #endif - if (ifFolderExists(special)) - SpecialFolder = getFolderId(special); - else - SpecialFolder = addFolder(special); - } catch (storage::StorageException & e) { - throw storage::StorageExceptionInitialization(e.getMessage(), - e.getErrorCode()); - } - - m_dbFoldersInitialised = true; + if (ifFolderExists(special)) + SpecialFolder = getFolderId(special); + else + SpecialFolder = addFolder(special); + } + catch(storage::StorageException & e) { + throw storage::StorageExceptionInitialization(e.getMessage(), + e.getErrorCode()); + } + + m_dbFoldersInitialised = true; + } + + M_ASSERT(m_dbFoldersInitialised); } - M_ASSERT(m_dbFoldersInitialised); -} - -services::SharedBookmarkFolder FoldersStorage::getFolder(unsigned int id) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - std::string name = getFolderName(id); - unsigned int count = getFolderNumber(id); - services::SharedBookmarkFolder folder; - if (name != "") - folder = std::make_shared<services::BookmarkFolder>(id, name, count); - return folder; -} - -services::SharedBookmarkFolderList FoldersStorage::getFolders() -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - services::SharedBookmarkFolderList folders; - int foldersCount = getFoldersCount(); - if (foldersCount != 0) { - boost::format getFoldersString("SELECT %1%, %2%, %3% FROM %4% ;"); - getFoldersString % COL_FOLDER_ID % COL_FOLDER_NAME % COL_FOLDER_NUMBER % TABLE_FOLDER; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - storage::SQLQuery getFoldersQuery(connection->prepare(getFoldersString.str())); - getFoldersQuery.exec(); - for (int i = 0; i < foldersCount; ++i) { - services::SharedBookmarkFolder bookmark = std::make_shared<services::BookmarkFolder>( - getFoldersQuery.getInt(0), getFoldersQuery.getString(1), getFoldersQuery.getInt(2)); - folders.push_back(bookmark); - getFoldersQuery.next(); - } - } catch (storage::StorageException& e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); - } + services::SharedBookmarkFolder FoldersStorage::getFolder(unsigned int id) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + std::string name = getFolderName(id); + unsigned int count = getFolderNumber(id); + services::SharedBookmarkFolder folder; + if (name != "") + folder = + std::make_shared < services::BookmarkFolder > (id, name, count); + return folder; } - return folders; -} -unsigned int FoldersStorage::getFoldersCount() -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - boost::format getCountString("SELECT COUNT (*) FROM %1% ;"); - getCountString % TABLE_FOLDER; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - storage::SQLQuery getCountQuery(connection->prepare(getCountString.str())); - getCountQuery.exec(); - return getCountQuery.getInt(0); - } catch (storage::StorageException& e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + services::SharedBookmarkFolderList FoldersStorage::getFolders() { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + services::SharedBookmarkFolderList folders; + int foldersCount = getFoldersCount(); + if (foldersCount != 0) { + boost::format getFoldersString("SELECT %1%, %2%, %3% FROM %4% ;"); + getFoldersString % COL_FOLDER_ID % COL_FOLDER_NAME % + COL_FOLDER_NUMBER % TABLE_FOLDER; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + storage::SQLQuery getFoldersQuery(connection-> + prepare(getFoldersString.str())); + getFoldersQuery.exec(); + for (int i = 0; i < foldersCount; ++i) { + services::SharedBookmarkFolder bookmark = + std::make_shared < services::BookmarkFolder > + (getFoldersQuery.getInt(0), getFoldersQuery.getString(1), + getFoldersQuery.getInt(2)); + folders.push_back(bookmark); + getFoldersQuery.next(); + } + } catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + } + return folders; } - return 0; -} -unsigned int FoldersStorage::addFolder(const std::string& name) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - boost::format addFolderQueryString("INSERT OR REPLACE INTO %1% ( %2% ) VALUES ( ? );"); - addFolderQueryString % TABLE_FOLDER % COL_FOLDER_NAME; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> db = scope.database(); - storage::SQLQuery addFolderQuery(db->prepare(addFolderQueryString.str())); - addFolderQuery.bindText(1, name); - addFolderQuery.exec(); - return db->lastInsertId(); - } catch (storage::StorageException &e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + unsigned int FoldersStorage::getFoldersCount() + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + boost::format getCountString("SELECT COUNT (*) FROM %1% ;"); + getCountString % TABLE_FOLDER; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + storage::SQLQuery getCountQuery(connection-> + prepare(getCountString.str())); + getCountQuery.exec(); + return getCountQuery.getInt(0); + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + return 0; } - return 0; -} -void FoldersStorage::updateFolderName(unsigned int id, const std::string& newName) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - if (id == AllFolder) - return; - boost::format updateFolderNameString("UPDATE %1% SET %2% = ? WHERE %3% = ?" ); - updateFolderNameString % TABLE_FOLDER % COL_FOLDER_NAME % COL_FOLDER_ID; - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - try { - storage::SQLQuery updateFolderNameQuery(connection->prepare(updateFolderNameString.str())); - updateFolderNameQuery.bindText(1, newName); - updateFolderNameQuery.bindInt(2, id); - updateFolderNameQuery.exec(); - } catch (storage::StorageException &e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + unsigned int FoldersStorage::addFolder(const std::string & name) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + boost:: + format + addFolderQueryString + ("INSERT OR REPLACE INTO %1% ( %2% ) VALUES ( ? );"); + addFolderQueryString % TABLE_FOLDER % COL_FOLDER_NAME; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > db = scope.database(); + storage::SQLQuery addFolderQuery(db-> + prepare(addFolderQueryString.str())); + addFolderQuery.bindText(1, name); + addFolderQuery.exec(); + return db->lastInsertId(); + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + return 0; } -} -void FoldersStorage::addNumberInFolder(unsigned int id) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - if (id != AllFolder) - addNumberInFolder(AllFolder); - boost::format updateFolderNameString("UPDATE %1% SET %2% = ? WHERE %3% = ?" ); - updateFolderNameString % TABLE_FOLDER % COL_FOLDER_NUMBER % COL_FOLDER_ID; - int count = getFolderNumber(id); - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - try { - storage::SQLQuery updateFolderNameQuery(connection->prepare(updateFolderNameString.str())); - updateFolderNameQuery.bindInt(1, count+1); - updateFolderNameQuery.bindInt(2, id); - updateFolderNameQuery.exec(); - } catch (storage::StorageException &e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + void FoldersStorage::updateFolderName(unsigned int id, + const std::string & newName) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + if (id == AllFolder) + return; + boost:: + format + updateFolderNameString("UPDATE %1% SET %2% = ? WHERE %3% = ?"); + updateFolderNameString % TABLE_FOLDER % COL_FOLDER_NAME % COL_FOLDER_ID; + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = scope.database(); + try { + storage::SQLQuery updateFolderNameQuery(connection-> + prepare + (updateFolderNameString. + str())); + updateFolderNameQuery.bindText(1, newName); + updateFolderNameQuery.bindInt(2, id); + updateFolderNameQuery.exec(); + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } } -} -void FoldersStorage::removeNumberInFolder(unsigned int id) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - if (id != AllFolder) - removeNumberInFolder(AllFolder); - boost::format updateFolderNameString("UPDATE %1% SET %2% = ? WHERE %3% = ?" ); - updateFolderNameString % TABLE_FOLDER % COL_FOLDER_NUMBER % COL_FOLDER_ID; - int count = getFolderNumber(id); - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - try { - storage::SQLQuery updateFolderNameQuery(connection->prepare(updateFolderNameString.str())); - updateFolderNameQuery.bindInt(1, count-1); - updateFolderNameQuery.bindInt(2, id); - updateFolderNameQuery.exec(); - } catch (storage::StorageException &e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + void FoldersStorage::addNumberInFolder(unsigned int id) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + if (id != AllFolder) + addNumberInFolder(AllFolder); + boost:: + format updateFolderNameString("UPDATE %1% SET %2% = ? WHERE %3% = ?"); + updateFolderNameString % TABLE_FOLDER % COL_FOLDER_NUMBER % + COL_FOLDER_ID; + int count = getFolderNumber(id); + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = scope.database(); + try { + storage::SQLQuery updateFolderNameQuery(connection-> + prepare + (updateFolderNameString. + str())); + updateFolderNameQuery.bindInt(1, count + 1); + updateFolderNameQuery.bindInt(2, id); + updateFolderNameQuery.exec(); + } catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } } -} -void FoldersStorage::deleteAllFolders() -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - boost::format deleteFoldersString("DELETE FROM %1% WHERE %2% != ? AND %3% != ? ;"); - deleteFoldersString % TABLE_FOLDER % COL_FOLDER_ID % COL_FOLDER_ID; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - - storage::SQLQuery deleteFoldersQuery(connection->prepare(deleteFoldersString.str())); - deleteFoldersQuery.bindInt(1, AllFolder); - deleteFoldersQuery.bindInt(2, SpecialFolder); - deleteFoldersQuery.exec(); - } catch( storage::StorageException &e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + void FoldersStorage::removeNumberInFolder(unsigned int id) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + if (id != AllFolder) + removeNumberInFolder(AllFolder); + boost:: + format updateFolderNameString("UPDATE %1% SET %2% = ? WHERE %3% = ?"); + updateFolderNameString % TABLE_FOLDER % COL_FOLDER_NUMBER % + COL_FOLDER_ID; + int count = getFolderNumber(id); + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = scope.database(); + try { + storage::SQLQuery updateFolderNameQuery(connection-> + prepare + (updateFolderNameString. + str())); + updateFolderNameQuery.bindInt(1, count - 1); + updateFolderNameQuery.bindInt(2, id); + updateFolderNameQuery.exec(); + } catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } } - boost::format updateFoldersCountString("UPDATE %1% SET %2% = ? WHERE %3% = ? OR %4% = ?"); - updateFoldersCountString % TABLE_FOLDER % COL_FOLDER_NUMBER % COL_FOLDER_ID % COL_FOLDER_ID; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - - storage::SQLQuery updateFoldersCountQuery(connection->prepare(updateFoldersCountString.str())); - updateFoldersCountQuery.bindInt(1, 0); - updateFoldersCountQuery.bindInt(2, AllFolder); - updateFoldersCountQuery.bindInt(3, SpecialFolder); - updateFoldersCountQuery.exec(); - } catch( storage::StorageException &e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + void FoldersStorage::deleteAllFolders() + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + boost:: + format + deleteFoldersString("DELETE FROM %1% WHERE %2% != ? AND %3% != ? ;"); + deleteFoldersString % TABLE_FOLDER % COL_FOLDER_ID % COL_FOLDER_ID; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + + storage::SQLQuery deleteFoldersQuery(connection-> + prepare(deleteFoldersString. + str())); + deleteFoldersQuery.bindInt(1, AllFolder); + deleteFoldersQuery.bindInt(2, SpecialFolder); + deleteFoldersQuery.exec(); + } catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + + boost:: + format + updateFoldersCountString + ("UPDATE %1% SET %2% = ? WHERE %3% = ? OR %4% = ?"); + updateFoldersCountString % TABLE_FOLDER % COL_FOLDER_NUMBER % + COL_FOLDER_ID % COL_FOLDER_ID; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + + storage::SQLQuery updateFoldersCountQuery(connection-> + prepare + (updateFoldersCountString. + str())); + updateFoldersCountQuery.bindInt(1, 0); + updateFoldersCountQuery.bindInt(2, AllFolder); + updateFoldersCountQuery.bindInt(3, SpecialFolder); + updateFoldersCountQuery.exec(); + } catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } } -} -void FoldersStorage::deleteFolder(unsigned int id) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - if (id == AllFolder || id == SpecialFolder) - return; - boost::format deleteFolderString("DELETE FROM %1% WHERE %2% = ?;"); - deleteFolderString % TABLE_FOLDER % COL_FOLDER_ID; - - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - try { - storage::SQLQuery deleteFolderQurey(connection->prepare(deleteFolderString.str())); - deleteFolderQurey.bindInt(1, id); - deleteFolderQurey.exec(); - } catch (storage::StorageException &e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + void FoldersStorage::deleteFolder(unsigned int id) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + if (id == AllFolder || id == SpecialFolder) + return; + boost::format deleteFolderString("DELETE FROM %1% WHERE %2% = ?;"); + deleteFolderString % TABLE_FOLDER % COL_FOLDER_ID; + + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = scope.database(); + try { + storage::SQLQuery deleteFolderQurey(connection-> + prepare(deleteFolderString. + str())); + deleteFolderQurey.bindInt(1, id); + deleteFolderQurey.exec(); + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } } -} -bool FoldersStorage::ifFolderExists(const std::string& name) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - boost::format getCountString("SELECT COUNT (*) FROM %1% WHERE %2% = ?;"); - getCountString % TABLE_FOLDER % COL_FOLDER_NAME; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - storage::SQLQuery getCountQuery(connection->prepare(getCountString.str())); - getCountQuery.bindText(1, name); - getCountQuery.exec(); - int number = getCountQuery.getInt(0); - return number != 0; - } catch (storage::StorageException& e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + bool FoldersStorage::ifFolderExists(const std::string & name) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + boost:: + format getCountString("SELECT COUNT (*) FROM %1% WHERE %2% = ?;"); + getCountString % TABLE_FOLDER % COL_FOLDER_NAME; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + storage::SQLQuery getCountQuery(connection-> + prepare(getCountString.str())); + getCountQuery.bindText(1, name); + getCountQuery.exec(); + int number = getCountQuery.getInt(0); + return number != 0; + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + return true; } - return true; -} -unsigned int FoldersStorage::getFolderId(const std::string& name) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - boost::format getIdString("SELECT %1% FROM %2% WHERE %3% = ?;"); - getIdString % COL_FOLDER_ID % TABLE_FOLDER % COL_FOLDER_NAME; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - storage::SQLQuery getIdQuery(connection->prepare(getIdString.str())); - getIdQuery.bindText(1, name); - getIdQuery.exec(); - return getIdQuery.getInt(0); - } catch (storage::StorageException& e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + unsigned int FoldersStorage::getFolderId(const std::string & name) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + boost::format getIdString("SELECT %1% FROM %2% WHERE %3% = ?;"); + getIdString % COL_FOLDER_ID % TABLE_FOLDER % COL_FOLDER_NAME; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + storage::SQLQuery getIdQuery(connection->prepare(getIdString.str())); + getIdQuery.bindText(1, name); + getIdQuery.exec(); + return getIdQuery.getInt(0); + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + return 0; } - return 0; -} -std::string FoldersStorage::getFolderName(unsigned int id) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - boost::format getNameString("SELECT %1% FROM %2% WHERE %3% = ?;"); - getNameString % COL_FOLDER_NAME % TABLE_FOLDER % COL_FOLDER_ID; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - storage::SQLQuery getNameQuery(connection->prepare(getNameString.str())); - getNameQuery.bindInt(1, id); - getNameQuery.exec(); - - return getNameQuery.getString(0); - } catch (storage::StorageException& e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + std::string FoldersStorage::getFolderName(unsigned int id) { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + boost::format getNameString("SELECT %1% FROM %2% WHERE %3% = ?;"); + getNameString % COL_FOLDER_NAME % TABLE_FOLDER % COL_FOLDER_ID; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + storage::SQLQuery getNameQuery(connection-> + prepare(getNameString.str())); + getNameQuery.bindInt(1, id); + getNameQuery.exec(); + + return getNameQuery.getString(0); + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + return std::string(); } - return std::string(); -} -unsigned int FoldersStorage::getFolderNumber(unsigned int id) -{ - BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); - boost::format getNameString("SELECT %1% FROM %2% WHERE %3% = ?;"); - getNameString % COL_FOLDER_NUMBER % TABLE_FOLDER % COL_FOLDER_ID; - try { - storage::SQLTransactionScope scope(storage::DriverManager::getDatabase(DB_FOLDERS)); - std::shared_ptr<storage::SQLDatabase> connection = scope.database(); - storage::SQLQuery getNameQuery(connection->prepare(getNameString.str())); - getNameQuery.bindInt(1, id); - getNameQuery.exec(); - - return getNameQuery.getInt(0); - } catch (storage::StorageException& e) { - BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, __LINE__, e.getErrorCode(), e.getMessage()); + unsigned int FoldersStorage::getFolderNumber(unsigned int id) + { + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + boost::format getNameString("SELECT %1% FROM %2% WHERE %3% = ?;"); + getNameString % COL_FOLDER_NUMBER % TABLE_FOLDER % COL_FOLDER_ID; + try { + storage::SQLTransactionScope scope(storage::DriverManager:: + getDatabase(DB_FOLDERS)); + std::shared_ptr < storage::SQLDatabase > connection = + scope.database(); + storage::SQLQuery getNameQuery(connection-> + prepare(getNameString.str())); + getNameQuery.bindInt(1, id); + getNameQuery.exec(); + + return getNameQuery.getInt(0); + } + catch(storage::StorageException & e) { + BROWSER_LOGD("[%s:%d] SQLException (%d): %s ", __PRETTY_FUNCTION__, + __LINE__, e.getErrorCode(), e.getMessage()); + } + return 0; } - return 0; -} -}//end namespace storage -}//end namespace tizen_browser + } //end namespace storage +} //end namespace tizen_browser diff --git a/services/StorageService/FoldersStorage.h b/services/StorageService/FoldersStorage.h index 72b8061b..72b8061b 100644..100755 --- a/services/StorageService/FoldersStorage.h +++ b/services/StorageService/FoldersStorage.h diff --git a/services/StorageService/SQLDatabase.cpp b/services/StorageService/SQLDatabase.cpp index 7c04dc0c..30834454 100755 --- a/services/StorageService/SQLDatabase.cpp +++ b/services/StorageService/SQLDatabase.cpp @@ -27,715 +27,732 @@ #include <Eina.h> -namespace tizen_browser { -namespace storage { +namespace tizen_browser +{ + namespace storage + { #define SQL_RETRY_TIME_US 100000 #define SQL_RETRY_COUNT 200 -static FieldPtr _null_field(new Field()); + static FieldPtr _null_field(new Field()); -static inline int sql_prepare(sqlite3 * db, sqlite3_stmt ** stmt, const char * query) -{ - int retry = 0; - int rc; + static inline int sql_prepare(sqlite3 * db, sqlite3_stmt ** stmt, + const char *query) + { + int retry = 0; + int rc; - do { - rc = sqlite3_prepare_v2(db, query, -1, stmt, NULL); - 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)); + do + { + rc = sqlite3_prepare_v2(db, query, -1, stmt, NULL); + 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)); - if(rc != SQLITE_OK) { - BROWSER_LOGE("[sql_db] Can't prepare query from string '%s' with result %d (%s)", - query, - rc, - sqlite3_errmsg(db)); + if (rc != SQLITE_OK) { + BROWSER_LOGE + ("[sql_db] Can't prepare query from string '%s' with result %d (%s)", + query, rc, sqlite3_errmsg(db)); - return rc; + return rc; + } + + return rc; } - return rc; -} + static inline int sql_step(sqlite3_stmt * stmt) + { + int rc; + int retry = 0; -static inline int sql_step(sqlite3_stmt * stmt) -{ - int rc; - int retry = 0; + do { + rc = sqlite3_step(stmt); - do { - rc = sqlite3_step(stmt); + 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) { + ++retry; + std::this_thread::sleep_for(std::chrono:: + milliseconds(SQL_RETRY_TIME_US)); + } + } while (retry < SQL_RETRY_COUNT + && (rc == SQLITE_BUSY || 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) { - ++retry; - std::this_thread::sleep_for(std::chrono::milliseconds(SQL_RETRY_TIME_US)); - } - } while(retry < SQL_RETRY_COUNT && (rc == SQLITE_BUSY || rc == SQLITE_LOCKED)); + if (retry == SQL_RETRY_COUNT) { + BROWSER_LOGE("[sql_db] Database timeout"); + } - if(retry == SQL_RETRY_COUNT) { - BROWSER_LOGE("[sql_db] Database timeout"); - } + if (rc == SQLITE_MISUSE) { + BROWSER_LOGE("[sql_db] Sqlite misuse"); + } - if(rc == SQLITE_MISUSE) { - BROWSER_LOGE("[sql_db] Sqlite misuse"); + return rc; } - return rc; -} + static inline bool sql_begin(sqlite3 * db) + { + sqlite3_stmt *stmt = 0; + if (sql_prepare(db, &stmt, "BEGIN EXCLUSIVE TRANSACTION")) { + BROWSER_LOGE("[sql_db] Can't begin SQL transaction"); + return false; + } -static inline bool sql_begin(sqlite3 * db) -{ - sqlite3_stmt * stmt = 0; - 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); - int result = sql_step(stmt); - sqlite3_finalize(stmt); + if (result && result != SQLITE_DONE) { + BROWSER_LOGE("[sql_db] Error while starting transaction"); + return false; + } - if(result && result != SQLITE_DONE) { - BROWSER_LOGE("[sql_db] Error while starting transaction"); - return false; + return true; } - return true; -} + static inline bool sql_commit(sqlite3 * db) + { + sqlite3_stmt *stmt = 0; + if (sql_prepare(db, &stmt, "COMMIT")) { + BROWSER_LOGE("[sql_db] Can't commit SQL transaction"); + return false; + } -static inline bool sql_commit(sqlite3 * db) -{ - sqlite3_stmt * stmt = 0; - 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); - int result = sql_step(stmt); - sqlite3_finalize(stmt); + if (result && result != SQLITE_DONE) { + BROWSER_LOGD("[sql_db] Error while commiting transaction"); + return false; + } - if(result && result != SQLITE_DONE) { - BROWSER_LOGD("[sql_db] Error while commiting transaction"); - return false; + return true; } - return true; -} + static inline bool sql_rollback(sqlite3 * db) + { + sqlite3_stmt *stmt = 0; + if (sql_prepare(db, &stmt, "ROLLBACK")) { + BROWSER_LOGE("[sql_db] Can't rollback SQL transaction"); + return false; + } -static inline bool sql_rollback(sqlite3 * db) -{ - sqlite3_stmt * stmt = 0; - 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); - int result = sql_step(stmt); - sqlite3_finalize(stmt); + if (result && result != SQLITE_DONE) { + BROWSER_LOGD("[sql_db] Error while rolling transaction back"); + return false; + } - if(result && result != SQLITE_DONE) { - BROWSER_LOGD("[sql_db] Error while rolling transaction back"); - return false; + return true; } - return true; -} - -SQLQueryPrivate::SQLQueryPrivate(std::shared_ptr<SQLDatabase> db_ref, - sqlite3 * db, - sqlite3_stmt * stmt, - const std::string& query) : + SQLQueryPrivate::SQLQueryPrivate(std::shared_ptr < SQLDatabase > db_ref, sqlite3 * db, sqlite3_stmt * stmt, const std::string & query): _db_ref(db_ref), - _db(db), - _stmt(stmt), - _hasNext(false), - _query(query) -{ -} - -SQLQueryPrivate::SQLQueryPrivate(const SQLQueryPrivate& other) : - _db_ref(other._db_ref), - _db(other._db), - _stmt(other._stmt), - _hasNext(other._hasNext), - _query(other._query) -{ - const_cast<SQLQueryPrivate &>(other)._stmt = NULL; -} - -SQLQueryPrivate::~SQLQueryPrivate() -{ - if(_stmt) - sqlite3_finalize(_stmt); -} - -SQLDatabasePrivate::SQLDatabasePrivate() : - _db(NULL) -{ -} - -SQLDatabasePrivate::~SQLDatabasePrivate() -{ - close(); -} - -void SQLDatabasePrivate::close() -{ - if(_db) { - sqlite3_close(_db); - _db = NULL; + _db(db), _stmt(stmt), _hasNext(false), _query(query) { } -} - -SQLQuery::SQLQuery() : - d(NULL) -{ -} -SQLQuery::SQLQuery(const SQLQuery& other) -{ - if(other.d) - d = new SQLQueryPrivate(*other.d); - else - d = NULL; -} + SQLQueryPrivate:: + SQLQueryPrivate(const SQLQueryPrivate & other):_db_ref(other._db_ref), + _db(other._db), _stmt(other._stmt), _hasNext(other._hasNext), + _query(other._query) + { + const_cast < SQLQueryPrivate & >(other)._stmt = NULL; + } -SQLQuery::~SQLQuery() -{ - delete d; -} + SQLQueryPrivate::~SQLQueryPrivate() { + if (_stmt) + sqlite3_finalize(_stmt); + } -SQLQuery& SQLQuery::operator = (const SQLQuery& other) -{ - if(d != other.d) { - if(other.d) { - SQLQueryPrivate * new_d = new SQLQueryPrivate(*other.d); - delete d; - d = new_d; - } else { - delete d; - d = NULL; - } - } - return *this; -} - -bool SQLQuery::isValid() const -{ - return d && d->_stmt && !d->_db_ref.expired(); -} + SQLDatabasePrivate::SQLDatabasePrivate(): + _db(NULL) { + } -void SQLQuery::bindText(int paramNo, const char * text, int length) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + SQLDatabasePrivate::~SQLDatabasePrivate() { + close(); + } - int error = sqlite3_bind_text(d->_stmt, paramNo, text, length, NULL); + void SQLDatabasePrivate::close() + { + if (_db) { + sqlite3_close(_db); + _db = NULL; + } + } - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + SQLQuery::SQLQuery(): + d(NULL) { } -} -void SQLQuery::bindText(int paramNo, const std::string& text) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + SQLQuery::SQLQuery(const SQLQuery & other) + { + if (other.d) + d = new SQLQueryPrivate(*other.d); + else + d = NULL; + } - int error = sqlite3_bind_text(d->_stmt, paramNo, text.c_str(), text.length(), NULL); + SQLQuery::~SQLQuery() { + delete d; + } - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + SQLQuery & SQLQuery::operator =(const SQLQuery & other) + { + if (d != other.d) { + if (other.d) { + SQLQueryPrivate *new_d = new SQLQueryPrivate(*other.d); + delete d; + d = new_d; + } else { + delete d; + d = NULL; + } + } + return *this; + } + + bool SQLQuery::isValid() const + { + return d && d->_stmt && !d->_db_ref.expired(); } -} -void SQLQuery::bindBlob(int paramNo, std::unique_ptr<tizen_browser::tools::Blob> blob) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + void SQLQuery::bindText(int paramNo, const char *text, int length) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - int error = sqlite3_bind_blob(d->_stmt, paramNo, blob->getData(), blob->getLength(), - SQLITE_TRANSIENT); + int error = sqlite3_bind_text(d->_stmt, paramNo, text, length, NULL); - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } } -} -void SQLQuery::bindBlob(int paramNo, const void * data, size_t length) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + void SQLQuery::bindText(int paramNo, const std::string & text) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - int error = sqlite3_bind_blob(d->_stmt, paramNo, data, length, SQLITE_TRANSIENT); + int error = + sqlite3_bind_text(d->_stmt, paramNo, text.c_str(), text.length(), + NULL); - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } } -} -void SQLQuery::bindInt(int paramNo, int value) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + void SQLQuery::bindBlob(int paramNo, + std::unique_ptr < tizen_browser::tools::Blob > + blob) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - int error = sqlite3_bind_int(d->_stmt, paramNo, value); + int error = + sqlite3_bind_blob(d->_stmt, paramNo, blob->getData(), + blob->getLength(), + SQLITE_TRANSIENT); - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } } -} -void SQLQuery::bindInt64(int paramNo, long long value) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + void SQLQuery::bindBlob(int paramNo, const void *data, size_t length) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - int error = sqlite3_bind_int64(d->_stmt, paramNo, value); + int error = + sqlite3_bind_blob(d->_stmt, paramNo, data, length, SQLITE_TRANSIENT); - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } } -} -void SQLQuery::bindDouble(int paramNo, double value) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + void SQLQuery::bindInt(int paramNo, int value) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - int error = sqlite3_bind_double(d->_stmt, paramNo, value); + int error = sqlite3_bind_int(d->_stmt, paramNo, value); - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } } -} -void SQLQuery::bindNull(int paramNo) -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + void SQLQuery::bindInt64(int paramNo, long long value) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - int error = sqlite3_bind_null(d->_stmt, paramNo); + int error = sqlite3_bind_int64(d->_stmt, paramNo, value); - if (error != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), error); + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } } -} - -const char * SQLQuery::getCString(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); - return (const char *)sqlite3_column_text(d->_stmt, column); -} - -std::string SQLQuery::getString(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + void SQLQuery::bindDouble(int paramNo, double value) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - const char * str = (const char *)sqlite3_column_text(d->_stmt, column); + int error = sqlite3_bind_double(d->_stmt, paramNo, value); - if(!str) - return std::string(); + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } + } - return str; -} + void SQLQuery::bindNull(int paramNo) + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); -int SQLQuery::getInt(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + int error = sqlite3_bind_null(d->_stmt, paramNo); - return sqlite3_column_int(d->_stmt, column); -} + if (error != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), error); + } + } -long long SQLQuery::getInt64(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + const char *SQLQuery::getCString(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - return sqlite3_column_int64(d->_stmt, column); -} + return (const char *) sqlite3_column_text(d->_stmt, column); + } -double SQLQuery::getDouble(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + std::string SQLQuery::getString(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - return sqlite3_column_double(d->_stmt, column); -} + const char *str = (const char *) sqlite3_column_text(d->_stmt, column); -std::shared_ptr<tizen_browser::tools::Blob> SQLQuery::getBlob(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + if (!str) + return std::string(); - const void * blob = sqlite3_column_blob(d->_stmt, column); - - if(blob == NULL) { - return std::shared_ptr<tizen_browser::tools::Blob>(); + return str; } - int length = sqlite3_column_bytes(d->_stmt, column); - - return std::make_shared<tizen_browser::tools::Blob>(blob, length); -} + int SQLQuery::getInt(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); -size_t SQLQuery::getDataLength(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + return sqlite3_column_int(d->_stmt, column); + } - int result = sqlite3_column_bytes(d->_stmt, column); + long long SQLQuery::getInt64(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - if(result <= 0) { - if(sqlite3_errcode(d->_db) != SQLITE_OK) { - throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db)); - } + return sqlite3_column_int64(d->_stmt, column); } - return result; -} + double SQLQuery::getDouble(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); -int SQLQuery::fieldType(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + return sqlite3_column_double(d->_stmt, column); + } - return sqlite3_column_type(d->_stmt, column); -} + std::shared_ptr < tizen_browser::tools::Blob > + SQLQuery::getBlob(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); -FieldPtr SQLQuery::getField(int column) const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + const void *blob = sqlite3_column_blob(d->_stmt, column); - int col_type = sqlite3_column_type(d->_stmt, column); + if (blob == NULL) { + return std::shared_ptr < tizen_browser::tools::Blob > (); + } - if(col_type == 0) - throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db)); + int length = sqlite3_column_bytes(d->_stmt, column); - switch(col_type) - { - case SQLITE_INTEGER: - return std::make_shared<Field>(sqlite3_column_int(d->_stmt, column)); - case SQLITE_BLOB: - return std::make_shared<Field>(getBlob(column)); - case SQLITE_NULL: - return _null_field; - case SQLITE_TEXT: - return std::make_shared<Field>(getString(column)); - case SQLITE_FLOAT: - return std::make_shared<Field>(getDouble(column)); - default: - throw _null_field; + return std::make_shared < tizen_browser::tools::Blob > (blob, length); } -} -int SQLQuery::columnCount() const -{ - M_ASSERT(d); - M_ASSERT(d->_stmt); - M_ASSERT(!d->_db_ref.expired()); + size_t SQLQuery::getDataLength(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - return sqlite3_column_count(d->_stmt); -} + int result = sqlite3_column_bytes(d->_stmt, column); -bool SQLQuery::hasNext() const -{ - M_ASSERT(d); + if (result <= 0) + { + if (sqlite3_errcode(d->_db) != SQLITE_OK) { + throw StorageException(sqlite3_errmsg(d->_db), + sqlite3_errcode(d->_db)); + } + } - return d->_hasNext; -} - -bool SQLQuery::next() -{ - M_ASSERT(d); - M_ASSERT(!d->_db_ref.expired()); + return result; + } - if(d->_hasNext) { - int error = sql_step(d->_stmt); + int SQLQuery::fieldType(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - if (error == SQLITE_DONE) { - d->_hasNext = false; - return true; - } else if (error == SQLITE_ROW) { - d->_hasNext = true; - return true; - } else { - d->_hasNext = false; - BROWSER_LOGE("[SQLQuery] Unknown result received while executing query - %d - %s", error, d->_query.c_str()); - return false; - } + return sqlite3_column_type(d->_stmt, column); } - return false; -} - -void SQLQuery::reset() -{ - M_ASSERT(d); + FieldPtr SQLQuery::getField(int column) const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); + + int col_type = sqlite3_column_type(d->_stmt, column); + + if (col_type == 0) + throw StorageException(sqlite3_errmsg(d->_db), + sqlite3_errcode(d->_db)); + + switch (col_type) { + case SQLITE_INTEGER: + return std::make_shared < Field > + (sqlite3_column_int(d->_stmt, column)); + case SQLITE_BLOB:return std::make_shared < Field > (getBlob(column)); + case SQLITE_NULL:return _null_field; + case SQLITE_TEXT:return std::make_shared < Field > + (getString(column)); + case SQLITE_FLOAT:return std::make_shared < Field > + (getDouble(column)); + default:throw _null_field; + } + } + + int SQLQuery::columnCount() const + { + M_ASSERT(d); + M_ASSERT(d->_stmt); + M_ASSERT(!d->_db_ref.expired()); - if(d->_stmt) { - M_ASSERT(!d->_db_ref.expired()); - sqlite3_reset(d->_stmt); + return sqlite3_column_count(d->_stmt); } -} -void SQLQuery::clearBindings() -{ - M_ASSERT(d); + bool SQLQuery::hasNext() const + { + M_ASSERT(d); - if(d->_stmt) { - M_ASSERT(!d->_db_ref.expired()); - sqlite3_clear_bindings(d->_stmt); + return d->_hasNext; } -} -void SQLQuery::exec() -{ - M_ASSERT(d); - M_ASSERT(!d->_db_ref.expired()); + bool SQLQuery::next() + { + M_ASSERT(d); + M_ASSERT(!d->_db_ref.expired()); + + if (d->_hasNext) { + int error = sql_step(d->_stmt); + + if (error == SQLITE_DONE) { + d->_hasNext = false; + return true; + } else if (error == SQLITE_ROW) { + d->_hasNext = true; + return true; + } else { + d->_hasNext = false; + BROWSER_LOGE + ("[SQLQuery] Unknown result received while executing query - %d - %s", + error, d->_query.c_str()); + return false; + } + } + + return false; + } + + void SQLQuery::reset() + { + M_ASSERT(d); - if(!d->_stmt) { - throw StorageException("[SQLQuery] Statement not active", 0); + if (d->_stmt) { + M_ASSERT(!d->_db_ref.expired()); + sqlite3_reset(d->_stmt); + } } - int error = sql_step(d->_stmt); + void SQLQuery::clearBindings() + { + M_ASSERT(d); - if (error == SQLITE_DONE) { - // No more data available - d->_hasNext= false; - } else if (error == SQLITE_ROW) { - // Data is available - d->_hasNext = true; - } else if (error == SQLITE_ERROR) { - BROWSER_LOGE("[SQLQuery] Can't execute SELECT query because of error '%s' - %s", sqlite3_errmsg(d->_db), d->_query.c_str()); - d->_hasNext = false; - throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db)); - } else { - BROWSER_LOGE("[SQLQuery] Can't execute SELECT query because of result %d - %s", error, d->_query.c_str()); - throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db)); + if (d->_stmt) { + M_ASSERT(!d->_db_ref.expired()); + sqlite3_clear_bindings(d->_stmt); + } } -} -std::vector<std::string> SQLQuery::columnNames() const -{ - M_ASSERT(d); - M_ASSERT(!d->_db_ref.expired()); - M_ASSERT(d->_stmt); + void SQLQuery::exec() + { + M_ASSERT(d); + M_ASSERT(!d->_db_ref.expired()); + + if (!d->_stmt) { + throw StorageException("[SQLQuery] Statement not active", 0); + } + + int error = sql_step(d->_stmt); + + if (error == SQLITE_DONE) { + // No more data available + d->_hasNext = false; + } else if (error == SQLITE_ROW) { + // Data is available + d->_hasNext = true; + } else if (error == SQLITE_ERROR) { + BROWSER_LOGE + ("[SQLQuery] Can't execute SELECT query because of error '%s' - %s", + sqlite3_errmsg(d->_db), d->_query.c_str()); + d->_hasNext = false; + throw StorageException(sqlite3_errmsg(d->_db), + sqlite3_errcode(d->_db)); + } else { + BROWSER_LOGE + ("[SQLQuery] Can't execute SELECT query because of result %d - %s", + error, d->_query.c_str()); + throw StorageException(sqlite3_errmsg(d->_db), + sqlite3_errcode(d->_db)); + } + } + + std::vector < std::string > SQLQuery::columnNames()const + { + M_ASSERT(d); + M_ASSERT(!d->_db_ref.expired()); + M_ASSERT(d->_stmt); + + std::vector < std::string > result; - std::vector<std::string> result; + int cols = sqlite3_column_count(d->_stmt); + result.reserve(cols); - int cols = sqlite3_column_count(d->_stmt); - result.reserve(cols); + for (int i = 0; i < cols; ++i) + { + result.push_back(std::string(sqlite3_column_name(d->_stmt, i))); + } - for(int i = 0 ; i < cols ; ++i) { - result.push_back(std::string(sqlite3_column_name(d->_stmt, i))); + return result; } - return result; -} + std::shared_ptr < SQLDatabase > SQLDatabase::make_shared() { + return std::shared_ptr < SQLDatabase > (new SQLDatabase()); + } -std::shared_ptr<SQLDatabase> SQLDatabase::make_shared() -{ - return std::shared_ptr<SQLDatabase>(new SQLDatabase()); -} + SQLDatabase::SQLDatabase(): + d(new SQLDatabasePrivate()) { + } -SQLDatabase::SQLDatabase() : - d(new SQLDatabasePrivate()) -{ -} + SQLDatabase::~SQLDatabase() { + delete d; + } -SQLDatabase::~SQLDatabase() -{ - delete d; -} + std::shared_ptr < SQLDatabase > SQLDatabase::newInstance() { + std::shared_ptr < SQLDatabase > db = make_shared(); + db->d->_db_self_weak = db; + return db; + } -std::shared_ptr<SQLDatabase> SQLDatabase::newInstance() -{ - std::shared_ptr<SQLDatabase> db = make_shared(); - db->d->_db_self_weak = db; - return db; -} + void SQLDatabase::open(const std::string & path) + { + M_ASSERT(!d->_db); -void SQLDatabase::open(const std::string& path) -{ - M_ASSERT(!d->_db); + int error = + sqlite3_open_v2(path.c_str(), &d->_db, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); - int error = sqlite3_open_v2(path.c_str(), &d->_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); + if (error != SQLITE_OK) { + BROWSER_LOGE + ("[SQLDatabase] Can't open sqlite database from file '%s' with error %d", + path.c_str(), error); - if(error != SQLITE_OK) { - BROWSER_LOGE("[SQLDatabase] Can't open sqlite database from file '%s' with error %d", - path.c_str(), - error); + throw StorageException(sqlite3_errmsg(d->_db), error); + } - throw StorageException(sqlite3_errmsg(d->_db), error); + SQLQuery query(prepare("PRAGMA foreign_keys = ON")); + query.exec(); } - SQLQuery query(prepare("PRAGMA foreign_keys = ON")); - query.exec(); -} + void SQLDatabase::close() + { + d->close(); + } -void SQLDatabase::close() -{ - d->close(); -} + SQLQuery SQLDatabase::prepare(const std::string & query) const + { + EINA_SAFETY_ON_NULL_RETURN_VAL(d->_db, SQLQuery()); -SQLQuery SQLDatabase::prepare(const std::string& query) const -{ - EINA_SAFETY_ON_NULL_RETURN_VAL(d->_db, SQLQuery()); + sqlite3_stmt *stmt = NULL; + int rc = sql_prepare(d->_db, &stmt, query.c_str()); - sqlite3_stmt * stmt = NULL; - int rc = sql_prepare(d->_db, &stmt, query.c_str()); + if (rc != SQLITE_OK) + { + BROWSER_LOGE + ("[SQLDatabase] Can't prepare query from string '%s' with result %d (%s)", + query.c_str(), rc, sqlite3_errmsg(d->_db)); - if(rc != SQLITE_OK) { - BROWSER_LOGE("[SQLDatabase] Can't prepare query from string '%s' with result %d (%s)", - query.c_str(), - rc, - sqlite3_errmsg(d->_db)); + return SQLQuery(); + } - return SQLQuery(); - } + SQLQuery result; - SQLQuery result; + try { + result.d = + new SQLQueryPrivate(d->_db_self_weak.lock(), d->_db, stmt, query); + } + catch( ...) { + sqlite3_finalize(stmt); + throw; + } - try { - result.d = new SQLQueryPrivate(d->_db_self_weak.lock(), d->_db, stmt, query); - } catch(...) { - sqlite3_finalize(stmt); - throw; + return result; } - return result; -} - -bool SQLDatabase::tableExists(const std::string& name) const -{ - if(!d->_db) - return false; + bool SQLDatabase::tableExists(const std::string & name) const + { + if (!d->_db) + return false; - SQLQuery query(prepare("select count(*) from sqlite_master where type='table' and name=?")); - query.bindText(1, name); - query.exec(); + SQLQuery + query(prepare + ("select count(*) from sqlite_master where type='table' and name=?")); + query.bindText(1, name); + query.exec(); - return query.getInt(0) > 0; -} + return query.getInt(0) > 0; + } -long long SQLDatabase::lastInsertId() const -{ - BROWSER_LOGD("lastInsertId"); - if(!d->_db) - return -1; + long long SQLDatabase::lastInsertId() const + { + BROWSER_LOGD("lastInsertId"); + if (!d->_db) + return -1; - long long id = sqlite3_last_insert_rowid(d->_db); + long long id = sqlite3_last_insert_rowid(d->_db); - BROWSER_LOGD("lastInsertId: %d", id); - return id; -} + BROWSER_LOGD("lastInsertId: %d", id); + return id; + } -bool SQLDatabase::exec(const std::string& command) const -{ - if(!d->_db) - return false; - - sqlite3_stmt * stmt = NULL; - int rc = sql_prepare(d->_db, &stmt, command.c_str()); - - if(rc != SQLITE_OK) { - const char * errorMessage = sqlite3_errmsg(d->_db); - int errorCode = sqlite3_errcode(d->_db); - std::string error( errorMessage ? errorMessage : "" ); - BROWSER_LOGE("[SQLDatabase] Can't prepare query from string '%s' with result %d (%s)", - command.c_str(), - rc, - error.c_str()); - throw StorageException(error, errorCode); + bool SQLDatabase::exec(const std::string & command) const + { + if (!d->_db) + return false; + + sqlite3_stmt *stmt = NULL; + int rc = sql_prepare(d->_db, &stmt, command.c_str()); + + if (rc != SQLITE_OK) + { + const char *errorMessage = sqlite3_errmsg(d->_db); + int errorCode = sqlite3_errcode(d->_db); + std::string error(errorMessage ? errorMessage : ""); + BROWSER_LOGE + ("[SQLDatabase] Can't prepare query from string '%s' with result %d (%s)", + command.c_str(), rc, error.c_str()); + throw StorageException(error, errorCode); // return false; - } + } + + rc = sql_step(stmt); + sqlite3_finalize(stmt); - rc = sql_step(stmt); - sqlite3_finalize(stmt); + 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, sqlite3_errmsg(d->_db)); + throw StorageException(sqlite3_errmsg(d->_db), + sqlite3_errcode(d->_db)); + } - 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, - sqlite3_errmsg(d->_db)); - throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db)); + return true; } - return true; -} + std::vector < std::string > + SQLDatabase::tableColumnNames(const std::string & table) const + { + std::string query_str("PRAGMA table_info("); + query_str.append(table); + query_str.append(")"); -std::vector<std::string> SQLDatabase::tableColumnNames(const std::string& table) const -{ - std::string query_str("PRAGMA table_info("); - query_str.append(table); - query_str.append(")"); + std::vector < std::string > result; - std::vector<std::string> result; + SQLQuery query(prepare(query_str)); + query.exec(); - SQLQuery query(prepare(query_str)); - query.exec(); + while (query.hasNext()) + { + result.push_back(query.getString(1)); + query.next(); + } - while(query.hasNext()) { - result.push_back(query.getString(1)); - query.next(); + return result; } - return result; -} - -void SQLDatabase::begin() -{ - if(!sql_begin(d->_db)) { - throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db)); + void SQLDatabase::begin() + { + if (!sql_begin(d->_db)) { + throw StorageException(sqlite3_errmsg(d->_db), + sqlite3_errcode(d->_db)); + } } -} -void SQLDatabase::commit() -{ - if(!sql_commit(d->_db)) { - throw StorageException(sqlite3_errmsg(d->_db), sqlite3_errcode(d->_db)); + void SQLDatabase::commit() + { + if (!sql_commit(d->_db)) { + throw StorageException(sqlite3_errmsg(d->_db), + sqlite3_errcode(d->_db)); + } } -} -void SQLDatabase::rollback() -{ - sql_rollback(d->_db); -} + void SQLDatabase::rollback() + { + sql_rollback(d->_db); + } -std::shared_ptr<SQLDatabase> SQLDatabase::cloneForThread(void) -{ - std::shared_ptr<SQLDatabase> result(newInstance()); - result->open(d->_path); - return result; -} + std::shared_ptr < SQLDatabase > SQLDatabase::cloneForThread(void) + { + std::shared_ptr < SQLDatabase > result(newInstance()); + result->open(d->_path); + return result; + } -} /* namespace storage */ -} /* namespace tizen_browser */ + } /* namespace storage */ +} /* namespace tizen_browser */ diff --git a/services/StorageService/SQLDatabase.h b/services/StorageService/SQLDatabase.h index a22fc909..a22fc909 100644..100755 --- a/services/StorageService/SQLDatabase.h +++ b/services/StorageService/SQLDatabase.h diff --git a/services/StorageService/SQLDatabaseImpl.h b/services/StorageService/SQLDatabaseImpl.h index 9af2e04e..9af2e04e 100644..100755 --- a/services/StorageService/SQLDatabaseImpl.h +++ b/services/StorageService/SQLDatabaseImpl.h diff --git a/services/StorageService/SQLTransactionScope.cpp b/services/StorageService/SQLTransactionScope.cpp index 76d0d253..cc66cba9 100644..100755 --- a/services/StorageService/SQLTransactionScope.cpp +++ b/services/StorageService/SQLTransactionScope.cpp @@ -19,43 +19,45 @@ #include "BrowserAssert.h" #include "BrowserLogger.h" -namespace tizen_browser { -namespace storage { - -SQLTransactionScope::SQLTransactionScope(std::shared_ptr<SQLDatabase> db) : - _db(db), - _inTransaction(false) +namespace tizen_browser { - M_ASSERT(db); + namespace storage + { - db->begin(); - _inTransaction = true; -} + SQLTransactionScope::SQLTransactionScope(std::shared_ptr < SQLDatabase > + db):_db(db), + _inTransaction(false) + { + M_ASSERT(db); -SQLTransactionScope::~SQLTransactionScope() -{ - if(std::uncaught_exception()) { - if(_inTransaction) - _db->rollback(); - } else { - if(_inTransaction) - _db->commit(); + db->begin(); + _inTransaction = true; } -} -void SQLTransactionScope::commit() -{ - M_ASSERT(_inTransaction); - _inTransaction = false; - _db->commit(); -} + SQLTransactionScope::~SQLTransactionScope() + { + if (std::uncaught_exception()) { + if (_inTransaction) + _db->rollback(); + } else { + if (_inTransaction) + _db->commit(); + } + } -void SQLTransactionScope::rollback() -{ - _inTransaction = false; - _db->rollback(); -} + void SQLTransactionScope::commit() + { + M_ASSERT(_inTransaction); + _inTransaction = false; + _db->commit(); + } + void SQLTransactionScope::rollback() + { + _inTransaction = false; + _db->rollback(); + } -} + + } } diff --git a/services/StorageService/SQLTransactionScope.h b/services/StorageService/SQLTransactionScope.h index 02c42e24..02c42e24 100644..100755 --- a/services/StorageService/SQLTransactionScope.h +++ b/services/StorageService/SQLTransactionScope.h diff --git a/services/StorageService/SettingsStorage.cpp b/services/StorageService/SettingsStorage.cpp index ac862b95..ac862b95 100644..100755 --- a/services/StorageService/SettingsStorage.cpp +++ b/services/StorageService/SettingsStorage.cpp diff --git a/services/StorageService/SettingsStorage.h b/services/StorageService/SettingsStorage.h index 9ae00a33..bbbb459e 100644..100755 --- a/services/StorageService/SettingsStorage.h +++ b/services/StorageService/SettingsStorage.h @@ -71,7 +71,7 @@ public: void init(bool testmode = false); void initWebEngineSettingsFromDB(); - boost::signals2::signal<void (basic_webengine::WebEngineSettings, bool)> setWebEngineSettingsParam; + boost::signals2::signal<void(basic_webengine::WebEngineSettings, bool)> setWebEngineSettingsParam; private: /** * @throws StorageExceptionInitialization on error diff --git a/services/StorageService/StorageException.cpp b/services/StorageService/StorageException.cpp index df106125..7b2b1400 100644..100755 --- a/services/StorageService/StorageException.cpp +++ b/services/StorageService/StorageException.cpp @@ -16,28 +16,30 @@ #include "StorageException.h" -namespace tizen_browser { -namespace storage { - -StorageException::StorageException(const std::string & message, int code) : - m_code(code), m_message(message) -{ -} - -StorageException::~StorageException() throw () -{ - -} - -int StorageException::getErrorCode() const -{ - return m_code; -} - -const char * StorageException::getMessage() const throw () +namespace tizen_browser { - return m_message.c_str(); -} - -} + namespace storage + { + + StorageException::StorageException(const std::string & message, + int code):m_code(code), + m_message(message) + { + } + + StorageException::~StorageException() throw() + { + } + + int StorageException::getErrorCode() const + { + return m_code; + } + + const char *StorageException::getMessage() const throw() + { + return m_message.c_str(); + } + + } } diff --git a/services/StorageService/StorageException.h b/services/StorageService/StorageException.h index 1522748c..e65710e6 100644..100755 --- a/services/StorageService/StorageException.h +++ b/services/StorageService/StorageException.h @@ -31,9 +31,9 @@ class BROWSER_EXPORT StorageException: public std::exception { public: explicit StorageException(const std::string & message, int code = SQLITE_ERROR); - virtual ~StorageException() throw (); + virtual ~StorageException() throw(); virtual int getErrorCode() const; - virtual const char * getMessage() const throw (); + virtual const char * getMessage() const throw(); virtual const char* what() const throw() {return m_message.c_str();}; protected: int m_code; diff --git a/services/StorageService/StorageExceptionInitialization.cpp b/services/StorageService/StorageExceptionInitialization.cpp index df9d7d77..ba09abe7 100644..100755 --- a/services/StorageService/StorageExceptionInitialization.cpp +++ b/services/StorageService/StorageExceptionInitialization.cpp @@ -16,28 +16,33 @@ #include "StorageExceptionInitialization.h" -namespace tizen_browser { -namespace storage { - -StorageExceptionInitialization::StorageExceptionInitialization(const std::string & message, int code) : - StorageException(message, code) -{ -} - -StorageExceptionInitialization::~StorageExceptionInitialization() throw () -{ - -} - -int StorageExceptionInitialization::getErrorCode() const -{ - return m_code; -} - -const char * StorageExceptionInitialization::getMessage() const throw () +namespace tizen_browser { - return m_message.c_str(); -} - -} + namespace storage + { + + StorageExceptionInitialization::StorageExceptionInitialization(const std:: + string & + message, + int + code):StorageException + (message, code) + { + } + + StorageExceptionInitialization::~StorageExceptionInitialization() throw() + { + } + + int StorageExceptionInitialization::getErrorCode() const + { + return m_code; + } + + const char *StorageExceptionInitialization::getMessage() const throw() + { + return m_message.c_str(); + } + + } } diff --git a/services/StorageService/StorageExceptionInitialization.h b/services/StorageService/StorageExceptionInitialization.h index 8abc20ee..1698c777 100644..100755 --- a/services/StorageService/StorageExceptionInitialization.h +++ b/services/StorageService/StorageExceptionInitialization.h @@ -32,9 +32,9 @@ class BROWSER_EXPORT StorageExceptionInitialization: public StorageException { public: explicit StorageExceptionInitialization(const std::string & message, int code = SQLITE_ERROR); - virtual ~StorageExceptionInitialization() throw (); + virtual ~StorageExceptionInitialization() throw(); virtual int getErrorCode() const; - virtual const char * getMessage() const throw (); + virtual const char * getMessage() const throw(); }; } diff --git a/services/StorageService/StorageService.cpp b/services/StorageService/StorageService.cpp index bdd1ad5d..c35d689c 100644..100755 --- a/services/StorageService/StorageService.cpp +++ b/services/StorageService/StorageService.cpp @@ -31,7 +31,6 @@ StorageService::StorageService() StorageService::~StorageService() { - } } diff --git a/services/StorageService/StorageService.h b/services/StorageService/StorageService.h index f73c1243..f73c1243 100644..100755 --- a/services/StorageService/StorageService.h +++ b/services/StorageService/StorageService.h |