From: 최종헌/Common Platform Lab(SR)/Engineer/삼성전자 Date: Fri, 7 Aug 2020 07:58:43 +0000 (+0900) Subject: Change to execute SQL commands simply (#265) X-Git-Tag: accepted/tizen/unified/20200810.123138^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=049f808219555800e1f378054143ce52a45d4e6d;p=platform%2Fcore%2Fdotnet%2Flauncher.git Change to execute SQL commands simply (#265) Change-Id: I34f793661b41700a9ebf2cb1b75334434a5cdc3f --- diff --git a/NativeLauncher/inc/db_manager.h b/NativeLauncher/inc/db_manager.h index 0622e57..5683ca2 100644 --- a/NativeLauncher/inc/db_manager.h +++ b/NativeLauncher/inc/db_manager.h @@ -36,9 +36,9 @@ sqlite3* dbCreate(std::string path, std::string query); sqlite3* dbOpen(std::string path); void dbClose(sqlite3 *tac_db); void dbRollback(sqlite3 *tac_db); -bool dbUpdate(sqlite3 *tac_db, std::string path, std::string query); -bool dbInsert(sqlite3 *tac_db, std::string path, std::string query); -std::vector dbSelect(sqlite3 *tac_db, std::string path, std::string query); -bool dbDelete(sqlite3 *tac_db, std::string path, std::string query); +bool dbUpdate(sqlite3 *tac_db, std::string query); +bool dbInsert(sqlite3 *tac_db, std::string query); +bool dbDelete(sqlite3 *tac_db, std::string query); +std::vector dbSelect(sqlite3 *tac_db, std::string query); #endif /* __DB_MANAGER_H__ */ diff --git a/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc b/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc index c0bf094..44d70a7 100644 --- a/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc +++ b/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc @@ -162,7 +162,7 @@ static void copyNCreateTlcSymlink(const char* pkgId, std::vector Li bf::create_symlink(concatPath(tlcDir, fileSha), library); char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str()); - if (!dbInsert(tlc_db, TLC_APP_LIST_DB, sql)) { + if (!dbInsert(tlc_db, sql)) { _ERR("Sqlite insert error"); sqlite3_free(sql); copyFile(concatPath(tlcDir, fileSha), library); @@ -234,6 +234,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app return 0; } } + sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL); if (tacDB.empty()) { _INFO("Not exist data for TAC in %s", pkgId); @@ -270,7 +271,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app char *sql = sqlite3_mprintf( "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str()); - dbInsert(tac_db, TAC_APP_LIST_DB, sql); + dbInsert(tac_db, sql); sqlite3_free(sql); } else { _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str()); @@ -284,7 +285,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app char *sql = sqlite3_mprintf( "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str()); - dbInsert(tac_db, TAC_APP_LIST_DB, sql); + dbInsert(tac_db, sql); sqlite3_free(sql); } else { _INFO("Different nuget : %s", np.c_str()); @@ -321,6 +322,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app return 0; } } + sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL); copyNCreateTlcSymlink(pkgId, getLibrariesInfo(rootPath), tlcDir); @@ -443,15 +445,16 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app return 0; } } + sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL); char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId); - updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql); + updateTac = dbSelect(tac_db, sql); sqlite3_free(sql); bool skipTLC = false; if (tacDB.empty()) { sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId); - dbDelete(tac_db, TAC_APP_LIST_DB, sql); + dbDelete(tac_db, sql); sqlite3_free(sql); if (updateTacDB(tac_db) < 0) { return -1; @@ -500,13 +503,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app sql = sqlite3_mprintf( "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;", tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str()); - dbUpdate(tac_db, TAC_APP_LIST_DB, sql); + dbUpdate(tac_db, sql); sqlite3_free(sql); } else if (count == 0) { sql = sqlite3_mprintf( "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str()); - dbInsert(tac_db, TAC_APP_LIST_DB, sql); + dbInsert(tac_db, sql); sqlite3_free(sql); } } else { @@ -532,13 +535,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app sql = sqlite3_mprintf( "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;", tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str()); - dbUpdate(tac_db, TAC_APP_LIST_DB, sql); + dbUpdate(tac_db, sql); sqlite3_free(sql); } else if (count == 0) { sql = sqlite3_mprintf( "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str()); - dbInsert(tac_db, TAC_APP_LIST_DB, sql); + dbInsert(tac_db, sql); sqlite3_free(sql); } } else { @@ -565,7 +568,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app } if (!isExits) { char *sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q AND NUGET = %Q;", pkgId, unp.c_str()); - dbDelete(tac_db, TAC_APP_LIST_DB, sql); + dbDelete(tac_db, sql); sqlite3_free(sql); } } @@ -594,13 +597,14 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app return 0; } } + sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL); sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId); - std::vector updateTlc = dbSelect(tlc_db, TLC_APP_LIST_DB, sql); + std::vector updateTlc = dbSelect(tlc_db, sql); sqlite3_free(sql); sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId); - dbDelete(tlc_db, TLC_APP_LIST_DB, sql); + dbDelete(tlc_db, sql); sqlite3_free(sql); std::vector librariesInfo = getLibrariesInfo(rootPath); @@ -641,13 +645,14 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *a return 0; } } + sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL); char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId); - updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql); + updateTac = dbSelect(tac_db, sql); sqlite3_free(sql); sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId); - dbDelete(tac_db, TAC_APP_LIST_DB, sql); + dbDelete(tac_db, sql); sqlite3_free(sql); if (updateTacDB(tac_db) < 0) { @@ -668,13 +673,14 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *a return 0; } } + sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL); sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId); - std::vector updateTlc = dbSelect(tlc_db, TLC_APP_LIST_DB, sql); + std::vector updateTlc = dbSelect(tlc_db, sql); sqlite3_free(sql); sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId); - dbDelete(tlc_db, TLC_APP_LIST_DB, sql); + dbDelete(tlc_db, sql); sqlite3_free(sql); updateTlcDB(tlc_db, updateTlc, concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR)); diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 2454ab8..594fe3a 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -733,9 +733,10 @@ static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData) fprintf(stderr, "Sqlite open error\n"); return -1; } + sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL); char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId); - std::vector nugets = dbSelect(tac_db, TAC_APP_LIST_DB, sql); + std::vector nugets = dbSelect(tac_db, sql); sqlite3_free(sql); if (tac_db) { diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index 2714b26..0dc053f 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -127,7 +127,7 @@ static int restoreTACDBCb(pkgmgrinfo_appinfo_h handle, void *userData) char *sql = sqlite3_mprintf( "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \ "VALUES (%Q, %Q, %Q, %Q);", pkgId, nuget.c_str(), name.c_str(), version.c_str()); - dbInsert(tac_db, TAC_APP_LIST_RESTORE_DB, sql); + dbInsert(tac_db, sql); restore_nuget.push_back(concatPath(__DOTNET_DIR, nuget)); sqlite3_free(sql); } @@ -154,6 +154,7 @@ tac_error_e restoreTACDB() fprintf(stderr, "Sqlite create error\n"); return TAC_ERROR_UNKNOWN; } + sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL); pkgmgrinfo_appinfo_metadata_filter_h handle; int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle); @@ -496,7 +497,7 @@ static int restoreTLCDBCb(pkgmgrinfo_appinfo_h handle, void *userData) if (bf::exists(library)) { std::string fileSha = library.substr(library.rfind('/') + 1) + ".." + librarySha.substr(librarySha.find(':') + 1); char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str()); - dbInsert(tlc_db, TLC_APP_LIST_RESTORE_DB, sql); + dbInsert(tlc_db, sql); restore_library.push_back(fileSha); sqlite3_free(sql); } @@ -522,6 +523,7 @@ tac_error_e restoreTLCDB() fprintf(stderr, "Sqlite create error\n"); return TAC_ERROR_UNKNOWN; } + sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL); pkgmgrinfo_appinfo_metadata_filter_h handle; int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle); diff --git a/NativeLauncher/util/db_manager.cc b/NativeLauncher/util/db_manager.cc index 0e05814..67adeed 100644 --- a/NativeLauncher/util/db_manager.cc +++ b/NativeLauncher/util/db_manager.cc @@ -116,84 +116,45 @@ void dbRollback(sqlite3 *sqlite) } } -bool dbUpdate(sqlite3 *sqlite, std::string path, std::string query) +static bool dbExec(sqlite3 *sqlite, std::string query) { - sqlite3_stmt *stmt = NULL; - int ret = sqlite3_exec(sqlite, "BEGIN;", NULL, NULL, NULL); - ret = sqlite3_prepare(sqlite, query.c_str(), query.size(), &stmt, NULL); + int ret = sqlite3_exec(sqlite, query.c_str(), NULL, NULL, NULL); if (ret != SQLITE_OK) { _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(sqlite)); - dbClose(sqlite); return false; } - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE && ret != SQLITE_ROW && ret != SQLITE_OK) { - _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(sqlite)); - dbFinalize(stmt); - dbClose(sqlite); - return false; - } - dbFinalize(stmt); return true; } -bool dbInsert(sqlite3 *sqlite, std::string path, std::string query) +bool dbUpdate(sqlite3 *sqlite, std::string query) { - sqlite3_stmt *stmt = NULL; - int ret = sqlite3_exec(sqlite, "BEGIN;", NULL, NULL, NULL); - ret = sqlite3_prepare(sqlite, query.c_str(), query.size(), &stmt, NULL); - if (ret != SQLITE_OK) { - _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(sqlite)); - dbClose(sqlite); - return false; - } - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE && ret != SQLITE_ROW && ret != SQLITE_OK) { - _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(sqlite)); - dbFinalize(stmt); - dbClose(sqlite); - return false; - } - dbFinalize(stmt); - return true; + return dbExec(sqlite, query); +} + +bool dbInsert(sqlite3 *sqlite, std::string query) +{ + return dbExec(sqlite, query); } -std::vector dbSelect(sqlite3 *sqlite, std::string path, std::string query) +bool dbDelete(sqlite3 *sqlite, std::string query) { - std::vector updateDB; + return dbExec(sqlite, query); +} + +std::vector dbSelect(sqlite3 *sqlite, std::string query) +{ + std::vector selectData; sqlite3_stmt* stmt = NULL; const char* str = NULL; int ret = sqlite3_prepare_v2(sqlite, query.c_str(), query.size(), &stmt, NULL); if (ret != SQLITE_OK) { _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(sqlite)); - dbClose(sqlite); - return updateDB; + return selectData; } while (sqlite3_step(stmt) == SQLITE_ROW) { str = (const char *) sqlite3_column_text(stmt, 2); - updateDB.push_back((!str || !strlen(str)) ? NULL : strdup(str)); + selectData.push_back((!str || !strlen(str)) ? NULL : strdup(str)); } dbFinalize(stmt); - return updateDB; -} - -bool dbDelete(sqlite3 *sqlite, std::string path, std::string query) -{ - sqlite3_stmt *stmt = NULL; - int ret = sqlite3_exec(sqlite, "BEGIN;", NULL, NULL, NULL); - ret = sqlite3_prepare(sqlite, query.c_str(), query.size(), &stmt, NULL); - if (ret != SQLITE_OK) { - _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(sqlite)); - dbClose(sqlite); - return false; - } - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE && ret != SQLITE_ROW && ret != SQLITE_OK) { - _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(sqlite)); - dbFinalize(stmt); - dbClose(sqlite); - return false; - } - dbFinalize(stmt); - return true; + return selectData; }