女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

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

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

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

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

ITMING ? 來源:ITMING ? 作者: ITMING ? 2023-03-28 18:06 ? 次閱讀

1 ResultSet(結(jié)果集)

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

表1-1 ResultSet屬性

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

表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é)果集的指定行,相對于當前行位置偏移offset: 表示相對于當前行位置偏移量boolean:操作成功,則為true,否則為false
goToRow(position: number): boolean 轉(zhuǎn)到結(jié)果集的指定行position: 表示要移動到的指定位置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ù)組的形式獲取當前行中指定列的值指定的列索引,從0開始Uint8Array: 以字節(jié)數(shù)組的形式返回指定列的值
getString(columnIndex: number): string 以字符串形式獲取當前行中指定列的值columnIndex: 指定的列索引,從0開始string: 以字符串形式返回指定列的值
getLong(columnIndex: number): number 以Long形式獲取當前行中指定列的值columnIndex: 指定的列索引,從0開始number: 以Long形式返回指定列的值。該接口支持的數(shù)據(jù)范圍是:Number.MIN_SAFE_INTEGER~Number.MAX_SAFE_INTEGER,若超出該范圍,則建議使用getDouble
getDouble(columnIndex: number): number 以double形式獲取當前行中指定列的值columnIndex: 指定的列索引,從0開始number: 以double形式返回指定列的值
isColumnNull(columnIndex: number): boolean 檢查當前行中指定列的值是否為nullcolumnIndex: 指定的列索引,從0開始boolean: 當前行中指定列的值為null,則返回true,否則為false
close(): void 關閉結(jié)果集

2 流程

3 步驟

3.1 獲取ResultSet結(jié)果集

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

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

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

自定義TableResultSet類用于前臺展示。

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并不能直接用來展示,通過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ù)第一行開始讀取
      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ào)試方式

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

  • 頁面顯示
// 顯示表名稱
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)站授權轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
收藏 人收藏

    評論

    相關推薦
    熱點推薦

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

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

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

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

    HarmonyOS關系數(shù)據(jù)庫和對象關系數(shù)據(jù)庫的使用方法

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

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

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

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

    查詢一、實驗目的通過基于關系網(wǎng)絡數(shù)據(jù)庫管理系統(tǒng)SQL Server的上機實驗,使學生進一步了解關系
    發(fā)表于 05-10 10:55 ?0次下載

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

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

    什么是關系數(shù)據(jù)庫

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

    什么是非關系數(shù)據(jù)庫

    什么是非關系數(shù)據(jù)庫 談到非關系數(shù)據(jù)庫設計的難點,朱海峰說:“我們可以從一些場景來看這個問題
    發(fā)表于 06-17 15:49 ?3206次閱讀

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

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

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

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

    數(shù)據(jù)庫原理的關系代數(shù)詳細講解

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

    OpenHarmony關系數(shù)據(jù)庫概述

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

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

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

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

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

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

    關系數(shù)據(jù)庫和非關系數(shù)據(jù)庫在多個方面存在顯著差異,主機推薦小編為您整理發(fā)布
    的頭像 發(fā)表于 01-10 09:58 ?512次閱讀