4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
28 #include "syspopup_db.h"
29 #include "simple_util.h"
31 #define SYSPOPUP_DB_PATH "/opt/dbspace/.syspopup.db"
32 #define QUERY_MAXLEN 4096
34 #define SP_INFO_TBL "syspopup_info"
35 #define SP_INFO_TBL_F_NAME "name"
37 static sqlite3 *db = NULL;
42 static int __init(void)
47 _D("Already initialized\n");
51 rc = sqlite3_open(SYSPOPUP_DB_PATH, &db);
52 if (rc != SQLITE_OK) {
53 _E("Can't open database: %s / %d / %d", sqlite3_errmsg(db),
54 rc, sqlite3_extended_errcode(db));
63 static int __fini(void)
72 syspopup_info_t *_syspopup_info_get(const char *popup_name)
75 char sqlbuf[256] = {0,};
76 sqlite3_stmt *stmt = NULL;
77 syspopup_info_t *pinfo = NULL;
79 if (popup_name == NULL) {
88 "SELECT name,prio,focus,timeout,term_act,endkey_act,pkgname FROM %s WHERE %s = ?;",
89 SP_INFO_TBL, SP_INFO_TBL_F_NAME);
91 rc = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
92 if (rc == SQLITE_OK) {
93 rc =sqlite3_bind_text(stmt, 1, popup_name, strlen(popup_name), SQLITE_STATIC);
95 _E("popup name bind error(%d) \n", rc);
96 sqlite3_finalize(stmt);
100 rc = sqlite3_step(stmt);
101 if (rc == SQLITE_ROW) {
102 pinfo = (syspopup_info_t *) malloc(sizeof(syspopup_info_t));
105 sqlite3_finalize(stmt);
108 pinfo->name = strdup((char *) sqlite3_column_text(stmt, 0));
109 pinfo->prio = sqlite3_column_int(stmt, 1);
110 pinfo->focus = sqlite3_column_int(stmt, 2);
111 pinfo->timeout = sqlite3_column_int(stmt, 3);
112 pinfo->term_act = sqlite3_column_int(stmt, 4);
113 pinfo->endkey_act = sqlite3_column_int(stmt, 5);
114 if (sqlite3_column_text(stmt, 6) != NULL)
115 pinfo->pkgname = strdup((char *) sqlite3_column_text(stmt, 6));
117 pinfo->pkgname = NULL;
119 sqlite3_finalize(stmt);
123 _E("error(%d) in prepare", rc);
131 void _syspopup_info_free(syspopup_info_t *pinfo)
136 free(pinfo->pkgname);