Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8b3c8f98
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8b3c8f98
编写于
2月 20, 2023
作者:
L
lihuihui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docsV9
Signed-off-by:
N
lihuihui
<
lihuihui29@huawei.com
>
上级
37b688d2
变更
2
展开全部
显示空白变更内容
内联
并排
Showing
2 changed file
with
189 addition
and
3128 deletion
+189
-3128
zh-cn/application-dev/reference/apis/js-apis-data-rdb.md
zh-cn/application-dev/reference/apis/js-apis-data-rdb.md
+189
-2598
zh-cn/application-dev/reference/apis/js-apis-data-resultset.md
.../application-dev/reference/apis/js-apis-data-resultset.md
+0
-530
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-rdb.md
浏览文件 @
8b3c8f98
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-data-resultset.md
浏览文件 @
8b3c8f98
...
...
@@ -8,536 +8,6 @@
>
> 从API Version 9开始,该接口不再维护,推荐使用新接口[@ohos.data.relationalStore#ResultSet](js-apis-data-relationalStore.md#resultset)。
## ResultSetV9<sup>9+</sup>
提供通过查询数据库生成的数据库结果集的访问方法。
### 使用说明
需要通过
[
RdbStoreV9.query()
](
js-apis-data-rdb.md#query
)
获取resultSetV9对象。
```
js
import
dataRdb
from
'
@ohos.data.rdb
'
;
let
predicatesV9
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
predicatesV9
.
equalTo
(
"
AGE
"
,
18
);
let
promise
=
rdbStoreV9
.
query
(
predicatesV9
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promise
.
then
((
resultSetV9
)
=>
{
console
.
log
(
TAG
+
"
resultSet columnNames:
"
+
resultSetV9
.
columnNames
);
console
.
log
(
TAG
+
"
resultSet columnCount:
"
+
resultSetV9
.
columnCount
);
});
```
### 属性<sup>9+</sup>
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
| 名称 | 类型 | 必填 | 说明 |
| ------------ | ------------------- | ---- | -------------------------------- |
| columnNames | Array
<
string
>
| 是 | 获取结果集中所有列的名称。 |
| columnCount | number | 是 | 获取结果集中的列数。 |
| rowCount | number | 是 | 获取结果集中的行数。 |
| rowIndex | number | 是 | 获取结果集当前行的索引。 |
| isAtFirstRow | boolean | 是 | 检查结果集是否位于第一行。 |
| isAtLastRow | boolean | 是 | 检查结果集是否位于最后一行。 |
| isEnded | boolean | 是 | 检查结果集是否位于最后一行之后。 |
| isStarted | boolean | 是 | 检查指针是否移动过。 |
| isClosed | boolean | 是 | 检查当前结果集是否关闭。 |
### getColumnIndex<sup>9+</sup>
getColumnIndex(columnName: string): number
根据指定的列名获取列索引。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | -------------------------- |
| columnName | string | 是 | 表示结果集中指定列的名称。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------ |
| number | 返回指定列的索引。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**示例:**
```
js
resultSetV9
.
goToFirstRow
();
const
id
=
resultSetV9
.
getLong
(
resultSetV9
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSetV9
.
getString
(
resultSetV9
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSetV9
.
getLong
(
resultSetV9
.
getColumnIndex
(
"
AGE
"
));
const
salary
=
resultSetV9
.
getDouble
(
resultSetV9
.
getColumnIndex
(
"
SALARY
"
));
```
### getColumnName<sup>9+</sup>
getColumnName(columnIndex: number): string
根据指定的列索引获取列名。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | -------------------------- |
| columnIndex | number | 是 | 表示结果集中指定列的索引。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------ |
| string | 返回指定列的名称。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**示例:**
```
js
const
id
=
resultSetV9
.
getColumnName
(
0
);
const
name
=
resultSetV9
.
getColumnName
(
1
);
const
age
=
resultSetV9
.
getColumnName
(
2
);
```
### goTo<sup>9+</sup>
goTo(offset:number): boolean
向前或向后转至结果集的指定行,相对于其当前位置偏移。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------------- |
| offset | number | 是 | 表示相对于当前位置的偏移量。 |
**返回值:**
| 类型 | 说明 |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**示例:**
```
js
let
predicatesV9goto
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
let
promisequerygoto
=
rdbStoreV9
.
query
(
predicatesV9goto
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promisequerygoto
.
then
((
resultSetV9
)
=>
{
resultSetV9
.
goTo
(
1
);
resultSetV9
.
close
();
}).
catch
((
err
)
=>
{
console
.
log
(
'
query failed
'
);
});
```
### goToRow<sup>9+</sup>
goToRow(position: number): boolean
转到结果集的指定行。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------ |
| position | number | 是 | 表示要移动到的指定位置。 |
**返回值:**
| 类型 | 说明 |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**示例:**
```
js
let
predicatesV9gotorow
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
let
promisequerygotorow
=
rdbStoreV9
.
query
(
predicatesV9gotorow
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promisequerygotorow
.
then
((
resultSetV9
)
=>
{
resultSetV9
.
goToRow
(
5
);
resultSetV9
.
close
();
}).
catch
((
err
)
=>
{
console
.
log
(
'
query failed
'
);
});
```
### goToFirstRow<sup>9+</sup>
goToFirstRow(): boolean
转到结果集的第一行。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**返回值:**
| 类型 | 说明 |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**示例:**
```
js
let
predicatesV9goFirst
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
let
promisequerygoFirst
=
rdbStoreV9
.
query
(
predicatesV9goFirst
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promisequerygoFirst
.
then
((
resultSetV9
)
=>
{
resultSetV9
.
goToFirstRow
();
resultSetV9
.
close
();
}).
catch
((
err
)
=>
{
console
.
log
(
'
query failed
'
);
});
```
### goToLastRow<sup>9+</sup>
goToLastRow(): boolean
转到结果集的最后一行。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**返回值:**
| 类型 | 说明 |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**示例:**
```
js
let
predicatesV9goLast
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
let
promisequerygoLast
=
rdbStoreV9
.
query
(
predicatesV9goLast
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promisequerygoLast
.
then
((
resultSetV9
)
=>
{
resultSetV9
.
goToLastRow
();
resultSetV9
.
close
();
}).
catch
((
err
)
=>
{
console
.
log
(
'
query failed
'
);
});
```
### goToNextRow<sup>9+</sup>
goToNextRow(): boolean
转到结果集的下一行。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**返回值:**
| 类型 | 说明 |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**示例:**
```
js
let
predicatesV9goNext
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
let
promisequerygoNext
=
rdbStoreV9
.
query
(
predicatesV9goNext
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promisequerygoNext
.
then
((
resultSetV9
)
=>
{
resultSetV9
.
goToNextRow
();
resultSetV9
.
close
();
}).
catch
((
err
)
=>
{
console
.
log
(
'
query failed
'
);
});
```
### goToPreviousRow<sup>9+</sup>
goToPreviousRow(): boolean
转到结果集的上一行。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**返回值:**
| 类型 | 说明 |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**示例:**
```
js
let
predicatesV9goPrev
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
let
promisequerygoPrev
=
rdbStoreV9
.
query
(
predicatesV9goPrev
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promisequerygoPrev
.
then
((
resultSetV9
)
=>
{
resultSetV9
.
goToPreviousRow
();
resultSetV9
.
close
();
}).
catch
((
err
)
=>
{
console
.
log
(
'
query failed
'
);
});
```
### getBlob<sup>9+</sup>
getBlob(columnIndex: number): Uint8Array
以字节数组的形式获取当前行中指定列的值。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是 | 指定的列索引,从0开始。 |
**返回值:**
| 类型 | 说明 |
| ---------- | -------------------------------- |
| Uint8Array | 以字节数组的形式返回指定列的值。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**示例:**
```
js
const
codes
=
resultSetV9
.
getBlob
(
resultSetV9
.
getColumnIndex
(
"
CODES
"
));
```
### getString<sup>9+</sup>
getString(columnIndex: number): string
以字符串形式获取当前行中指定列的值。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是 | 指定的列索引,从0开始。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| string | 以字符串形式返回指定列的值。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**示例:**
```
js
const
name
=
resultSetV9
.
getString
(
resultSetV9
.
getColumnIndex
(
"
NAME
"
));
```
### getLong<sup>9+</sup>
getLong(columnIndex: number): number
以Long形式获取当前行中指定列的值。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是 | 指定的列索引,从0开始。 |
**返回值:**
| 类型 | 说明 |
| ------ | -------------------------- |
| number | 以Long形式返回指定列的值。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**示例:**
```
js
const
age
=
resultSetV9
.
getLong
(
resultSetV9
.
getColumnIndex
(
"
AGE
"
));
```
### getDouble<sup>9+</sup>
getDouble(columnIndex: number): number
以double形式获取当前行中指定列的值。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是 | 指定的列索引,从0开始。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| number | 以double形式返回指定列的值。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**示例:**
```
js
const
salary
=
resultSetV9
.
getDouble
(
resultSetV9
.
getColumnIndex
(
"
SALARY
"
));
```
### isColumnNull<sup>9+</sup>
isColumnNull(columnIndex: number): boolean
检查当前行中指定列的值是否为null。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是 | 指定的列索引,从0开始。 |
**返回值:**
| 类型 | 说明 |
| ------- | --------------------------------------------------------- |
| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 |
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**示例:**
```
js
const
isColumnNull
=
resultSetV9
.
isColumnNull
(
resultSetV9
.
getColumnIndex
(
"
CODES
"
));
```
### close<sup>9+</sup>
close(): void
关闭结果集。
**系统能力:**
SystemCapability.DistributedDataManager.RelationalStore.Core
**示例:**
```
js
let
predicatesV9Close
=
new
dataRdb
.
RdbPredicatesV9
(
"
EMPLOYEE
"
);
let
promiseClose
=
rdbStoreV9
.
query
(
predicatesV9Close
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
CODES
"
]);
promiseClose
.
then
((
resultSetV9
)
=>
{
resultSetV9
.
close
();
}).
catch
((
err
)
=>
{
console
.
log
(
'
resultset close failed
'
);
});
```
**错误码:**
以下错误码的详细介绍请参见
[
关系型数据库错误码
](
../errorcodes/errorcode-data-rdb.md
)
。
|
**错误码ID**
|
**错误信息**
|
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
## ResultSet
提供通过查询数据库生成的数据库结果集的访问方法。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录