1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stddef.h>
17 #include <stdint.h>
18 
19 #include "sqlite3sym.h"
20 
SqliteOpen(const char * fileName,void ** ppDb)21 int SqliteOpen(const char *fileName, void **ppDb)
22 {
23     return sqlite3_open(fileName, (sqlite3 **)ppDb);
24 }
25 
SqliteCloseV2(void * db)26 int SqliteCloseV2(void *db)
27 {
28     return sqlite3_close_v2((sqlite3 *)db);
29 }
30 
SqliteExec(void * db,const char * zSql,char ** pzErrMsg)31 int SqliteExec(void *db, const char *zSql, char **pzErrMsg)
32 {
33     return sqlite3_exec((sqlite3 *)db, zSql, NULL, NULL, pzErrMsg);
34 }
35 
SqliteFinalize(void * pStmt)36 int SqliteFinalize(void *pStmt)
37 {
38     return sqlite3_finalize((sqlite3_stmt *)pStmt);
39 }
40 
SqliteFree(void * p)41 void SqliteFree(void *p)
42 {
43     sqlite3_free(p);
44 }
45 
SqliteChanges(void * db)46 int SqliteChanges(void *db)
47 {
48     return sqlite3_changes((sqlite3 *)db);
49 }
50 
SqlitePrepareV2(void * db,const char * zSql,void ** ppStmt,const char ** pzTail)51 int SqlitePrepareV2(void *db, const char *zSql, void **ppStmt, const char **pzTail)
52 {
53     return sqlite3_prepare_v2((sqlite3 *)db, zSql, -1, (sqlite3_stmt **)ppStmt, pzTail);
54 }
55 
SqliteBindBlob(void * pStmt,int index,const void * zData,int nData,void (* xDel)(void *))56 int SqliteBindBlob(void *pStmt, int index, const void *zData, int nData, void(*xDel)(void*))
57 {
58     return sqlite3_bind_blob((sqlite3_stmt *)pStmt, index, zData, nData, xDel);
59 }
60 
SqliteBindInt64(void * pStmt,int index,int64_t iValue)61 int SqliteBindInt64(void *pStmt, int index, int64_t iValue)
62 {
63     return sqlite3_bind_int64((sqlite3_stmt *)pStmt, index, iValue);
64 }
65 
SqliteErrMsg(void * db)66 const char *SqliteErrMsg(void *db)
67 {
68     return sqlite3_errmsg((sqlite3 *)db);
69 }
70 
SqliteStep(void * pStmt)71 int SqliteStep(void *pStmt)
72 {
73     return sqlite3_step((sqlite3_stmt *)pStmt);
74 }
75 
SqliteColumnName(void * pStmt,int col)76 const char *SqliteColumnName(void *pStmt, int col)
77 {
78     return sqlite3_column_name((sqlite3_stmt *)pStmt, col);
79 }
80 
SqliteDataCount(void * pStmt)81 int SqliteDataCount(void *pStmt)
82 {
83     return sqlite3_data_count((sqlite3_stmt *)pStmt);
84 }
85 
SqliteColumnBlob(void * pStmt,int col)86 const void *SqliteColumnBlob(void *pStmt, int col)
87 {
88     return sqlite3_column_blob((sqlite3_stmt *)pStmt, col);
89 }
90 
SqliteColumnInt(void * pStmt,int col)91 int SqliteColumnInt(void *pStmt, int col)
92 {
93     return sqlite3_column_int((sqlite3_stmt *)pStmt, col);
94 }
95 
SqliteColumnInt64(void * pStmt,int col)96 int64_t SqliteColumnInt64(void *pStmt, int col)
97 {
98     return sqlite3_column_int64((sqlite3_stmt *)pStmt, col);
99 }
100 
SqliteColumnBytes(void * pStmt,int col)101 int SqliteColumnBytes(void *pStmt, int col)
102 {
103     return sqlite3_column_bytes((sqlite3_stmt *)pStmt, col);
104 }
105 
SqliteColumnType(void * pStmt,int col)106 int SqliteColumnType(void *pStmt, int col)
107 {
108     return sqlite3_column_type((sqlite3_stmt *)pStmt, col);
109 }
110 
SqliteReset(void * pStmt)111 int SqliteReset(void *pStmt)
112 {
113     return sqlite3_reset((sqlite3_stmt *)pStmt);
114 }
115 
SqliteKey(void * db,const void * pKey,int nKey)116 int SqliteKey(void *db, const void *pKey, int nKey)
117 {
118     return sqlite3_key((sqlite3 *)db, pKey, nKey);
119 }