#define VAL_ALERTING VAL_CONNECTING
#define VAL_INCOMING VAL_CONNECTING
-
#define COLUMN_NAME_DELIMITER ","
+#define APPHISTORY_SQL_LEN_MAX 256
+#define APPHISTORY_SNPRINTF(dest, size, format, arg...)\
+ do {\
+ snprintf(dest, size-1, format, ##arg);\
+ } while (0)
+
#endif
bool ctx::AppInstallMonitor::__appInfoCb(package_info_app_component_type_e compType, const char *appId, void *userData)
{
Database* database = DatabaseManager::getInstance();
+ int count = 1;
if (__lastEventType == PACKAGE_MANAGER_EVENT_TYPE_INSTALL) {
- std::stringstream query;
- query << "INSERT INTO " APP_TABLE_REMOVABLE_APP " (" KEY_APP_ID ") VALUES ('" << appId << "')";
- database->execute(query.str(), NULL);
+ apphistory_stmt hstmt = NULL;
+ char query[APPHISTORY_SQL_LEN_MAX] = {0, };
+
+ APPHISTORY_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AppId) VALUES " "(?) ", APP_TABLE_REMOVABLE_APP);
+
+ hstmt = database->prepare_query(query);
+ database->query_bind_text(hstmt, count, appId);
+ database->execute(hstmt);
+
} else if (__lastEventType == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) {
- database->execute(__createDeletionQuery(APP_TABLE_REMOVABLE_APP, appId), NULL);
- database->execute(__createDeletionQuery(APP_TABLE_USAGE_LOG, appId), NULL);
+ database->execute(__createDeletionQuery(APP_TABLE_REMOVABLE_APP, appId));
+ database->execute(__createDeletionQuery(APP_TABLE_USAGE_LOG, appId));
}
return true;
}
-std::string ctx::AppInstallMonitor::__createDeletionQuery(const char* tableName, const char* appId)
+apphistory_stmt ctx::AppInstallMonitor::__createDeletionQuery(const char* tableName, const char* appId)
{
- std::stringstream query;
- query << "DELETE FROM " << tableName;
- query << " WHERE " KEY_APP_ID " = '" << appId << "'";
- return query.str();
+ Database *database = DatabaseManager::getInstance();
+ int count = 1;
+
+ apphistory_stmt hstmt = NULL;
+ char query[APPHISTORY_SQL_LEN_MAX] = {0, };
+
+ APPHISTORY_SNPRINTF(query, sizeof(query), "DELETE FROM %s(AppId) WHERE KEY_APP_ID = ? ", tableName);
+
+ hstmt = database->prepare_query(query);
+ database->query_bind_text(hstmt, count, appId);
+ return hstmt;
}
+
#include <string>
#include <package_manager.h>
+#include <sqlite3.h>
+
+typedef sqlite3_stmt* apphistory_stmt;
namespace ctx {
bool __startMonitoring();
void __stopMonitoring();
- static std::string __createDeletionQuery(const char* tableName, const char* appId);
- static void __packageEventCb(const char *type, const char *package, package_manager_event_type_e eventType, package_manager_event_state_e eventState, int progress, package_manager_error_e error, void *userData);
+ static apphistory_stmt __createDeletionQuery(const char* tableName, const char* appId);
+ static void __packageEventCb(const char *type, const char *package, package_manager_event_type_e eventType,
+ package_manager_event_state_e eventState, int progress, package_manager_error_e error, void *userData);
static bool __appInfoCb(package_info_app_component_type_e compType, const char *appId, void *userData);
public: