bytedance / bytedance/rdbStore

数据库表的字段为INTEGER的类型,查询到的值精度丢失

Open
#20 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
74
Forks
17
PR merge metrics
No merged PRs in 30d

Description

数据库表的字段为INTEGER的类型,然后插入了一条112233445566778899的数据,再查询的时候这个字段返回的值为112233445566778900

```ts
import { BigIntStrConvertor, Columns, ColumnType, Entity } from "rdbstore"

@Entity({
tableName: 'user',
})
export class User {
@Columns({
name: 'uid',
type: ColumnType.INTEGER,
convertor: BigIntStrConvertor
})
id: string = ''

@Columns({
name: 'name',
type: ColumnType.TEXT
})
name: string = ''
}

@Entry
@ComponentV2
struct Index {
@Local message: string = 'Hello World';
@Local inputValue:string = '112233445566778899'

build() {
Column({space:15}) {

Text(this.message)

TextInput({text:$$this.inputValue})

Button('insert user')
.onClick(() =>{
RdbProxy.userDao?.executeSql(`INSERT INTO user (uid, name) VALUES (${this.inputValue}, '${this.inputValue}' )`)
})

Button('query user')
.onClick(async () =>{
const userDao = RdbProxy.userDao
if(userDao){
let predicates = new relationalStore.RdbPredicates('user')
predicates.equalTo('uid',this.inputValue)
let users = userDao.querySync(predicates)
this.message = JSON.stringify(users)
}
})
}
.height('100%')
.width('100%')
.padding(15)
}
}
```

获取当前行中指定列的值,如果值类型是ValueType中指定的任意类型,返回指定类型的值,否则返回14800000。如果值类型为INTEGER,值大于 Number.MAX_SAFE_INTEGER 或小于 Number.MIN_SAFE_INTEGER 且不希望丢失精度,建议使用[getString](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-data-relationalstore-resultset#getstring)接口获取。

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.