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