日B视频 亚洲,啪啪啪网站一区二区,91色情精品久久,日日噜狠狠色综合久,超碰人妻少妇97在线,999青青视频,亚洲一区二卡,让本一区二区视频,日韩网站推荐

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

OpenHarmony關(guān)系型數(shù)據(jù)庫(kù)查詢結(jié)果呈現(xiàn)

ITMING ? 來(lái)源:ITMING ? 作者: ITMING ? 2023-03-28 18:06 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

1 ResultSet(結(jié)果集)

ResultSet(結(jié)果集)是OpenHarmony關(guān)系型數(shù)據(jù)庫(kù)提供查詢數(shù)據(jù)表返回結(jié)果的方法,提供了多種靈活的數(shù)據(jù)訪問(wèn)方式,以便于開(kāi)發(fā)者獲取各項(xiàng)數(shù)據(jù),ResultSet屬性如表1-1所示,ResultSet方法如表1-2所示。

表1-1 ResultSet屬性

名稱 類型 必填 說(shuō)明
columnNames Array 結(jié)果集中所有列的名稱
columnCount number 結(jié)果集中的列數(shù)
rowCount number 結(jié)果集中的行數(shù)
rowIndex number 結(jié)果集當(dāng)前行的索引
isAtFirstRow boolean 結(jié)果集是否位于第一行
isAtLastRow boolean 結(jié)果集是否位于最后一行
isEnded boolean 結(jié)果集是否位于最后一行之后
isStarted boolean 指針是否移動(dòng)過(guò)
isClosed boolean 當(dāng)前結(jié)果集是否關(guān)閉

表1-2 ResultSet方法

名稱 描述
getColumnIndex(columnName: string): number 根據(jù)指定的列名獲取列索引columnName: 結(jié)果集中指定列的名稱 number: 返回指定列的索引
getColumnName(columnIndex: number): string 根據(jù)指定的列索引獲取列名columnIndex: 結(jié)果集中指定列的索引string: 返回指定列的名稱
goTo(offset: number): boolean 向前或向后轉(zhuǎn)至結(jié)果集的指定行,相對(duì)于當(dāng)前行位置偏移offset: 表示相對(duì)于當(dāng)前行位置偏移量boolean:操作成功,則為true,否則為false
goToRow(position: number): boolean 轉(zhuǎn)到結(jié)果集的指定行position: 表示要移動(dòng)到的指定位置boolean: 操作成功,則為true,否則為false
goToFirstRow(): boolean 轉(zhuǎn)到結(jié)果集的第一行boolean: 操作成功,則為true,否則為false
goToLastRow(): boolean 轉(zhuǎn)到結(jié)果集的最后一行boolean: 操作成功,則為true,否則為false
goToNextRow(): boolean 轉(zhuǎn)到結(jié)果集的下一行boolean: 操作成功,則為true,否則為false
goToPreviousRow(): boolean 轉(zhuǎn)到結(jié)果集上一行boolean: 操作成功,則為true,否則為false
getBlob(columnIndex: number): Uint8Array 以字節(jié)數(shù)組的形式獲取當(dāng)前行中指定列的值指定的列索引,從0開(kāi)始Uint8Array: 以字節(jié)數(shù)組的形式返回指定列的值
getString(columnIndex: number): string 以字符串形式獲取當(dāng)前行中指定列的值columnIndex: 指定的列索引,從0開(kāi)始string: 以字符串形式返回指定列的值
getLong(columnIndex: number): number 以Long形式獲取當(dāng)前行中指定列的值columnIndex: 指定的列索引,從0開(kāi)始number: 以Long形式返回指定列的值。該接口支持的數(shù)據(jù)范圍是:Number.MIN_SAFE_INTEGER~Number.MAX_SAFE_INTEGER,若超出該范圍,則建議使用getDouble
getDouble(columnIndex: number): number 以double形式獲取當(dāng)前行中指定列的值columnIndex: 指定的列索引,從0開(kāi)始number: 以double形式返回指定列的值
isColumnNull(columnIndex: number): boolean 檢查當(dāng)前行中指定列的值是否為nullcolumnIndex: 指定的列索引,從0開(kāi)始boolean: 當(dāng)前行中指定列的值為null,則返回true,否則為false
close(): void 關(guān)閉結(jié)果集

