1 /* 2 * Copyright (c) 2021 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 #ifndef NATIVE_RDB_SHARE_BLOCK_H 17 #define NATIVE_RDB_SHARE_BLOCK_H 18 19 #include "shared_block.h" 20 #include <sqlite3sym.h> 21 #include <string> 22 23 namespace OHOS { 24 namespace NativeRdb { 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 enum FillOneRowResult { 29 FILL_ONE_ROW_SUCESS, 30 SHARED_BLOCK_IS_FULL, 31 FILL_ONE_ROW_FAIL, 32 }; 33 34 struct SharedBlockInfo { 35 AppDataFwk::SharedBlock *sharedBlock = nullptr; 36 37 int startPos; 38 int addedRows; 39 int requiredPos; 40 int totalRows; 41 int isCountAllRows; 42 int columnNum; 43 bool isFull; 44 bool hasException; 45 SharedBlockInfoSharedBlockInfo46 SharedBlockInfo(AppDataFwk::SharedBlock* sharedBlock) : sharedBlock(sharedBlock) 47 { 48 startPos = 0; 49 addedRows = 0; 50 requiredPos = 0; 51 totalRows = 0; 52 isCountAllRows = 0; 53 columnNum = 0; 54 isFull = false; 55 hasException = false; 56 } 57 }; 58 59 int DefAddRow(void *pCtx, int addedRows); 60 int DefReset(void *pCtx, int startPos); 61 int DefFinish(void *pCtx, int addedRows, int totalRows); 62 int DefPutString(void *pCtx, int addedRows, int column, const char *text, int size); 63 int DefPutLong(void *pCtx, int addedRows, int column, sqlite3_int64 value); 64 int DefPutDouble(void *pCtx, int addedRows, int column, double value); 65 int DefPutBlob(void *pCtx, int addedRows, int column, const void *blob, int len); 66 int DefPutNull(void *pCtx, int addedRows, int column); 67 int DefPutOther(void *pCtx, int addedRows, int column); 68 int SeriAddRow(void *pCtx, int addedRows); 69 int SeriReset(void *pCtx, int startPos); 70 int SeriFinish(void *pCtx, int addedRows, int totalRows); 71 int SeriPutString(void *pCtx, int addedRows, int column, const char *text, int size); 72 int SeriPutLong(void *pCtx, int addedRows, int column, sqlite3_int64 value); 73 int SeriPutDouble(void *pCtx, int addedRows, int column, double value); 74 int SeriPutBlob(void *pCtx, int addedRows, int column, const void *blob, int len); 75 int SeriPutNull(void *pCtx, int addedRows, int column); 76 int SeriPutOther(void *pCtx, int addedRows, int column); 77 int ClearSharedBlock(AppDataFwk::SharedBlock *sharedBlock); 78 int SharedBlockSetColumnNum(AppDataFwk::SharedBlock *sharedBlock, int columnNum); 79 int FillSharedBlockOpt(SharedBlockInfo *info, sqlite3_stmt *stmt); 80 FillOneRowResult FillOneRowOfString(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 81 int addedRows, int pos); 82 FillOneRowResult FillOneRowOfLong(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 83 int addedRows, int pos); 84 FillOneRowResult FillOneRowOfFloat(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 85 int addedRows, int pos); 86 FillOneRowResult FillOneRowOfBlob(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 87 int addedRows, int pos); 88 FillOneRowResult FillOneRowOfNull(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 89 int addedRows, int pos); 90 FillOneRowResult FillOneRow(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int numColumns, 91 int startPos, int addedRows); 92 void FillRow(SharedBlockInfo *info, sqlite3_stmt *stmt); 93 void DefFillRow(SharedBlockInfo *info, sqlite3_stmt *stmt); 94 int FillSharedBlock(SharedBlockInfo *info, sqlite3_stmt *stmt); 95 bool ResetStatement(SharedBlockInfo *info, sqlite3_stmt *stmt); 96 #ifdef __cplusplus 97 } 98 #endif 99 } // namespace NativeRdb 100 } // namespace OHOS 101 102 #endif 103