List of usage examples for android.database.sqlite SQLiteStatement bindString
public void bindString(int index, String value)
From source file:com.ichi2.anki.SyncClient.java
private void updateCards(JSONArray cards) { int len = cards.length(); if (len > 0) { AnkiDb ankiDB = AnkiDatabaseManager.getDatabase(mDeck.getDeckPath()); ArrayList<String> ids = new ArrayList<String>(); for (int i = 0; i < len; i++) { try { ids.add(cards.getJSONArray(i).getString(0)); } catch (JSONException e) { Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); }//from w w w.j a v a 2s .co m } String idsString = Utils.ids2str(ids); mDeck.setCardCount((int) (mDeck.getCardCount() + (len - ankiDB.queryScalar("SELECT COUNT(*) FROM cards WHERE id IN " + idsString)))); String sql = "INSERT OR REPLACE INTO cards (id, factId, cardModelId, created, modified, tags, ordinal, " + "priority, interval, lastInterval, due, lastDue, factor, firstAnswered, reps, successive, " + "averageTime, reviewTime, youngEase0, youngEase1, youngEase2, youngEase3, youngEase4, " + "matureEase0, matureEase1, matureEase2, matureEase3, matureEase4, yesCount, noCount, question, " + "answer, lastFactor, spaceUntil, type, combinedDue, relativeDelay, isDue) " + "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, 0, 0)"; SQLiteStatement statement = ankiDB.getDatabase().compileStatement(sql); for (int i = 0; i < len; i++) { try { JSONArray card = cards.getJSONArray(i); // id statement.bindLong(1, card.getLong(0)); // factId statement.bindLong(2, card.getLong(1)); // cardModelId statement.bindLong(3, card.getLong(2)); // created statement.bindDouble(4, card.getDouble(3)); // modified statement.bindDouble(5, card.getDouble(4)); // tags statement.bindString(6, card.getString(5)); // ordinal statement.bindString(7, card.getString(6)); // priority statement.bindString(8, card.getString(7)); // interval statement.bindDouble(9, card.getDouble(8)); // lastInterval statement.bindDouble(10, card.getDouble(9)); // due statement.bindDouble(11, card.getDouble(10)); // lastDue statement.bindDouble(12, card.getDouble(11)); // factor statement.bindDouble(13, card.getDouble(12)); // firstAnswered statement.bindDouble(14, card.getDouble(13)); // reps statement.bindString(15, card.getString(14)); // successive statement.bindString(16, card.getString(15)); // averageTime statement.bindDouble(17, card.getDouble(16)); // reviewTime statement.bindDouble(18, card.getDouble(17)); // youngEase0 statement.bindString(19, card.getString(18)); // youngEase1 statement.bindString(20, card.getString(19)); // youngEase2 statement.bindString(21, card.getString(20)); // youngEase3 statement.bindString(22, card.getString(21)); // youngEase4 statement.bindString(23, card.getString(22)); // matureEase0 statement.bindString(24, card.getString(23)); // matureEase1 statement.bindString(25, card.getString(24)); // matureEase2 statement.bindString(26, card.getString(25)); // matureEase3 statement.bindString(27, card.getString(26)); // matureEase4 statement.bindString(28, card.getString(27)); // yesCount statement.bindString(29, card.getString(28)); // noCount statement.bindString(30, card.getString(29)); // question statement.bindString(31, card.getString(30)); // answer statement.bindString(32, card.getString(31)); // lastFactor statement.bindDouble(33, card.getDouble(32)); // spaceUntil statement.bindDouble(34, card.getDouble(33)); // type statement.bindString(35, card.getString(34)); // combinedDue statement.bindString(36, card.getString(35)); statement.execute(); } catch (JSONException e) { Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); } } statement.close(); ankiDB.getDatabase().execSQL("DELETE FROM cardsDeleted WHERE cardId IN " + idsString); } }
From source file:com.newsrob.EntryManager.java
private void deleteArticlesFromDb(final SyncJob job, final List<String> articleIdsToDeleteInDatabase) { if (articleIdsToDeleteInDatabase.isEmpty()) return;// ww w . j a va 2 s . co m Timing t2 = new Timing("Delete Articles From Db", ctx); job.setJobDescription("Cleaning up database"); job.target = articleIdsToDeleteInDatabase.size(); job.actual = 0; fireStatusUpdated(); SQLiteDatabase db = databaseHelper.getDb(); final String sql1 = "DELETE FROM " + Entries.TABLE_NAME + " WHERE " + Entries.__ID + "=?;"; final String sql2 = "DELETE FROM " + EntryLabelAssociations.TABLE_NAME + " WHERE " + EntryLabelAssociations.ENTRY_ID + "=?;"; final SQLiteStatement stmt1 = db.compileStatement(sql1); final SQLiteStatement stmt2 = db.compileStatement(sql2); try { // outter loop does the chunking and holds the transaction context while (!articleIdsToDeleteInDatabase.isEmpty()) { db.beginTransaction(); while (!articleIdsToDeleteInDatabase.isEmpty()) { String id = articleIdsToDeleteInDatabase.remove(0); stmt1.bindString(1, id); stmt1.execute(); stmt2.bindString(1, id); stmt2.execute(); job.actual++; if (job.actual % 10 == 0) fireStatusUpdated(); // commit every 35 articles if (job.actual >= 35) break; } db.setTransactionSuccessful(); db.endTransaction(); } } finally { stmt1.close(); stmt2.close(); } fireStatusUpdated(); t2.stop(); }
From source file:com.grazerss.EntryManager.java
private void deleteArticlesFromDb(final SyncJob job, final List<String> articleIdsToDeleteInDatabase) { if (articleIdsToDeleteInDatabase.isEmpty()) { return;/*from w ww . j a v a 2 s . c o m*/ } Timing t2 = new Timing("Delete Articles From Db", ctx); job.setJobDescription("Cleaning up database"); job.target = articleIdsToDeleteInDatabase.size(); job.actual = 0; fireStatusUpdated(); SQLiteDatabase db = databaseHelper.getDb(); final String sql1 = "DELETE FROM " + Entries.TABLE_NAME + " WHERE " + Entries.__ID + "=?;"; final String sql2 = "DELETE FROM " + EntryLabelAssociations.TABLE_NAME + " WHERE " + EntryLabelAssociations.ENTRY_ID + "=?;"; final SQLiteStatement stmt1 = db.compileStatement(sql1); final SQLiteStatement stmt2 = db.compileStatement(sql2); try { // outter loop does the chunking and holds the transaction context while (!articleIdsToDeleteInDatabase.isEmpty()) { db.beginTransaction(); while (!articleIdsToDeleteInDatabase.isEmpty()) { String id = articleIdsToDeleteInDatabase.remove(0); stmt1.bindString(1, id); stmt1.execute(); stmt2.bindString(1, id); stmt2.execute(); job.actual++; if ((job.actual % 10) == 0) { fireStatusUpdated(); } // commit every 35 articles if (job.actual >= 35) { break; } } db.setTransactionSuccessful(); db.endTransaction(); } } finally { stmt1.close(); stmt2.close(); } fireStatusUpdated(); t2.stop(); }
From source file:mobile.tiis.appv2.base.BackboneApplication.java
public void updateChildVaccinationEventVaccinationAppointment(ChildCollector childCollector) { Child child = childCollector.getChildEntity(); List<VaccinationEvent> vaccinationEvents = childCollector.getVeList(); List<VaccinationAppointment> vaccinationAppointments = childCollector.getVaList(); ContentValues childCV = new ContentValues(); DatabaseHandler db = getDatabaseInstance(); SQLiteDatabase db1 = db.getWritableDatabase(); db1.beginTransactionNonExclusive();//from w w w.j a va2 s . c o m try { 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.CUMULATIVE_SERIAL_NUMBER + "," + SQLHandler.ChildColumns.CHILD_REGISTRY_YEAR + "," + SQLHandler.ChildColumns.MOTHER_TT2_STS + "," + SQLHandler.ChildColumns.MOTHER_VVU_STS + "," + SQLHandler.ChildColumns.PHONE + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt0 = db1.compileStatement(sql0); 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.getStatus() == null ? "" : child.getStatus()); stmt0.bindString(18, child.getMotherFirstname() == null ? "" : child.getMotherFirstname()); stmt0.bindString(19, child.getMotherLastname() == null ? "" : child.getMotherLastname()); stmt0.bindString(20, child.getChildCumulativeSn() == null ? "" : child.getChildCumulativeSn()); stmt0.bindString(21, child.getChildRegistryYear() == null ? "" : child.getChildRegistryYear()); stmt0.bindString(22, child.getMotherTT2Status() == null ? "" : child.getMotherTT2Status()); stmt0.bindString(23, child.getMotherHivStatus() == null ? "" : child.getMotherHivStatus()); stmt0.bindString(24, child.getPhone() == null ? "" : child.getPhone()); stmt0.execute(); stmt0.clearBindings(); 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) { 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(); } 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) { 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()); stmt1.execute(); stmt1.clearBindings(); } db1.setTransactionSuccessful(); db1.endTransaction(); } catch (Exception e) { db1.endTransaction(); e.printStackTrace(); } }
From source file:mobile.tiis.appv2.base.BackboneApplication.java
/** * method used to add child, vaccination appointments and vaccination events into the database * * @param childCollector/* ww w . j a v a 2s . c o m*/ */ public void addChildVaccinationEventVaccinationAppointment(ChildCollector childCollector) { Child child = childCollector.getChildEntity(); List<VaccinationEvent> vaccinationEvents = childCollector.getVeList(); List<VaccinationAppointment> vaccinationAppointments = childCollector.getVaList(); ContentValues childCV = new ContentValues(); DatabaseHandler db = getDatabaseInstance(); SQLiteDatabase db1 = db.getWritableDatabase(); db1.beginTransactionNonExclusive(); try { 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.CUMULATIVE_SERIAL_NUMBER + "," + SQLHandler.ChildColumns.CHILD_REGISTRY_YEAR + "," + SQLHandler.ChildColumns.MOTHER_TT2_STS + "," + SQLHandler.ChildColumns.MOTHER_VVU_STS + "," + SQLHandler.ChildColumns.PHONE + " ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; SQLiteStatement stmt0 = db1.compileStatement(sql0); 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.getStatus() == null ? "" : child.getStatus()); stmt0.bindString(18, child.getMotherFirstname() == null ? "" : child.getMotherFirstname()); stmt0.bindString(19, child.getMotherLastname() == null ? "" : child.getMotherLastname()); stmt0.bindString(20, child.getChildCumulativeSn() == null ? "" : child.getChildCumulativeSn()); stmt0.bindString(21, child.getChildRegistryYear() == null ? "" : child.getChildRegistryYear()); stmt0.bindString(22, child.getMotherTT2Status() == null ? "" : child.getMotherTT2Status()); stmt0.bindString(23, child.getMotherHivStatus() == null ? "" : child.getMotherHivStatus()); stmt0.bindString(24, child.getPhone() == null ? "" : child.getPhone()); stmt0.execute(); stmt0.clearBindings(); 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) { 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(); } 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) { 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()); stmt1.execute(); stmt1.clearBindings(); } db1.setTransactionSuccessful(); db1.endTransaction(); } catch (Exception e) { db1.endTransaction(); e.printStackTrace(); } }
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();// w w w . j a v a 2s . c o 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; }