• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sqlite3sym.h>
20 
21 #include <string>
22 
23 #include "shared_block.h"
24 
25 namespace OHOS {
26 namespace NativeRdb {
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 enum FillOneRowResult {
31     FILL_ONE_ROW_SUCESS,
32     SHARED_BLOCK_IS_FULL,
33     FILL_ONE_ROW_FAIL,
34 };
35 
36 struct SharedBlockInfo {
37     AppDataFwk::SharedBlock *sharedBlock = nullptr;
38 
39     int startPos;
40     int addedRows;
41     int requiredPos;
42     int totalRows;
43     int isCountAllRows;
44     int columnNum;
45     bool isFull;
46     bool hasException;
47 
SharedBlockInfoSharedBlockInfo48     SharedBlockInfo(AppDataFwk::SharedBlock *sharedBlock) : sharedBlock(sharedBlock)
49     {
50         startPos = 0;
51         addedRows = 0;
52         requiredPos = 0;
53         totalRows = 0;
54         isCountAllRows = 0;
55         columnNum = 0;
56         isFull = false;
57         hasException = false;
58     }
59 };
60 
61 int DefAddRow(void *pCtx, int addedRows);
62 int DefReset(void *pCtx, int startPos);
63 int DefFinish(void *pCtx, int addedRows, int totalRows);
64 int DefPutString(void *pCtx, int addedRows, int column, const char *text, int size);
65 int DefPutLong(void *pCtx, int addedRows, int column, sqlite3_int64 value);
66 int DefPutDouble(void *pCtx, int addedRows, int column, double value);
67 int DefPutBlob(void *pCtx, int addedRows, int column, const void *blob, int len);
68 int DefPutNull(void *pCtx, int addedRows, int column);
69 int DefPutOther(void *pCtx, int addedRows, int column);
70 int SeriAddRow(void *pCtx, int addedRows);
71 int SeriReset(void *pCtx, int startPos);
72 int SeriFinish(void *pCtx, int addedRows, int totalRows);
73 int SeriPutString(void *pCtx, int addedRows, int column, const char *text, int size);
74 int SeriPutLong(void *pCtx, int addedRows, int column, sqlite3_int64 value);
75 int SeriPutDouble(void *pCtx, int addedRows, int column, double value);
76 int SeriPutBlob(void *pCtx, int addedRows, int column, const void *blob, int len);
77 int SeriPutNull(void *pCtx, int addedRows, int column);
78 int SeriPutOther(void *pCtx, int addedRows, int column);
79 int ClearSharedBlock(AppDataFwk::SharedBlock *sharedBlock);
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