diff --git a/api/@ohos.application.DataShareExtensionAbility.d.ts b/api/@ohos.application.DataShareExtensionAbility.d.ts index 4293b42d0484ba9c116167de5238f5baee8b87d2..25fb04f05361be0c938a5921559c5229ab676c47 100644 --- a/api/@ohos.application.DataShareExtensionAbility.d.ts +++ b/api/@ohos.application.DataShareExtensionAbility.d.ts @@ -14,11 +14,10 @@ */ import { AsyncCallback } from "./basic"; -import { ResultSet } from './data/rdb/resultSet'; import ExtensionContext from "./application/ExtensionContext"; import Want from './@ohos.application.Want'; -import dataAbility from './@ohos.data.dataAbility'; -import rdb from './@ohos.data.rdb'; +import DataSharePredicates from './@ohos.data.DataSharePredicates'; +import { ValuesBucket } from './@ohos.data.ValuesBucket'; /** * class of datashare extension ability. @@ -29,22 +28,6 @@ import rdb from './@ohos.data.rdb'; * @StageModelOnly */ export default class DataShareExtensionAbility { - /** - * Opens a file in a specified remote path. - * - * @since 9 - * @syscap SystemCapability.DistributedDataManager.DataShare.Provider - * @param uri Indicates the path of the file to open. - * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access - * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing - * file, "wa" for write-only access to append to any existing data, "rw" for read and write access on - * any existing data, or "rwt" for read and write access that truncates any existing file. - * @param callback Indicates the callback when openfile success - * @return Returns the file descriptor. - * @StageModelOnly - */ - openFile(uri: string, mode: string, callback: AsyncCallback): void; - openFile(uri: string, mode: string): Promise; /** * Indicates datashare extension ability context. * @@ -68,21 +51,21 @@ export default class DataShareExtensionAbility { onCreate?(want: Want): void; /** - * Obtains the MIME type of files. This method should be implemented by a data share. + * Opens a file in a specified remote path. * * @since 9 * @syscap SystemCapability.DistributedDataManager.DataShare.Provider - * @param uri Indicates the path of the files to obtain. - * @param mimeTypeFilter Indicates the MIME type of the files to obtain. This parameter cannot be set to {@code - * null}. - *

1. "*/*": Obtains all types supported by a data share. - *

2. "image/*": Obtains files whose main type is image of any subtype. - *

3. "*/jpg": Obtains files whose subtype is JPG of any main type. - * @systemapi Hide this for inner system use. - * @return Returns the MIME type of the matched files; returns null if there is no type that matches the Data + * @param uri Indicates the path of the file to open. + * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access + * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing + * file, "wa" for write-only access to append to any existing data, "rw" for read and write access on + * any existing data, or "rwt" for read and write access that truncates any existing file. + * @param callback Indicates the callback when openfile success + * @return Returns the file descriptor. * @StageModelOnly */ - getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback>): void; + openFile(uri: string, mode: string, callback: AsyncCallback): void; + openFile(uri: string, mode: string): Promise; /** * Inserts a data record into the database. This method should be implemented by a data share. @@ -95,23 +78,7 @@ export default class DataShareExtensionAbility { * @return Returns the index of the newly inserted data record. * @StageModelOnly */ - insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback): void; - - /** - * Updates one or more data records in the database. This method should be implemented by a data share. - * - * @since 9 - * @syscap SystemCapability.DistributedDataManager.DataShare.Provider - * @param uri Indicates the database table storing the data to update. - * @param valueBucket Indicates the data to update. This parameter can be null. - * @param predicates Indicates filter criteria. If this parameter is null, all data records will be updated by - * default. - * @systemapi Hide this for inner system use. - * @return Returns the number of data records updated. - * @StageModelOnly - */ - update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, - callback: AsyncCallback): void; + insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback): void; /** * Deletes one or more data records. This method should be implemented by a data share. @@ -125,7 +92,7 @@ export default class DataShareExtensionAbility { * @return Returns the number of data records deleted. * @StageModelOnly */ - delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback): void; + delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback): void; /** * Queries one or more data records in the database. This method should be implemented by a data share. @@ -133,16 +100,45 @@ export default class DataShareExtensionAbility { * @since 9 * @syscap SystemCapability.DistributedDataManager.DataShare.Provider * @param uri Indicates the database table storing the data to query. - * @param columns Indicates the columns to be queried, in array, for example, {"name","age"}. You should define - * the processing logic when this parameter is null. * @param predicates Indicates filter criteria. If this parameter is null, all data records will be queried by * default. + * @param columns Indicates the columns to be queried, in array, for example, {"name","age"}. You should define + * the processing logic when this parameter is null. * @systemapi Hide this for inner system use. * @return Returns the queried data. * @StageModelOnly */ - query?(uri: string, columns: Array, predicates: dataAbility.DataAbilityPredicates, - callback: AsyncCallback): void; + query?(uri: string, predicates: DataSharePredicates, columns: Array, callback: AsyncCallback): void; + + /** + * Updates one or more data records in the database. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @param uri Indicates the database table storing the data to update. + * @param valueBucket Indicates the data to update. This parameter can be null. + * @param predicates Indicates filter criteria. If this parameter is null, all data records will be updated by + * default. + * @systemapi Hide this for inner system use. + * @return Returns the number of data records updated. + * @StageModelOnly + */ + update?(uri: string, valueBucket: ValuesBucket, predicates: DataSharePredicates, + callback: AsyncCallback): void; + + /** + * Inserts multiple data records into the database. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @param uri Indicates the position where the data is to insert. + * @param valueBuckets Indicates the data to insert. + * @systemapi Hide this for inner system use. + * @return Returns the number of data records inserted. + * @StageModelOnly + */ + batchInsert?(uri: string, valueBuckets: Array, + callback: AsyncCallback): void; /** * Obtains the MIME type matching the data specified by the URI of the data share. This method should be @@ -160,17 +156,21 @@ export default class DataShareExtensionAbility { getType?(uri: string, callback: AsyncCallback): void; /** - * Inserts multiple data records into the database. This method should be implemented by a data share. + * Obtains the MIME type of files. This method should be implemented by a data share. * * @since 9 * @syscap SystemCapability.DistributedDataManager.DataShare.Provider - * @param uri Indicates the position where the data is to insert. - * @param valueBuckets Indicates the data to insert. + * @param uri Indicates the path of the files to obtain. + * @param mimeTypeFilter Indicates the MIME type of the files to obtain. This parameter cannot be set to {@code + * null}. + *

1. "*/*": Obtains all types supported by a data share. + *

