中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
关系型数据库如何查询指定设备上的数据?
微信扫码分享
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) } }