2 * Copyright 2012 Samsung Electronics Co., Ltd
\r
4 * Licensed under the Flora License, Version 1.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.tizenopensource.org/license
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using namespace std;
\r
19 #include "browser-user-agent-db.h"
\r
21 sqlite3* Browser_User_Agent_DB::m_db_descriptor = NULL;
\r
23 Browser_User_Agent_DB::Browser_User_Agent_DB(void)
\r
25 BROWSER_LOGD("[%s]", __func__);
\r
28 Browser_User_Agent_DB::~Browser_User_Agent_DB(void)
\r
30 BROWSER_LOGD("[%s]", __func__);
\r
33 Eina_Bool Browser_User_Agent_DB::_open_db(void)
\r
35 BROWSER_LOGD("[%s]", __func__);
\r
36 int error = db_util_open(BROWSER_USER_AGENT_DB_PATH, &m_db_descriptor, DB_UTIL_REGISTER_HOOK_METHOD);
\r
37 if (error != SQLITE_OK) {
\r
38 db_util_close(m_db_descriptor);
\r
39 m_db_descriptor = NULL;
\r
46 Eina_Bool Browser_User_Agent_DB::_close_db(void)
\r
48 BROWSER_LOGD("[%s]", __func__);
\r
49 if (m_db_descriptor)
\r
51 int error = db_util_close(m_db_descriptor);
\r
52 if (error != SQLITE_OK) {
\r
53 BROWSER_LOGE("db_util_close error");
\r
54 m_db_descriptor = NULL;
\r
57 m_db_descriptor = NULL;
\r
63 Eina_Bool Browser_User_Agent_DB::get_user_agent(const char *title, char *&user_agent)
\r
65 BROWSER_LOGD("[%s]", __func__);
\r
66 if (_open_db() == EINA_FALSE)
\r
69 sqlite3_stmt *sqlite3_stmt = NULL;
\r
70 int error = sqlite3_prepare_v2(m_db_descriptor, "select value from user_agents where name=?",
\r
71 -1, &sqlite3_stmt, NULL);
\r
72 if (error != SQLITE_OK) {
\r
73 BROWSER_LOGD("SQL error=%d", error);
\r
74 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
75 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
80 if (sqlite3_bind_text(sqlite3_stmt, 1, title, -1, NULL) != SQLITE_OK)
\r
81 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
83 error = sqlite3_step(sqlite3_stmt);
\r
86 if (error == SQLITE_ROW)
\r
87 value = reinterpret_cast<const char*>(sqlite3_column_text(sqlite3_stmt, 0));
\r
89 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
90 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
93 user_agent = strdup(value.c_str());
\r
99 return (error == SQLITE_DONE || error == SQLITE_ROW);
\r