2. "image/*": Obtains files whose main type is image of any subtype. + *

3. "*/jpg": Obtains files whose subtype is JPG of any main type. * @systemapi Hide this for inner system use. - * @return Returns the number of data records inserted. + * @return Returns the MIME type of the matched files; returns null if there is no type that matches the Data * @StageModelOnly */ - batchInsert?(uri: string, valueBuckets: Array, callback: AsyncCallback): void; + getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback>): void; /** * Converts the given {@code uri} that refer to the data share into a normalized URI. A normalized URI can be diff --git a/api/@ohos.data.DataSharePredicates.d.ts b/api/@ohos.data.DataSharePredicates.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1122bc0d6880e56006d739e1afad9265da1a1c8b --- /dev/null +++ b/api/@ohos.data.DataSharePredicates.d.ts @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ValueType } from './@ohos.data.ValuesBucket'; + +/** + * Manages relational database configurations. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import import data_dataShare from '@ohos.data.dataShare'; + * @permission N/A + */ +export default class DataSharePredicates { + /** + * Configures the DataSharePredicates to match the field whose data type is ValueType and value is equal + * to a specified value. + * + * @note This method is similar to = of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataSharePredicates. + * @return Returns the DataSharePredicates that match the specified field. + */ + equalTo(field: string, value: ValueType): DataSharePredicates; + + /** + * Configures the DataSharePredicates to match the field whose data type is ValueType and value is unequal to + * a specified value. + * + * @note This method is similar to != of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataSharePredicates. + * @return Returns the DataSharePredicates that match the specified field. + */ + notEqualTo(field: string, value: ValueType): DataSharePredicates; + + /** + * Adds a left parenthesis to the DataSharePredicates. + * + * @note This method is similar to ( of the SQL statement and needs to be used together with endWrap(). + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns the DataSharePredicates with the left parenthesis. + */ + beginWrap(): DataSharePredicates; + + /** + * Adds a right parenthesis to the DataSharePredicates. + * + * @note This method is similar to ) of the SQL statement and needs to be used together + * with beginWrap(). + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns the DataSharePredicates with the right parenthesis. + */ + endWrap(): DataSharePredicates; + + /** + * Adds an or condition to the DataSharePredicates. + * + * @note This method is similar to or of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns the DataSharePredicates with the or condition. + */ + or(): DataSharePredicates; + + /** + * Adds an and condition to the DataSharePredicates. + * + * @note This method is similar to and of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns the DataSharePredicates with the and condition. + */ + and(): DataSharePredicates; + /** + * Configures the DataSharePredicates to match the field whose data type is string and value + * contains a specified value. + * + * @note This method is similar to contains of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataSharePredicates. + * @return Returns the DataSharePredicates that match the specified field. + */ + contains(field: string, value: string): DataSharePredicates; + + /** + * Configures the DataSharePredicates to match the field whose data type is string and value starts + * with a specified string. + * + * @note This method is similar to value% of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataSharePredicates. + * @return Returns the DataSharePredicates that match the specified field. + */ + beginsWith(field: string, value: string): DataSharePredicates; + + /** + * Configures the DataSharePredicates to match the field whose data type is string and value + * ends with a specified string. + * + * @note This method is similar to %value of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataSharePredicates. + * @return Returns the DataSharePredicates that match the specified field. + */ + endsWith(field: string, value: string): DataSharePredicates; + + /** + * Configures the DataSharePredicates to match the fields whose value is null. + * + * @note This method is similar to is null of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @return Returns the DataSharePredicates that match the specified field. + */ + isNull(field: string): DataSharePredicates; + + /** + * Configures the DataSharePredicates to match the specified fields whose value is not null. + * + * @note This method is similar to is not null of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @return Returns the DataSharePredicates that match the specified field. + */ + isNotNull(field: string): DataSharePredicates; + + /** + * Configures the DataSharePredicates to match the fields whose data type is string and value is + * similar to a specified string. + * + * @note This method is similar to like of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataSharePredicates. The percent sign (%) in the value + * is a wildcard (like * in a regular expression). + * @return Returns the DataSharePredicates that match the specified field. + */ + like(field: string, value: string): DataSharePredicates; + + /** + * Configures the DataSharePredicates to match the fields whose data type is string and value is + * similar to a specified string. + * + * @note This method is similar to unlike of the SQL statement. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataSharePredicates. The percent sign (%) in the value + * is a wildcard (like * in a regular expression). + * @return Returns the DataSharePredicates that match the specified field. + */ + unlike(field: string, value: string): DataSharePredicates; + + /** + * Configures DataSharePredicates to match the specified field whose data type is string and the value contains + * a wildcard. + * + * @note Different from like, the input parameters of this method are case-sensitive. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with DataSharePredicates. + * @return Returns the SQL statement with the specified DataSharePredicates. + */ + glob(field: string, value: string): DataSharePredicates; + + /** + * Restricts the value of the field to the range between low value and high value. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name. + * @param low Indicates the minimum value. + * @param high Indicates the maximum value. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + between(field: string, low: ValueType, high: ValueType): DataSharePredicates; + + /** + * Configures DataSharePredicates to match the specified field whose data type is int and value is + * out of a given range. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param low Indicates the minimum value to match with DataSharePredicates. + * @param high Indicates the maximum value to match with DataSharePredicates. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + notBetween(field: string, low: ValueType, high: ValueType): DataSharePredicates; + + /** + * Restricts the value of the field to be greater than the specified value. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + greaterThan(field: string, value: ValueType): DataSharePredicates; + + /** + * Restricts the value of the field to be smaller than the specified value. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + lessThan(field: string, value: ValueType): DataSharePredicates; + + /** + * Restricts the value of the field to be greater than or equal to the specified value. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + greaterThanOrEqualTo(field: string, value: ValueType): DataSharePredicates; + + /** + * Restricts the value of the field to be smaller than or equal to the specified value. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + lessThanOrEqualTo(field: string, value: ValueType): DataSharePredicates; + + /** + * Restricts the ascending order of the return list. When there are several orders, + * the one close to the head has the highest priority. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name for sorting the return list. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + orderByAsc(field: string): DataSharePredicates; + + /** + * Restricts the descending order of the return list. When there are several orders, + * the one close to the head has the highest priority. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name for sorting the return list. + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + orderByDesc(field: string): DataSharePredicates; + + /** + * Restricts each row of the query result to be unique. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns the SQL query statement with the specified DataSharePredicates. + */ + distinct(): DataSharePredicates; + + /** + * Construct a query object to specify the number of results and the starting position. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param total Represents the specified number of results. + * @param offset Indicates the starting position. + * @return Returns the query object. + */ + limit(total: number, offset: number): DataSharePredicates; + + /** + * Configures {@code DataSharePredicates} to group query results by specified columns. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param fields Indicates the specified columns by which query results are grouped. + * @return Returns the DataSharePredicates with the specified columns by which query results are grouped. + */ + groupBy(fields: Array): DataSharePredicates; + + /** + * Configures {@code DataSharePredicates} to specify the index column. + * + * @note Before using this method, you need to create an index column. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the name of the index column. + * @return Returns DataSharePredicates with the specified index column. + */ + indexedBy(field: string): DataSharePredicates; + + /** + * Configures {@code DataSharePredicates} to match the specified field whose data type is ValueType array and values + * are within a given range. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param values Indicates the values to match with DataSharePredicates. + * @return Returns DataSharePredicates that matches the specified field. + */ + in(field: string, value: Array): DataSharePredicates; + + /** + * Configures {@code DataSharePredicates} to match the specified field whose data type is String array and values + * are out of a given range. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param field Indicates the column name in the database table. + * @param values Indicates the values to match with DataSharePredicates. + * @return Returns DataSharePredicates that matches the specified field. + */ + notIn(field: string, value: Array): DataSharePredicates; + + /** + * Configures {@code DataSharePredicates} Creates a query condition using the specified key prefix. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param prefix Represents the specified key prefix. + * @return Returns the query object. + */ + prefixKey(prefix: string): DataSharePredicates; + + /** + * Configures {@code DataSharePredicates} to match the specified value whose key is within a given range. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param keys Represents the key names. + * @return Returns the query object. + */ + inKeys(keys: Array): DataSharePredicates; +} diff --git a/api/@ohos.data.DataShareResultSet.d.ts b/api/@ohos.data.DataShareResultSet.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..b451cc427bcb57418bf1c9acf416872eec5764a0 --- /dev/null +++ b/api/@ohos.data.DataShareResultSet.d.ts @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Indicates the {@code DataType}. + * + *

