2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
28 SqliteDB::SqliteDB(std::string dbPath)
39 bool SqliteDB::openDB()
43 ret = db_util_open(m_path.c_str(), &m_handle, DB_UTIL_REGISTER_HOOK_METHOD);
44 if (ret != SQLITE_OK) {
51 void SqliteDB::closeDB()
58 db_util_close(m_handle);
63 sqlite3_finalize(m_stmt);
64 db_util_close(m_handle);
69 bool SqliteDB::setCommand(std::string& query, const char* fmt, ...)
71 if (!m_handle || !fmt) {
76 sqlite3_prepare_v2(m_handle, query.c_str(), -1, &m_stmt, NULL);
78 if (ret != SQLITE_OK) {
82 // bind values to query
88 for (int i = 0; i < strlen(fmt); i++) {
91 intValue = va_arg(ap, int);
92 ret = sqlite3_bind_int(m_stmt, i + 1, intValue);
93 if (ret != SQLITE_OK) {
99 stringValue = va_arg(ap, char*);
100 ret = sqlite3_bind_text(m_stmt, i + 1, stringValue, -1, NULL);
101 if (ret != SQLITE_OK) {
115 bool SqliteDB::executeCommand()
118 sqlite3_step(m_stmt);
120 if (ret != SQLITE_ROW) {
127 const char* SqliteDB::getText(int col)
130 reinterpret_cast<const char*>(sqlite3_column_text(m_stmt, col));
135 int SqliteDB::getInt(int col)
137 return sqlite3_column_int(m_stmt, col);