List of usage examples for android.database.sqlite SQLiteDatabase compileStatement
public SQLiteStatement compileStatement(String sql) throws SQLException
From source file:mobile.tiis.appv2.base.BackboneApplication.java
public boolean addChildVaccinationEventVaccinationAppointment(ChildCollector2 childCollector) { Log.d("coze", "saving data to db"); boolean containsData = false; List<Child> children = childCollector.getChildList(); List<VaccinationEvent> vaccinationEvents = childCollector.getVeList(); List<VaccinationAppointment> vaccinationAppointments = childCollector.getVaList(); DatabaseHandler db = getDatabaseInstance(); SQLiteDatabase db1 = db.getWritableDatabase(); db1.beginTransactionNonExclusive();/*from ww w. java 2 s . co m*/ try { if (children != null) { String sql0 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.CHILD + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.ChildColumns.ID + "," + SQLHandler.ChildColumns.BARCODE_ID + "," + SQLHandler.ChildColumns.FIRSTNAME1 + "," + SQLHandler.ChildColumns.FIRSTNAME2 + "," + SQLHandler.ChildColumns.LASTNAME1 + "," + SQLHandler.ChildColumns.BIRTHDATE + "," + SQLHandler.ChildColumns.GENDER + "," + SQLHandler.ChildColumns.TEMP_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY + "," + SQLHandler.ChildColumns.DOMICILE + "," + SQLHandler.ChildColumns.DOMICILE_ID + "," + SQLHandler.ChildColumns.HEALTH_FACILITY_ID + "," + SQLHandler.ChildColumns.STATUS_ID + "," + SQLHandler.ChildColumns.BIRTHPLACE_ID + "," + SQLHandler.ChildColumns.NOTES + "," + SQLHandler.ChildColumns.STATUS + "," + SQLHandler.ChildColumns.MOTHER_FIRSTNAME + "," + SQLHandler.ChildColumns.MOTHER_LASTNAME + "," + SQLHandler.ChildColumns.PHONE + "," + SQLHandler.ChildColumns.CUMULATIVE_SERIAL_NUMBER + "," + SQLHandler.ChildColumns.CHILD_REGISTRY_YEAR + "," + SQLHandler.ChildColumns.MOTHER_VVU_STS + "," + SQLHandler.ChildColumns.MOTHER_TT2_STS + "," + SQLHandler.ChildColumns.MODIFIED_ON + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?)"; SQLiteStatement stmt0 = db1.compileStatement(sql0); for (Child child : children) { containsData = true; stmt0.bindString(1, "1"); stmt0.bindString(2, child.getId() == null ? "" : child.getId()); stmt0.bindString(3, child.getBarcodeID() == null ? "" : child.getBarcodeID()); stmt0.bindString(4, child.getFirstname1() == null ? "" : child.getFirstname1()); stmt0.bindString(5, child.getFirstname2() == null ? "" : child.getFirstname2()); stmt0.bindString(6, child.getLastname1() == null ? "" : child.getLastname1()); stmt0.bindString(7, child.getBirthdate() == null ? "" : child.getBirthdate()); stmt0.bindString(8, child.getGender() == null ? "" : child.getGender()); stmt0.bindString(9, child.getTempId() == null ? "" : child.getTempId()); stmt0.bindString(10, child.getHealthcenter() == null ? "" : child.getHealthcenter()); stmt0.bindString(11, child.getDomicile() == null ? "" : child.getDomicile()); stmt0.bindString(12, child.getDomicileId() == null ? "" : child.getDomicileId()); stmt0.bindString(13, child.getHealthcenterId() == null ? "" : child.getHealthcenterId()); stmt0.bindString(14, child.getStatusId() == null ? "" : child.getStatusId()); stmt0.bindString(15, child.getBirthplaceId() == null ? "" : child.getBirthplaceId()); stmt0.bindString(16, child.getNotes() == null ? "" : child.getNotes()); stmt0.bindString(17, child.getDomicile() == null ? "" : child.getDomicile()); stmt0.bindString(18, child.getMotherFirstname() == null ? "" : child.getMotherFirstname()); stmt0.bindString(19, child.getMotherLastname() == null ? "" : child.getMotherLastname()); stmt0.bindString(20, child.getPhone() == null ? "" : child.getPhone()); stmt0.bindString(21, child.getChildCumulativeSn() == null ? "" : child.getChildCumulativeSn()); stmt0.bindString(22, child.getChildRegistryYear() == null ? "" : child.getChildRegistryYear()); stmt0.bindString(23, child.getMotherHivStatus() == null ? "" : child.getMotherHivStatus()); stmt0.bindString(24, child.getMotherTT2Status() == null ? "" : child.getMotherTT2Status()); stmt0.bindString(25, child.getModifiedOn() == null ? "" : child.getModifiedOn()); stmt0.execute(); stmt0.clearBindings(); } } if (vaccinationEvents != null) { String sql = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_EVENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationEventColumns.APPOINTMENT_ID + "," + SQLHandler.VaccinationEventColumns.CHILD_ID + "," + SQLHandler.VaccinationEventColumns.DOSE_ID + "," + SQLHandler.VaccinationEventColumns.HEALTH_FACILITY_ID + "," + SQLHandler.VaccinationEventColumns.ID + "," + SQLHandler.VaccinationEventColumns.IS_ACTIVE + "," + SQLHandler.VaccinationEventColumns.MODIFIED_BY + "," + SQLHandler.VaccinationEventColumns.MODIFIED_ON + "," + SQLHandler.VaccinationEventColumns.NONVACCINATION_REASON_ID + "," + SQLHandler.VaccinationEventColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_DATE + "," + SQLHandler.VaccinationEventColumns.VACCINATION_STATUS + "," + SQLHandler.VaccinationEventColumns.VACCINE_LOT_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt = db1.compileStatement(sql); for (VaccinationEvent vaccinationEvent : vaccinationEvents) { containsData = true; stmt.bindString(1, "1"); stmt.bindString(2, vaccinationEvent.getAppointmentId()); stmt.bindString(3, vaccinationEvent.getChildId()); stmt.bindString(4, vaccinationEvent.getDoseId()); stmt.bindString(5, vaccinationEvent.getHealthFacilityId()); stmt.bindString(6, vaccinationEvent.getId()); stmt.bindString(7, vaccinationEvent.getIsActive()); stmt.bindString(8, vaccinationEvent.getModifiedBy()); stmt.bindString(9, vaccinationEvent.getModifiedOn()); stmt.bindString(10, vaccinationEvent.getNonvaccinationReasonId()); stmt.bindString(11, vaccinationEvent.getScheduledDate()); stmt.bindString(12, vaccinationEvent.getVaccinationDate()); stmt.bindString(13, vaccinationEvent.getVaccinationStatus()); stmt.bindString(14, vaccinationEvent.getVaccineLotId()); stmt.execute(); stmt.clearBindings(); } } if (vaccinationAppointments != null) { String sql1 = "INSERT OR REPLACE INTO " + SQLHandler.Tables.VACCINATION_APPOINTMENT + " ( " + SQLHandler.SyncColumns.UPDATED + ", " + SQLHandler.VaccinationAppointmentColumns.CHILD_ID + "," + SQLHandler.VaccinationAppointmentColumns.ID + "," + SQLHandler.VaccinationAppointmentColumns.IS_ACTIVE + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_BY + "," + SQLHandler.VaccinationAppointmentColumns.MODIFIED_ON + "," + SQLHandler.VaccinationAppointmentColumns.NOTES + "," + SQLHandler.VaccinationAppointmentColumns.OUTREACH + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_DATE + "," + SQLHandler.VaccinationAppointmentColumns.SCHEDULED_FACILITY_ID + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?,?)"; SQLiteStatement stmt1 = db1.compileStatement(sql1); for (VaccinationAppointment vaccinationAppointment : vaccinationAppointments) { containsData = true; stmt1.bindString(1, "1"); stmt1.bindString(2, vaccinationAppointment.getChildId()); stmt1.bindString(3, vaccinationAppointment.getId()); stmt1.bindString(4, vaccinationAppointment.getIsActive()); stmt1.bindString(5, vaccinationAppointment.getModifiedBy()); stmt1.bindString(6, vaccinationAppointment.getModifiedOn()); stmt1.bindString(7, vaccinationAppointment.getNotes()); stmt1.bindString(8, vaccinationAppointment.getOutreach()); stmt1.bindString(9, vaccinationAppointment.getScheduledDate()); stmt1.bindString(10, vaccinationAppointment.getScheduledFacilityId()); Log.d("day20", "Out Reach for " + vaccinationAppointment.getChildId() + " is : " + vaccinationAppointment.getOutreach()); stmt1.execute(); stmt1.clearBindings(); } } db1.setTransactionSuccessful(); db1.endTransaction(); } catch (Exception e) { try { db1.endTransaction(); } catch (Exception e1) { e1.printStackTrace(); } e.printStackTrace(); } Log.d("coze", "saving data to db returning = " + containsData); return containsData; }