{@code DataType} is obtained based on the value. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + */ +export enum DataType { + /** + * Indicates that the data type is null. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + */ + TYPE_NULL = 0, + + /** + * Indicates that the data type is long. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + */ + TYPE_LONG = 1, + + /** + * Indicates that the data type is double. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + */ + TYPE_DOUBLE = 2, + + /** + * Indicates that the data type is byte string. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + * */ + TYPE_STRING = 3, + + /** + * Indicates that the data type is blob. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + * */ + TYPE_BLOB = 4 +} + +/** + * Provides methods for accessing a datashare result set generated by querying the database. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ +export default interface DataShareResultSet { + /** + * Obtains the names of all columns or keys in a result set. + * + * @note The column or key names are returned as a string array, in which the strings are in the same order + * as the columns or keys in the result set. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + columnNames: Array; + + /** + * Obtains the number of columns or keys in the result set. + * + * @note The returned number is equal to the length of the string array returned by the columnCount method. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + columnCount: number; + + /** + * Obtains the number of rows in the result set. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + rowCount: number; + + /** + * Checks whether the current result set is closed. + * + * If the result set is closed by calling the close method, true will be returned. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + isClosed: boolean; + + /** + * Go to the first row of the result set. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns true if the result set is moved successfully; + * returns false otherwise, for example, if the result set is empty. + */ + goToFirstRow(): boolean; + + /** + * Go to the last row of the result set. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns true if the result set is moved successfully; + * returns false otherwise, for example, if the result set is empty. + */ + goToLastRow(): boolean; + + /** + * Go to the next row of the result set. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns true if the result set is moved successfully; + * returns false otherwise, for example, if the result set is already in the last row. + */ + goToNextRow(): boolean; + + /** + * Go to the previous row of the result set. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns true if the result set is moved successfully; + * returns false otherwise, for example, if the result set is already in the first row. + */ + goToPreviousRow(): boolean; + + /** + * Go to the specified row of the result set forwards or backwards by an offset relative to its current position. + * A positive offset indicates moving backwards, and a negative offset indicates moving forwards. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param offset Indicates the offset relative to the current position. + * @return Returns true if the result set is moved successfully and does not go beyond the range; + * returns false otherwise. + */ + goTo(offset: number): boolean; + + /** + * Go to the specified row of the result set. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param position Indicates the index of the specified row, which starts from 1. + * @return Returns true if the result set is moved successfully; returns false otherwise. + */ + goToRow(position: number): boolean; + + /** + * Obtains the value of the specified column or key in the current row as a byte array. + * + * @note The implementation class determines whether to throw an exception if the value of the specified + * column or key in the current row is null or the specified column or key is not of the Blob type. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param columnIndex Indicates the specified column index or key index, which starts from 0. + * @return Returns the value of the specified column or key as a byte array. + */ + getBlob(columnIndex: number): Uint8Array; + + /** + * Obtains the value of the specified column or key in the current row as string. + * + * @note The implementation class determines whether to throw an exception if the value of the specified + * column or key in the current row is null or the specified column or key is not of the string type. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param columnIndex Indicates the specified column index or key index, which starts from 0. + * @return Returns the value of the specified column or key as a string. + */ + getString(columnIndex: number): string; + + /** + * Obtains the value of the specified column or key in the current row as long. + * + * @note The implementation class determines whether to throw an exception if the value of the specified + * column or key in the current row is null, the specified column or key is not of the long type. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param columnIndex Indicates the specified column index or key index, which starts from 0. + * @return Returns the value of the specified column or key as a long. + */ + getLong(columnIndex: number): number; + + /** + * Obtains the value of the specified column or key in the current row as double. + * + * @note The implementation class determines whether to throw an exception if the value of the specified + * column or key in the current row is null, the specified column or key is not of the double type. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param columnIndex Indicates the specified column index or key index, which starts from 0. + * @return Returns the value of the specified column or key as a double. + */ + getDouble(columnIndex: number): number; + + /** + * Closes the result set. + * + * @note Calling this method on the result set will release all of its resources and makes it ineffective. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @return Returns true if the result set is closed; returns false otherwise. + */ + close(): void; + + /** + * Obtains the column index or key index based on the specified column name or key name. + * + * @note The column name or key name is passed as an input parameter. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param columnName Indicates the name of the specified column or key in the result set. + * @return Returns the index of the specified column or key. + */ + getColumnIndex(columnName: string): number; + + /** + * Obtains the column name or key name based on the specified column index or key index. + * + * @note The column index or key index is passed as an input parameter. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param columnIndex Indicates the index of the specified column or key in the result set. + * @return Returns the name of the specified column or key. + */ + getColumnName(columnIndex: number): string; + + /** + * Obtains the dataType of the specified column or key. + * + * @note The implementation class determines whether to throw an exception if the value of the specified + * column or key in the current row is null, the specified column or key is not in the data type. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @param columnIndex Indicates the specified column index or key index, which starts from 0. + * @return Returns the dataType of the specified column or key. + */ + getDataType(columnIndex: number): DataType; +} \ No newline at end of file diff --git a/api/@ohos.data.ValuesBucket.d.ts b/api/@ohos.data.ValuesBucket.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..32a6025be8fb61c86b8a2e4eda04527eeaf0513b --- /dev/null +++ b/api/@ohos.data.ValuesBucket.d.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Indicates possible value types + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + */ +export type ValueType = number | string | boolean; + +/** + * Values in buckets are stored in key-value pairs + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * @import N/A + */ +export type ValuesBucket = { + [key: string]: ValueType | Uint8Array | null; +} \ No newline at end of file diff --git a/api/@ohos.data.dataShare.d.ts b/api/@ohos.data.dataShare.d.ts index 7637fb041c6a6234e17b37f3cc0e4dbaecbb2060..374d1bde49b616570476c5b1c83ce9b5ba319d53 100644 --- a/api/@ohos.data.dataShare.d.ts +++ b/api/@ohos.data.dataShare.d.ts @@ -14,11 +14,11 @@ */ import { AsyncCallback } from './basic'; -import Want from './@ohos.application.want'; -import { ResultSet } from './data/rdb/resultSet'; +import { Want } from './ability/want'; import Context from './application/Context'; -import dataAbility from './@ohos.data.dataAbility'; -import rdb from './@ohos.data.rdb'; +import DataShareResultSet from './@ohos.data.DataShareResultSet'; +import DataSharePredicates from './@ohos.data.DataSharePredicates'; +import { ValuesBucket } from './@ohos.data.ValuesBucket'; declare namespace dataShare { /** @@ -30,7 +30,8 @@ declare namespace dataShare { * @param uri Indicates the path of the file to open. * @return Returns the dataShareHelper. */ - function createDataShareHelper(context: Context, want: Want, uri: string): DataShareHelper; + function createDataShareHelper(context: Context, want: Want, uri: string, callback: AsyncCallback): void; + function createDataShareHelper(context: Context, want: Want, uri: string): Promise; /** * DataShareHelper @@ -55,6 +56,7 @@ declare namespace dataShare { */ openFile(uri: string, mode: string, callback: AsyncCallback): void; openFile(uri: string, mode: string): Promise; + /** * Registers an observer to observe data specified by the given uri. * @since 9 @@ -88,8 +90,8 @@ declare namespace dataShare { * @return Returns the index of the inserted data record. * @StageModelOnly */ - insert(uri: string, value: rdb.ValuesBucket, callback: AsyncCallback): void; - insert(uri: string, value: rdb.ValuesBucket): Promise; + insert(uri: string, value: ValuesBucket, callback: AsyncCallback): void; + insert(uri: string, value: ValuesBucket): Promise; /** * Deletes one or more data records from the database. @@ -100,22 +102,21 @@ declare namespace dataShare { * @return Returns the number of data records deleted. * @StageModelOnly */ - delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback): void; - delete(uri: string, predicates: dataAbility.DataAbilityPredicates): Promise; - + delete(uri: string, predicates: DataSharePredicates, callback: AsyncCallback): void; + delete(uri: string, predicates: DataSharePredicates): Promise; /** * Queries data in the database. * @since 9 * @syscap SystemCapability.DistributedDataManager.DataShare.Consumer * @param uri Indicates the path of data to query. - * @param columns Indicates the columns to query. If this parameter is null, all columns are queried. * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. + * @param columns Indicates the columns to query. If this parameter is null, all columns are queried. * @return Returns the query result. * @StageModelOnly */ - query(uri: string, columns: Array, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback): void; - query(uri: string, columns: Array, predicates: dataAbility.DataAbilityPredicates): Promise; + query(uri: string, predicates: DataSharePredicates, columns: Array, callback: AsyncCallback): void; + query(uri: string, predicates: DataSharePredicates, columns: Array): Promise; /** * Updates data records in the database. @@ -127,9 +128,8 @@ declare namespace dataShare { * @return Returns the number of data records updated. * @StageModelOnly */ - update(uri: string, value: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback): void; - update(uri: string, value: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): Promise; - + update(uri: string, value: ValuesBucket, predicates: DataSharePredicates, callback: AsyncCallback): void; + update(uri: string, value: ValuesBucket, predicates: DataSharePredicates): Promise; /** * Inserts multiple data records into the database. @@ -140,8 +140,8 @@ declare namespace dataShare { * @return Returns the number of data records inserted. * @StageModelOnly */ - batchInsert(uri: string, values: Array, callback: AsyncCallback): void; - batchInsert(uri: string, values: Array): Promise; + batchInsert(uri: string, values: Array, callback: AsyncCallback): void; + batchInsert(uri: string, values: Array): Promise; /** * Obtains the MIME type of the date specified by the given uri. @@ -170,7 +170,7 @@ declare namespace dataShare { getFileTypes(uri: string, mimeTypeFilter: string): Promise>; /** - * Converts the given {@code uri} that refers to the Data ability into a normalized {@link ohos.utils.net.Uri}. + * Converts the given {@code uri} that refers to the DataShare into a normalized {@link ohos.utils.net.Uri}. * A normalized uri can be used across devices, persisted, backed up, and restored. *

To transfer a normalized uri from another environment to the current environment, you should call this * method again to re-normalize the uri for the current environment or call {@link #denormalizeUri(Uri)} @@ -178,7 +178,7 @@ declare namespace dataShare { * @since 9 * @syscap SystemCapability.DistributedDataManager.DataShare.Consumer * @param uri Indicates the {@link ohos.utils.net.Uri} object to normalize. - * @return Returns the normalized {@code Uri} object if the Data ability supports uri normalization; + * @return Returns the normalized {@code Uri} object if the DataShare supports uri normalization; * returns {@code null} otherwise. * @throws DataShareRemoteException Throws this exception if the remote process exits. * @throws NullPointerException Throws this exception if {@code uri} is null. diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index 0244e6b8c120c6caff4170bc8dcf679848f36cd8..42724c758c602e8326f0d3b6b87fbe1a9460fcc3 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -16,6 +16,8 @@ import {AsyncCallback, Callback} from './basic'; import { ResultSet } from './data/rdb/resultSet'; import Context from "./application/Context"; +import DataSharePredicates from './@ohos.data.DataSharePredicates'; +import { ValueType, ValuesBucket } from './@ohos.data.ValuesBucket'; /** * Provides methods for rdbStore create and delete. @@ -123,6 +125,19 @@ declare namespace rdb { insert(name: string, values: ValuesBucket, callback: AsyncCallback): void; insert(name: string, values: ValuesBucket): Promise; + /** + * Inserts a row of data into the target table. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core + * @param name Indicates the target table. + * @param values Indicates the row of data to be inserted into the table. + * @return Returns the row ID if the operation is successful; returns -1 otherwise. + */ + insert(name: string, values: ValuesBucket, callback: AsyncCallback): void; + insert(name: string, values: ValuesBucket): Promise; + /** * Updates data in the database based on a a specified instance object of rdbPredicates. * @@ -136,6 +151,20 @@ declare namespace rdb { update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback): void; update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise; + /** + * Updates data in the database based on a a specified instance object of rdbPredicates. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core + * @param name Indicates the target table. + * @param values Indicates the row of data to be updated in the database.The key-value pairs are associated with column names of the database table. + * @param predicates Indicates the specified update condition by the instance object of RdbPredicates. + * @return Returns the number of affected rows. + */ + update(name: string, values: ValuesBucket, predicates: DataSharePredicates, callback: AsyncCallback): void; + update(name: string, values: ValuesBucket, predicates: DataSharePredicates): Promise; + /** * Deletes data from the database based on a specified instance object of rdbPredicates. * @@ -148,6 +177,19 @@ declare namespace rdb { delete(rdbPredicates: RdbPredicates, callback: AsyncCallback): void; delete(rdbPredicates: RdbPredicates): Promise; + /** + * Deletes data from the database based on a specified instance object of rdbPredicates. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core + * @param name Indicates the target table. + * @param predicates Indicates the specified delete condition by the instance object of RdbPredicates. + * @return Returns the number of affected rows. + */ + delete(name: string, predicates: DataSharePredicates, callback: AsyncCallback): void; + delete(name: string, predicates: DataSharePredicates): Promise; + /** * Queries data in the database based on specified conditions. * @@ -161,6 +203,19 @@ declare namespace rdb { query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback): void; query(rdbPredicates: RdbPredicates, columns?: Array): Promise; + /** + * Queries data in the database based on specified conditions. + * + * @note N/A + * @since 9 + * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core + * @param predicates Indicates the specified query condition by the instance object of RdbPredicates. + * @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; + */ + query(name: string, predicates: DataSharePredicates, columns: Array, callback: AsyncCallback): void; + query(name: string, predicates: DataSharePredicates, columns?: Array): Promise; + /** * Queries data in the database based on SQL statement. * @@ -280,26 +335,6 @@ declare namespace rdb { off(event:'dataChange', type: SubscribeType, observer: Callback>): void; } - /** - * Indicates possible value types - * - * @since 7 - * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core - * @import import data_rdb from '@ohos.data.rdb'; - */ - type ValueType = number | string | boolean; - - /** - * Values in buckets are stored in key-value pairs - * - * @since 7 - * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core - * @import import data_rdb from '@ohos.data.rdb'; - */ - type ValuesBucket = { - [key: string]: ValueType | Uint8Array | null; - } - /** * Manages relational database configurations. *