From 1ae7b18c946f5c6cff2370db21c5c743a16def5e Mon Sep 17 00:00:00 2001 From: mangtsang Date: Mon, 3 Jan 2022 12:39:18 +0800 Subject: [PATCH 1/3] add querySql interface by appdatamgr Signed-off-by: mangtsang --- api/@ohos.data.rdb.d.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index df961acd5e..37034e74ae 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -123,6 +123,20 @@ declare namespace rdb { query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback): void; query(rdbPredicates: RdbPredicates, columns: Array): Promise; + /** + * Queries data in the database based on SQL statement. + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param sql Indicates the SQL statement to execute. + * @param columns Indicates the columns to query. If the value is null, the query applies to all columns. + * @return Returns a ResultSet object if the operation is successful; + */ + querySql(sql: string, columns: Array, callback: AsyncCallback): void; + querySql(sql: string, columns?: Array): Promise; + /** * Executes an SQL statement that contains specified parameters but returns no value. * -- Gitee From 654d10fe54214688c3d79eaa50af102a10fe23c5 Mon Sep 17 00:00:00 2001 From: mangtsang Date: Mon, 3 Jan 2022 12:45:24 +0800 Subject: [PATCH 2/3] add multiple tables query interfaces by appdatamgr Signed-off-by: mangtsang --- api/@ohos.data.rdb.d.ts | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index 37034e74ae..93b6ac4558 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -589,6 +589,89 @@ declare namespace rdb { * @return Returns RdbPredicates that matches the specified field. */ notIn(field: string, value: Array): RdbPredicates; + + + /** + * Adds a {@code cross join} condition to a SQL statement. + * + *

In SQLite, you can use cross joins to associate two unrelated tables. The cross join joins every row from + * the first table with every row from the second table, and the result set is the product of rows in both tables. + * Exercise caution when using cross joins during application development because they will exert heavy load on + * memory and subsequent data processing. + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param tableName Indicates the names of the tables to join. + * @return Returns the predicate with the {@code cross join} condition. + */ + crossJoin(tableName: string): RdbPredicates; + + /** + * Adds an {@code inner join} condition to a SQL statement. + * + *

In SQLite, you can use inner joins to query data from two related tables. The inner join selects all the rows + * to display in the result set from the related tables only if both tables meet the conditions specified in + * the ON clause. The inner joins are syntactically equivalent to the cross joins. Note that inner joins must be + * used together with {@link RdbPredicates#on(string...)}. Otherwise, use {@link RdbPredicates#crossJoin(string)} + * instead. + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param tableName Indicates the names of the tables to join. + * @return Returns the predicate with the {@code inner join} condition. + */ + innerJoin(tableName: string): RdbPredicates; + + /** + * Adds a {@code left outer join} condition to a SQL statement. + * + *

The left join or left outer join allows you to query data from tables A and B and returns the inner joins + * between A and B and the unmatched rows of A. A is the first join defined in the clause, and is + * therefore left join. + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param tableName Indicates the names of the tables to join. + * @return Returns the predicate with the {@code left outer join} condition. + */ + leftOuterJoin(tableName: string): RdbPredicates; + + /** + * Adds a {@code using} condition to the predicate. This method is similar to {@code using} of the SQL statement. + * + *

{@code using} is the abbreviation of the specified join condition in the left join + * {@link RdbPredicates#leftOuterJoin} or inner join {@link RdbPredicates#innerJoin}. + * When adding the {@code using} condition, ensure that the specified columns exist in both tables. + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param fields Indicates the column names in the database table. + * @return Returns the predicate with the {@code using} condition. + */ + using(...fields: Array): RdbPredicates; + + /** + * Adds an {@code on} condition to the predicate. + * + *

{@code on} is used to set the join conditions of multiple tables when obtaining the join type. It is used + * with the left join {@link RdbPredicates#leftOuterJoin} or inner join {@link RdbPredicates#innerJoin}. + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param clauses Indicates the conditions of the join clauses. + * @return Returns the predicate with the {@code on} condition. + */ + on(...clauses: Array): RdbPredicates; } } -- Gitee From ced41205bf272ea5a11d5e413cc09ff788dc9dd8 Mon Sep 17 00:00:00 2001 From: mangtsang Date: Tue, 4 Jan 2022 14:10:19 +0800 Subject: [PATCH 3/3] update to optional args Signed-off-by: mangtsang --- api/@ohos.data.rdb.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index 93b6ac4558..4215bf0bb4 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -121,7 +121,7 @@ declare namespace rdb { * @return Returns a ResultSet object if the operation is successful; */ query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback): void; - query(rdbPredicates: RdbPredicates, columns: Array): Promise; + query(rdbPredicates: RdbPredicates, columns?: Array): Promise; /** * Queries data in the database based on SQL statement. @@ -131,11 +131,11 @@ declare namespace rdb { * @sysCap SystemCapability.Data.DATA_APPDATAMGR * @devices phone, tablet, tv, wearable, car * @param sql Indicates the SQL statement to execute. - * @param columns Indicates the columns to query. If the value is null, the query applies to all columns. + * @param bindArgs Indicates the values of the parameters in the SQL statement. The values are strings. * @return Returns a ResultSet object if the operation is successful; */ - querySql(sql: string, columns: Array, callback: AsyncCallback): void; - querySql(sql: string, columns?: Array): Promise; + querySql(sql: string, bindArgs: Array, callback: AsyncCallback): void; + querySql(sql: string, bindArgs?: Array): Promise; /** * Executes an SQL statement that contains specified parameters but returns no value. @@ -148,7 +148,7 @@ declare namespace rdb { * @param bindArgs Indicates the values of the parameters in the SQL statement. The values are strings. */ executeSql(sql: string, bindArgs: Array, callback: AsyncCallback): void; - executeSql(sql: string, bindArgs: Array): Promise; + executeSql(sql: string, bindArgs?: Array): Promise; /** * change the encrypted key(not null) if the database is configured with encrypted key. -- Gitee