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