1 /*
2 * Copyright (c) 2024-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 #include "mock.h"
17
18 #include "relational_store_client.h"
19 #include "share_block.h"
20 #include "sqlite_errno.h"
21
22 constexpr int RETRY_TIME = 50;
23
24 namespace OHOS {
PathToRealPath(const std::string & path,std::string & realPath)25 __attribute__((visibility("default"))) bool PathToRealPath(const std::string &path, std::string &realPath)
26 {
27 realPath = path;
28 return true;
29 }
30
ExtractFilePath(const std::string & fileFullName)31 __attribute__((visibility("default"))) std::string ExtractFilePath(const std::string &fileFullName)
32 {
33 return std::string(fileFullName).substr(0, fileFullName.rfind("/") + 1);
34 }
35
36 namespace NativeRdb {
gettid()37 __attribute__((visibility("default"))) int gettid()
38 {
39 return 0;
40 }
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
FillSharedBlockOpt(SharedBlockInfo * info,sqlite3_stmt * stmt)44 __attribute__((visibility("default"))) int FillSharedBlockOpt(SharedBlockInfo *info, sqlite3_stmt *stmt)
45 {
46 return FillSharedBlock(info, stmt);
47 }
48
FillSharedBlock(SharedBlockInfo * info,sqlite3_stmt * stmt)49 __attribute__((visibility("default"))) int FillSharedBlock(SharedBlockInfo *info, sqlite3_stmt *stmt)
50 {
51 int retryCount = 0;
52 info->totalRows = info->addedRows = 0;
53 bool isFull = false;
54 bool hasException = false;
55 while (!hasException && (!isFull || info->isCountAllRows)) {
56 int err = sqlite3_step(stmt);
57 if (err == SQLITE_ROW) {
58 retryCount = 0;
59 info->totalRows += 1;
60 if (info->startPos >= info->totalRows || isFull) {
61 continue;
62 }
63 info->isFull = true;
64 isFull = info->isFull;
65 hasException = info->hasException;
66 } else if (err == SQLITE_DONE) {
67 break;
68 } else if (err == SQLITE_LOCKED || err == SQLITE_BUSY) {
69 if (retryCount > RETRY_TIME) {
70 hasException = true;
71 return E_DATABASE_BUSY;
72 } else {
73 retryCount++;
74 }
75 } else {
76 hasException = true;
77 return SQLiteError::ErrNo(err);
78 }
79 }
80 return E_OK;
81 }
82
ResetStatement(SharedBlockInfo * info,sqlite3_stmt * stmt)83 __attribute__((visibility("default"))) bool ResetStatement(SharedBlockInfo *info, sqlite3_stmt *stmt)
84 {
85 (void)info;
86 (void)stmt;
87 return true;
88 }
89
90 #ifdef __cplusplus
91 }
92 #endif
93 } // namespace NativeRdb
94 } // namespace OHOS
95
96 using namespace DistributedDB;
UnRegisterClientObserver(sqlite3 * db)97 __attribute__((visibility("default"))) DBStatus UnRegisterClientObserver(sqlite3 *db)
98 {
99 return DBStatus::OK;
100 }
101
RegisterStoreObserver(sqlite3 * db,const std::shared_ptr<StoreObserver> & storeObserver)102 __attribute__((visibility("default"))) DBStatus RegisterStoreObserver(
103 sqlite3 *db, const std::shared_ptr<StoreObserver> &storeObserver)
104 {
105 return DBStatus::OK;
106 }
107
UnregisterStoreObserver(sqlite3 * db,const std::shared_ptr<StoreObserver> & storeObserver)108 __attribute__((visibility("default"))) DBStatus UnregisterStoreObserver(
109 sqlite3 *db, const std::shared_ptr<StoreObserver> &storeObserver)
110 {
111 return DBStatus::OK;
112 }
113
UnregisterStoreObserver(sqlite3 * db)114 __attribute__((visibility("default"))) DBStatus UnregisterStoreObserver(sqlite3 *db)
115 {
116 return DBStatus::OK;
117 }
118
Lock(const std::string & tableName,const std::vector<std::vector<uint8_t>> & hashKey,sqlite3 * db)119 __attribute__((visibility("default"))) DBStatus Lock(
120 const std::string &tableName, const std::vector<std::vector<uint8_t>> &hashKey, sqlite3 *db)
121 {
122 return DBStatus::OK;
123 }
124
UnLock(const std::string & tableName,const std::vector<std::vector<uint8_t>> & hashKey,sqlite3 * db)125 __attribute__((visibility("default"))) DBStatus UnLock(
126 const std::string &tableName, const std::vector<std::vector<uint8_t>> &hashKey, sqlite3 *db)
127 {
128 return DBStatus::OK;
129 }
130
DropLogicDeletedData(sqlite3 * db,const std::string & tableName,uint64_t cursor)131 __attribute__((visibility("default"))) DBStatus DropLogicDeletedData(
132 sqlite3 *db, const std::string &tableName, uint64_t cursor)
133 {
134 (void)db;
135 (void)tableName;
136 (void)cursor;
137 return DBStatus::OK;
138 }
139
RegisterDbHook(sqlite3 * db)140 __attribute__((visibility("default"))) void RegisterDbHook(sqlite3 *db)
141 {
142 (void)db;
143 }
144
UnregisterDbHook(sqlite3 * db)145 __attribute__((visibility("default"))) void UnregisterDbHook(sqlite3 *db)
146 {
147 (void)db;
148 }
149
CreateDataChangeTempTrigger(sqlite3 * db)150 __attribute__((visibility("default"))) DBStatus CreateDataChangeTempTrigger(sqlite3 *db)
151 {
152 (void)db;
153 return DBStatus::OK;
154 }
155
GetDistributedLogTableName(const std::string & tableName)156 __attribute__((visibility("default"))) std::string DistributedDB::RelationalStoreManager::GetDistributedLogTableName(
157 const std::string &tableName)
158 {
159 return "";
160 }
161
SetKnowledgeSourceSchema(sqlite3 * db,const DistributedDB::KnowledgeSourceSchema & schema)162 __attribute__((visibility("default"))) DistributedDB::DBStatus SetKnowledgeSourceSchema([[gnu::unused]] sqlite3 *db,
163 [[gnu::unused]] const DistributedDB::KnowledgeSourceSchema &schema)
164 {
165 return DBStatus::OK;
166 }
167
CleanDeletedData(sqlite3 * db,const std::string & tableName,uint64_t cursor)168 __attribute__((visibility("default"))) DistributedDB::DBStatus CleanDeletedData([[gnu::unused]] sqlite3 *db,
169 [[gnu::unused]] const std::string &tableName, [[gnu::unused]] uint64_t cursor)
170 {
171 return DBStatus::OK;
172 }
173
Clean(bool isOpenSslClean)174 __attribute__((visibility("default"))) void Clean([[gnu::unused]] bool isOpenSslClean)
175 {
176 return;
177 }