• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Logger from '../util/Logger'
17
18const TAG: string = 'BookModel'
19
20export class BookModel {
21  id: number
22  name: string
23  introduction: string
24
25  constructor(id?: number, name?: string, introduction?: string) {
26    this.id = id
27    this.name = name
28    this.introduction = introduction
29  }
30}
31
32export function getBooksFromResultSet(resultSet) {
33  let books = []
34  Logger.info(TAG, `getBooksFromResultSet columnNames= ${resultSet.columnNames}, rowCount= ${resultSet.rowCount}`)
35  if (resultSet !== null) {
36    resultSet.goToFirstRow()
37    let idIndex = resultSet.getColumnIndex('id')
38    let nameIndex = resultSet.getColumnIndex('name')
39    let introductionIndex = resultSet.getColumnIndex('introduction')
40    Logger.info(TAG, `ID = ${resultSet.getColumnIndex('id')}, name = ${resultSet.getColumnIndex('name')},
41              introduction = ${resultSet.getColumnIndex('introduction')}`)
42    for (let i = 0; i < resultSet.rowCount; i++) {
43      let id = resultSet.getDouble(idIndex)
44      let name = resultSet.getString(nameIndex)
45      let introduction = resultSet.getString(introductionIndex)
46      Logger.info(TAG, `id = ${id}, name = ${name}, introduction = ${introduction}`)
47      books.push(new BookModel(id, name, introduction))
48      Logger.info(TAG, `getBooksFromResultSet resultSet books: ${JSON.stringify(books)}`)
49      resultSet.goToNextRow()
50    }
51  }
52  return books
53}