tizen 2.4 release
[framework/context/context-common.git] / src / db_mgr.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <types_internal.h>
18 #include <json.h>
19 #include <db_listener_iface.h>
20 #include <db_mgr.h>
21 #include <db_mgr_iface.h>
22
23 static ctx::db_manager_iface *_instance = NULL;
24
25 void ctx::db_manager::set_instance(ctx::db_manager_iface* mgr)
26 {
27         _instance = mgr;
28 }
29
30 bool ctx::db_manager::create_table(unsigned int query_id, const char* table_name, const char* columns, const char* option, db_listener_iface* listener)
31 {
32         IF_FAIL_RETURN_TAG(_instance, false, _E, "Not initialized");
33         return _instance->create_table(query_id, table_name, columns, option, listener);
34 }
35
36 bool ctx::db_manager::insert(unsigned int query_id, const char* table_name, json& record, db_listener_iface* listener)
37 {
38         IF_FAIL_RETURN_TAG(_instance, false, _E, "Not initialized");
39         return _instance->insert(query_id, table_name, record, listener);
40 }
41
42 bool ctx::db_manager::execute(unsigned int query_id, const char* query, db_listener_iface* listener)
43 {
44         IF_FAIL_RETURN_TAG(_instance, false, _E, "Not initialized");
45         return _instance->execute(query_id, query, listener);
46 }
47
48 bool ctx::db_manager::insert_sync(const char* table_name, json& record, int64_t* row_id)
49 {
50         IF_FAIL_RETURN_TAG(_instance, false, _E, "Not initialized");
51         return _instance->insert_sync(table_name, record, row_id);
52 }
53
54 bool ctx::db_manager::execute_sync(const char* query, std::vector<json>* records)
55 {
56         IF_FAIL_RETURN_TAG(_instance, false, _E, "Not initialized");
57         return _instance->execute_sync(query, records);
58 }