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 SharedBlockInfoOHOS::NativeRdb::SharedBlockInfo46 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 SeriAddRow(void *pCtx, int addedRows); 60 int SeriReset(void *pCtx, int startPos); 61 int SeriFinish(void *pCtx, int addedRows, int totalRows); 62 int SeriPutString(void *pCtx, int addedRows, int column, const char *text, int size); 63 int SeriPutLong(void *pCtx, int addedRows, int column, sqlite3_int64 value); 64 int SeriPutDouble(void *pCtx, int addedRows, int column, double value); 65 int SeriPutBlob(void *pCtx, int addedRows, int column, const void *blob, int len); 66 int SeriPutNull(void *pCtx, int addedRows, int column); 67 int SeriPutOther(void *pCtx, int addedRows, int column); 68 int ClearSharedBlock(AppDataFwk::SharedBlock *sharedBlock); 69 int SharedBlockSetColumnNum(AppDataFwk::SharedBlock *sharedBlock, int columnNum); 70 int FillSharedBlockOpt(SharedBlockInfo *info, sqlite3_stmt *stmt); 71 FillOneRowResult FillOneRowOfString(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 72 int addedRows, int pos); 73 FillOneRowResult FillOneRowOfLong(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 74 int addedRows, int pos); 75 FillOneRowResult FillOneRowOfFloat(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 76 int addedRows, int pos); 77 FillOneRowResult FillOneRowOfBlob(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 78 int addedRows, int pos); 79 FillOneRowResult FillOneRowOfNull(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, 80 int addedRows, int pos); 81 FillOneRowResult FillOneRow(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int numColumns, 82 int startPos, int addedRows); 83 void FillRow(SharedBlockInfo *info, sqlite3_stmt *stmt); 84 int FillSharedBlock(SharedBlockInfo *info, sqlite3_stmt *stmt); 85 bool ResetStatement(SharedBlockInfo *info, sqlite3_stmt *stmt); 86 int64_t GetCombinedData(int startPos, int totalRows); 87 #ifdef __cplusplus 88 } 89 #endif 90 } // namespace NativeRdb 91 } // namespace OHOS 92 93 #endif 94