• 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 startPos;
55     int addedRows;
56     int requiredPos;
57     int totalRows;
58     int isCountAllRows;
59     int columnNum;
60     bool isFull;
61     bool hasException;
62 
SharedBlockInfoSharedBlockInfo63     SharedBlockInfo(SqliteConnectionS *connection, AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement)
64         : connection(connection), sharedBlock(sharedBlock), statement(statement)
65     {
66         startPos = 0;
67         addedRows = 0;
68         requiredPos = 0;
69         totalRows = 0;
70         isCountAllRows = 0;
71         columnNum = 0;
72         isFull = false;
73         hasException = false;
74     }
75 };
76 
77 int SeriAddRow(void *pCtx, int addedRows);
78 int SeriReset(void *pCtx, int startPos);
79 int SeriFinish(void *pCtx, int addedRows, int totalRows);
80 int SeriPutString(void *pCtx, int addedRows, int column, const char *text, int size);
81 int SeriPutLong(void *pCtx, int addedRows, int column, sqlite3_int64 value);
82 int SeriPutDouble(void *pCtx, int addedRows, int column, double value);
83 int SeriPutBlob(void *pCtx, int addedRows, int column, const void *blob, int len);
84 int SeriPutNull(void *pCtx, int addedRows, int column);
85 int SeriPutOther(void *pCtx, int addedRows, int column);
86 int ClearSharedBlock(AppDataFwk::SharedBlock *sharedBlock);
87 int SharedBlockSetColumnNum(AppDataFwk::SharedBlock *sharedBlock, int columnNum);
88 void FillSharedBlockOpt(SharedBlockInfo *info);
89 FillOneRowResult FillOneRowOfString(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
90     int addedRows, int pos);
91 FillOneRowResult FillOneRowOfLong(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
92     int addedRows, int pos);
93 FillOneRowResult FillOneRowOfFloat(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
94     int addedRows, int pos);
95 FillOneRowResult FillOneRowOfBlob(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
96     int addedRows, int pos);
97 FillOneRowResult FillOneRowOfNull(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
98     int addedRows, int pos);
99 FillOneRowResult FillOneRow(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int numColumns,
100     int startPos, int addedRows);
101 void FillRow(SharedBlockInfo *info);
102 void FillSharedBlock(SharedBlockInfo *info);
103 bool ResetStatement(SharedBlockInfo *sharedBlockInfo);
104 int64_t GetCombinedData(int startPos, int totalRows);
105 #ifdef __cplusplus
106 }
107 #endif
108 } // namespace NativeRdb
109 } // namespace OHOS
110 
111 #endif
112