2 流程

3 步驟

3.1 獲取ResultSet結(jié)果集

通過(guò)RdbStore實(shí)例的query()querySql()方法獲得ResultSet結(jié)果集。

let predicates = new relationalStore.RdbPredicates(this.tableName);
let result = await this.rdbStore.query(predicates, columns);

3.2 自定義返回結(jié)果類

自定義TableResultSet類用于前臺(tái)展示。

export class TableResultSet {
    private total: number;                 // 總條數(shù)
    private data: any;                     // 數(shù)據(jù)表數(shù)據(jù)

    setTotal(total: number) {
        this.total = total;
    }

    setData(data: any) {
        this.data = data;
    }
}

3.3 結(jié)果集轉(zhuǎn)返回結(jié)果

ResultSet并不能直接用來(lái)展示,通過(guò)ResultSet提供的各類方法獲取需要的信息。

private resultToObject(result: relationalStore.ResultSet) {
    let trs = new TableResultSet();
    trs.setData(result.rowCount);
    let data: Array<any> = [];
    let count = result.rowCount;
    if (count === 0 || typeof count === 'string') {
      trs.setData([]);
    } else {
      // 從數(shù)據(jù)第一行開(kāi)始讀取
      result.goToFirstRow();
      for (let j = 0; j < count; j++) {
        let temp: any = {};
        for (let i = 0; i < this.fields.length; i++) {
          let field = this.fields[i];
          if (field.type === 'INTEGER' || field.type === 'integer') {
            temp[field.name] = result.getLong(result.getColumnIndex(field.name));
          } else if (field.type === 'REAL' || field.type === 'real') {
            temp[field.name] = result.getDouble(result.getColumnIndex(field.name));
          } else if (field.type === 'TEXT' || field.type === 'text') {
            temp[field.name] = result.getString(result.getColumnIndex(field.name));
          } else if (field.type === 'BLOB' || field.type === 'blob') {
            temp[field.name] = result.getBlob(result.getColumnIndex(field.name));
          }
        }
        data.push(temp);
        result.goToNextRow();
      }
      trs.setData(data);
    }
    return trs;
  }

4 呈現(xiàn)結(jié)果

  • 使用斷點(diǎn)調(diào)試方式

  • 使用日志調(diào)試方式
Log.info(TAG, `Query of ${this.tableName} table data succeeded. data: ` + JSON.stringify(result));

  • 頁(yè)面顯示
// 顯示表名稱
Text(TableConstants.T_ACCOUNT_NAME)
  .fontSize(18)
  .fontWeight(700)
  .width('90%').height(54)
