// // Open Service Platform // Copyright (c) 2012 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @file DatabaseManager.cpp * @brief This is the implementation file for %DatabaseManager class. */ #include #include #include #include #include #include #include "DatabaseManager.h" #include "SmackManager.h" using namespace Tizen::App; using namespace Tizen::App::Package; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Io; DatabaseManager::DatabaseManager(void) { CreatePackageTables(); } DatabaseManager::~DatabaseManager(void) { } bool DatabaseManager::RegisterPackageInfo(InstallationContext* pContext) const { bool res = true; Database db; String query; result r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r+"); TryReturn(r == E_SUCCESS, false, "db.Construct failed. [%s]", GetErrorMessage(r)); query.Format(1024, L"INSERT INTO PkgInfo " "(PKG_ID, PKG_SECRET, PKG_VERSION, PKG_TYPE, PKG_MIMETYPE, PKG_APIVERSION, PKG_NAME, PKG_VENDOR, PKG_DESCRIPTION, PKG_URL, PKG_CID, PKG_READONLY_SIZE, PKG_DATA_SIZE, PKG_PARENT_ID," " PKG_ATTRIBUTE, PKG_ROOTPATH, PKG_STORAGE_TYPE, PKG_INSTALLATION_DATE, PKG_STATE, PKG_INITIATOR) " "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); std::unique_ptr< DbStatement > pStmt(_PackageManagerImpl::CreateStatementN(db, query)); TryReturn(pStmt, false, "CreateStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); PackageId packageId = pContext->__packageId; String version = pContext->__version; String apiVersion = pContext->__apiVersion; String name = pContext->__displayName; String rootPath = pContext->__rootPath; if (!packageId.IsEmpty()) { r = pStmt.get()->BindString(0, packageId); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!version.IsEmpty()) { r = pStmt->BindString(2, version); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!apiVersion.IsEmpty()) { r = pStmt->BindString(5, apiVersion); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!name.IsEmpty()) { r = pStmt->BindString(6, name); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!rootPath.IsEmpty()) { r = pStmt->BindString(15, rootPath); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } std::unique_ptr< DbEnumerator > pEnum(_PackageManagerImpl::ExecuteStatementN(db, pStmt.get())); TryReturn(!IsFailed(GetLastResult()), false, "ExecuteStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); res = RegisterPrivilegeInfo(pContext, db); TryReturn(res == true, false, "RegisterPrivilegeInfo() failed. [%s]", GetErrorMessage(GetLastResult())); res = RegisterAppInfoList(pContext, db); TryReturn(res == true, false, "RegisterAppInfoList() failed. [%s]", GetErrorMessage(GetLastResult())); return true; } bool DatabaseManager::RegisterPrivilegeInfo(InstallationContext* pContext, Database& db) const { result r = E_SUCCESS; String query; PackageId packageId = pContext->__packageId; query.Format(1024, L"INSERT INTO PkgPrivileges (ID, PRIVILEGES, HMAC_PPRIVILEGES, CERTIFICATE_TYPE, STR_PRIVILEGES) " "VALUES ((SELECT PkgInfo.UNIQUE_ID FROM PkgInfo WHERE PkgInfo.PKG_ID = '%ls'), ?, ?, ?, ?)", packageId.GetPointer()); std::unique_ptr< DbStatement > pStmt(_PackageManagerImpl::CreateStatementN(db, query)); TryReturn(pStmt, false, "CreateStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); String privileges = pContext->__privileges; String hmacPrivileges = pContext->__hmacPrivileges; int certType = pContext->__certType; ArrayList* pStringPrivilegeList = pContext->__pStringPrivilegeList; if (!privileges.IsEmpty()) { r = pStmt->BindString(0, privileges); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!hmacPrivileges.IsEmpty()) { r = pStmt->BindString(1, hmacPrivileges); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (certType != 0) { r = pStmt->BindInt(2, certType); TryReturn(r == E_SUCCESS, false, "BindInt() failed. [%s]", GetErrorMessage(r)); } if (pStringPrivilegeList != null) { IEnumerator* pEnum = pStringPrivilegeList->GetEnumeratorN(); String MergedString; while(pEnum->MoveNext() == E_SUCCESS) { MergedString.Append(*(static_cast(pEnum->GetCurrent()))); MergedString.Append(L"#"); } delete pEnum; r = pStmt->BindString(3, MergedString); TryReturn(r == E_SUCCESS, false, "BindInt() failed. [%s]", GetErrorMessage(r)); } std::unique_ptr< DbEnumerator > pEnum(_PackageManagerImpl::ExecuteStatementN(db, pStmt.get())); TryReturn(!IsFailed(GetLastResult()), false, "ExecuteStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); return true; } bool DatabaseManager::RegisterAppInfoList(InstallationContext* pContext, Database& db) const { result r = E_SUCCESS; bool res = true; String query; IListT* pAppDataList = pContext->__pAppDataList; TryReturn(pAppDataList, false, "pAppDataList is null"); int count = pAppDataList->GetCount(); for (int i = 0; i < count; i++) { AppData* pAppData = null; pAppDataList->GetAt(i, pAppData); if (pAppData) { String name = pAppData->__name; String main = pAppData->__main; String mainmenuIcon = pAppData->__mainmenuIcon; String settingIcon = pAppData->__settingIcon; String notificationIcon = pAppData->__notificationIcon; int feature = pAppData->__feature; String appId = pAppData->__appId; String type = pAppData->__type; query.Format(1024, L"INSERT INTO AppInfo " "(ID, APP_NAME, APP_DEFAULT, APP_MAINMENU_ICON, APP_SETTING_ICON, APP_TICKER_ICON, APP_QUICKPANEL_ICON, APP_LAUNCHIMAGE_ICON, APP_FEATURE, PACKAGE_NAME, APP_TYPE) " "VALUES ((SELECT PkgInfo.UNIQUE_ID FROM PkgInfo WHERE PkgInfo.PKG_ID = '%ls'),?,?,?,?,?,?,?,?,?,?)", pContext->__packageId.GetPointer()); std::unique_ptr< DbStatement > pStmt(_PackageManagerImpl::CreateStatementN(db, query)); TryReturn(pStmt, false, "CreateStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); if (!name.IsEmpty()) { r = pStmt->BindString(0, name); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!main.IsEmpty()) { r = pStmt->BindString(1, main); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!mainmenuIcon.IsEmpty()) { r = pStmt->BindString(2, mainmenuIcon); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!settingIcon.IsEmpty()) { r = pStmt->BindString(3, settingIcon); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!notificationIcon.IsEmpty()) { r = pStmt->BindString(5, notificationIcon); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (feature != 0) { r = pStmt->BindInt(7, feature); TryReturn(r == E_SUCCESS, false, "BindInt() failed. [%s]", GetErrorMessage(r)); } if (!appId.IsEmpty()) { r = pStmt->BindString(8, appId); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!type.IsEmpty()) { r = pStmt->BindString(9, type); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } std::unique_ptr< DbEnumerator > pEnum(_PackageManagerImpl::ExecuteStatementN(db, pStmt.get())); TryReturn(!IsFailed(GetLastResult()), false, "ExecuteStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); if (pAppData->__pLaunchConditionList) { res = RegisterLaunchConditionList(pAppData, db); TryReturn(res == true, false, "RegisterLaunchConditionList() failed. [%s]", GetErrorMessage(r)); } if (pAppData->__pFeatureList) { res = RegisterAppFeatureList(pAppData, db); TryReturn(res == true, false, "RegisterAppFeatureList() failed. [%s]", GetErrorMessage(r)); } if (pAppData->__pDataControlList) { res = RegisterDataControlList(pAppData, db); TryReturn(res == true, false, "RegisterDataControlList() failed. [%s]", GetErrorMessage(r)); } } } return true; } bool DatabaseManager::RegisterLaunchConditionList(AppData* pAppData, Database& db) const { TryReturn(pAppData, E_SYSTEM, "pAppData is null."); TryReturn(pAppData->__pLaunchConditionList, E_SYSTEM, "__pLaunchConditionList is null."); result r = E_SUCCESS; HashMap* pList = pAppData->__pLaunchConditionList; std::unique_ptr< IMapEnumerator > pEnum(pList->GetMapEnumeratorN()); TryReturn(pEnum, false, "GetMapEnumeratorN() failed. [%s]", GetErrorMessage(GetLastResult())); while (pEnum->MoveNext() == E_SUCCESS) { String* pKey = static_cast< String* > (pEnum->GetKey()); TryReturn(pEnum, false, "GetKey() failed. [%s]", GetErrorMessage(GetLastResult())); String* pValue = static_cast< String* > (pEnum->GetValue()); TryReturn(pEnum, false, "GetValue() failed. [%s]", GetErrorMessage(GetLastResult())); String query; query.Format(1024, L"INSERT INTO LaunchCondition (ID, NAME, VALUE) VALUES ((SELECT AppInfo.UNIQUE_ID FROM AppInfo WHERE AppInfo.PACKAGE_NAME = '%ls'),?,?)", pAppData->__appId.GetPointer()); std::unique_ptr< DbStatement > pStmt(_PackageManagerImpl::CreateStatementN(db, query)); TryReturn(pStmt, false, "CreateStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); if (!(pKey->IsEmpty())) { r = pStmt->BindString(0, *pKey); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!(pValue->IsEmpty())) { r = pStmt->BindString(1, *pValue); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } std::unique_ptr< DbEnumerator > pEnum(_PackageManagerImpl::ExecuteStatementN(db, pStmt.get())); TryReturn(!IsFailed(GetLastResult()), false, "ExecuteStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); } return true; } bool DatabaseManager::RegisterAppFeatureList(AppData* pAppData, Database& db) const { TryReturn(pAppData, E_SYSTEM, "pAppData is null."); TryReturn(pAppData->__pFeatureList, E_SYSTEM, "__pFeatureList is null."); result r = E_SUCCESS; HashMap* pList = pAppData->__pFeatureList; std::unique_ptr< IMapEnumerator > pEnum(pList->GetMapEnumeratorN()); TryReturn(pEnum, false, "GetMapEnumeratorN() failed. [%s]", GetErrorMessage(GetLastResult())); while (pEnum->MoveNext() == E_SUCCESS) { String* pKey = static_cast< String* > (pEnum->GetKey()); TryReturn(pEnum, false, "GetKey() failed. [%s]", GetErrorMessage(GetLastResult())); String* pValue = static_cast< String* > (pEnum->GetValue()); TryReturn(pEnum, false, "GetValue() failed. [%s]", GetErrorMessage(GetLastResult())); String query; query.Format(1024, L"INSERT INTO AppFeature (ID, NAME, VALUE) VALUES ((SELECT AppInfo.UNIQUE_ID FROM AppInfo WHERE AppInfo.PACKAGE_NAME = '%ls'),?,?)", pAppData->__appId.GetPointer()); std::unique_ptr< DbStatement > pStmt(_PackageManagerImpl::CreateStatementN(db, query)); TryReturn(pStmt, false, "CreateStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); if (!(pKey->IsEmpty())) { r = pStmt->BindString(0, *pKey); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!(pValue->IsEmpty())) { r = pStmt->BindString(1, *pValue); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } std::unique_ptr< DbEnumerator > pEnum(_PackageManagerImpl::ExecuteStatementN(db, pStmt.get())); TryReturn(!IsFailed(GetLastResult()), false, "ExecuteStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); } return true; } bool DatabaseManager::RegisterDataControlList(AppData* pAppData, Database& db) const { TryReturn(pAppData, E_SYSTEM, "pAppData is null."); TryReturn(pAppData->__pDataControlList, E_SYSTEM, "__pDataControlList is null."); result r = E_SUCCESS; IListT* pDataControlList = pAppData->__pDataControlList; TryReturn(pDataControlList, false, "pDataControlList is null."); for (int i = 0; i < pDataControlList->GetCount(); i++) { DataControlInfo* pDataControlInfo = null; pDataControlList->GetAt(i, pDataControlInfo); TryReturn(pDataControlInfo, false, "pDataControlInfo is null."); String providerId = pDataControlInfo->__providerId; IListT* pTypeList = pDataControlInfo->__pControlTypeList; TryReturn(pTypeList, false, "pTypeList is null."); for (int j = 0; j < pTypeList->GetCount(); j++) { DataControlType* pDataControlType = null; pTypeList->GetAt(j, pDataControlType); TryReturn(pDataControlType, false, "pDataControlType is null."); String access = pDataControlType->__access; String type = pDataControlType->__type; String query; query.Format(1024, L"INSERT INTO DataControl (ID, PROVIDER_ID, TYPE, ACCESS) VALUES ((SELECT AppInfo.UNIQUE_ID FROM AppInfo WHERE AppInfo.PACKAGE_NAME = '%ls'),?,?,?)", pAppData->__appId.GetPointer()); std::unique_ptr< DbStatement > pStmt(_PackageManagerImpl::CreateStatementN(db, query)); TryReturn(pStmt, false, "CreateStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); if (!providerId.IsEmpty()) { r = pStmt->BindString(0, providerId); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!type.IsEmpty()) { r = pStmt->BindString(1, type); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } if (!access.IsEmpty()) { r = pStmt->BindString(2, access); TryReturn(r == E_SUCCESS, false, "BindString() failed. [%s]", GetErrorMessage(r)); } std::unique_ptr< DbEnumerator > pEnum(_PackageManagerImpl::ExecuteStatementN(db, pStmt.get())); TryReturn(!IsFailed(GetLastResult()), false, "ExecuteStatementN() failed. [%s]", GetErrorMessage(GetLastResult())); } } return true; } bool DatabaseManager::UnregisterPackageInfo(InstallationContext* pContext) const { Database db; String query; PackageId packageId = pContext->__packageId; result r = db.Construct(L"/opt/usr/dbspace/.app-package.db", "r+"); TryReturn(r == E_SUCCESS, false, "db.Construct failed. [%s]", GetErrorMessage(r)); // DataControl query.Format(1024, L"DELETE FROM DataControl WHERE DataControl.ID IN " "(SELECT AppInfo.UNIQUE_ID FROM PkgInfo, AppInfo " "WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and PkgInfo.PKG_ID = '%ls')", packageId.GetPointer()); r = db.ExecuteSql(query, true); if (r != E_SUCCESS) { AppLog("ExecuteSql() failed. [%ls][%s]", query.GetPointer(), GetErrorMessage(r)); } query.Clear(); // LaunchCondition query.Format(1024, L"DELETE FROM LaunchCondition WHERE LaunchCondition.ID IN " "(SELECT AppInfo.UNIQUE_ID FROM PkgInfo, AppInfo " "WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and PkgInfo.PKG_ID = '%ls')", packageId.GetPointer()); r = db.ExecuteSql(query, true); if (r != E_SUCCESS) { AppLog("ExecuteSql() failed. [%ls][%s]", query.GetPointer(), GetErrorMessage(r)); } query.Clear(); // Notification query.Format(1024, L"DELETE FROM Notification WHERE Notification.ID IN " "(SELECT AppInfo.UNIQUE_ID FROM PkgInfo, AppInfo " "WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and PkgInfo.PKG_ID = '%ls')", packageId.GetPointer()); r = db.ExecuteSql(query, true); if (r != E_SUCCESS) { AppLog("ExecuteSql() failed. [%ls][%s]", query.GetPointer(), GetErrorMessage(r)); } query.Clear(); // AppFeature query.Format(1024, L"DELETE FROM AppFeature WHERE AppFeature.ID IN " "(SELECT AppInfo.UNIQUE_ID FROM PkgInfo, AppInfo " "WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and PkgInfo.PKG_ID = '%ls')", packageId.GetPointer()); r = db.ExecuteSql(query, true); if (r != E_SUCCESS) { AppLog("ExecuteSql() failed. [%ls][%s]", query.GetPointer(), GetErrorMessage(r)); } query.Clear(); // AppInfo query.Format(1024, L"DELETE FROM AppInfo WHERE AppInfo.ID IN " "(SELECT PkgInfo.UNIQUE_ID FROM PkgInfo, AppInfo " "WHERE PkgInfo.UNIQUE_ID = AppInfo.ID and PkgInfo.PKG_ID = '%ls')", packageId.GetPointer()); r = db.ExecuteSql(query, true); if (r != E_SUCCESS) { AppLog("ExecuteSql() failed. [%ls][%s]", query.GetPointer(), GetErrorMessage(r)); } query.Clear(); // PkgPrivileges query.Format(1024, L"DELETE FROM PkgPrivileges WHERE PkgPrivileges.ID IN " "(SELECT PkgInfo.UNIQUE_ID FROM PkgInfo, PkgPrivileges " "WHERE PkgInfo.UNIQUE_ID = PkgPrivileges.ID and PkgInfo.PKG_ID = '%ls')", packageId.GetPointer()); r = db.ExecuteSql(query, true); if (r != E_SUCCESS) { AppLog("ExecuteSql() failed. [%ls][%s]", query.GetPointer(), GetErrorMessage(r)); } query.Clear(); // PkgInfo query.Format(1024, L"DELETE FROM PkgInfo WHERE PKG_ID = '%ls'", packageId.GetPointer()); r = db.ExecuteSql(query, true); if (r != E_SUCCESS) { AppLog("ExecuteSql() failed. [%ls][%s]", query.GetPointer(), GetErrorMessage(r)); } query.Clear(); return true; } bool DatabaseManager::CreatePackageTables(void) const { if (File::IsFileExist(PACKAGE_DATABASE_FILE_NAME) == true) { return true; } result r = E_SUCCESS; Database db; String createQuery; r = db.Construct(PACKAGE_DATABASE_FILE_NAME, true); TryReturn(r == E_SUCCESS, false, "db.Construct is failed. [%s]", GetErrorMessage(r)); // PkgInfo createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS PkgInfo" "( UNIQUE_ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," "PKG_ID TEXT," "PKG_SECRET TEXT," "PKG_VERSION TEXT," "PKG_TYPE TEXT," "PKG_MIMETYPE TEXT," "PKG_APIVERSION TEXT," "PKG_NAME TEXT," "PKG_VENDOR TEXT," "PKG_DESCRIPTION TEXT," "PKG_URL TEXT," "PKG_CID TEXT," "PKG_READONLY_SIZE INTEGER," "PKG_DATA_SIZE INTEGER," "PKG_PARENT_ID TEXT," "PKG_ATTRIBUTE INTEGER," "PKG_ROOTPATH TEXT," "PKG_STORAGE_TYPE INTEGER," "PKG_INSTALLATION_DATE TEXT," "PKG_STATE INTEGER," "PKG_INITIATOR INTEGER )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // PkgPrivileges createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS PkgPrivileges" "( ID INTEGER," "PRIVILEGES TEXT," "HMAC_PPRIVILEGES TEXT," "CERTIFICATE_TYPE INTEGER," "STR_PRIVILEGES TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // PkgIntegrity createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS PkgIntegrity" "( ID INTEGER," "HMAC_APPID TEXT," "HMAC_APPSECRET TEXT," "HMAC_HTB TEXT," "SLOT_NUM INTEGER )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // AppInfo createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppInfo" "( UNIQUE_ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," "ID INTEGER," "APP_NAME TEXT," "APP_TYPE TEXT," "APP_DEFAULT TEXT," "APP_MAINMENU_ICON TEXT," "APP_SETTING_ICON TEXT," "APP_TICKER_ICON TEXT," "APP_QUICKPANEL_ICON TEXT," "APP_LAUNCHIMAGE_ICON TEXT," "APP_FEATURE INTEGER," "PACKAGE_NAME TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // Notification createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS Notification" "( ID INTEGER," "NAME TEXT," "VALUE TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // AppFeature createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppFeature" "( ID INTEGER," "NAME TEXT," "VALUE TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // LaunchCondition createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS LaunchCondition" "( ID INTEGER," "NAME TEXT," "VALUE TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // DataControl createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS DataControl" "( ID INTEGER," "PROVIDER_ID TEXT," "TYPE TEXT," "ACCESS TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // Capability createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS Capability" "( ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," "OPERATION_ID TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // ResolutionUriScheme createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS ResolutionUriScheme" "( ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," "URI_SCHEME TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // ResolutionMimeType createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS ResolutionMimeType" "( ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," "MIME_TYPE TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // AppControl createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppControl" "( ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," "PROVIDER_ID TEXT," "CATEGORY TEXT )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); // AppInfoLookup createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppInfoLookup" "( AppInfoID INTEGER," "CapabilityID INTEGER," "ResolutionUriSchemeID INTEGER," "ResolutionMimeTypeID INTEGER," "AppControlID INTEGER )"); r = db.ExecuteSql(createQuery, true); TryReturn(r == E_SUCCESS, false, "db.ExecuteSql is failed. [%s]", GetErrorMessage(r)); createQuery.Clear(); String label("app-package::db"); String dbPath("/opt/usr/dbspace/.app-package.db"); String dbJournalPath("/opt/usr/dbspace/.app-package.db-journal"); SmackManager smackManager; smackManager.AddLabelDir(label, dbPath); smackManager.AddLabelDir(label, dbJournalPath); return r; }