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 SHARED_BLOCK_SERIALIZER_INFO_H 17 #define SHARED_BLOCK_SERIALIZER_INFO_H 18 19 #include <sqlite3sym.h> 20 21 #include "shared_block.h" 22 23 namespace OHOS { 24 namespace NativeRdb { 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 class SharedBlockSerializerInfo { 29 public: 30 SharedBlockSerializerInfo(AppDataFwk::SharedBlock *sharedBlock, int numColumns, int startPos); 31 ~SharedBlockSerializerInfo(); 32 int AddRow(int addedRows); 33 int Reset(int startPos); 34 int Finish(int addedRows, int totalRows); 35 int PutString(int row, int column, const char *text, int sizeIncludingNull); 36 int PutLong(int row, int column, sqlite3_int64 value); 37 int PutDouble(int row, int column, double value); 38 int PutBlob(int row, int column, const void *blob, int len); 39 int PutNull(int row, int column); 40 int PutOther(int row, int column); 41 int GetTotalRows() const; 42 int GetAddedRows() const; 43 int GetStartPos() const; 44 private: 45 AppDataFwk::SharedBlock *sharedBlock_; 46 int anumColumns; 47 int atotalRows; 48 int astartPos; 49 int raddedRows; 50 bool risFull; 51 }; 52 53 struct Sqlite3SharedBlockMethods { 54 int iVersion; 55 void *pContext; 56 int countAllRows; 57 int startPos; 58 int requiredPos; 59 int (*xAddRow)(void *pCtx, int addedRows); 60 int (*xReset)(void *pCtx, int startPos); 61 int (*xFinish)(void *pCtx, int addedRows, int totalRows); 62 int (*xPutString)(void *pCtx, int addedRows, int column, const char *text, int len); 63 int (*xPutLong)(void *pCtx, int addedRows, int column, sqlite3_int64 value); 64 int (*xPutDouble)(void *pCtx, int addedRows, int column, double value); 65 int (*xPutBlob)(void *pCtx, int addedRows, int column, const void *blob, int len); 66 int (*xPutNull)(void *pCtx, int addedRows, int column); 67 int (*xPutOther)(void *pCtx, int addedRows, int column); 68 // Additional methods may be added in future releases 69 }; 70 71 static const int SQLITE_DBCONFIG_SET_SHAREDBLOCK = 2004; 72 73 static const int SQLITE_DBCONFIG_USE_SHAREDBLOCK = 2005; 74 #ifdef __cplusplus 75 } 76 #endif 77 } // namespace NativeRdb 78 } // namespace OHOS 79 80 #endif 81