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 #include "sqlite_single_ver_storage_executor.h"
17
18 #include <algorithm>
19
20 #include "cloud/cloud_store_types.h"
21 #include "data_transformer.h"
22 #include "db_constant.h"
23 #include "db_common.h"
24 #include "db_errno.h"
25 #include "parcel.h"
26 #include "platform_specific.h"
27 #include "res_finalizer.h"
28 #include "runtime_context.h"
29 #include "sqlite_meta_executor.h"
30 #include "sqlite_single_ver_storage_executor_sql.h"
31 #include "log_print.h"
32 #include "log_table_manager_factory.h"
33
34 namespace DistributedDB {
35 namespace {
36 constexpr const char *HWM_HEAD = "naturalbase_cloud_meta_sync_data_";
37 }
38
BindSyncDataTime(sqlite3_stmt * statement,const DataItem & dataItem,bool isUpdate)39 int SQLiteSingleVerStorageExecutor::BindSyncDataTime(sqlite3_stmt *statement, const DataItem &dataItem, bool isUpdate)
40 {
41 int errCode = SQLiteUtils::BindInt64ToStatement(statement, BIND_SYNC_STAMP_INDEX, dataItem.timestamp);
42 if (errCode != E_OK) {
43 LOGE("Bind saved sync data stamp failed:%d", errCode);
44 return errCode;
45 }
46
47 const int writeTimeIndex = isUpdate ? BIND_SYNC_UPDATE_W_TIME_INDEX : BIND_SYNC_W_TIME_INDEX;
48 errCode = SQLiteUtils::BindInt64ToStatement(statement, writeTimeIndex, dataItem.writeTimestamp);
49 if (errCode != E_OK) {
50 LOGE("Bind saved sync data write stamp failed:%d", errCode);
51 return errCode;
52 }
53
54 const int modifyTimeIndex = isUpdate ? BIND_SYNC_UPDATE_MODIFY_TIME_INDEX : BIND_SYNC_MODIFY_TIME_INDEX;
55 errCode = SQLiteUtils::BindInt64ToStatement(statement, modifyTimeIndex, dataItem.modifyTime);
56 if (errCode != E_OK) {
57 LOGE("Bind saved sync data modify time failed:%d", errCode);
58 return errCode;
59 }
60
61 const int createTimeIndex = isUpdate ? BIND_SYNC_UPDATE_CREATE_TIME_INDEX : BIND_SYNC_CREATE_TIME_INDEX;
62 errCode = SQLiteUtils::BindInt64ToStatement(statement, createTimeIndex, dataItem.createTime);
63 if (errCode != E_OK) {
64 LOGE("Bind saved sync data create time failed:%d", errCode);
65 return errCode;
66 }
67
68 if (IsPrintTimestamp()) {
69 LOGI("Write timestamp:%" PRIu64 " timestamp:%" PRIu64 ", flag:%" PRIu64 " modifyTime:%" PRIu64 " createTime:%"
70 PRIu64 ", key size:%" PRIu32 ", value size:%" PRIu32, dataItem.writeTimestamp, dataItem.timestamp,
71 dataItem.flag, dataItem.modifyTime, dataItem.createTime, dataItem.key.size(), dataItem.value.size());
72 }
73 return errCode;
74 }
75
CreateCloudLogTable()76 int SQLiteSingleVerStorageExecutor::CreateCloudLogTable()
77 {
78 if (dbHandle_ == nullptr) {
79 return -E_INVALID_DB;
80 }
81 return SqliteLogTableManager::CreateKvSyncLogTable(dbHandle_);
82 }
83
CloudExcuteRemoveOrUpdate(const std::string & sql,const std::string & deviceName,const std::string & user,bool isUserBlobType)84 int SQLiteSingleVerStorageExecutor::CloudExcuteRemoveOrUpdate(const std::string &sql, const std::string &deviceName,
85 const std::string &user, bool isUserBlobType)
86 {
87 int errCode = E_OK;
88 sqlite3_stmt *statement = nullptr;
89 errCode = SQLiteUtils::GetStatement(dbHandle_, sql, statement);
90 if (errCode != E_OK) {
91 return errCode;
92 }
93 // device name always hash string.
94 int bindIndex = 1; // 1 is the first index for blob to bind.
95 int ret = E_OK;
96 if (!user.empty()) {
97 if (isUserBlobType) {
98 std::vector<uint8_t> useVect(user.begin(), user.end());
99 errCode = SQLiteUtils::BindBlobToStatement(statement, bindIndex, useVect, true);
100 } else {
101 errCode = SQLiteUtils::BindTextToStatement(statement, bindIndex, user);
102 }
103 if (errCode != E_OK) {
104 LOGE("Failed to bind the removed device:%d", errCode);
105 SQLiteUtils::ResetStatement(statement, true, ret);
106 return errCode;
107 }
108 bindIndex++;
109 }
110 if (!deviceName.empty()) {
111 std::vector<uint8_t> devVect(deviceName.begin(), deviceName.end());
112 errCode = SQLiteUtils::BindBlobToStatement(statement, bindIndex, devVect, true); // only one arg.
113 if (errCode != E_OK) {
114 LOGE("Failed to bind the removed device:%d", errCode);
115 SQLiteUtils::ResetStatement(statement, true, ret);
116 return errCode;
117 }
118 }
119 errCode = SQLiteUtils::StepWithRetry(statement, isMemDb_);
120 if (errCode != SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) {
121 LOGE("Failed to execute rm the device synced data:%d", errCode);
122 } else {
123 errCode = E_OK;
124 }
125 SQLiteUtils::ResetStatement(statement, true, ret);
126 return errCode != E_OK ? errCode : ret;
127 }
128
CloudCheckDataExist(const std::string & sql,const std::string & deviceName,const std::string & user,bool & isExist)129 int SQLiteSingleVerStorageExecutor::CloudCheckDataExist(const std::string &sql, const std::string &deviceName,
130 const std::string &user, bool &isExist)
131 {
132 int errCode = E_OK;
133 sqlite3_stmt *statement = nullptr;
134 errCode = SQLiteUtils::GetStatement(dbHandle_, sql, statement);
135 if (errCode != E_OK) {
136 return errCode;
137 }
138 int bindIndex = 1; // 1 is the first index for blob to bind.
139 int ret = E_OK;
140 if (!user.empty()) {
141 errCode = SQLiteUtils::BindTextToStatement(statement, bindIndex, user); // only one arg.
142 if (errCode != E_OK) {
143 LOGE("Failed to bind the removed device:%d", errCode);
144 SQLiteUtils::ResetStatement(statement, true, ret);
145 return errCode;
146 }
147 bindIndex++;
148 if (sql == SELECT_CLOUD_LOG_DATA_BY_USERID_HASHKEY_SQL) { // the second argument is also userid.
149 errCode = SQLiteUtils::BindTextToStatement(statement, bindIndex, user); // only one arg.
150 if (errCode != E_OK) {
151 LOGE("Failed to bind the removed device:%d", errCode);
152 SQLiteUtils::ResetStatement(statement, true, ret);
153 return errCode;
154 }
155 }
156 }
157 if (!deviceName.empty()) {
158 std::vector<uint8_t> devVect(deviceName.begin(), deviceName.end());
159 errCode = SQLiteUtils::BindBlobToStatement(statement, bindIndex, devVect, true); // only one arg.
160 if (errCode != E_OK) {
161 LOGE("Failed to bind the removed device:%d", errCode);
162 SQLiteUtils::ResetStatement(statement, true, ret);
163 return errCode;
164 }
165 }
166 errCode = SQLiteUtils::StepWithRetry(statement, isMemDb_);
167 if (errCode != SQLiteUtils::MapSQLiteErrno(SQLITE_DONE) && errCode != SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) {
168 LOGE("Failed to execute find the device synced data:%d", errCode);
169 } else {
170 if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { // means deviceId can be matched in log table
171 isExist = true;
172 }
173 SQLiteUtils::ResetStatement(statement, true, ret);
174 return E_OK;
175 }
176 SQLiteUtils::ResetStatement(statement, true, ret);
177 return errCode != E_OK ? errCode : ret;
178 }
179
RemoveDeviceDataInner(ClearMode mode)180 int SQLiteSingleVerStorageExecutor::RemoveDeviceDataInner(ClearMode mode)
181 {
182 if (mode == ClearMode::DEFAULT) {
183 return CloudExcuteRemoveOrUpdate(REMOVE_ALL_DEV_SYNC_DATA_SQL, "", "");
184 }
185 int errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_ALL_HWM_DATA_SQL, "", "", true);
186 if (errCode != E_OK) {
187 return errCode;
188 }
189 errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_ALL_LOG_DATA_SQL, "", "");
190 if (errCode != E_OK) {
191 return errCode;
192 }
193 if (mode == FLAG_AND_DATA) {
194 return CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_ALL_DEV_DATA_SQL, "", "");
195 } else if (mode == FLAG_ONLY) {
196 errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_ALL_DEV_DATA_VERSION_SQL, "", "");
197 if (errCode != E_OK) {
198 return errCode;
199 }
200 }
201 return CloudExcuteRemoveOrUpdate(UPDATE_CLOUD_ALL_DEV_DATA_SQL, "", "");
202 }
203
RemoveDeviceDataInner(const std::string & deviceName,ClearMode mode)204 int SQLiteSingleVerStorageExecutor::RemoveDeviceDataInner(const std::string &deviceName, ClearMode mode)
205 {
206 if (mode == ClearMode::DEFAULT) {
207 return CloudExcuteRemoveOrUpdate(REMOVE_DEV_SYNC_DATA_BY_DEV_ID_SQL, deviceName, "");
208 }
209 int errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_ALL_HWM_DATA_SQL, "", "", true);
210 if (errCode != E_OK) {
211 return errCode;
212 }
213 errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_LOG_DATA_BY_DEVID_SQL, deviceName, "");
214 if (errCode != E_OK) {
215 return errCode;
216 }
217 if (mode == FLAG_AND_DATA) {
218 return CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_DEV_DATA_BY_DEVID_SQL, deviceName, "");
219 } else if (mode == FLAG_ONLY) {
220 errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_DEV_DATA_VERSION_BY_DEVID_SQL, deviceName, "");
221 if (errCode != E_OK) {
222 return errCode;
223 }
224 }
225 return CloudExcuteRemoveOrUpdate(UPDATE_CLOUD_DEV_DATA_BY_DEVID_SQL, deviceName, "");
226 }
227
RemoveDeviceDataWithUserInner(const std::string & user,ClearMode mode)228 int SQLiteSingleVerStorageExecutor::RemoveDeviceDataWithUserInner(const std::string &user, ClearMode mode)
229 {
230 int errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_HWM_DATA_BY_USERID_SQL, "",
231 std::string(HWM_HEAD) + user, true);
232 if (errCode != E_OK) {
233 return errCode;
234 }
235 if (mode == FLAG_AND_DATA) {
236 bool isMultiHashExistInLog = false;
237 errCode = CloudCheckDataExist(SELECT_CLOUD_LOG_DATA_BY_USERID_HASHKEY_SQL, "", user, isMultiHashExistInLog);
238 if (errCode != E_OK) {
239 return errCode;
240 }
241 if (!isMultiHashExistInLog) { // means the hashKey is unique in the log table.
242 errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_DEV_DATA_BY_USERID_SQL, "", user);
243 if (errCode != E_OK) {
244 return errCode;
245 }
246 }
247 }
248 errCode = CloudExcuteRemoveOrUpdate(UPDATE_CLOUD_DEV_DATA_BY_USERID_SQL, "", user); // delete synclog table.
249 if (errCode != E_OK) {
250 return errCode;
251 }
252 return CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_LOG_DATA_BY_USERID_SQL, "", user);
253 }
254
RemoveDeviceDataWithUserInner(const std::string & deviceName,const std::string & user,ClearMode mode)255 int SQLiteSingleVerStorageExecutor::RemoveDeviceDataWithUserInner(const std::string &deviceName,
256 const std::string &user, ClearMode mode)
257 {
258 int errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_HWM_DATA_BY_USERID_SQL, "",
259 std::string(HWM_HEAD) + user, true);
260 if (errCode != E_OK) {
261 return errCode;
262 }
263 bool isMultiHashExistInLog = false;
264 int ret = CloudCheckDataExist(SELECT_CLOUD_LOG_DATA_BY_USERID_HASHKEY_SQL, "", user, isMultiHashExistInLog);
265 if (ret != E_OK) {
266 return ret;
267 }
268 errCode = CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_LOG_DATA_BY_USERID_DEVID_SQL, deviceName, user);
269 if (errCode != E_OK) {
270 return errCode;
271 }
272 if (mode == FLAG_AND_DATA) {
273 if (!isMultiHashExistInLog) { // means the hashKey is unique in the log table.
274 // If the hashKey does not exist in the syncLog table and type is cloud data, the data should be deleted
275 return CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_DEV_DATA_BY_DEVID_HASHKEY_NOTIN_SQL, deviceName, "");
276 }
277 }
278 return CloudExcuteRemoveOrUpdate(UPDATE_CLOUD_DEV_DATA_BY_DEVID_HASHKEY_NOTIN_SQL, deviceName, "");
279 }
280
RemoveDeviceData(const std::string & deviceName,ClearMode mode)281 int SQLiteSingleVerStorageExecutor::RemoveDeviceData(const std::string &deviceName, ClearMode mode)
282 {
283 if (deviceName.empty()) {
284 return CheckCorruptedStatus(RemoveDeviceDataInner(mode));
285 }
286 bool isDataExist = false;
287 int errCode = CloudCheckDataExist(SELECT_CLOUD_LOG_DATA_BY_DEVID_SQL, deviceName, "", isDataExist);
288 // means deviceId can not be matched in log table
289 if (mode != ClearMode::DEFAULT && (!isDataExist || errCode != E_OK)) {
290 return CheckCorruptedStatus(errCode);
291 }
292 return CheckCorruptedStatus(RemoveDeviceDataInner(deviceName, mode));
293 }
294
RemoveDeviceData(const std::string & deviceName,const std::string & user,ClearMode mode)295 int SQLiteSingleVerStorageExecutor::RemoveDeviceData(const std::string &deviceName, const std::string &user,
296 ClearMode mode)
297 {
298 if (mode == ClearMode::DEFAULT) {
299 return CheckCorruptedStatus(deviceName.empty() ?
300 RemoveDeviceDataInner(mode) : RemoveDeviceDataInner(deviceName, mode));
301 }
302 int errCode = E_OK;
303 bool isDataExist = false;
304 if (deviceName.empty()) {
305 errCode = CloudCheckDataExist(SELECT_CLOUD_DEV_DATA_BY_USERID_SQL, "", user, isDataExist);
306 if (errCode != E_OK || !isDataExist) {
307 return CheckCorruptedStatus(errCode);
308 }
309 return CheckCorruptedStatus(RemoveDeviceDataWithUserInner(user, mode));
310 }
311 errCode = CloudCheckDataExist(SELECT_CLOUD_LOG_DATA_BY_USERID_DEVID_SQL, deviceName, user, isDataExist);
312 if (errCode != E_OK || !isDataExist) {
313 return CheckCorruptedStatus(errCode);
314 }
315 return CheckCorruptedStatus(RemoveDeviceDataWithUserInner(deviceName, user, mode));
316 }
317
GetEntries(const std::string & device,std::vector<Entry> & entries) const318 int SQLiteSingleVerStorageExecutor::GetEntries(const std::string &device, std::vector<Entry> &entries) const
319 {
320 const std::string sql = SELECT_SYNC_ENTRIES_BY_DEVICE_SQL;
321 sqlite3_stmt *stmt = nullptr;
322 int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, stmt);
323 if (errCode != E_OK) {
324 LOGE("[SQLiteSingleVerStorageExecutor] Get entries by device statement failed:%d", errCode);
325 return errCode;
326 }
327 ResFinalizer finalizer([stmt]() {
328 sqlite3_stmt *statement = stmt;
329 int ret = E_OK;
330 SQLiteUtils::ResetStatement(statement, true, ret);
331 if (ret != E_OK) {
332 LOGW("[SQLiteSingleVerStorageExecutor] Reset get entries statement failed:%d", ret);
333 }
334 });
335 auto hashDev = DBCommon::TransferHashString(device);
336 Value blobDev;
337 DBCommon::StringToVector(hashDev, blobDev);
338 errCode = SQLiteUtils::BindBlobToStatement(stmt, BIND_GET_ENTRIES_DEVICE_INDEX, blobDev);
339 if (errCode != E_OK) {
340 LOGE("[SQLiteSingleVerStorageExecutor] Bind hash device[%s] to statement failed:%d",
341 DBCommon::TransferStringToHex(hashDev).c_str(), errCode);
342 return errCode;
343 }
344 errCode = StepForResultEntries(true, stmt, entries);
345 if (errCode != E_OK) {
346 LOGE("[SQLiteSingleVerStorageExecutor] Get device[%s] entries failed:%d",
347 DBCommon::TransferStringToHex(hashDev).c_str(), errCode);
348 return errCode;
349 }
350 LOGD("[SQLiteSingleVerStorageExecutor] Get %zu entries by device", entries.size());
351 return errCode;
352 }
353
PrepareForUnSyncTotalByTime(Timestamp begin,Timestamp end,sqlite3_stmt * & statement,bool getDeletedData) const354 int SQLiteSingleVerStorageExecutor::PrepareForUnSyncTotalByTime(Timestamp begin, Timestamp end,
355 sqlite3_stmt *&statement, bool getDeletedData) const
356 {
357 if (dbHandle_ == nullptr) {
358 return -E_INVALID_DB;
359 }
360
361 const std::string sql = (getDeletedData ? COUNT_SYNC_DELETED_ENTRIES_SQL : COUNT_SYNC_ENTRIES_SQL);
362 int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, statement);
363 if (errCode != E_OK) {
364 LOGE("Prepare the sync num entries statement error:%d", errCode);
365 return errCode;
366 }
367
368 errCode = SQLiteUtils::BindInt64ToStatement(statement, BIND_BEGIN_STAMP_INDEX, begin);
369 if (errCode != E_OK) {
370 LOGE("Bind the begin timestamp for getting sync num error:%d", errCode);
371 int ret = E_OK;
372 SQLiteUtils::ResetStatement(statement, true, ret);
373 return CheckCorruptedStatus(errCode);
374 }
375
376 errCode = SQLiteUtils::BindInt64ToStatement(statement, BIND_END_STAMP_INDEX, end);
377 if (errCode != E_OK) {
378 LOGE("Bind the end timestamp for getting sync num error:%d", errCode);
379 int ret = E_OK;
380 SQLiteUtils::ResetStatement(statement, true, ret);
381 }
382 return CheckCorruptedStatus(errCode);
383 }
384
GetCountValue(sqlite3_stmt * & countStatement,uint32_t & total) const385 int SQLiteSingleVerStorageExecutor::GetCountValue(sqlite3_stmt *&countStatement, uint32_t &total) const
386 {
387 int errCode = SQLiteUtils::StepWithRetry(countStatement, isMemDb_);
388 if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) {
389 uint64_t readCount = static_cast<uint64_t>(sqlite3_column_int64(countStatement, 0));
390 if (readCount > UINT32_MAX) {
391 LOGW("ReadCount is beyond UINT32_MAX");
392 total = 0;
393 errCode = -E_UNEXPECTED_DATA;
394 } else {
395 total = static_cast<uint32_t>(readCount);
396 errCode = E_OK;
397 }
398 LOGD("[GetCountValue]Entry count in this result set is %" PRIu32 "", total);
399 } else {
400 errCode = -E_UNEXPECTED_DATA;
401 }
402 int ret = E_OK;
403 SQLiteUtils::ResetStatement(countStatement, true, ret);
404 return CheckCorruptedStatus(errCode);
405 }
406
GetUnSyncTotalByTimestamp(Timestamp begin,Timestamp end,uint32_t & total) const407 int SQLiteSingleVerStorageExecutor::GetUnSyncTotalByTimestamp(Timestamp begin, Timestamp end, uint32_t &total) const
408 {
409 sqlite3_stmt *countStatement = nullptr;
410 int errCode = PrepareForUnSyncTotalByTime(begin, end, countStatement);
411 if (errCode != E_OK) {
412 return errCode;
413 }
414 return GetCountValue(countStatement, total);
415 }
416
GetDeletedSyncTotalByTimestamp(Timestamp begin,Timestamp end,uint32_t & total) const417 int SQLiteSingleVerStorageExecutor::GetDeletedSyncTotalByTimestamp(Timestamp begin, Timestamp end,
418 uint32_t &total) const
419 {
420 sqlite3_stmt *countStatement = nullptr;
421 int errCode = PrepareForUnSyncTotalByTime(begin, end, countStatement, true);
422 if (errCode != E_OK) {
423 return errCode;
424 }
425 return GetCountValue(countStatement, total);
426 }
427
GetSyncTotalWithQuery(QueryObject & query,const std::pair<Timestamp,Timestamp> & timeRange,uint32_t & total) const428 int SQLiteSingleVerStorageExecutor::GetSyncTotalWithQuery(QueryObject &query,
429 const std::pair<Timestamp, Timestamp> &timeRange, uint32_t &total) const
430 {
431 int errCode = E_OK;
432 SqliteQueryHelper helper = query.GetQueryHelper(errCode);
433 if (errCode != E_OK) {
434 return errCode;
435 }
436 sqlite3_stmt *queryStmt = nullptr;
437 errCode = helper.GetQuerySyncStatement(dbHandle_, timeRange.first, timeRange.second, queryStmt, true);
438 if (errCode != E_OK) {
439 LOGE("Get query sync num statement failed. %d", errCode);
440 return errCode;
441 }
442 return GetCountValue(queryStmt, total);
443 }
444
RemoveCloudUploadFlag(const std::vector<uint8_t> & hashKey)445 int SQLiteSingleVerStorageExecutor::RemoveCloudUploadFlag(const std::vector<uint8_t> &hashKey)
446 {
447 const std::string tableName = "naturalbase_kv_aux_sync_data_log";
448 bool isCreate = false;
449 int errCode = SQLiteUtils::CheckTableExists(dbHandle_, tableName, isCreate);
450 if (errCode != E_OK) {
451 return errCode;
452 }
453 if (!isCreate) {
454 return E_OK;
455 }
456 std::string removeSql = "UPDATE " + tableName + " SET cloud_flag=0 WHERE hash_key=?";
457 sqlite3_stmt *stmt = nullptr;
458 errCode = SQLiteUtils::GetStatement(dbHandle_, removeSql, stmt);
459 if (errCode != E_OK) {
460 LOGE("[SQLiteSingleVerStorageExecutor] Remove cloud flag get stmt failed %d", errCode);
461 return errCode;
462 }
463 errCode = SQLiteUtils::BindBlobToStatement(stmt, BIND_HASH_KEY_INDEX, hashKey);
464 if (errCode != E_OK) {
465 LOGE("[SQLiteSingleVerStorageExecutor] Remove cloud flag bind hashKey failed %d", errCode);
466 return errCode;
467 }
468 errCode = SQLiteUtils::StepWithRetry(stmt, isMemDb_);
469 if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW) || errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) {
470 errCode = E_OK;
471 }
472 int ret = E_OK;
473 SQLiteUtils::ResetStatement(stmt, true, ret);
474 if (ret != E_OK) {
475 LOGW("[SQLiteSingleVerStorageExecutor] Finalize stmt failed %d", ret);
476 }
477 return errCode == E_OK ? ret : errCode;
478 }
479
IsFromDataOwner(const DataItem & itemGet,const std::string & syncDev)480 bool SQLiteSingleVerStorageExecutor::IsFromDataOwner(const DataItem &itemGet, const std::string &syncDev)
481 {
482 return itemGet.dev == syncDev ||
483 (conflictResolvePolicy_ == DENY_OTHER_DEV_AMEND_CUR_DEV_DATA && itemGet.origDev == syncDev);
484 }
485
ClearCloudWatermark()486 int SQLiteSingleVerStorageExecutor::ClearCloudWatermark()
487 {
488 return CloudExcuteRemoveOrUpdate(REMOVE_CLOUD_ALL_HWM_DATA_SQL, "", "", true);
489 }
490
GetMetaDataByPrefixKey(const Key & keyPrefix,std::map<Key,Value> & data) const491 int SQLiteSingleVerStorageExecutor::GetMetaDataByPrefixKey(const Key &keyPrefix, std::map<Key, Value> &data) const
492 {
493 std::string metaTableName = "meta_data";
494 return SqliteMetaExecutor::GetMetaDataByPrefixKey(dbHandle_, isMemDb_, metaTableName, keyPrefix, data);
495 }
496 } // namespace DistributedDB
497