diff --git a/api/@ohos.application.DataShareExtensionAbility.d.ts b/api/@ohos.application.DataShareExtensionAbility.d.ts index 4293b42d0484ba9c116167de5238f5baee8b87d2..d1b5009136937631dfbfaa835dcfffea9f11ccc1 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. * @@ -65,7 +48,7 @@ export default class DataShareExtensionAbility { * @return - * @StageModelOnly */ - onCreate?(want: Want): void; + onCreate?(want: Want, callback: AsyncCallback): void; /** * Obtains the MIME type of files. This method should be implemented by a data share. @@ -84,6 +67,22 @@ export default class DataShareExtensionAbility { */ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback>): void; + /** + * 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; + /** * Inserts a data record into the database. This method should be implemented by a data share. * @@ -95,7 +94,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; + insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback): void; /** * Updates one or more data records in the database. This method should be implemented by a data share. @@ -103,14 +102,14 @@ export default class DataShareExtensionAbility { * @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. + * @param valueBucket Indicates the data to update. This parameter can be null. * @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, + update?(uri: string, predicates: DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback): void; /** @@ -125,24 +124,25 @@ 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. * + * @note Only RDB and distributed KVDB resultsets are supported. The current version does not support custom resultsets. * @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. + * @return Returns the queried data, only support result set of rdb or kvstore. * @StageModelOnly */ - query?(uri: string, columns: Array, predicates: dataAbility.DataAbilityPredicates, - callback: AsyncCallback): void; + query?(uri: string, predicates: DataSharePredicates, columns: Array, + callback: AsyncCallback): void; /** * Obtains the MIME type matching the data specified by the URI of the data share. This method should be @@ -170,7 +170,7 @@ export default class DataShareExtensionAbility { * @return Returns the number of data records inserted. * @StageModelOnly */ - batchInsert?(uri: string, valueBuckets: Array, callback: AsyncCallback): void; + batchInsert?(uri: string, valueBuckets: Array, 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..e75193a0d6950e5113dec894d8073ec125d140ae --- /dev/null +++ b/api/@ohos.data.DataSharePredicates.d.ts @@ -0,0 +1,369 @@ +/* + * 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'; + */ +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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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..0e1d089768555e742be573a364f24ae1ec32eaab --- /dev/null +++ b/api/@ohos.data.DataShareResultSet.d.ts @@ -0,0 +1,258 @@ +/* + * 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 + */ +export enum DataType { + /** + * Indicates that the data type is null. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + TYPE_NULL = 0, + + /** + * Indicates that the data type is long. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + TYPE_LONG = 1, + + /** + * Indicates that the data type is double. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + TYPE_DOUBLE = 2, + + /** + * Indicates that the data type is byte string. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * */ + TYPE_STRING = 3, + + /** + * Indicates that the data type is blob. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + * */ + 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. + * + * @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. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ + isClosed: boolean; + + /** + * Go to the first row of the result set. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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. + * + * @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..10727c1eec4a221b5475e680fb86c5cc056fb061 --- /dev/null +++ b/api/@ohos.data.ValuesBucket.d.ts @@ -0,0 +1,32 @@ +/* + * 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 + */ +export type ValueType = number | string | boolean; + +/** + * Values in buckets are stored in key-value pairs + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Core + */ +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 0f7490b47d3e1723c0e8c5d42cedc6d8f389cecc..74ea62fb3874264397603ec07e65e10321d9bfec 100644 --- a/api/@ohos.data.dataShare.d.ts +++ b/api/@ohos.data.dataShare.d.ts @@ -14,10 +14,10 @@ */ import { AsyncCallback } from './basic'; -import { ResultSet } from './data/rdb/resultSet'; 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 { /** @@ -28,7 +28,8 @@ declare namespace dataShare { * @param uri Indicates the path of the file to open. * @return Returns the dataShareHelper. */ - function createDataShareHelper(context: Context, uri: string): DataShareHelper; + function createDataShareHelper(context: Context, uri: string, callback: AsyncCallback): void; + function createDataShareHelper(context: Context, uri: string): Promise; /** * DataShareHelper @@ -53,6 +54,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 @@ -86,8 +88,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. @@ -98,36 +100,34 @@ 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. * @since 9 * @syscap SystemCapability.DistributedDataManager.DataShare.Consumer * @param uri Indicates the path of data to update. - * @param value Indicates the data to update. This parameter can be null. * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. + * @param value Indicates the data to update. This parameter can be null. * @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, predicates: DataSharePredicates, value: ValuesBucket, callback: AsyncCallback): void; + update(uri: string, predicates: DataSharePredicates, value: ValuesBucket): Promise; /** * Inserts multiple data records into the database. @@ -138,8 +138,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. @@ -168,7 +168,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)} @@ -176,7 +176,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.