#include <shortcut_db.h>
#include <vconf.h>
#include <vconf-keys.h>
+#include <tzplatform_config.h>
#include "shortcut_error.h"
+#define QUERY_CREATE_SHORTCUT_TABLE \
+ "PRAGMA journal_mode = PERSIST;" \
+ "CREATE TABLE IF NOT EXISTS shortcut_service (\n" \
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" \
+ " pkgid TEXT,\n" \
+ " appid TEXT,\n" \
+ " icon TEXT,\n" \
+ " name TEXT,\n" \
+ " extra_key TEXT,\n" \
+ " extra_data TEXT);\n" \
+ "CREATE TABLE IF NOT EXISTS shortcut_name (\n" \
+ " id INTEGER,\n" \
+ " pkgid TEXT,\n" \
+ " lang TEXT,\n" \
+ " name TEXT,\n" \
+ " icon TEXT);"
+
+EAPI int shortcut_db_init()
+{
+ int ret = SHORTCUT_ERROR_NONE;
+ int sql_ret;
+ sqlite3 *db = NULL;
+ char *errmsg = NULL;
+
+ sql_ret = sqlite3_open_v2(DB_PATH, &db,
+ SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+ if (sql_ret != SQLITE_OK) {
+ SHORTCUT_ERR("Failed to open db[%d]", sql_ret);
+ return SHORTCUT_ERROR_IO_ERROR;
+ }
+
+ sql_ret = sqlite3_exec(db, QUERY_CREATE_SHORTCUT_TABLE,
+ NULL, NULL, &errmsg);
+ if (sql_ret != SQLITE_OK) {
+ SHORTCUT_ERR("Failed to exec query [%d][%s]", sql_ret, errmsg);
+ ret = SHORTCUT_ERROR_IO_ERROR;
+ }
+
+ if (errmsg)
+ sqlite3_free(errmsg);
+ if (db)
+ sqlite3_close(db);
+
+ return ret;
+}
+
static sqlite3 *_open_db(void)
{
int ret;
mkdir %{TZ_SYS_DB}
fi
-if [ ! -f %{TZ_SYS_DB}/.shortcut_service.db ]
-then
- sqlite3 %{TZ_SYS_DB}/.shortcut_service.db 'PRAGMA journal_mode = PERSIST;
- CREATE TABLE shortcut_service (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- pkgid TEXT,
- appid TEXT,
- icon TEXT,
- name TEXT,
- extra_key TEXT,
- extra_data TEXT);
-
- CREATE TABLE shortcut_name (
- id INTEGER,
- pkgid TEXT,
- lang TEXT,
- name TEXT,
- icon TEXT);
- '
-fi
-
-chmod 644 %{TZ_SYS_DB}/.shortcut_service.db
-chmod 644 %{TZ_SYS_DB}/.shortcut_service.db-journal
-chsmack -a System %{TZ_SYS_DB}/.shortcut_service.db
-chsmack -a System %{TZ_SYS_DB}/.shortcut_service.db-journal
-chown app_fw:app_fw %{TZ_SYS_DB}/.shortcut_service.db
-chown app_fw:app_fw %{TZ_SYS_DB}/.shortcut_service.db-journal
-
%postun -n %{name} -p /sbin/ldconfig
%files -n libshortcut