4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #ifndef __CTSVC_DB_SQLITE_H__
21 #define __CTSVC_DB_SQLITE_H__
25 #define CTS_SQL_MAX_LEN 2048 /* normal string length */
26 #define CTS_SQL_MIN_LEN 1024 /* short sql string length */
28 typedef sqlite3_stmt * cts_stmt;
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);
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);
40 int ctsvc_stmt_step(cts_stmt stmt);
41 void ctsvc_stmt_reset(cts_stmt stmt);
42 void ctsvc_stmt_finalize(cts_stmt stmt);
44 int ctsvc_stmt_get_first_int_result(cts_stmt stmt, int *result);
47 static inline double ctsvc_stmt_get_dbl(cts_stmt stmt, int pos)
49 return sqlite3_column_double(stmt, pos);
51 static inline int ctsvc_stmt_get_int(cts_stmt stmt, int pos)
53 return sqlite3_column_int(stmt, pos);
55 static inline char* ctsvc_stmt_get_text(cts_stmt stmt, int pos)
57 return (char *)sqlite3_column_text(stmt, pos);
59 static inline long long int ctsvc_stmt_get_int64(cts_stmt stmt, int pos)
61 return sqlite3_column_int64(stmt, pos);
64 static inline int ctsvc_stmt_bind_int(cts_stmt stmt, int pos, int num)
66 return sqlite3_bind_int(stmt, pos, num);
68 static inline int ctsvc_stmt_bind_text(cts_stmt stmt, int pos, const char *str)
70 return sqlite3_bind_text(stmt, pos, str, strlen(str), SQLITE_STATIC);
72 static inline int ctsvc_stmt_bind_copy_text(cts_stmt stmt, int pos,
73 const char *str, int strlen)
75 return sqlite3_bind_text(stmt, pos, str, strlen, SQLITE_TRANSIENT);
78 int ctsvc_stmt_bind_copy_text(cts_stmt stmt, int pos, const char *str, int strlen);
81 #endif /* __CTSVC_DB_SQLITE_H__ */