• 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 "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 SqliteConnectionS {
35     // Open flags.
36     // Must be kept in sync with the constants defined in SQLiteDatabase.java.
37     enum {
38         OPEN_READONLY = 0x00000001,
39         OPEN_READWRITE = 0x00000002,
40         CREATE_IF_NECESSARY = 0x00000004,
41     };
42     sqlite3 * const db;
43     const int openFlags;
44     std::string path;
45 
SqliteConnectionSSqliteConnectionS46     SqliteConnectionS(sqlite3 *db, int openFlags, const std::string &path) : db(db), openFlags(openFlags), path(path) {}
47 };
48 
49 struct SharedBlockInfo {
50     SqliteConnectionS *connection;
51     AppDataFwk::SharedBlock *sharedBlock;
52     sqlite3_stmt *statement;
53 
54     int numColumns;
55     int startPos;
56     int addedRows;
57     int requiredPos;
58     int totalRows;
59     int isCountAllRows;
60     int columnNum;
61     bool isFull;
62     bool hasException;
63 
SharedBlockInfoSharedBlockInfo64     SharedBlockInfo(SqliteConnectionS *connection, AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement)
65         : connection(connection), sharedBlock(sharedBlock), statement(statement)
66     {
67         numColumns = 0;
68         startPos = 0;
69         addedRows = 0;
70         requiredPos = 0;
71         totalRows = 0;
72         isCountAllRows = 0;
73         columnNum = 0;
74         isFull = false;
75         hasException = false;
76     }
77 };
78 
79 int SeriAddRow(void *pCtx, int addedRows);
80 int SeriReset(void *pCtx, int startPos);
81 int SeriFinish(void *pCtx, int addedRows, int totalRows);
82 int SeriPutString(void *pCtx, int addedRows, int column, const char *text, int size);
83 int SeriPutLong(void *pCtx, int addedRows, int column, sqlite3_int64 value);
84 int SeriPutDouble(void *pCtx, int addedRows, int column, double value);
85 int SeriPutBlob(void *pCtx, int addedRows, int column, const void *blob, int len);
86 int SeriPutNull(void *pCtx, int addedRows, int column);
87 int SeriPutOther(void *pCtx, int addedRows, int column);
88 int ClearSharedBlock(AppDataFwk::SharedBlock *sharedBlock);
89 int SharedBlockSetColumnNum(AppDataFwk::SharedBlock *sharedBlock, int columnNum);
90 void FillSharedBlockOpt(SharedBlockInfo *info);
91 FillOneRowResult FillOneRowOfString(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
92     int addedRows, int pos);
93 FillOneRowResult FillOneRowOfLong(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
94     int addedRows, int pos);
95 FillOneRowResult FillOneRowOfFloat(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
96     int addedRows, int pos);
97 FillOneRowResult FillOneRowOfBlob(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
98     int addedRows, int pos);
99 FillOneRowResult FillOneRowOfNull(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
100     int addedRows, int pos);
101 FillOneRowResult FillOneRow(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int numColumns,
102     int startPos, int addedRows);
103 void FillRow(SharedBlockInfo *info);
104 void FillSharedBlock(SharedBlockInfo *info);
105 bool ResetStatement(SharedBlockInfo *sharedBlockInfo);
106 int64_t GetCombinedData(int startPos, int totalRows);
107 #ifdef __cplusplus
108 }
109 #endif
110 } // namespace NativeRdb
111 } // namespace OHOS
112 
113 #endif
114