#鸿蒙学习大百科#关系型数据库如何查询指定设备上的数据?

关系型数据库如何查询指定设备上的数据?

HarmonyOS
2024-10-24 09:09:47
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
无敌大暴龙
import deviceManager from '@ohos.distributedDeviceManager';
import { BusinessError } from '@ohos.base'

let dmInstance: deviceManager.DeviceManager;
let deviceId: string | undefined = undefined ;
@Entry
@Component
struct Index {
  build() {
    Column() {
      Button("").onClick(() => {
        try {
          dmInstance = deviceManager.createDeviceManager("com.jason.demo");
          let devices = dmInstance.getAvailableDeviceListSync();

          deviceId = devices[0].networkId;
          // 构造用于查询分布式表的谓词对象
          let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
          // 调用跨设备查询接口,并返回查询结果
          if(store != undefined && deviceId != undefined) {
            (store as relationalStore.RdbStore).remoteQuery(deviceId, 'EMPLOYEE', predicates, ['ID', 'NAME', 'AGE', 'SALARY', 'CODES'],
              (err: BusinessError, resultSet: relationalStore.ResultSet) => {
                if (err) {
                  console.error(`Failed to remoteQuery data. Code:${err.code},message:${err.message}`);
                  return;
                }
                console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
              }
            )
          }
        } catch (err) {
          let code = (err as BusinessError).code;
          let message = (err as BusinessError).message;
          console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
        }
      })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
分享
微博
QQ
微信
回复
2024-10-24 17:02:27
相关问题