1 /*
2  * Copyright (c) 2022 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_RDB_STORE_H
17 #define NATIVE_RDB_RDB_STORE_H
18 
19 #include <memory>
20 #include <stdint.h>
21 #include <string>
22 #include <vector>
23 
24 #include "abs_rdb_predicates.h"
25 #include "abs_shared_result_set.h"
26 #include "rdb_common.h"
27 #include "rdb_errno.h"
28 #include "rdb_store_config.h"
29 #include "rdb_types.h"
30 #include "result_set.h"
31 #include "transaction.h"
32 #include "value_object.h"
33 #include "values_bucket.h"
34 #include "values_buckets.h"
35 
36 namespace OHOS::NativeRdb {
37 class API_EXPORT RdbStore {
38 public:
39     /**
40      * @brief Use SyncOption replace DistributedRdb::SyncOption namespace.
41      */
42     using SyncOption = DistributedRdb::SyncOption;
43 
44     /**
45      * @brief Use AsyncBrief replace DistributedRdb::AsyncBrief namespace.
46      */
47     using Briefs = DistributedRdb::Briefs;
48     using AsyncBrief = DistributedRdb::AsyncBrief;
49 
50     /**
51      * @brief Use AsyncBrief replace DistributedRdb::AsyncBrief namespace.
52      */
53     using Details = DistributedRdb::Details;
54     using AsyncDetail = DistributedRdb::AsyncDetail;
55 
56     /**
57      * @brief Use SubscribeMode replace DistributedRdb::SubscribeMode namespace.
58      */
59     using SubscribeMode = DistributedRdb::SubscribeMode;
60 
61     /**
62      * @brief Use SubscribeOption replace DistributedRdb::SubscribeOption namespace.
63      */
64     using SubscribeOption = DistributedRdb::SubscribeOption;
65 
66     /**
67      * @brief Use DropOption replace DistributedRdb::DropOption namespace.
68      */
69     using DropOption = DistributedRdb::DropOption;
70 
71     /**
72      * @brief Use RdbStoreObserver replace DistributedRdb::RdbStoreObserver namespace.
73      */
74     using RdbStoreObserver = DistributedRdb::RdbStoreObserver;
75     using PRIKey = RdbStoreObserver::PrimaryKey;
76 
77     /**
78      * @brief Use RdbSyncObserver replace DistributedRdb::RdbSyncObserver namespace.
79      */
80     using DetailProgressObserver = DistributedRdb::DetailProgressObserver;
81 
82     /**
83      * @brief Use Date replace DistributedRdb::Date namespace.
84      */
85     using Date = DistributedRdb::Date;
86 
87     /**
88      * @brief Use Fields replace std::vector<std::string> columns.
89      */
90     using Fields = std::vector<std::string>;
91 
92     /**
93      * @brief Use Olds replace std::vector<std::string> args.
94      */
95     using Olds = std::vector<std::string>;
96 
97     /**
98      * @brief Use Values replace std::vector<ValueObject> args.
99      */
100     using Values = std::vector<ValueObject>;
101 
102     /**
103      * @brief Use Row replace ValuesBucket.
104      */
105     using Row = ValuesBucket;
106 
107     /**
108      * @brief Use Rows replace std::vector<Row>.
109      */
110     using Rows = std::vector<Row>;
111 
112     /**
113      * @brief Use Rows replace std::vector<Row>.
114      */
115     using RefRows = ValuesBuckets;
116 
117     /**
118      * @brief Use Resolution replace ConflictResolution.
119      */
120     using Resolution = ConflictResolution;
121 
122     class API_EXPORT ModifyTime {
123     public:
124         ModifyTime() = default;
125         API_EXPORT ModifyTime(std::shared_ptr<ResultSet> result, std::map<std::vector<uint8_t>, PRIKey> hashKeys,
126             bool isFromRowId);
127         API_EXPORT operator std::map<PRIKey, Date>();
128         API_EXPORT operator std::shared_ptr<ResultSet>();
129         API_EXPORT PRIKey GetOriginKey(const std::vector<uint8_t> &hash);
130         API_EXPORT size_t GetMaxOriginKeySize();
131         API_EXPORT bool NeedConvert() const;
132 
133     private:
134         std::shared_ptr<ResultSet> result_;
135         std::map<std::vector<uint8_t>, PRIKey> hash_;
136         size_t maxOriginKeySize_ = sizeof(int64_t);
137         bool isFromRowId_{ false };
138     };
139 
140     static constexpr Resolution NO_ACTION = ConflictResolution::ON_CONFLICT_NONE;
141 
142     /**
143      * @brief Destructor.
144      */
145     virtual ~RdbStore() = default;
146 
147     /**
148      * @brief Inserts a row of data into the target table.
149      *
150      * @param table Indicates the target table.
151      * @param row Indicates the row of data {@link ValuesBucket} to be inserted into the table.
152      * @param resolution Indicates the {@link ConflictResolution} to insert data into the table.
153      */
154     virtual std::pair<int, int64_t> Insert(const std::string &table, const Row &row, Resolution resolution = NO_ACTION);
155 
156     /**
157      * @brief Inserts a row of data into the target table.
158      *
159      * @param table Indicates the target table.
160      * @param row Indicates the row of data {@link ValuesBucket} to be inserted into the table.
161      */
162     virtual int Insert(int64_t &outRowId, const std::string &table, const Row &row);
163 
164     /**
165      * @brief Inserts a row of data into the target table.
166      *
167      * @param table Indicates the target table.
168      * @param row Indicates the row of data {@link ValuesBucket} to be inserted into the table.
169      * @param resolution Indicates the {@link ConflictResolution} to insert data into the table.
170      */
171     [[deprecated("Use Insert(const std::string &, const Row &, Resolution) instead.")]]
172     virtual int InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const Row &row,
173         Resolution resolution = NO_ACTION);
174 
175     /**
176      * @brief Replaces a row of data into the target table.
177      *
178      * @param table Indicates the target table.
179      * @param row Indicates the row of data {@link ValuesBucket} to be replaced into the table.
180      */
181     virtual int Replace(int64_t &outRowId, const std::string &table, const Row &row);
182 
183     /**
184      * @brief Inserts a batch of data into the target table.
185      *
186      * @param table Indicates the target table.
187      * @param rows Indicates the rows of data {@link ValuesBucket} to be inserted into the table.
188      */
189     virtual int BatchInsert(int64_t &outInsertNum, const std::string &table, const Rows &rows);
190 
191     /**
192      * @brief Inserts a batch of data into the target table.
193      *
194      * @param table Indicates the target table.
195      * @param values Indicates the rows of data {@link ValuesBuckets} to be inserted into the table.
196      */
197     virtual std::pair<int, int64_t> BatchInsert(const std::string &table, const RefRows &rows);
198 
199     /**
200      * @brief Updates data in the database based on specified conditions.
201      *
202      * @param table Indicates the target table.
203      * @param row Indicates the row of data to be updated in the database.
204      * The key-value pairs are associated with column names of the database table.
205      * @param whereClause Indicates the where clause.
206      * @param args Indicates the where arguments.
207      */
208     virtual std::pair<int, int> Update(const std::string &table, const Row &row, const std::string &where = "",
209         const Values &args = {}, Resolution resolution = NO_ACTION);
210 
211     /**
212      * @brief Updates data in the database based on specified conditions.
213      *
214      * @param table Indicates the target table.
215      * @param row Indicates the row of data to be updated in the database.
216      * The key-value pairs are associated with column names of the database table.
217      * @param whereClause Indicates the where clause.
218      * @param args Indicates the where arguments.
219      */
220     virtual int Update(int &changedRows, const std::string &table, const Row &row, const std::string &whereClause = "",
221                        const Values &args = {});
222 
223     /**
224      * @brief Updates data in the database based on a a specified instance object of AbsRdbPredicates.
225      *
226      * @param values Indicates the row of data to be updated in the database.
227      * The key-value pairs are associated with column names of the database table.
228      * @param predicates Indicates the specified update condition by the instance object of {@link AbsRdbPredicates}.
229      */
230     virtual int Update(int &changedRows, const Row &row, const AbsRdbPredicates &predicates);
231 
232     /**
233      * @brief Updates data in the database based on specified conditions.
234      *
235      * @param table Indicates the target table.
236      * @param row Indicates the row of data to be updated in the database.
237      * The key-value pairs are associated with column names of the database table.
238      * @param whereClause Indicates the where clause.
239      * @param args Indicates the where arguments.
240      */
241     [[deprecated("Use Update(int &, const std::string &, const Row &, const std::string &, const Values &) instead.")]]
242     virtual int Update(int &changedRows, const std::string &table, const Row &row, const std::string &whereClause,
243         const Olds &args);
244 
245     /**
246      * @brief Updates data in the database based on a a specified instance object of RdbPredicates.
247      *
248      * @param table Indicates the target table.
249      * @param row Indicates the row of data to be updated in the database.
250      * The key-value pairs are associated with column names of the database table.
251      * @param whereClause Indicates the where clause.
252      * @param args Indicates the where arguments.
253      * @param resolution Indicates the {@link ConflictResolution} to insert data into the table.
254      */
255     [[deprecated("Use UpdateWithConflictResolution(int &, const std::string &, const Row &, const std::string &, "
256                  "const Values &, ConflictResolution conflictResolution) instead.")]]
257     virtual int UpdateWithConflictResolution(int &changedRows, const std::string &table, const Row &row,
258         const std::string &whereClause, const Olds &args, Resolution resolution = NO_ACTION);
259 
260     /**
261      * @brief Updates data in the database based on a a specified instance object of RdbPredicates.
262      *
263      * @param table Indicates the target table.
264      * @param row Indicates the row of data to be updated in the database.
265      * The key-value pairs are associated with column names of the database table.
266      * @param whereClause Indicates the where clause.
267      * @param args Indicates the where arguments.
268      * @param resolution Indicates the {@link ConflictResolution} to update data into the table.
269      */
270     virtual int UpdateWithConflictResolution(int &changedRows, const std::string &table, const Row &row,
271         const std::string &whereClause = "", const Values &args = {}, Resolution resolution = NO_ACTION);
272 
273     /**
274      * @brief Deletes data from the database based on specified conditions.
275      *
276      * @param table Indicates the target table.
277      * @param whereClause Indicates the where clause.
278      * @param args Indicates the where arguments.
279      */
280     [[deprecated("Use Delete(int &, const std::string &, const std::string &, const Values &) instead.")]]
281     virtual int Delete(int &deletedRows, const std::string &table, const std::string &whereClause,
282         const Olds &args);
283 
284     /**
285      * @brief Deletes data from the database based on a specified instance object of AbsRdbPredicates.
286      *
287      * @param predicates Indicates the specified update condition by the instance object of {@link AbsRdbPredicates}.
288      */
289     virtual int Delete(int &deletedRows, const AbsRdbPredicates &predicates);
290 
291     /**
292      * @brief Deletes data from the database based on specified conditions.
293      *
294      * @param table Indicates the target table.
295      * @param whereClause Indicates the where clause.
296      * @param args Indicates the where arguments.
297      */
298     virtual int Delete(int &deletedRows, const std::string &table, const std::string &whereClause = "",
299         const Values &args = {}) = 0;
300 
301     /**
302      * @brief Queries data in the database based on specified conditions.
303      *
304      * @param distinct Indicates whether to eliminate all duplicate records in the result set.
305      * @param table Indicates the target table.
306      * @param columns Indicates the columns to query. If the value is empty array, the query applies to all columns.
307      * @param whereClause Indicates the selection.
308      * @param args Indicates the selection arguments.
309      * @param groupBy Indicates the groupBy argument.
310      * @param indexName Indicates the index by argument.
311      * @param orderBy Indicates the orderBy argument.
312      * @param limit Indicates the limit argument.
313      */
314     [[deprecated("Use Query(int &, const std::string &, const std::string &, const Values &) instead.")]]
315     virtual std::shared_ptr<AbsSharedResultSet> Query(int &errCode, bool distinct, const std::string &table,
316         const Fields &columns, const std::string &whereClause = "", const Values &args = {},
317         const std::string &groupBy = "", const std::string &indexName = "", const std::string &orderBy = "",
318         const int &limit = AbsPredicates::INIT_LIMIT_VALUE, const int &offset = AbsPredicates::INIT_LIMIT_VALUE);
319 
320     /**
321      * @brief Queries data in the database based on specified conditions.
322      *
323      * @param predicates Indicates the specified query condition by the instance object of {@link AbsRdbPredicates}.
324      * @param columns Indicates the columns to query. If the value is empty array, the query applies to all columns.
325      */
326     virtual std::shared_ptr<AbsSharedResultSet> Query(const AbsRdbPredicates &predicates, const Fields &columns = {});
327 
328     /**
329      * @brief Queries data in the database based on SQL statement.
330      *
331      * @param sql Indicates the SQL statement to execute.
332      * @param args Indicates the selection arguments.
333      */
334     [[deprecated("Use QuerySql(const std::string &, const Values &) instead.")]]
335     virtual std::shared_ptr<AbsSharedResultSet> QuerySql(const std::string &sql, const Olds &args);
336 
337     /**
338      * @brief Queries data in the database based on SQL statement.
339      *
340      * @param sql Indicates the SQL statement to execute.
341      * @param args Indicates the selection arguments.
342      */
343     virtual std::shared_ptr<AbsSharedResultSet> QuerySql(const std::string &sql, const Values &args = {}) = 0;
344 
345     /**
346      * @brief Queries data in the database based on SQL statement.
347      *
348      * @param sql Indicates the SQL statement to execute.
349      * @param args Indicates the selection arguments.
350      */
351     [[deprecated("Use QueryByStep(const std::string &, const Values &) instead.")]]
352     virtual std::shared_ptr<ResultSet> QueryByStep(const std::string &sql, const Olds &args);
353 
354     /**
355      * @brief Queries data in the database based on SQL statement.
356      *
357      * @param sql Indicates the SQL statement to execute.
358      * @param args Indicates the selection arguments.
359      * @param preCount IIndicates whether to calculate the count during query.
360      */
361     virtual std::shared_ptr<ResultSet> QueryByStep(const std::string &sql, const Values &args = {},
362         bool preCount = true) = 0;
363 
364     /**
365      * @brief Queries data in the database based on specified conditions.
366      *
367      * @param predicates Indicates the specified query condition by the instance object of {@link AbsRdbPredicates}.
368      * @param columns Indicates the columns to query. If the value is empty array, the query applies to all columns.
369      * @param preCount IIndicates whether to calculate the count during query.
370      */
371     virtual std::shared_ptr<ResultSet> QueryByStep(const AbsRdbPredicates &predicates, const Fields &columns = {},
372         bool preCount = true);
373 
374     /**
375      * @brief Queries remote data in the database based on specified conditions before Synchronizing Data.
376      *
377      * @param device Indicates specified remote device.
378      * @param predicates Indicates the specified query condition by the instance object of {@link AbsRdbPredicates}.
379      * @param columns Indicates the columns to query. If the value is empty array, the query applies to all columns.
380      */
381     virtual std::shared_ptr<ResultSet> RemoteQuery(const std::string &device, const AbsRdbPredicates &predicates,
382         const Fields &columns, int &errCode);
383 
384     /**
385      * @brief Queries data in the database based on specified conditions.
386      *
387      * @param predicates Indicates the specified query condition by the instance object of {@link AbsRdbPredicates}.
388      * @param columns Indicates the columns to query. If the value is empty array, the query applies to all columns.
389      */
390     virtual std::pair<int32_t, std::shared_ptr<ResultSet>> QuerySharingResource(const AbsRdbPredicates &predicates,
391         const Fields &columns);
392 
393     /**
394      * @brief Executes an SQL statement that contains specified parameters.
395      *
396      * @param sql Indicates the SQL statement to execute.
397      * @param args Indicates the {@link ValueObject} values of the parameters in the SQL statement.
398      */
399     [[deprecated("Use Execute(const std::string &, const Values &, int64_t) instead.")]]
400     virtual int ExecuteSql(const std::string &sql, const Values &args = {});
401 
402     /**
403      * @brief Executes an SQL statement that contains specified parameters and
404      *        get two values of type int and ValueObject.
405      *
406      * @param sql Indicates the SQL statement to execute.
407      * @param args Indicates the {@link ValueObject} values of the parameters in the SQL statement.
408      */
409     virtual std::pair<int32_t, ValueObject> Execute(const std::string &sql, const Values &args = {}, int64_t trxId = 0);
410 
411     /**
412      * @brief Executes an SQL statement that contains specified parameters and get a long integer value.
413      *
414      * @param sql Indicates the SQL statement to execute.
415      * @param args Indicates the {@link ValueObject} values of the parameters in the SQL statement.
416      */
417     [[deprecated("Use Execute(const std::string &, const Values &, int64_t) instead.")]]
418     virtual int ExecuteAndGetLong(int64_t &outValue, const std::string &sql, const Values &args = {});
419 
420     /**
421      * @brief Executes an SQL statement that contains specified parameters.
422      *
423      * @param sql Indicates the SQL statement to execute.
424      * @param args Indicates the {@link ValueObject} values of the parameters in the SQL statement.
425      */
426     [[deprecated("Use Execute(const std::string &, const Values &, int64_t) instead.")]]
427     virtual int ExecuteAndGetString(std::string &outValue, const std::string &sql, const Values &args = {});
428 
429     /**
430      * @brief Executes for last insert row id that contains specified parameters.
431      *
432      * @param sql Indicates the SQL statement to execute.
433      * @param args Indicates the {@link ValueObject} values of the parameters in the SQL statement.
434      */
435     virtual int ExecuteForLastInsertedRowId(int64_t &outValue, const std::string &sql, const Values &args = {});
436 
437     /**
438      * @brief Executes for change row count that contains specified parameters.
439      *
440      * @param sql Indicates the SQL statement to execute.
441      * @param args Indicates the {@link ValueObject} values of the parameters in the SQL statement.
442      */
443     virtual int ExecuteForChangedRowCount(int64_t &outValue, const std::string &sql, const Values &args = {});
444 
445     /**
446      * @brief Restores a database from a specified encrypted or unencrypted database file.
447      *
448      * @param databasePath Indicates the database file path.
449      * @param encryptKey Indicates the database encrypt key.
450      */
451     virtual int Backup(const std::string &databasePath, const std::vector<uint8_t> &encryptKey = {});
452 
453     /**
454      * @brief Attaches a database.
455      *
456      * @param alias Indicates the database alias.
457      * @param pathName Indicates the database file pathname.
458      * @param destEncryptKey Indicates the database encrypt key.
459      */
460     [[deprecated("Use Attach(const RdbStoreConfig &, const std::string &, int32_t) instead.")]]
461     virtual int Attach(const std::string &alias, const std::string &pathName, const std::vector<uint8_t> encryptKey);
462 
463     /**
464      * @brief Get the value of the column based on specified conditions.
465      *
466      * @param predicates Indicates the {@link AbsRdbPredicates} AbsRdbPredicates object.
467      */
468     virtual int Count(int64_t &outValue, const AbsRdbPredicates &predicates);
469 
470     /**
471      * @brief Gets the version of the database.
472      */
473     virtual int GetVersion(int &version) = 0;
474 
475     /**
476      * @brief Sets the version of a new database.
477      */
478     virtual int SetVersion(int version) = 0;
479 
480     /**
481      * @brief Create a transaction of a new database connection.
482      */
483     virtual std::pair<int32_t, std::shared_ptr<Transaction>> CreateTransaction(int32_t type);
484 
485     /**
486      * @brief Begins a transaction in EXCLUSIVE mode.
487      */
488     [[deprecated("Use CreateTransaction(int32_t) instead.")]]
489     virtual int BeginTransaction();
490     virtual std::pair<int, int64_t> BeginTrans();
491 
492     /**
493      * @brief Rollback a transaction in EXCLUSIVE mode.
494      */
495     [[deprecated("Use CreateTransaction(int32_t) instead.")]]
496     virtual int RollBack();
497     virtual int RollBack(int64_t trxId);
498 
499     /**
500      * @brief Commit a transaction in EXCLUSIVE mode.
501      */
502     [[deprecated("Use CreateTransaction(int32_t) instead.")]]
503     virtual int Commit();
504     virtual int Commit(int64_t trxId);
505 
506     /**
507      * @brief Check the current connection is in transaction.
508      */
509     virtual bool IsInTransaction();
510 
511     /**
512      * @brief Get database path.
513      */
514     virtual std::string GetPath();
515 
516     /**
517      * @brief Check the current connection pool is holding connection.
518      */
519     virtual bool IsHoldingConnection();
520 
521     /**
522      * @brief Check the current database is open.
523      */
524     virtual bool IsOpen() const;
525 
526     /**
527      * @brief Check the current database is read only.
528      */
529     virtual bool IsReadOnly() const;
530 
531     /**
532      * @brief Check the current database is memory database.
533      */
534     virtual bool IsMemoryRdb() const;
535 
536     /**
537      * @brief Restores a database from a specified database file.
538      *
539      * @param backupPath  Indicates the name that saves the database file path.
540      * @param newKey Indicates the database new key.
541      */
542     virtual int Restore(const std::string &backupPath, const std::vector<uint8_t> &newKey = {});
543 
544     /**
545      * @brief Set table to be distributed table.
546      *
547      * @param tables Indicates the tables name you want to set.
548      */
549     virtual int SetDistributedTables(const std::vector<std::string> &tables,
550         int32_t type = DistributedRdb::DistributedTableType::DISTRIBUTED_DEVICE,
551         const DistributedRdb::DistributedConfig &distributedConfig = { true });
552 
553     /**
554      * @brief Obtain distributed table name of specified remote device according to local table name.
555      * When query remote device database, distributed table name is needed.
556      *
557      * @param device Indicates the remote device.
558      *
559      * @return Returns the distributed table name.
560      */
561     virtual std::string ObtainDistributedTableName(const std::string &device, const std::string &table, int &errCode);
562 
563     /**
564      * @brief Sync data between devices or cloud.
565      *
566      * @param device Indicates the remote device.
567      * @param predicate Indicates the AbsRdbPredicates {@link AbsRdbPredicates} object.
568      */
569     virtual int Sync(const SyncOption &option, const AbsRdbPredicates &predicate, const AsyncBrief &async);
570 
571     /**
572      * @brief Sync data between devices or cloud.
573      *
574      * @param device Indicates the remote device.
575      * @param predicate Indicates the AbsRdbPredicates {@link AbsRdbPredicates} object.
576      */
577     virtual int Sync(const SyncOption &option, const std::vector<std::string> &tables, const AsyncDetail &async);
578 
579     /**
580      * @brief Sync data between devices or cloud.
581      *
582      * @param device Indicates the remote device.
583      * @param predicate Indicates the AbsRdbPredicates {@link AbsRdbPredicates} object.
584      */
585     virtual int Sync(const SyncOption &option, const AbsRdbPredicates &predicate, const AsyncDetail &async);
586 
587     /**
588      * @brief Subscribe to event changes.
589      */
590     virtual int Subscribe(const SubscribeOption& option, RdbStoreObserver *observer);
591 
592     /**
593      * @brief UnSubscribe to event changes.
594      */
595     virtual int UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer);
596 
597     /**
598      * @brief SubscribeObserver to event changes.
599      */
600     virtual int SubscribeObserver(const SubscribeOption& option, const std::shared_ptr<RdbStoreObserver> &observer);
601 
602     /**
603      * @brief UnsubscribeObserver to event changes.
604      */
605     virtual int UnsubscribeObserver(const SubscribeOption& option, const std::shared_ptr<RdbStoreObserver> &observer);
606 
607     /**
608      * @brief Register message for auto sync operation.
609      */
610     virtual int RegisterAutoSyncCallback(std::shared_ptr<DetailProgressObserver> observer);
611 
612     /**
613      * @brief UnRegister message for auto sync operation.
614      */
615     virtual int UnregisterAutoSyncCallback(std::shared_ptr<DetailProgressObserver> observer);
616 
617     /**
618      * @brief When SubscribeMode is LOCAL or LOCALSHARED, this function needs to be called to trigger callback.
619      */
620     virtual int Notify(const std::string &event);
621 
622     /**
623      * @brief Check the slave database is different from current database.
624      */
625     virtual bool IsSlaveDiffFromMaster() const;
626 
627     virtual int32_t GetDbType() const;
628 
629     virtual std::pair<int32_t, uint32_t> LockCloudContainer();
630 
631     virtual int32_t UnlockCloudContainer();
632 
633     virtual int InterruptBackup();
634 
635     virtual int32_t GetBackupStatus() const;
636 
637     /**
638      * @brief Get the the specified column modify time.
639      *
640      * @param table Indicates the specified table.
641      * @param column Indicates the column.
642      * @param keys Indicates the primary key.
643      *
644      * @return Returns the specified column modify time.
645      */
646     virtual ModifyTime GetModifyTime(const std::string &table, const std::string &column, std::vector<PRIKey> &keys);
647 
648     /**
649      * @brief Cleans dirty data deleted in the cloud.
650      *
651      * If a cursor is specified, data with a cursor smaller than the specified cursor will be cleaned up.
652      * otherwise clean all.
653      *
654      * @param table Indicates the specified table.
655      */
656     virtual int CleanDirtyData(const std::string &table, uint64_t cursor = UINT64_MAX);
657 
658     /**
659      * @brief Gets the rebuilt_ status of the database.
660      */
661     virtual int GetRebuilt(RebuiltType &rebuilt);
662 
663     /**
664      * @brief Attaches a database file to the currently linked database.
665      *
666      * @param config Indicates the {@link RdbStoreConfig} configuration of the database related to this RDB store.
667      * @param attachName Indicates the alias of the database.
668      * @param waitTime Indicates the maximum time allowed for attaching the database file.
669      */
670     virtual std::pair<int32_t, int32_t> Attach(
671         const RdbStoreConfig &config, const std::string &attachName, int32_t waitTime = 2);
672 
673     /**
674      * @brief Detaches a database from this database.
675      *
676      * @param attachName Indicates the alias of the database.
677      * @param waitTime Indicates the maximum time allowed for attaching the database file.
678      */
679     virtual std::pair<int32_t, int32_t> Detach(const std::string &attachName, int32_t waitTime = 2);
680 
681     /**
682      * @brief Locks/Unlocks data from the database based on a specified instance object of AbsRdbPredicates.
683      *
684      * @param predicates Indicates the specified update condition by the instance object of {@link AbsRdbPredicates}.
685      */
686     virtual int ModifyLockStatus(const AbsRdbPredicates &predicates, bool isLock);
687 
688     /**
689      * @brief Set search enable or disable.
690      *
691      * @param isSearchable Indicates enable or disable.
692      */
693     virtual int SetSearchable(bool isSearchable);
694 
695 protected:
696     virtual std::string GetLogTableName(const std::string &tableName);
697 };
698 } // namespace OHOS::NativeRdb
699 #endif
700