HarmonyOS鸿蒙Next中测试rdb失败,请教一下是什么原因。我这context和rdbStore的打印结果正常吗?

HarmonyOS鸿蒙Next中测试rdb失败,请教一下是什么原因。我这context和rdbStore的打印结果正常吗?

import data_rdb from '@ohos.data.rdb'
import featureAbility from '@ohos.ability.featureAbility';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  myRdbStore:data_rdb.RdbStore=null
  
  aboutToAppear(){
    const CREATE_TABLE_ARTICLE = "CREATE TABLE IF NOT EXISTS tbl_article (" +
    "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
    "title TEXT, " +
    "cover TEXT, " +
    "time TEXT)";
    
    const STORE_CONFIG = {name: "myrdbstore.db"}
    
    let context=featureAbility.getContext()
    
    context.getOrCreateLocalDir().then((data)=>{
      console.info("context context context data=" + data);
    })
    
    data_rdb.getRdbStore(context,STORE_CONFIG,1,function(err,rdbStore){
      console.info('111111111111111111'+JSON.stringify(context))
      rdbStore.executeSql(CREATE_TABLE_ARTICLE)
      console.info('create table done.')
      console.info('22222222222222222'+JSON.stringify(rdbStore))
      this.myRdbStore=rdbStore
      console.info('333333333333333333'+JSON.stringify(this.myRdbStore))
    })
  }
  
  insert(rdbStore:data_rdb.RdbStore,table_name:string,valueBucket:any){
    console.info('233333')
    console.info(JSON.stringify(rdbStore))
    console.info(table_name)
    console.info(JSON.stringify(valueBucket))
    rdbStore.insert(table_name,valueBucket,(err,ret)=>{
      if(err){
        console.info('fail'+err)
        return
      }
      console.info('done'+ret)
    })
    return []
  }
  
  testInsert(){
    console.info('点击测试后:来了来了')
    let valueBucket1 = {title: "第一测试文章", cover: "icecream.png", time: "2022-08-25"}
    this.insert(this.myRdbStore,'tbl_article',valueBucket1)
  }
  
  build() {
    Row () {
      Column () {
        Button('测试')
          .onClick(()=>{
            this.testInsert()
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

preview模式

远程模拟器log

09-26 08:44:15.881 27750-27750/com.example.testrdbstore E Ark runtime: Unknown bits set in runtime_flags: 16787458

09-26 08:44:15.901 27750-27762/com.example.testrdbstore E Ark runtime: Failed to set a thread name: HDC-JDWP Connection Control Thread

09-26 08:44:15.932 27750-27755/com.example.testrdbstore E Ark gc : GcHung: GC overtime: total:7.936h cause: Threshold

09-26 08:44:16.093 27750-27775/com.example.testrdbstore E BehaviorCollectManager: Fail to acquire dataAnalyzerService…

09-26 08:44:16.362 27750-27750/com.example.testrdbstore E Ark pandafile: Can’t find entry classes.abc

09-26 08:44:16.362 27750-27750/com.example.testrdbstore E Ark pandafile: Can’t fopen location: /system/framework/android.test.base.abc

09-26 08:44:16.362 27750-27750/com.example.testrdbstore E Ark pandafile: Can’t fopen location: /system/framework/android.test.base.abc

09-26 08:44:16.509 27750-27750/com.example.testrdbstore E Ark pandafile: Can’t find entry classes.abc

09-26 08:44:16.516 27750-27750/com.example.testrdbstore E Ark runtime: ProfileSaver is forbidden

09-26 08:44:16.517 27750-27750/com.example.testrdbstore E Ark runtime: DProfiller already started

09-26 08:44:16.517 27750-27750/com.example.testrdbstore E Ark runtime: ProfileSaver is forbidden

09-26 08:44:16.647 27750-27750/com.example.testrdbstore E Ark pandafile: Can’t find entry classes.abc

09-26 08:44:16.720 27750-27970/com.example.testrdbstore E OpenGLRenderer: RenderThread: progress name = [com.example.testrdbstore], get AGPService failed!

09-26 08:44:16.762 27750-27949/com.example.testrdbstore E libdnetwork: binder invoke failed:err code -129

09-26 08:44:16.854 27750-28005/com.example.testrdbstore E AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@dd8b3d3

09-26 08:44:17.105 27750-27755/com.example.testrdbstore E Ark gc : GcHung: GC overtime: total:115.962ms cause: Threshold

09-26 08:44:17.367 27750-27755/com.example.testrdbstore E Ark gc : GcHung: GC overtime: total:117.950ms cause: Threshold

09-26 08:44:17.691 27750-28078/com.example.testrdbstore E Ark gc : GcHung: GC overtime: total:56.989ms cause: Young

09-26 08:44:18.165 27750-27750/com.example.testrdbstore E le.testrdbstor: [ZeroHung]ZrhungIoctl: open /dev/hwlog_exception failed

09-26 08:44:18.165 27750-27750/com.example.testrdbstore E le.testrdbstor: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0123]

09-26 08:44:18.165 27750-27750/com.example.testrdbstore E ZrHung.AppEyeNoDraw: Failed to get config from zrhung291

09-26 08:44:18.188 27750-27750/com.example.testrdbstore E RtgSchedIpcFile: RtgSchedIpcFile failed to open /proc/27750/rtg

09-26 08:44:18.188 27750-27750/com.example.testrdbstore E RtgSchedIpcFile: RtgSchedIpcFile failed to open /proc/27750/rtg

09-26 08:44:18.188 27750-27750/com.example.testrdbstore E RtgSchedIpcFile: setCommandByIoctl not opened


更多关于HarmonyOS鸿蒙Next中测试rdb失败,请教一下是什么原因。我这context和rdbStore的打印结果正常吗?的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

更多关于HarmonyOS鸿蒙Next中测试rdb失败,请教一下是什么原因。我这context和rdbStore的打印结果正常吗?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


借组件显示试了以下,数据操作应该是没问题的。{}和各种unknow的原因是preview环境,到远程模拟器测试应该就有值了。这个远程测试的日志报错是什么原因呢?重装软件还是这样。

微信截图_20220927093020.png

09-27 09:25:42.752 10709-10787/com.example.xstory E libdnetwork: binder invoke failed:err code -129

09-27 09:25:42.758 10709-10811/com.example.xstory E OpenGLRenderer: RenderThread: progress name = [com.example.xstory], get AGPService failed!

09-27 09:25:42.393 10709-10709/? E Ark runtime: Unknown bits set in runtime_flags: 16787458

09-27 09:25:42.398 10709-10727/? E Ark runtime: Failed to set a thread name: HDC-JDWP Connection Control Thread

09-27 09:25:42.502 10709-10735/? E BehaviorCollectManager: Fail to acquire dataAnalyzerService…

09-27 09:25:42.536 10709-10709/? E Ark pandafile: Can’t find entry classes.abc

09-27 09:25:42.537 10709-10709/? E Ark pandafile: Can’t fopen location: /system/framework/android.test.base.abc

09-27 09:25:42.537 10709-10709/? E Ark pandafile: Can’t fopen location: /system/framework/android.test.base.abc

09-27 09:25:42.664 10709-10709/? E Ark pandafile: Can’t find entry classes.abc

09-27 09:25:42.669 10709-10709/? E Ark runtime: ProfileSaver is forbidden

09-27 09:25:42.670 10709-10709/? E Ark runtime: DProfiller already started

09-27 09:25:42.670 10709-10709/? E Ark runtime: ProfileSaver is forbidden

09-27 09:25:42.724 10709-10709/? E Ark pandafile: Can’t find entry classes.abc

09-27 09:25:42.737 10709-10804/? E AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@6c10fde

09-27 09:25:43.481 10709-10709/com.example.xstory E .example.xstor: [ZeroHung]ZrhungIoctl: open /dev/hwlog_exception failed

09-27 09:25:43.482 10709-10709/com.example.xstory E .example.xstor: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0123]

09-27 09:25:43.482 10709-10709/com.example.xstory E ZrHung.AppEyeNoDraw: Failed to get config from zrhung291

09-27 09:25:43.511 10709-10709/com.example.xstory E RtgSchedIpcFile: RtgSchedIpcFile failed to open /proc/10709/rtg

09-27 09:25:43.511 10709-10709/com.example.xstory E RtgSchedIpcFile: RtgSchedIpcFile failed to open /proc/10709/rtg

09-27 09:25:43.511 10709-10709/com.example.xstory E RtgSchedIpcFile: setCommandByIoctl not opened

在HarmonyOS鸿蒙Next中,测试RDB(Relational Database)失败可能涉及多个因素。首先,确保contextrdbStore的初始化过程正确无误。context是应用上下文,用于获取数据库路径和配置,而rdbStore是RDB的核心对象,负责数据库的创建、打开和操作。

如果contextrdbStore的打印结果正常,表明初始化和配置步骤可能没有问题。接下来,检查数据库表结构和SQL语句是否正确,确保表名、字段名和数据类型与代码中的定义一致。此外,确认数据库文件路径和权限设置是否正确,确保应用有权限访问和操作数据库。

如果以上步骤均无问题,可能是数据库操作过程中出现了异常。检查日志输出,查看是否有错误信息或异常堆栈,这有助于定位问题。还可以尝试在数据库操作前后添加日志,观察数据的变化和操作流程,进一步排查问题。

最后,确保使用的HarmonyOS SDK版本与开发环境兼容,避免因版本不匹配导致的兼容性问题。如果问题依然存在,可以尝试简化测试用例,逐步排查问题根源。

在HarmonyOS鸿蒙Next中,测试RDB(Relational Database)失败可能有多种原因。首先,确保contextrdbStore的初始化逻辑正确。如果打印结果正常,可能的问题包括:权限未正确配置、数据库路径错误、SQL语句有误、或设备存储空间不足。建议检查日志以获取详细错误信息,并确保所有依赖项和配置正确。如果问题持续,可以尝试重启设备或重新安装应用。

回到顶部