Column({space: 5}) {
  if (this.result !== null) {
    // 顯示表字段
    GridRow({
      columns: TableConstants.T_ACCOUNT_FIELDS.length,
      direction: GridRowDirection.Row
    }) {
      ForEach(this.result.fields, (field) => {
        GridCol() {
          Text(field)
            .width("100%").height(54)
            .fontSize(16)
            .textAlign(TextAlign.Center)
        }
        .colStyle()
      })
    }
    .width('90%').height(54)
    .backgroundColor(0xE5E5E5)
    // 顯示表數(shù)據(jù)
    ForEach(this.result.data, (item) => {
      GridRow({
        columns: TableConstants.T_ACCOUNT_FIELDS.length,
        direction: GridRowDirection.Row
      }) {
        ForEach(TableConstants.T_ACCOUNT_FIELDS, (field) => {
          GridCol() {
            this.Label(item[field.name].toString())
          }
          .colStyle()
        })
      }
      .width('90%').height(54)
      .backgroundColor(0xF5F5F5)
    }, temp => temp.toString())
  }
}
.width('100%')

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    HarmonyOS開(kāi)發(fā)案例:【搭建關(guān)系數(shù)據(jù)庫(kù)】(4)

    本節(jié)將介紹如何調(diào)用關(guān)系數(shù)據(jù)庫(kù)接口在本地搭建數(shù)據(jù)庫(kù),并讀寫相應(yīng)的用戶數(shù)據(jù)
    的頭像 發(fā)表于 05-11 10:27 ?2127次閱讀
    HarmonyOS開(kāi)發(fā)案例:【搭建<b class='flag-5'>關(guān)系</b><b class='flag-5'>型</b><b class='flag-5'>數(shù)據(jù)庫(kù)</b>】(4)

    關(guān)系數(shù)據(jù)庫(kù)與非關(guān)系數(shù)據(jù)庫(kù)的區(qū)別淺析

    關(guān)系數(shù)據(jù)庫(kù)的一個(gè)劣勢(shì)就是 阻抗失諧(impedance mismatch):關(guān)系模型和內(nèi)存中的數(shù)據(jù)結(jié)構(gòu)之間存在差異
    發(fā)表于 06-03 06:03

    HarmonyOS關(guān)系數(shù)據(jù)庫(kù)和對(duì)象關(guān)系數(shù)據(jù)庫(kù)的使用方法

    容易就上手的知識(shí)。本篇速成教程直接使用最精準(zhǔn)和簡(jiǎn)短的文字,再配上講解代碼,讓我們能在10分鐘左右就能掌握最基本的數(shù)據(jù)庫(kù)使用方法。數(shù)據(jù)庫(kù)的三大要素:數(shù)據(jù)庫(kù)、表、字段,接下來(lái)為大家介紹關(guān)系
    發(fā)表于 03-29 14:10

    基于數(shù)據(jù)庫(kù)查詢過(guò)程優(yōu)化設(shè)計(jì)

    在大型關(guān)系數(shù)據(jù)庫(kù)管理與開(kāi)發(fā)中,優(yōu)化設(shè)計(jì)極大地提高數(shù)據(jù)庫(kù)的性能。通過(guò)對(duì)一大數(shù)據(jù)庫(kù)查詢語(yǔ)句執(zhí)行過(guò)程的討論,提出了對(duì)同一表格進(jìn)行多個(gè)選擇運(yùn)算的優(yōu)
    發(fā)表于 02-27 16:05 ?18次下載

    數(shù)據(jù)庫(kù)查詢

    庫(kù)查詢一、實(shí)驗(yàn)?zāi)康耐ㄟ^(guò)基于關(guān)系網(wǎng)絡(luò)數(shù)據(jù)庫(kù)管理系統(tǒng)SQL Server的上機(jī)實(shí)驗(yàn),使學(xué)生進(jìn)一步了解關(guān)系
    發(fā)表于 05-10 10:55 ?0次下載

    查詢數(shù)據(jù)庫(kù)的最完美技巧

    查詢數(shù)據(jù)庫(kù)的最完美技巧.rar
    發(fā)表于 03-15 14:15 ?24次下載

    什么是關(guān)系數(shù)據(jù)庫(kù)

    什么是關(guān)系數(shù)據(jù)庫(kù) 關(guān)系數(shù)據(jù)庫(kù)簡(jiǎn)介   關(guān)系
    發(fā)表于 06-17 07:38 ?9382次閱讀

    什么是非關(guān)系數(shù)據(jù)庫(kù)

    什么是非關(guān)系數(shù)據(jù)庫(kù) 談到非關(guān)系數(shù)據(jù)庫(kù)設(shè)計(jì)的難點(diǎn),朱海峰說(shuō):“我們可以從一些場(chǎng)景來(lái)看這個(gè)問(wèn)題
    發(fā)表于 06-17 15:49 ?3345次閱讀

    hbase和關(guān)系數(shù)據(jù)庫(kù)的區(qū)別

    hbase和關(guān)系數(shù)據(jù)庫(kù)的區(qū)別就是對(duì)于傳統(tǒng)數(shù)據(jù)庫(kù),增加列對(duì)于一個(gè)項(xiàng)目來(lái)講,改變是非常大的。但是對(duì)于nosql,插入列和刪除列,跟傳統(tǒng)數(shù)據(jù)庫(kù)
    發(fā)表于 12-27 15:51 ?1.7w次閱讀
    hbase和<b class='flag-5'>關(guān)系</b><b class='flag-5'>型</b><b class='flag-5'>數(shù)據(jù)庫(kù)</b>的區(qū)別

    數(shù)據(jù)庫(kù)系統(tǒng)概論之如何進(jìn)行關(guān)系查詢處理和查詢優(yōu)化

    本文檔的主要內(nèi)容詳細(xì)介紹的是數(shù)據(jù)庫(kù)系統(tǒng)概論之如何進(jìn)行關(guān)系查詢處理和查詢優(yōu)化主要內(nèi)容包括了:1、關(guān)系數(shù)據(jù)庫(kù)系統(tǒng)的
    發(fā)表于 11-15 15:12 ?11次下載
    <b class='flag-5'>數(shù)據(jù)庫(kù)</b>系統(tǒng)概論之如何進(jìn)行<b class='flag-5'>關(guān)系</b><b class='flag-5'>查詢</b>處理和<b class='flag-5'>查詢</b>優(yōu)化

    數(shù)據(jù)庫(kù)原理的關(guān)系代數(shù)詳細(xì)講解

    關(guān)系代數(shù)與關(guān)系數(shù)據(jù)庫(kù)操作   關(guān)系代數(shù)是關(guān)系數(shù)據(jù)庫(kù)系統(tǒng)查詢語(yǔ)言的理論基礎(chǔ)。
    發(fā)表于 10-31 11:53 ?5次下載

    OpenHarmony關(guān)系數(shù)據(jù)庫(kù)概述

    關(guān)系數(shù)據(jù)庫(kù)(Relational Database, 以下簡(jiǎn)稱RDB)是一種基于關(guān)系模型來(lái)管理數(shù)據(jù)數(shù)
    的頭像 發(fā)表于 03-28 18:08 ?2125次閱讀
    <b class='flag-5'>OpenHarmony</b><b class='flag-5'>關(guān)系</b><b class='flag-5'>型</b><b class='flag-5'>數(shù)據(jù)庫(kù)</b>概述

    關(guān)系數(shù)據(jù)庫(kù)的基本原理(什么是關(guān)系數(shù)據(jù)庫(kù)

    組成。關(guān)系數(shù)據(jù)庫(kù)是基于實(shí)用和可重復(fù)使用的概念,是支持高性能交互查詢、交易處理能力、安全性和靈活性的關(guān)鍵數(shù)據(jù)存儲(chǔ)和維護(hù)方法。關(guān)系
    的頭像 發(fā)表于 07-10 09:06 ?2296次閱讀

    python讀取數(shù)據(jù)庫(kù)數(shù)據(jù) python查詢數(shù)據(jù)庫(kù) python數(shù)據(jù)庫(kù)連接

    python讀取數(shù)據(jù)庫(kù)數(shù)據(jù) python查詢數(shù)據(jù)庫(kù) python數(shù)據(jù)庫(kù)連接 Python是一門高級(jí)編程語(yǔ)言,廣泛應(yīng)用于各種領(lǐng)域。其中,Pyt
    的頭像 發(fā)表于 08-28 17:09 ?3305次閱讀

    關(guān)系數(shù)據(jù)庫(kù)和非關(guān)系區(qū)別

    關(guān)系數(shù)據(jù)庫(kù)和非關(guān)系數(shù)據(jù)庫(kù)在多個(gè)方面存在顯著差異,主機(jī)推薦小編為您整理發(fā)布
    的頭像 發(fā)表于 01-10 09:58 ?1841次閱讀
    阿合奇县| 秦安县| 平邑县| 景洪市| 洪泽县| 吉安市| 和田市| 齐齐哈尔市| 青河县| 滦南县| 望城县| 扶绥县| 太保市| 北京市| 阜康市| 桂林市| 柘城县| 浠水县| 宣城市| 贵港市| 温泉县| 阿克陶县| 益阳市| 建德市| 监利县| 徐水县| 抚宁县| 奎屯市| 宁远县| 新蔡县| 杨浦区| 普陀区| 保靖县| 甘孜| 广安市| 高要市| 德兴市| 江孜县| 华池县| 绿春县| 曲周县|