2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef COMMON_DATABASE_HH_
18 #define COMMON_DATABASE_HH_
24 #include "common/exception.hh"
26 #define __PREPARE_V2(db, query, length, stmt) do { \
27 int ret = sqlite3_prepare_v2(db, query, length, &stmt, nullptr); \
28 if (ret != SQLITE_OK) { \
29 _E("sqlite3_prepare_v2() is failed. error(%s:%d)", \
30 sqlite3_errmsg(db), ret); \
36 #define __BIND_TEXT(db, stmt, i, text) do { \
37 int ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT); \
38 if (ret != SQLITE_OK) { \
39 _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)", \
40 i, sqlite3_errmsg(db), ret); \
45 #define __STEP(db, stmt) do { \
46 int ret = sqlite3_step(stmt); \
47 if (ret != SQLITE_DONE) { \
48 _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db), ret); \
57 Database(std::string path);
62 bool IntegrityCheck();
63 void BeginTransaction();
64 void EndTransaction();
67 std::string ColumnText(sqlite3_stmt* stmt, int index);
70 static int BusyHandler(void* data, int count);
74 sqlite3* db_ = nullptr;
79 #endif // COMMON_DATABASE_HH_