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