4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeonghoon Park <jh1979.park@samsung.com>, Youngjoo Park <yjoo93.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <notification_error.h>
31 #include <notification_debug.h>
32 #include <notification_db.h>
34 #define SDFTET "/opt/dbspace/.notification_noti.db"
36 sqlite3 *notification_db_open(const char *dbfile)
41 ret = db_util_open(dbfile, &db, 0);
42 if (ret != SQLITE_OK) {
43 NOTIFICATION_ERR("DB open error(%d), %s", ret, dbfile);
50 int notification_db_close(sqlite3 ** db)
54 if (db == NULL || *db == NULL) {
55 return NOTIFICATION_ERROR_INVALID_DATA;
58 ret = db_util_close(*db);
59 if (ret != SQLITE_OK) {
60 NOTIFICATION_ERR("DB close error(%d)", ret);
61 return NOTIFICATION_ERROR_FROM_DB;
66 return NOTIFICATION_ERROR_NONE;
69 int notification_db_exec(sqlite3 * db, const char *query)
75 return NOTIFICATION_ERROR_INVALID_DATA;
78 ret = sqlite3_exec(db, query, NULL, NULL, &err_msg);
79 if (ret != SQLITE_OK) {
80 NOTIFICATION_ERR("SQL error(%d) : %s", ret, err_msg);
81 sqlite3_free(err_msg);
82 return NOTIFICATION_ERROR_FROM_DB;
85 return NOTIFICATION_ERROR_NONE;
88 char *notification_db_column_text(sqlite3_stmt * stmt, int col)
90 const unsigned char *col_text = NULL;
92 col_text = sqlite3_column_text(stmt, col);
93 if (col_text == NULL || col_text[0] == '\0') {
97 return strdup((char *)col_text);
100 bundle *notification_db_column_bundle(sqlite3_stmt * stmt, int col)
102 const unsigned char *col_bundle = NULL;
104 col_bundle = sqlite3_column_text(stmt, col);
105 if (col_bundle == NULL || col_bundle[0] == '\0') {
109 return bundle_decode(col_bundle, strlen((char *)col_bundle));