[SVACE Issue Fixes]
[platform/core/pim/contacts-service.git] / server / db / ctsvc_db_sqlite.h
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __CTSVC_DB_SQLITE_H__
21 #define __CTSVC_DB_SQLITE_H__
22
23 #include <sqlite3.h>
24
25 #define CTS_SQL_MAX_LEN 2048 /* normal string length */
26 #define CTS_SQL_MIN_LEN 1024 /* short sql string length */
27
28 typedef sqlite3_stmt * cts_stmt;
29
30 int ctsvc_db_open(void);
31 int ctsvc_db_close(void);
32 int ctsvc_db_change();
33 int ctsvc_db_get_last_insert_id(void);
34 int ctsvc_db_get_next_id(const char *table);
35
36 int ctsvc_query_get_first_int_result(const char *query, int *result);
37 int ctsvc_query_exec(const char *query);
38 int ctsvc_query_prepare(char *query, cts_stmt *stmt);
39
40 int ctsvc_stmt_step(cts_stmt stmt);
41 void ctsvc_stmt_reset(cts_stmt stmt);
42 void ctsvc_stmt_finalize(cts_stmt stmt);
43
44 int ctsvc_stmt_get_first_int_result(cts_stmt stmt, int *result);
45
46
47 static inline double ctsvc_stmt_get_dbl(cts_stmt stmt, int pos)
48 {
49         return sqlite3_column_double(stmt, pos);
50 }
51 static inline int ctsvc_stmt_get_int(cts_stmt stmt, int pos)
52 {
53         return sqlite3_column_int(stmt, pos);
54 }
55 static inline char* ctsvc_stmt_get_text(cts_stmt stmt, int pos)
56 {
57         return (char *)sqlite3_column_text(stmt, pos);
58 }
59 static inline long long int ctsvc_stmt_get_int64(cts_stmt stmt, int pos)
60 {
61         return sqlite3_column_int64(stmt, pos);
62 }
63
64 static inline int ctsvc_stmt_bind_int(cts_stmt stmt, int pos, int num)
65 {
66         return sqlite3_bind_int(stmt, pos, num);
67 }
68 static inline int ctsvc_stmt_bind_text(cts_stmt stmt, int pos, const char *str)
69 {
70         return sqlite3_bind_text(stmt, pos, str, strlen(str), SQLITE_STATIC);
71 }
72 static inline int ctsvc_stmt_bind_copy_text(cts_stmt stmt, int pos,
73                 const char *str, int strlen)
74 {
75         return sqlite3_bind_text(stmt, pos, str, strlen, SQLITE_TRANSIENT);
76 }
77
78 int ctsvc_stmt_bind_copy_text(cts_stmt stmt, int pos, const char *str, int strlen);
79
80
81 #endif /* __CTSVC_DB_SQLITE_H__ */