public Update ( String tableName, String>.Dictionary |
||
tableName | String | The table to update. |
data | String>.Dictionary | A dictionary containing Column names and their new values. |
where | String | The where clause for the update statement. |
return | bool |
/** * Handle updating data. */ public override int Update(Uri uri, Android_Content.ContentValues values, string where, string[] whereArgs) { SQLiteDatabase db = mOpenHelper.GetWritableDatabase(); int count; string constWhere; switch (mUriMatcher.Match(uri)) { case MAIN: // If URI is main table, update uses incoming where clause and args. count = db.Update(MainTable.TABLE_NAME, values, where, whereArgs); break; case MAIN_ID: // If URI is for a particular row ID, update is based on incoming // data but modified to restrict to the given ID. constWhere = DatabaseUtilsCompat.ConcatenateWhere( IBaseColumnsConstants._ID + " = " + Android_Content.ContentUris.ParseId(uri), where); count = db.Update(MainTable.TABLE_NAME, values, constWhere, whereArgs); break; default: throw new System.ArgumentException("Unknown URI " + uri); } GetContext().GetContentResolver().NotifyChange(uri, null); return count; }
//Update Existing contact public void UpdateInfoMedica(InfoMedica infoMedica) { if (infoMedica == null) { return; } //Obtain writable database SQLiteDatabase db = this.WritableDatabase; //Prepare content values ContentValues vals = new ContentValues(); vals.Put("idPersona", infoMedica.idPersona); vals.Put("identificacion", infoMedica.identificacion); vals.Put("peso", infoMedica.peso); vals.Put("altura", infoMedica.altura); vals.Put("presionArterial", infoMedica.presionArterial); vals.Put("frecuenciaCardiaca", infoMedica.frecuenciaCardiaca); vals.Put("detalle", infoMedica.detalle); ICursor cursor = db.Query("InfoMedica", new String[] { "id", "idPersona", "identificacion", "peso", "altura", "presionArterial", "frecuenciaCardiaca", "detalle" }, "id=?", new string[] { infoMedica.id.ToString() }, null, null, null, null); if (cursor != null) { if (cursor.MoveToFirst()) { // update the row db.Update("InfoMedica", vals, "id=?", new String[] { cursor.GetString(0) }); } cursor.Close(); } }
//Сюди будемо передавати одиницю, якщо хочемо здійснити запис в базу даних protected override bool RunInBackground(params int[] @params) { int param = @params[0]; if (param == 1) { SQLiteOpenHelper updateRoomDatabaseHelper = new RationalCleaningDatabaseHelper(myActivity); try { SQLiteDatabase db = updateRoomDatabaseHelper.WritableDatabase; ContentValues roomValues = new ContentValues(); roomValues.Put("TITLE", roomTitle); roomValues.Put("IMAGE_ID", roomImageId); //Якщо провтикать, то вийде оновити title розділів, у яких title не повинен змінюватися (розділи із умовою isRoom == 0 (true)) //По хорошому, щоб ніде не провтичить, варто було б десь тут захист поставити. Сподіваюся найближчим часом я упорюсь і зроблю це. Інакше чекай новий фейлів db.Update("ROOM_TABLE", roomValues, "_id = ?", new string[] { roomId.ToString() }); db.Close(); return(true); } catch (SQLException) { return(false); } } return(false); }
//Update Existing contact public void UpdateUser(User useritem) { if (useritem == null) { return; } //Obtain writable database SQLiteDatabase db = this.WritableDatabase; //Prepare content values ContentValues vals = new ContentValues(); vals.Put("Firstname", useritem.Firstname); vals.Put("Lastname", useritem.Lastname); vals.Put("Address", useritem.Address); vals.Put("Email", useritem.Email); ICursor cursor = db.Query("User", new String[] { "Id", "Firstname", "Lastname", "Address", "Email" }, "Id=?", new string[] { useritem.Id.ToString() }, null, null, null, null); if (cursor != null) { if (cursor.MoveToFirst()) { // update the row db.Update("User", vals, "Id=?", new String[] { cursor.GetString(0) }); } cursor.Close(); } }
private void btn_next_keluarga_Click(object sender, EventArgs e) { SQLiteDatabase db = new SQLiteDatabase(); Dictionary <String, String> berkas = new Dictionary <String, String>(); berkas.Add("NILAI_SMT_4", txt_ntotal_4.Text); berkas.Add("NILAI_SMT_5", txt_ntotal_5.Text); berkas.Add("NILAI_SMT_6", txt_ntotal_6.Text); berkas.Add("JUMLAH_MAPEL_SMT_4", txt_jmapel_4.Text); berkas.Add("JUMLAH_MAPEL_SMT_5", txt_jmapel_5.Text); berkas.Add("JUMLAH_MAPEL_SMT_6", txt_jmapel_6.Text); berkas.Add("RANKING_SMT_4", txt_ranking_4.Text); berkas.Add("RANKING_SMT_5", txt_ranking_5.Text); berkas.Add("RANKING_SMT_6", txt_ranking_6.Text); berkas.Add("JURUSAN", cmb_jurusan_sekolah.SelectedValue.ToString()); berkas.Add("NILAI_UNAS", txt_nunas.Text); berkas.Add("JUMLAH_MAPEL_UNAS", txt_jmapel_unas.Text); try { db.Update("berkas", berkas, String.Format("NO_INDUK = {0}", IsianSiswa.NO_INDUK)); MessageBox.Show("Data berhasil tersimpan", "Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information); tc_siswa.SelectedTab = tp_prestasi; } catch (Exception crap) { MessageBox.Show(crap.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//Update Existing contact public void UpdateContact(AddressBook contitem) { if (contitem == null) { return; } //Obtain writable database SQLiteDatabase db = this.WritableDatabase; //Prepare content values ContentValues vals = new ContentValues(); vals.Put("FullName", contitem.FullName); vals.Put("Mobile", contitem.Mobile); vals.Put("Email", contitem.Email); vals.Put("Details", contitem.Details); ICursor cursor = db.Query("AddressBook", new String[] { "Id", "FullName", "Mobile", "Email", "Details" }, "Id=?", new string[] { contitem.Id.ToString() }, null, null, null, null); if (cursor != null) { if (cursor.MoveToFirst()) { // update the row db.Update("AddressBook", vals, "Id=?", new String[] { cursor.GetString(0) }); } cursor.Close(); } }
//Сюди будемо передавати одиницю, якщо хочемо здійснити запис в базу даних protected override bool RunInBackground(params int[] @params) { int param = @params[0]; if (param == 1) { SQLiteOpenHelper updateCleaningTaskDatabaseHelper = new RationalCleaningDatabaseHelper(myActivity); try { SQLiteDatabase db = updateCleaningTaskDatabaseHelper.WritableDatabase; ContentValues taskValues = new ContentValues(); //taskValues.Put("YEAR", year); //taskValues.Put("MONTH", month); //taskValues.Put("DAY_OF_MONTH", dayOfMonth); taskValues.Put("YEAR_OF_CHANGE", yearOfChange); taskValues.Put("MONTH_OF_CHANGE", monthOfChange); taskValues.Put("DAY_OF_MONTH_OF_CHANGE", dayOfMonthOfChange); db.Update("CLEANING_TASK_TABLE", taskValues, "_id = ?", new string[] { taskId.ToString() }); db.Close(); return(true); } catch (SQLException) { return(false); } } return(false); }
private void ButtonSave_Click(object sender, EventArgs e) { if (DataGridViewTimes.SelectedRows.Count > 0) { // vars string timeStampId = DataGridViewTimes.SelectedRows[0].Cells[2].Value.ToString(); try { //Make sure clockOut date is the same as clockIn date clockInTimePicker.Value = datePicker.Value.Date + clockInTimePicker.Value.TimeOfDay; clockOutTimePicker.Value = datePicker.Value.Date + clockOutTimePicker.Value.TimeOfDay; Dictionary <String, String> data = new Dictionary <String, String>(); data.Add("clockIn", clockInTimePicker.Value.ToString(StringFormats.sqlTimeFormat)); data.Add("clockOut", clockOutTimePicker.Value.ToString(StringFormats.sqlTimeFormat)); if (sql.Update("timeStamps", data, String.Format("timeStamps.id = {0}", timeStampId))) { DataGridViewTimes.SelectedRows[0].Cells[0].Value = clockInTimePicker.Value.ToString(StringFormats.timeStampFormat); DataGridViewTimes.SelectedRows[0].Cells[1].Value = clockOutTimePicker.Value.ToString(StringFormats.timeStampFormat); DataGridViewTimes.Sort(DataGridViewTimes.Columns[0], System.ComponentModel.ListSortDirection.Ascending); } // disable duplicate saving DisableUI(); DisableTimePickers(); } catch (Exception err) { MessageBox.Show(this, "There was an error while trying to save your changes.\n\n" + err.Message, "Time Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void Save(SQLiteDatabase sqLiteDatabase) { try { if (sqLiteDatabase.IsOpen) { if (IsNew) { try { string[] columns = { "ThoughtRecordID", "Alternative", "BeliefRating" }; ContentValues values = new ContentValues(); values.Put("ThoughtRecordID", ThoughtRecordId); values.Put("Alternative", Alternative.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("BeliefRating", BeliefRating); AlternativeThoughtsId = (int)sqLiteDatabase.Insert("AlternativeThoughts", null, values); IsNew = false; IsDirty = false; } catch (Exception newE) { throw new Exception("Unable to Save Alternative Thought in database - " + newE.Message); } } if (IsDirty) { try { ContentValues values = new ContentValues(); values.Put("ThoughtRecordID", ThoughtRecordId); values.Put("Alternative", Alternative.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("BeliefRating", BeliefRating); string whereClause = "AlternativeThoughtsID = " + AlternativeThoughtsId; sqLiteDatabase.Update("AlternativeThoughts", values, whereClause, null); IsDirty = false; } catch (Exception dirtyE) { throw new Exception("Unable to Update Alternative Thought in database - " + dirtyE.Message); } } } } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); } }
public void Save(SQLiteDatabase sqlDatabase) { if (sqlDatabase != null && sqlDatabase.IsOpen) { //ccannot save without a corresponding ActivityID if (ActivityID != -1) { Log.Info(TAG, "Save: Attempting to Save ActivityTime for Activity with ID " + ActivityID.ToString()); try { if (!string.IsNullOrEmpty(ActivityName)) { Log.Info(TAG, "Save: Found Activity Name - " + ActivityName); if (!(IsNew || IsDirty)) { Log.Info(TAG, "Save: Unchanged ActivityTime detected - no work to do!"); return; } ContentValues values = new ContentValues(); values.Put("ActivityName", ActivityName); values.Put("ActivityTime", (int)ActivityTime); values.Put("Achievement", Achievement); values.Put("Intimacy", Intimacy); values.Put("Pleasure", Pleasure); if (IsNew) { Log.Info(TAG, "Save: Is a new ActivityTime, using ActivityID - " + ActivityID.ToString()); values.Put("ActivityID", ActivityID); ActivityTimeID = (int)sqlDatabase.Insert("ActivityTimes", null, values); Log.Info(TAG, "Save: Saved ActivityTime with ID " + ActivityTimeID.ToString()); IsNew = false; IsDirty = false; } if (IsDirty) { Log.Info(TAG, "Save: Found existing ActivityTime with ActivityID - " + ActivityID.ToString() + " and ActivityTimesID - " + ActivityTimeID.ToString()); var whereClause = "ActivityID = " + ActivityID + " AND ActivityTimesID = " + ActivityTimeID; sqlDatabase.Update("ActivityTimes", values, whereClause, null); Log.Info(TAG, "Save: Updated successfully"); IsDirty = false; } } else { Log.Info(TAG, "Save: Skipping Save of ActivityTime because its name was null!"); } } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); } } else { throw new Exception("Cannot save Activity time details because Activity ID is invalid (did you forget to save the Main Activity?)"); } } }
public void Save(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { if (IsNew) { try { string[] columns = { "CountryName", "PoliceNumber", "AmbulanceNumber", "FireNumber", "Notes" }; ContentValues values = new ContentValues(); values.Put("CountryName", CountryName.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("PoliceNumber", PoliceNumber.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("AmbulanceNumber", AmbulanceNumber.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("FireNumber", FireNumber.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("Notes", Notes.Trim().Replace("'", "''").Replace("\"", "\"\"")); EmergencyNumberID = (int)sqLiteDatabase.Insert("EmergencyNumbers", null, values); IsNew = false; IsDirty = false; } catch (Exception newE) { throw new Exception("Unable to Save EmergencyNumber in database - " + newE.Message); } } if (IsDirty) { try { ContentValues values = new ContentValues(); values.Put("CountryName", CountryName.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("PoliceNumber", PoliceNumber.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("AmbulanceNumber", AmbulanceNumber.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("FireNumber", FireNumber.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("Notes", Notes.Trim().Replace("'", "''").Replace("\"", "\"\"")); string whereClause = "EmergencyNumberID = " + EmergencyNumberID; sqLiteDatabase.Update("EmergencyNumbers", values, whereClause, null); IsDirty = false; } catch (Exception dirtyE) { throw new Exception("Unable to Update Emergency Number in database - " + dirtyE.Message); } } } }
public void SetActualVersion(int version) { // SQLiteDatabase _objSQLiteDatabase = _sqliteUtil.WritableDatabase; ContentValues cv = new ContentValues(); cv.Put("VALUE", version.ToString()); _objSQLiteDatabase.Update("SETTING", cv, $"KEY='VERSION'", null); }
/** * Execute update using the current internal state as {@code WHERE} clause. */ public int Update(SQLiteDatabase db, ContentValues values) { AssertTable(); if (LOGV) { Log.Verbose(TAG, "update() " + this); } return(db.Update(mTable, values, GetSelection(), GetSelectionArgs())); }
public bool Save(int medicationSpreadID) { SQLiteDatabase sqlDatabase = null; try { Globals dbHelp = new Globals(); dbHelp.OpenDatabase(); sqlDatabase = dbHelp.GetSQLiteDatabase(); if (sqlDatabase != null) { if (sqlDatabase.IsOpen) { if (IsNew) { Log.Info(TAG, "Save: Saving new Medication Time to Spread ID - " + medicationSpreadID.ToString()); ContentValues values = new ContentValues(); values.Put("MedicationSpreadID", medicationSpreadID); values.Put("MedicationTime", (int)MedicationTime); values.Put("TakenTime", string.Format("{0:HH:mm:ss}", TakenTime)); Log.Info(TAG, "Save: Stored Medication Time - " + StringHelper.MedicationTimeForConstant(MedicationTime) + ", Time Taken - " + TakenTime.ToShortTimeString()); ID = (int)sqlDatabase.Insert("MedicationTime", null, values); Log.Info(TAG, "Save: Saved Medication Time with new ID - " + ID.ToString()); IsNew = false; IsDirty = false; Log.Info(TAG, "Save: IsNew - FALSE, IsDirty - FALSE"); } if (IsDirty) { Log.Info(TAG, "Save (Update): Updating existing Medication Time for Spread ID - " + medicationSpreadID.ToString()); ContentValues values = new ContentValues(); values.Put("MedicationSpreadID", medicationSpreadID); values.Put("MedicationTime", (int)MedicationTime); values.Put("TakenTime", string.Format("{0:HH:mm:ss}", TakenTime)); Log.Info(TAG, "Save (Update): Stored Medication Time - " + StringHelper.MedicationTimeForConstant(MedicationTime) + ", Taken Time - " + TakenTime.ToShortTimeString()); string whereClause = "ID = ?"; sqlDatabase.Update("MedicationTime", values, whereClause, new string[] { ID.ToString() }); IsDirty = false; Log.Info(TAG, "Save (Update): IsDirty - FALSE"); } sqlDatabase.Close(); return(true); } } return(false); } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); if (sqlDatabase != null && sqlDatabase.IsOpen) { sqlDatabase.Close(); } return(false); } }
public void Save() { SQLiteDatabase sqlDatabase = null; try { Globals dbHelp = new Globals(); dbHelp.OpenDatabase(); sqlDatabase = dbHelp.GetSQLiteDatabase(); if (sqlDatabase != null) { if (sqlDatabase.IsOpen) { if (IsNew) { ContentValues values = new ContentValues(); values.Put("WithWhom", WithWhom); values.Put("Type", (int)Type); values.Put("Strength", Strength); values.Put("Feeling", Feeling); values.Put("Action", (int)Action); values.Put("ActionOf", ActionOf); RelationshipsID = (int)sqlDatabase.Insert("Relationships", null, values); IsNew = false; IsDirty = false; } if (IsDirty) { ContentValues values = new ContentValues(); values.Put("WithWhom", WithWhom); values.Put("Type", (int)Type); values.Put("Strength", Strength); values.Put("Feeling", Feeling); values.Put("Action", (int)Action); values.Put("ActionOf", ActionOf); string whereClause = "RelationshipsID = ?"; sqlDatabase.Update("Relationships", values, whereClause, new string[] { RelationshipsID.ToString() }); IsDirty = false; } sqlDatabase.Close(); } } } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); if (sqlDatabase != null && sqlDatabase.IsOpen) { sqlDatabase.Close(); } } }
public void SaveShiftsEntry(ShiftsEntry item, bool overwrite) { //Datensatz erstellen string read = DatabaseHelper.BOOL_FALSE; if (item.MarkedRead) { read = DatabaseHelper.BOOL_TRUE; } ContentValues values = new ContentValues(); values.Put(DatabaseHelper.SHIFT_TABLE_COL_KEY, item.Key); values.Put(DatabaseHelper.SHIFT_TABLE_COL_TITLE, item.Title); values.Put(DatabaseHelper.SHIFT_TABLE_COL_MONTH, item.Month); values.Put(DatabaseHelper.SHIFT_TABLE_COL_YEAR, item.Year); values.Put(DatabaseHelper.SHIFT_TABLE_COL_UPDATE, TBL.EncodeDateToString(item.LastUpdate)); values.Put(DatabaseHelper.SHIFT_TABLE_COL_VERSION, item.LastVersion); values.Put(DatabaseHelper.SHIFT_TABLE_COL_READ, read); //Datenbank aktualisieren if (item.ID < 0) { //Neuen Eintrag anlegen int ID = (int)database.Insert(DatabaseHelper.SHIFT_TABLE, null, values); item.ID = ID; } else { if (overwrite) { //Bestehenden Eintrag überschreiben string id_filter = DatabaseHelper.SHIFT_TABLE_COL_ID + "='" + item.ID + "'"; database.Update(DatabaseHelper.SHIFT_TABLE, values, id_filter, null); } } //Feed-Anhänge aktualisieren SaveAttachment(item.ShiftAttachment, DatabaseHelper.OWNER_SHIFTS, item.ID, overwrite); }
public void Save(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { ContentValues values = new ContentValues(); try { values.Put("URI", ContactUri); values.Put("ContactName", ContactName.Trim()); values.Put("ContactTelephoneNumber", ContactTelephoneNumber.Trim()); values.Put("ContactPhotoId", 0); values.Put("ContactEmail", ContactEmail.Trim()); values.Put("ContactUseEmergencyCall", Convert.ToInt16(ContactEmergencyCall)); values.Put("ContactUseEmergencySms", Convert.ToInt16(ContactEmergencySms)); values.Put("ContactUseEmergencyEmail", Convert.ToInt16(ContactEmergencyEmail)); } catch (Exception valE) { Log.Error(TAG, "Save: Exception - " + valE.Message); return; } if (IsNew) { try { ID = (int)sqLiteDatabase.Insert("Contacts", null, values); IsNew = false; IsDirty = false; } catch (Exception newE) { Log.Error(TAG, "Save: Save Exception - " + newE.Message); throw new Exception("Unable to save Contact to database - " + newE.Message); } } if (IsDirty) { try { //values.Put("ID", ID); sqLiteDatabase.Update("Contacts", values, "ID = ?", new string[] { ID.ToString() }); IsDirty = false; } catch (Exception updE) { Log.Error(TAG, "Save: Update Exception - " + updE.Message); } } } }
public void Save(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { if (IsNew) { try { ContentValues values = new ContentValues(); values.Put("ThoughtRecordID", ThoughtRecordId); string what = What.Trim().Replace("'", "''").Replace("\"", "\"\""); values.Put("What", what); string when = When.Trim().Replace("'", "''").Replace("\"", "\"\""); values.Put("[When]", when); string where = Where.Trim().Replace("'", "''").Replace("\"", "\"\""); values.Put("[Where]", where); string who = Who.Trim().Replace("'", "''").Replace("\"", "\"\""); values.Put("Who", who); SituationId = (int)sqLiteDatabase.Insert("Situation", null, values); IsNew = false; IsDirty = false; } catch (Exception newE) { throw new Exception("Unable to Save Situation to database - " + newE.Message); } } if (IsDirty) { try { ContentValues values = new ContentValues(); values.Put("[ThoughtRecordID]", ThoughtRecordId); values.Put("Who", Who.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("What", What.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("When", When.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("Where", Where.Trim().Replace("'", "''").Replace("\"", "\"\"")); string whereClause = "SituationID = " + SituationId; sqLiteDatabase.Update("Situation", values, whereClause, null); IsDirty = false; } catch (Exception dirtyE) { throw new Exception("Unable to Update Situation in the database - " + dirtyE.Message); } } } }
public void Save() { SQLiteDatabase sqlDatabase = null; try { Globals dbHelp = new Globals(); dbHelp.OpenDatabase(); sqlDatabase = dbHelp.GetSQLiteDatabase(); if (sqlDatabase != null) { if (sqlDatabase.IsOpen) { if (IsNew) { ContentValues values = new ContentValues(); values.Put("Aspect", Aspect); values.Put("Importance", Importance); values.Put("Type", (int)Type); values.Put("Action", (int)Action); values.Put("ActionOf", ActionOf); HealthID = (int)sqlDatabase.Insert("Health", null, values); IsNew = false; IsDirty = false; } if (IsDirty) { ContentValues values = new ContentValues(); values.Put("Aspect", Aspect); values.Put("Importance", Importance); values.Put("Type", (int)Type); values.Put("Action", (int)Action); values.Put("ActionOf", ActionOf); string whereClause = "HealthID = ?"; sqlDatabase.Update("Health", values, whereClause, new string[] { HealthID.ToString() }); IsDirty = false; } sqlDatabase.Close(); } } } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); if (sqlDatabase != null && sqlDatabase.IsOpen) { sqlDatabase.Close(); } } }
public bool Save(int medicationID) { SQLiteDatabase sqlDatabase = null; try { Globals dbHelp = new Globals(); dbHelp.OpenDatabase(); sqlDatabase = dbHelp.GetSQLiteDatabase(); if (sqlDatabase != null) { if (sqlDatabase.IsOpen) { if (IsNew) { ContentValues values = new ContentValues(); values.Put("MedicationID", medicationID); values.Put("PrescriptionType", (int)PrescriptionType); values.Put("WeeklyDay", (int)WeeklyDay); values.Put("MonthlyDay", MonthlyDay); ID = (int)sqlDatabase.Insert("Prescription", null, values); IsNew = false; IsDirty = false; } if (IsDirty) { ContentValues values = new ContentValues(); values.Put("MedicationID", medicationID); values.Put("PrescriptionType", (int)PrescriptionType); values.Put("WeeklyDay", (int)WeeklyDay); values.Put("MonthlyDay", MonthlyDay); string whereClause = "ID = ?"; sqlDatabase.Update("Prescription", values, whereClause, new string[] { ID.ToString() }); IsDirty = false; } sqlDatabase.Close(); return(true); } } return(false); } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); if (sqlDatabase != null && sqlDatabase.IsOpen) { sqlDatabase.Close(); } return(false); } }
// update entry public bool updateProgressoInfo(int id, int DesafiosRespondidos, int DesafiosCorretos, int DesafiosIncorretos) //update { SQLiteDatabase db = this.WritableDatabase; ContentValues contentValues = new ContentValues(); contentValues.Put("respondidos", DesafiosRespondidos); contentValues.Put("corretos", DesafiosCorretos); contentValues.Put("incorretos", DesafiosIncorretos); db.Update("Progresso", contentValues, "id = ? ", new String[] { Convert.ToString(id) }); //Java.Lang.RuntimeException: no such column: DesafiosCorretos (code 1): , while compiling: UPDATE Progresso SET DesafiosCorretos=?,DesafiosRespondidos=?,DesafiosIncorretos=? WHERE id = ? return(true); }
public void WriteCorrectAnswers(List <QuestionModel> questions, int idLevel, int maxLevel) { SQLiteDatabase _objSQLiteDatabase = _sqliteUtil.WritableDatabase; foreach (var record in questions) { ContentValues cv = new ContentValues(); cv.Put("IS_ANSWERED", record.IsAnswered ? 1 : 0); _objSQLiteDatabase.Update("QUESTIONS", cv, $"ID={record.IdQuestion}", null); } //unlock next level if (maxLevel < idLevel + 1) { //cannot increment MAX } else { ContentValues cv = new ContentValues(); cv.Put("IS_LOCKED", 0); _objSQLiteDatabase.Update("LEVELS", cv, $"ID={idLevel+1}", null); } }
public void Save(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { if (IsNew) { try { ContentValues values = new ContentValues(); values.Put("ThoughtRecordID", ThoughtRecordId); values.Put("MoodListID", MoodListId); values.Put("MoodRating", MoodRating); MoodsId = (int)sqLiteDatabase.Insert("Mood", null, values); IsNew = false; IsDirty = false; } catch (Exception newE) { throw new Exception("Unable to Save Mood - " + newE.Message); } } if (IsDirty) { try { string commandText = "UPDATE Mood SET [ThoughtRecordID] = " + ThoughtRecordId + ", " + " [MoodListID] = " + MoodListId + ", " + " [MoodRating] = " + MoodRating + " WHERE [MoodsID] = " + MoodsId; ContentValues values = new ContentValues(); values.Put("ThoughtRecordID", ThoughtRecordId); values.Put("MoodListID", MoodListId); values.Put("MoodRating", MoodRating); string whereClause = "MoodsID = " + MoodsId; sqLiteDatabase.Update("Mood", values, whereClause, null); IsDirty = false; } catch (Exception dirtyE) { throw new Exception("Unable to Update Mood - " + dirtyE.Message); } } } }
public void Save(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { if (IsNew) { try { ContentValues values = new ContentValues(); values.Put("CalmMyself", CalmMyself.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("TellMyself", TellMyself.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("WillCall", WillCall.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("WillGoTo", WillGoTo.Trim().Replace("'", "''").Replace("\"", "\"\"")); ID = (int)sqLiteDatabase.Insert("SafetyPlanCards", null, values); Log.Info(TAG, "Save: Saved to database successfully with an ID of " + ID.ToString()); IsNew = false; IsDirty = false; } catch (Exception newE) { Log.Error(TAG, "Save: Exception - " + newE.Message); throw new Exception("Unable to Save Safety Plan Card - " + newE.Message); } } if (IsDirty) { try { string whereClause = "ID = " + ID; ContentValues values = new ContentValues(); values.Put("CalmMyself", CalmMyself.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("TellMyself", TellMyself.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("WillCall", WillCall.Trim().Replace("'", "''").Replace("\"", "\"\"")); values.Put("WillGoTo", WillGoTo.Trim().Replace("'", "''").Replace("\"", "\"\"")); sqLiteDatabase.Update("SafetyPlanCards", values, whereClause, null); IsDirty = false; } catch (SQLException dirtyE) { Log.Error(TAG, "Save: Exception - " + dirtyE.Message); throw new Exception("Unable to Update Safety Plan Card - " + dirtyE.Message); } } } }
//Сюди будемо передавати одиницю, якщо хочемо здійснити запис в базу даних protected override bool RunInBackground(params int[] @params) { int param = @params[0]; if (param == 1) { SQLiteOpenHelper updateCleaningTaskDatabaseHelper = new RationalCleaningDatabaseHelper(myActivity); try { SQLiteDatabase db = updateCleaningTaskDatabaseHelper.WritableDatabase; ContentValues taskValues = new ContentValues(); taskValues.Put("TITLE", taskTitle); taskValues.Put("ROOM_ID", roomId); //-1 для year (обов'язково) та -1 для month та dayOfMonth (за бажанням) передаємо, щоб в уже створеного таска, якщо там dateDefault == 1, не змінювалася дата //адже її зміна може вплинути на те, що таск відразу потрапить у списку сьогоднішніх тасків, хоча був виконаний лише вчора і наступна дата була запланована на, наприклад, післязавтра if (dateDefault == 1 && year != -1) { taskValues.Put("YEAR", year); taskValues.Put("MONTH", month); taskValues.Put("DAY_OF_MONTH", dayOfMonth); } taskValues.Put("DATE_DEFAULT", dateDefault); taskValues.Put("HOUR", hour); taskValues.Put("MINUTE", minute); taskValues.Put("PERIODICITY", periodicity); taskValues.Put("TIME_OF_CLEANING", timeOfCleaning); taskValues.Put("CLEANNESS", 1); taskValues.Put("YEAR_OF_CHANGE", yearOfChange); taskValues.Put("MONTH_OF_CHANGE", monthOfChange); taskValues.Put("DAY_OF_MONTH_OF_CHANGE", dayOfMonthOfChange); db.Update("CLEANING_TASK_TABLE", taskValues, "_id = ?", new string[] { taskId.ToString() }); db.Close(); return(true); } catch (SQLException) { return(false); } } return(false); }
public override int Update(Android.Net.Uri uri, ContentValues values, string selection, string[] selectionArgs) { SQLiteDatabase db = dbHelper.WritableDatabase; int count; switch (uriMatcher.Match(uri)) { case LOCATIONS: count = db.Update(DATABASE_TABLE_NAME, values, selection, selectionArgs); break; case LOCATION_ID: String locationId = uri.PathSegments.ElementAt(1); string select = ""; if (selection != null) { if (selection.Length > 0) { select = " AND (" + selection + ")"; } } count = db.Update( DATABASE_TABLE_NAME, values, _ID + "=" + locationId + select, selectionArgs); break; default: throw new ArgumentException("Unknown URI " + uri); } Context.ContentResolver.NotifyChange(uri, null); return(count); }
public void Save(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { if (IsNew) { try { ContentValues values = new ContentValues(); values.Put("ThoughtRecordID", ThoughtRecordId); values.Put("AutomaticThoughtsID", AutomaticThoughtsId); values.Put("Evidence", Evidence.Trim().Replace("'", "''").Replace("\"", "\"\"")); EvidenceAgainstHotThoughtId = (int)sqLiteDatabase.Insert("EvidenceAgainstHotThought", null, values); IsNew = false; IsDirty = false; } catch (Exception newE) { throw new Exception("Unable to Save Evidence Against Hot Thought in database - " + newE.Message); } } if (IsDirty) { try { string whereClause = "EvidenceAgainstHotThoughtID = " + EvidenceAgainstHotThoughtId; ContentValues values = new ContentValues(); values.Put("ThoughtRecordID", ThoughtRecordId); values.Put("AutomaticThoughtsID", AutomaticThoughtsId); values.Put("Evidence", Evidence.Trim().Replace("'", "''").Replace("\"", "\"\"")); sqLiteDatabase.Update("EvidenceAgainstHotThought", values, whereClause, null); IsDirty = false; } catch (Exception dirtyE) { throw new Exception("Unable to Update Evidence Against Hot Thought in database - " + dirtyE.Message); } } } }
public void Save() { SQLiteDatabase sqlDatabase = null; try { Globals dbHelp = new Globals(); dbHelp.OpenDatabase(); sqlDatabase = dbHelp.GetSQLiteDatabase(); if (sqlDatabase != null) { if (sqlDatabase.IsOpen) { ContentValues values = new ContentValues(); values.Put("PlayListID", PlayListID); values.Put("TrackName", TrackName.Trim()); values.Put("TrackArtist", TrackArtist.Trim()); values.Put("TrackDuration", TrackDuration); values.Put("TrackOrderNumber", TrackOrderNumber); values.Put("TrackUri", TrackUri.Trim()); if (IsNew) { TrackID = (int)sqlDatabase.Insert("Tracks", null, values); IsNew = false; IsDirty = false; } if (IsDirty) { string whereClause = "TrackID = ?"; sqlDatabase.Update("Tracks", values, whereClause, new string[] { TrackID.ToString() }); IsDirty = false; } sqlDatabase.Close(); } } } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); if (sqlDatabase != null && sqlDatabase.IsOpen) { sqlDatabase.Close(); } } }
public void Save() { SQLiteDatabase sqlDatabase = null; try { Globals dbHelp = new Globals(); dbHelp.OpenDatabase(); sqlDatabase = dbHelp.GetSQLiteDatabase(); if (sqlDatabase != null) { if (sqlDatabase.IsOpen) { ContentValues values = new ContentValues(); values.Put("ProblemIdeaID", ProblemIdeaID); values.Put("ProblemStepID", ProblemStepID); values.Put("ProblemID", ProblemID); values.Put("ProblemProAndConText", ProblemProAndConText.Trim()); values.Put("ProblemProAndConType", (int)ProblemProAndConType); if (IsNew) { ProblemProAndConID = (int)sqlDatabase.Insert("ProblemProsAndCons", null, values); IsNew = false; IsDirty = false; } if (IsDirty) { string whereClause = "ProblemProAndConID = ?"; sqlDatabase.Update("ProblemProsAndCons", values, whereClause, new string[] { ProblemProAndConID.ToString() }); IsDirty = false; } sqlDatabase.Close(); } } } catch (Exception e) { Log.Error(TAG, "Save: Exception - " + e.Message); if (sqlDatabase != null && sqlDatabase.IsOpen) { sqlDatabase.Close(); } } }
public void Save(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { if (IsNew) { try { ContentValues values = new ContentValues(); values.Put("TextType", (int)TextType); values.Put("TextValue", TextValue.Trim()); ID = (int)sqLiteDatabase.Insert("GenericText", null, values); IsNew = false; IsDirty = false; } catch (Exception newE) { throw new Exception("Unable to save Generic Text to database - " + newE.Message); } } if (IsDirty) { try { string whereClause = "ID = " + ID; ContentValues values = new ContentValues(); values.Put("TextType", (int)TextType); values.Put("TextValue", TextValue.Trim()); sqLiteDatabase.Update("GenericText", values, whereClause, null); IsNew = false; IsDirty = false; } catch (Exception updE) { throw new Exception("Unable to update Generic Text in database - " + updE.Message); } } } }
public void TestSQLiteDBUpdate() { db = new SQLiteDatabase(); int id = 1; Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("name", "Black"); try { db.Update("colors", data, String.Format("colors.id = {0}", id)); } catch (Exception ex) { Console.Write("Error: {0}", ex.Message); } }
public void replace_set(string name_templ) { db = new SQLiteDatabase(); Dictionary<String, String> data = new Dictionary<String, String>(); data.Add("default_settings", name_templ); string where_str = "extra = '239'"; try { db.Update("default_set", data, where_str); } catch (Exception crap) { MessageBox.Show(crap.Message); } }
public void replace_row(string name_templ, Dictionary<String, String> dc) { db = new SQLiteDatabase(); string where_str = "template_name = '" + name_templ + "'"; try { db.Update("settings", dc, where_str); } catch (Exception crap) { MessageBox.Show(crap.Message); } }