diff --git a/api/@ohos.data.dataAbility.d.ts b/api/@ohos.data.dataAbility.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..76aabb8bd3db4436275bbcccbb5ed1bcec691dfc --- /dev/null +++ b/api/@ohos.data.dataAbility.d.ts @@ -0,0 +1,328 @@ +/* + * Copyright (c) 2021 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 { AsyncCallback } from './basic'; +import rdb from './@ohos.data.rdb'; + +declare namespace dataAbility { + /** + * Create an RdbPredicates by table name and DataAbilityPredicates. + * + * @param name Indicates the table name. + * @param dataAbilityPredicates Indicates the dataAbility predicates. + * @return Returns an RdbPredicates. + * @since 7 + */ + function createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates) : rdb.RdbPredicates; + + /** + * Manages relational database configurations. + * + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @version 7 + */ + class DataAbilityPredicates { + /** + * Configures the DataAbilityPredicates to match the field whose data type is ValueType and value is equal + * to a specified value. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataAbilityPredicates. + * @return Returns the DataAbilityPredicates that match the specified field. + */ + equalTo(field: string, value: ValueType): DataAbilityPredicates; + + /** + * Configures the DataAbilityPredicates to match the field whose data type is ValueType and value is unequal to + * a specified value. + * + * This method is similar to != of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataAbilityPredicates. + * @return Returns the DataAbilityPredicates that match the specified field. + */ + notEqualTo(field: string, value: ValueType): DataAbilityPredicates; + + /** + * Adds a left parenthesis to the DataAbilityPredicates. + * + * This method is similar to ( of the SQL statement and needs to be used together + * with endWrap(). + * + * @return Returns the DataAbilityPredicates with the left parenthesis. + */ + beginWrap(): DataAbilityPredicates; + + /** + * Adds a right parenthesis to the DataAbilityPredicates. + * + * This method is similar to ) of the SQL statement and needs to be used together + * with beginWrap(). + * + * @return Returns the DataAbilityPredicates with the right parenthesis. + */ + endWrap(): DataAbilityPredicates; + + /** + * Adds an or condition to the DataAbilityPredicates. + * + * This method is similar to or of the SQL statement. + * + * @return Returns the DataAbilityPredicates with the or condition. + */ + or(): DataAbilityPredicates; + + /** + * Adds an and condition to the DataAbilityPredicates. + * + * This method is similar to and of the SQL statement. + * + * @return Returns the DataAbilityPredicates with the and condition. + */ + and(): DataAbilityPredicates; + + /** + * Configures the DataAbilityPredicates to match the field whose data type is string and value + * contains a specified value. + * + * This method is similar to contains of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataAbilityPredicates. + * @return Returns the DataAbilityPredicates that match the specified field. + */ + contains(field: string, value: string): DataAbilityPredicates; + + /** + * Configures the DataAbilityPredicates to match the field whose data type is string and value starts + * with a specified string. + * + * This method is similar to value% of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataAbilityPredicates. + * @return Returns the DataAbilityPredicates that match the specified field. + */ + beginsWith(field: string, value: string): DataAbilityPredicates; + + /** + * Configures the DataAbilityPredicates to match the field whose data type is string and value + * ends with a specified string. + * + * This method is similar to %value of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataAbilityPredicates. + * @return Returns the DataAbilityPredicates that match the specified field. + */ + endsWith(field: string, value: string): DataAbilityPredicates; + + /** + * Configures the DataAbilityPredicates to match the fields whose value is null. + * + * This method is similar to is null of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @return Returns the DataAbilityPredicates that match the specified field. + */ + isNull(field: string): DataAbilityPredicates; + + /** + * Configures the DataAbilityPredicates to match the specified fields whose value is not null. + * + * This method is similar to is not null of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @return Returns the DataAbilityPredicates that match the specified field. + */ + isNotNull(field: string): DataAbilityPredicates; + + /** + * Configures the DataAbilityPredicates to match the fields whose data type is string and value is + * similar to a specified string. + * + * This method is similar to like of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the DataAbilityPredicates. The percent sign (%) in the value + * is a wildcard (like * in a regular expression). + * @return Returns the DataAbilityPredicates that match the specified field. + */ + like(field: string, value: string): DataAbilityPredicates; + + /** + * Configures DataAbilityPredicates to match the specified field whose data type is string and the value contains + * a wildcard. + * + * Different from like, the input parameters of this method are case-sensitive. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with DataAbilityPredicates. + * @return Returns the SQL statement with the specified DataAbilityPredicates. + * + */ + glob(field: string, value: string): DataAbilityPredicates; + + /** + * Restricts the value of the field to the range between low value and high value. + * + * @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 DataAbilityPredicates. + */ + between(field: string, low: ValueType, high: ValueType): DataAbilityPredicates; + + /** + * Configures DataAbilityPredicates to match the specified field whose data type is int and value is + * out of a given range. + * + * @param field Indicates the column name in the database table. + * @param low Indicates the minimum value to match with DataAbilityPredicates}. + * @param high Indicates the maximum value to match with DataAbilityPredicates}. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + * + */ + notBetween(field: string, low: ValueType, high: ValueType): DataAbilityPredicates; + + /** + * Restricts the value of the field to be greater than the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + */ + greaterThan(field: string, value: ValueType): DataAbilityPredicates; + + /** + * Restricts the value of the field to be smaller than the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + */ + lessThan(field: string, value: ValueType): DataAbilityPredicates; + + /** + * Restricts the value of the field to be greater than or equal to the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + */ + greaterThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates; + + /** + * Restricts the value of the field to be smaller than or equal to the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + */ + lessThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates; + + /** + * Restricts the ascending order of the return list. When there are several orders, + * the one close to the head has the highest priority. + * + * @param field Indicates the column name for sorting the return list. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + */ + orderByAsc(field: string): DataAbilityPredicates; + + /** + * Restricts the descending order of the return list. When there are several orders, + * the one close to the head has the highest priority. + * + * @param field Indicates the column name for sorting the return list. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + */ + orderByDesc(field: string): DataAbilityPredicates; + + /** + * Restricts each row of the query result to be unique. + * + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + */ + distinct(): DataAbilityPredicates; + + /** + * Restricts the max number of return records. + * + * @param value Indicates the max length of the return list. + * @return Returns the SQL query statement with the specified DataAbilityPredicates. + * @throws IllegalPredicateException Throws this exception if DataAbilityPredicates are added to a wrong position. + */ + limitAs(value: number): DataAbilityPredicates; + + /** + * Configures DataAbilityPredicates to specify the start position of the returned result. + * + * Use this method together with limit(int). + * + * @param rowOffset Indicates the start position of the returned result. The value is a positive integer. + * @return Returns the SQL query statement with the specified AbsPredicates. + * + */ + offsetAs(rowOffset: number): DataAbilityPredicates; + + /** + * Configures DataAbilityPredicates to group query results by specified columns. + * + * @param fields Indicates the specified columns by which query results are grouped. + * @return Returns the DataAbilityPredicates with the specified columns by which query results are grouped. + * + */ + groupBy(fields: Array): DataAbilityPredicates; + + /** + * Configures DataAbilityPredicates to specify the index column. + * + * Before using this method, you need to create an index column. + * + * @param indexName Indicates the name of the index column. + * @return Returns DataAbilityPredicates with the specified index column. + * + */ + indexedBy(field: string): DataAbilityPredicates; + + /** + * Configures DataAbilityPredicates to match the specified field whose data type is ValueType array and values + * are within a given range. + * + * @param field Indicates the column name in the database table. + * @param values Indicates the values to match with DataAbilityPredicates. + * @return Returns DataAbilityPredicates that matches the specified field. + * + */ + in(field: string, value: Array): DataAbilityPredicates; + + /** + * Configures {@code DataAbilityPredicates} to match the specified field whose data type is String array and values + * are out of a given range. + * + * @param field Indicates the column name in the database table. + * @param values Indicates the values to match with DataAbilityPredicates. + * @return Returns DataAbilityPredicates that matches the specified field. + */ + notIn(field: string, value: Array): DataAbilityPredicates; + } + /** + * Indicates possible value types + */ + type ValueType = number | string | boolean; +} + +export default dataAbility; diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..162c2bd3e2cfef6d0cdf6566915de354f21eb18d --- /dev/null +++ b/api/@ohos.data.rdb.d.ts @@ -0,0 +1,436 @@ +/* + * Copyright (c) 2021 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 { AsyncCallback } from './basic'; +import { ResultSet } from './data/rdb/resultSet'; + +declare namespace rdb { + /** + * Obtains an RDB store. + * + * You can set parameters of the RDB store as required. In general, this method is recommended + * to obtain a rdb store. + * + * @param config Indicates the configuration of the database related to this RDB store. The configurations include + * the database path, storage mode, and whether the database is read-only. + * @param version Indicates the database version for upgrade or downgrade. + * @return Returns an RDB store {@link ohos.data.rdb.RdbStore}. + * @since 7 + */ + function getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback): void; + function getRdbStore(config: StoreConfig, version: number): Promise; + + /** + * Deletes the database with a specified name. + * + * @param name Indicates the database name. + * @return Returns true if the database is deleted; returns false otherwise. + * @since 7 + */ + function deleteRdbStore(name: string, callback: AsyncCallback): void; + function deleteRdbStore(name: string): Promise; + + /** + * Provides methods for managing the relational database (RDB). + * + * This class provides methods for creating, querying, updating, and deleting RDBs. + * + * @devices phone, tablet, tv, wearable, car + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @version 7 + */ + interface RdbStore { + /** + * Inserts a row of data into the target table. + * + * @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. + * @since 7 + */ + 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. + * + * @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 rdbPredicates Indicates the specified update condition by the instance object of RdbPredicates. + * @return Returns the number of affected rows. + * @since 7 + */ + update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback): void; + update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise; + + /** + * Deletes data from the database based on a specified instance object of rdbPredicates. + * + * @param rdbPredicates Indicates the specified delete condition by the instance object of RdbPredicates. + * @return Returns the number of affected rows. + * @since 7 + */ + delete(rdbPredicates: RdbPredicates, callback: AsyncCallback): void; + delete(rdbPredicates: RdbPredicates): Promise; + + /** + * Queries data in the database based on specified conditions. + * + * @param rdbPredicates 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; + * @since 7 + */ + query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback): void; + query(rdbPredicates: RdbPredicates, columns: Array): Promise; + + /** + * Executes an SQL statement that contains specified parameters but returns no value. + * + * @param sql Indicates the SQL statement to execute. + * @param bindArgs Indicates the values of the parameters in the SQL statement. The values are strings. + * @since 7 + */ + executeSql(sql: string, bindArgs: Array, callback: AsyncCallback): void; + executeSql(sql: string, bindArgs: Array): Promise; + } + + /** + * Indicates possible value types + */ + type ValueType = number | string | boolean; + + /** + * Values in buckets are stored in key-value pairs + */ + type ValuesBucket = { + [key: string]: ValueType | Uint8Array | null; + } + + /** + * Manages relational database configurations. + * + * @devices phone, tablet, tv, wearable, car + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @version 7 + */ + interface StoreConfig { + /** + * Indicates the name of the database file + */ + name: string; + } + + /** + * Manages relational database configurations. + * + * @devices phone, tablet, tv, wearable, car + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @version 7 + */ + class RdbPredicates { + /** + * A parameterized constructor used to create an RdbPredicates instance. + * name Indicates the table name of the database. + */ + constructor(name: string) + + /** + * Configures the RdbPredicates to match the field whose data type is ValueType and value is equal + * to a specified value. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the RdbPredicates. + * @return Returns the RdbPredicates that match the specified field. + */ + equalTo(field: string, value: ValueType): RdbPredicates; + + /** + * Configures the RdbPredicates to match the field whose data type is ValueType and value is unequal to + * a specified value. + * + * This method is similar to != of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the RdbPredicates. + * @return Returns the RdbPredicates that match the specified field. + */ + notEqualTo(field: string, value: ValueType): RdbPredicates; + + /** + * Adds a left parenthesis to the RdbPredicates. + * + * This method is similar to ( of the SQL statement and needs to be used together + * with endWrap(). + * + * @return Returns the RdbPredicates with the left parenthesis. + */ + beginWrap(): RdbPredicates; + + /** + * Adds a right parenthesis to the RdbPredicates. + * + * This method is similar to ) of the SQL statement and needs to be used together + * with beginWrap(). + * + * @return Returns the RdbPredicates with the right parenthesis. + */ + endWrap(): RdbPredicates; + + /** + * Adds an or condition to the RdbPredicates. + * + * This method is similar to or of the SQL statement. + * + * @return Returns the RdbPredicates with the or condition. + */ + or(): RdbPredicates; + + /** + * Adds an and condition to the RdbPredicates. + * + * This method is similar to and of the SQL statement. + * + * @return Returns the RdbPredicates with the and condition. + */ + and(): RdbPredicates; + + /** + * Configures the RdbPredicates to match the field whose data type is string and value + * contains a specified value. + * + * This method is similar to contains of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the RdbPredicates. + * @return Returns the RdbPredicates that match the specified field. + */ + contains(field: string, value: string): RdbPredicates; + + /** + * Configures the RdbPredicates to match the field whose data type is string and value starts + * with a specified string. + * + * This method is similar to value% of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the RdbPredicates. + * @return Returns the RdbPredicates that match the specified field. + */ + beginsWith(field: string, value: string): RdbPredicates; + + /** + * Configures the RdbPredicates to match the field whose data type is string and value + * ends with a specified string. + * + * This method is similar to %value of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the RdbPredicates. + * @return Returns the RdbPredicates that match the specified field. + */ + endsWith(field: string, value: string): RdbPredicates; + + /** + * Configures the RdbPredicates to match the fields whose value is null. + * + * This method is similar to is null of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @return Returns the RdbPredicates that match the specified field. + */ + isNull(field: string): RdbPredicates; + + /** + * Configures the RdbPredicates to match the specified fields whose value is not null. + * + * This method is similar to is not null of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @return Returns the RdbPredicates that match the specified field. + */ + isNotNull(field: string): RdbPredicates; + + /** + * Configures the RdbPredicates to match the fields whose data type is string and value is + * similar to a specified string. + * + * This method is similar to like of the SQL statement. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with the RdbPredicates. The percent sign (%) in the value + * is a wildcard (like * in a regular expression). + * @return Returns the RdbPredicates that match the specified field. + */ + like(field: string, value: string): RdbPredicates; + + /** + * Configures RdbPredicates to match the specified field whose data type is string and the value contains + * a wildcard. + * + * Different from like, the input parameters of this method are case-sensitive. + * + * @param field Indicates the column name in the database table. + * @param value Indicates the value to match with RdbPredicates. + * @return Returns the SQL statement with the specified RdbPredicates. + * + */ + glob(field: string, value: string): RdbPredicates; + + /** + * Restricts the value of the field to the range between low value and high value. + * + * @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 RdbPredicates. + */ + between(field: string, low: ValueType, high: ValueType): RdbPredicates; + + /** + * Configures RdbPredicates to match the specified field whose data type is int and value is + * out of a given range. + * + * @param field Indicates the column name in the database table. + * @param low Indicates the minimum value to match with DataAbilityPredicates}. + * @param high Indicates the maximum value to match with DataAbilityPredicates}. + * @return Returns the SQL query statement with the specified RdbPredicates. + * + */ + notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates; + + /** + * Restricts the value of the field to be greater than the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified RdbPredicates. + */ + greaterThan(field: string, value: ValueType): RdbPredicates; + + /** + * Restricts the value of the field to be smaller than the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified RdbPredicates. + */ + lessThan(field: string, value: ValueType): RdbPredicates; + + /** + * Restricts the value of the field to be greater than or equal to the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified RdbPredicates. + */ + greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates; + + /** + * Restricts the value of the field to be smaller than or equal to the specified value. + * + * @param field Indicates the column name. + * @param value Indicates the String field. + * @return Returns the SQL query statement with the specified RdbPredicates. + */ + lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates; + + /** + * Restricts the ascending order of the return list. When there are several orders, + * the one close to the head has the highest priority. + * + * @param field Indicates the column name for sorting the return list. + * @return Returns the SQL query statement with the specified RdbPredicates. + */ + orderByAsc(field: string): RdbPredicates; + + /** + * Restricts the descending order of the return list. When there are several orders, + * the one close to the head has the highest priority. + * + * @param field Indicates the column name for sorting the return list. + * @return Returns the SQL query statement with the specified RdbPredicates. + */ + orderByDesc(field: string): RdbPredicates; + + /** + * Restricts each row of the query result to be unique. + * + * @return Returns the SQL query statement with the specified RdbPredicates. + */ + distinct(): RdbPredicates; + + /** + * Restricts the max number of return records. + * + * @param value Indicates the max length of the return list. + * @return Returns the SQL query statement with the specified RdbPredicates. + * @throws IllegalPredicateException Throws this exception if RdbPredicates are added to a wrong position. + */ + limitAs(value: number): RdbPredicates; + + /** + * Configures RdbPredicates to specify the start position of the returned result. + * + * Use this method together with limit(int). + * + * @param rowOffset Indicates the start position of the returned result. The value is a positive integer. + * @return Returns the SQL query statement with the specified AbsPredicates. + * + */ + offsetAs(rowOffset: number): RdbPredicates; + + /** + * Configures RdbPredicates to group query results by specified columns. + * + * @param fields Indicates the specified columns by which query results are grouped. + * @return Returns the RdbPredicates with the specified columns by which query results are grouped. + * + */ + groupBy(fields: Array): RdbPredicates; + + /** + * Configures RdbPredicates to specify the index column. + * + * Before using this method, you need to create an index column. + * + * @param indexName Indicates the name of the index column. + * @return Returns RdbPredicates with the specified index column. + * + */ + indexedBy(field: string): RdbPredicates; + + /** + * Configures RdbPredicates to match the specified field whose data type is ValueType array and values + * are within a given range. + * + * @param field Indicates the column name in the database table. + * @param values Indicates the values to match with RdbPredicates. + * @return Returns RdbPredicates that matches the specified field. + * + */ + in(field: string, value: Array): RdbPredicates; + + /** + * Configures RdbPredicates to match the specified field whose data type is ValueType array and values + * are out of a given range. + * + * @param field Indicates the column name in the database table. + * @param values Indicates the values to match with RdbPredicates. + * @return Returns RdbPredicates that matches the specified field. + */ + notIn(field: string, value: Array): RdbPredicates; + } +} + +export default rdb; diff --git a/api/data/rdb/resultSet.d.ts b/api/data/rdb/resultSet.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..799fdc4474dacc1073c12cb79affc478a3ae1e91 --- /dev/null +++ b/api/data/rdb/resultSet.d.ts @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2021 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 { AsyncCallback } from '../../basic' + +/** +* Provides methods for accessing a database result set generated by querying the database. +* +* @devices phone, tablet, tv, wearable, car +* @Syscap SystemCapability.Data.DATA_APPDATAMGR +* @version 7 +*/ + +interface ResultSet { + /** + * Obtains the names of all columns in a result set. + * + * The column names are returned as a string array, in which the strings are in the same order + * as the columns in the result set. + * + * @since 7 + */ + columnNames: Array; + + /** + * Obtains the number of columns in the result set. + * + * The returned number is equal to the length of the string array returned by the + * columnCount method. + * + * @since 7 + */ + columnCount: number; + + /** + * Obtains the number of rows in the result set. + * + * @since 7 + */ + rowCount: number; + + /** + * Obtains the current index of the result set. + * + * The result set index starts from 0. + * + * @since 7 + */ + rowIndex: number; + + /** + * Checks whether the result set is positioned at the first row. + * + * @since 7 + */ + isAtFirstRow: boolean; + + /** + * Checks whether the result set is positioned at the last row. + * + * @since 7 + */ + isAtLastRow: boolean; + + /** + * Checks whether the result set is positioned after the last row. + * + * @since 7 + */ + isEnded: boolean; + + /** + * Returns whether the cursor is pointing to the position before the first + * row. + * + * @since 7 + */ + isStarted: boolean; + + /** + * Checks whether the current result set is closed. + * + * If the result set is closed by calling the close method, true will be returned. + * + * @since 7 + */ + isClosed: boolean; + + /** + * Obtains the column index based on the specified column name. + * + * The column name is passed as an input parameter. + * + * @param columnName Indicates the name of the specified column in the result set. + * @return Returns the index of the specified column. + * @since 7 + */ + getColumnIndex(columnName: string): number; + + /** + * Obtains the column name based on the specified column index. + * + * The column index is passed as an input parameter. + * + * @param columnIndex Indicates the index of the specified column in the result set. + * @return Returns the name of the specified column. + * @since 7 + */ + getColumnName(columnIndex: number): string; + + /** + * 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. + * + * @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. + * @since 7 + */ + goTo(offset: number): boolean; + + /** + * Go to the specified row of the result set. + * + * @param rowIndex Indicates the index of the specified row, which starts from 0. + * @return Returns true if the result set is moved successfully; returns false otherwise. + * @since 7 + */ + goToRow(position: number): boolean; + + /** + * Go to the first row of the result set. + * + * @return Returns true if the result set is moved successfully; + * returns false otherwise, for example, if the result set is empty. + * @since 7 + */ + goToFirstRow(): boolean; + + /** + * Go to the last row of the result set. + * + * @return Returns true if the result set is moved successfully; + * returns false otherwise, for example, if the result set is empty. + * @since 7 + */ + goToLastRow(): boolean; + + /** + * Go to the next row of the result set. + * + * @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. + * @since 7 + */ + goToNextRow(): boolean; + + /** + * Go to the previous row of the result set. + * + * @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. + * @since 7 + */ + goToPreviousRow(): boolean; + + /** + * Obtains the value of the specified column in the current row as a byte array. + * + * The implementation class determines whether to throw an exception if the value of the specified column + * in the current row is null or the specified column is not of the Blob type. + * + * @param columnIndex Indicates the specified column index, which starts from 0. + * @return Returns the value of the specified column as a byte array. + * @since 7 + */ + getBlob(columnIndex: number): Uint8Array; + + /** + * Obtains the value of the specified column in the current row as string. + * + * The implementation class determines whether to throw an exception if the value of the specified column + * in the current row is null or the specified column is not of the string type. + * + * @param columnIndex Indicates the specified column index, which starts from 0. + * @return Returns the value of the specified column as a string. + * @since 7 + */ + getString(columnIndex: number): string; + + /** + * Obtains the value of the specified column in the current row as long. + * + * The implementation class determines whether to throw an exception if the value of the specified column + * in the current row is null, the specified column is not of the integer type + * + * @param columnIndex Indicates the specified column index, which starts from 0. + * @return Returns the value of the specified column as a long. + * @since 7 + */ + getLong(columnIndex: number): number; + + /** + * Obtains the value of the specified column in the current row as double. + * + * The implementation class determines whether to throw an exception if the value of the specified column + * in the current row is null, the specified column is not of the double type + * + * @param columnIndex Indicates the specified column index, which starts from 0. + * @return Returns the value of the specified column as a double. + * @since 7 + */ + getDouble(columnIndex: number): number; + + /** + * Checks whether the value of the specified column in the current row is null. + * + * @param columnIndex Indicates the specified column index, which starts from 0. + * @return Returns true if the value of the specified column in the current row is null; + * returns false otherwise. + * @since 7 + */ + isColumnNull(columnIndex: number): boolean; + + /** + * Closes the result set. + * + * Calling this method on the result set will release all of its resources and makes it ineffective. + * + * @return Returns true if the result set is closed; returns false otherwise. + * @since 7 + */ + close(): void; +} \ No newline at end of file