如何在领域数据库中添加数据?

时间:2017-05-31 05:43:19

标签: android realm

我是新手,我的问题是如何添加两个不同的数据示例(在sql数据库中创建两个不同的表来添加两个不同的数据),如何明智地如何在realm数据库中添加两个数据。 / p>

 public void addData(final RealmPhoneCallLogs phoneCallLog){
    realm.executeTransaction(new Realm.Transaction() {
                                 @Override
                                 public void execute(Realm realm) {
                                     RealmPhoneCallLogs phoneCallLogs = realm.createObject(RealmPhoneCallLogs.class);
                                     phoneCallLogs.setId(phoneCallLog.getId());
                                     phoneCallLogs.setStartTime(phoneCallLog.getStartTime());
                                     phoneCallLogs.setActualStartTime(phoneCallLog.getActualStartTime());
                                     phoneCallLogs.setCallDuration(phoneCallLog.getCallDuration());
                                     phoneCallLogs.setCallRecords(phoneCallLog.getCallRecords());
                                     phoneCallLogs.setCallStatus(phoneCallLog.getCallRecords());
                                     phoneCallLogs.setEndTime(phoneCallLog.getEndTime());
                                     phoneCallLogs.setNumber(phoneCallLog.getNumber());
                                     phoneCallLogs.setCallType(phoneCallLog.getCallType());
                                 }
                             }
    );
}

以上数据已添加到数据库中。

 public void addImportant(final RealmPhoneCallLogs importantPhonecallLog){
    realm.executeTransaction(new Realm.Transaction() {
        @Override
        public void execute(Realm realm) {
            RealmPhoneCallLogs importantCalls = realm.createObject(RealmPhoneCallLogs.class);
            importantCalls.setId(importantPhonecallLog.getId());
            importantCalls.setStartTime(importantPhonecallLog.getStartTime());
            importantCalls.setActualStartTime(importantPhonecallLog.getActualStartTime());
            importantCalls.setCallDuration(importantPhonecallLog.getCallDuration());
            importantCalls.setCallRecords(importantPhonecallLog.getCallRecords());
            importantCalls.setCallStatus(importantPhonecallLog.getCallRecords());
            importantCalls.setEndTime(importantPhonecallLog.getEndTime());
            importantCalls.setNumber(importantPhonecallLog.getNumber());
            importantCalls.setCallType(importantPhonecallLog.getCallType());

        }
    });
}

如何将数据添加到数据库中。如果我添加数据意味着它将添加到数据库中创建的现有对象中。如何将其添加到数据库中的单独表中。

0 个答案:

没有答案