List of usage examples for android.database.sqlite SQLiteDatabase update
public int update(String table, ContentValues values, String whereClause, String[] whereArgs)
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public boolean renameChat(String buddyId, String newName) { SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(MessageHistoryContract.ChatEntry.COLUMN_NAME_NAME, newName); String where = MessageHistoryContract.ChatEntry.COLUMN_NAME_BUDDY_ID + "=?"; int res = db.update(MessageHistoryContract.ChatEntry.TABLE_NAME_ALL_CHATS, cv, where, new String[] { buddyId }); db.close();/*from www.j a va2 s.co m*/ return (res > 0); }
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public void updateMessageStatus(String chatId, long _ID, String newStatus) { //Log.d("DATABASE", "Changing MessageStatus"); int index = chatId.indexOf('@'); if (index >= 0) { chatId = chatId.substring(0, index); }/*from w w w .ja v a2 s. c o m*/ SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_STATUS, newStatus); String whereClause = MessageHistoryContract.MessageEntry._ID + " == ?"; db.update(chatId, values, whereClause, new String[] { Long.toString(_ID) }); db.close(); }
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public void setOnline(String buddyId, String status) { int index = buddyId.indexOf('@'); if (index >= 0) { buddyId = buddyId.substring(0, index); }//w w w.j a v a 2s . c om //Log.d("DATABASE", "Changing OnlineStatus"); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(MessageHistoryContract.ChatEntry.COLUMN_NAME_LAST_ONLINE, status); String whereClause = MessageHistoryContract.ChatEntry.COLUMN_NAME_BUDDY_ID + " == ?"; db.update(MessageHistoryContract.ChatEntry.TABLE_NAME_ALL_CHATS, values, whereClause, new String[] { buddyId }); db.close(); }
From source file:eu.rubenrosado.tinypasswordmanager.AllRows.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0) { if (resultCode == Activity.RESULT_OK) { toastMessage(getString(R.string.saving)); int position = data.getIntExtra("position", -1); int id = data.getIntExtra("id", -1); String site = data.getStringExtra("site"); String user = data.getStringExtra("user"); String password = data.getStringExtra("password"); DBHelper dbhelper = new DBHelper(this); SQLiteDatabase sql = dbhelper.getWritableDatabase(); try { ObjectRows sp = new ObjectRows(id, Encryption.decrypt(Main.MASTERPASSWORD, site), Encryption.decrypt(Main.MASTERPASSWORD, user), HIDEPW); ContentValues cv = new ContentValues(); cv.put(DBHelper.COLSITE, site); cv.put(DBHelper.COLUSER, user); cv.put(DBHelper.COLPASS, password); if (position != -1) { sql.update(DBHelper.TABLENAME, cv, DBHelper.COLID + "=" + id, null); spArray.set(position, sp); decryptedPasswords.set(position, Encryption.decrypt(Main.MASTERPASSWORD, password)); } else { sql.insert(DBHelper.TABLENAME, null, cv); spArray.add(sp);//ww w . j a v a 2 s .co m decryptedPasswords.add(Encryption.decrypt(Main.MASTERPASSWORD, password)); } toastMessage(getString(R.string.saved)); } catch (Exception e) { toastMessage(getString(R.string.internal_error)); } finally { sql.close(); dbhelper.close(); } adapter.notifyDataSetChanged(); } } }
From source file:com.fan3cn.fishrecorder.ContentFragment.java
/** * ??//from ww w . ja va 2 s.c o m * @param view */ private void handleCompanyEvent(final View view) { Button addButton = (Button) view.findViewById(R.id.button_add); addButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText nameET = (EditText) view.findViewById(R.id.editText_com_name); EditText phoneET = (EditText) view.findViewById(R.id.editText_com_phone); EditText faxET = (EditText) view.findViewById(R.id.editText_com_fax); EditText emailET = (EditText) view.findViewById(R.id.editText_com_email); EditText addressET = (EditText) view.findViewById(R.id.editText_com_addr); CheckBox ckBox = (CheckBox) view.findViewById(R.id.checkBox_is_default); int isDefault = ckBox.isChecked() ? 1 : 0; String name = nameET.getText().toString(); String phone = phoneET.getText().toString(); String fax = faxET.getText().toString(); String email = emailET.getText().toString(); String address = addressET.getText().toString(); if (name.isEmpty() || phone.isEmpty() || fax.isEmpty() || email.isEmpty() || address.isEmpty()) { new AlertDialog.Builder(getActivity()).setTitle("??").setPositiveButton("", null) .setMessage("?").show(); return; } SQLiteDatabase db = MainActivity.getDbHelper().getWritableDatabase(); Cursor cursor = db.query(Constants.table.get(menuId), null, "is_default=?", new String[] { 1 + "" }, null, null, null); if (isDefault == 1 && cursor.getCount() > 0) { //? ContentValues cv1 = new ContentValues(); cv1.put("is_default", 0); db.update(Constants.table.get(menuId), cv1, "is_default=?", new String[] { 1 + "" }); } ContentValues cv = new ContentValues(); cv.put("name", name); cv.put("tel", phone); cv.put("fax", fax); cv.put("email", email); cv.put("address", address); cv.put("is_default", isDefault); db.insert(Constants.table.get(menuId), null, cv); //?? db.close(); Toast.makeText(getActivity(), "?!", Toast.LENGTH_SHORT).show(); } }); Button clearButton = (Button) view.findViewById(R.id.button_clear); clearButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub EditText nameET = (EditText) view.findViewById(R.id.editText_com_name); EditText phoneET = (EditText) view.findViewById(R.id.editText_com_phone); EditText faxET = (EditText) view.findViewById(R.id.editText_com_fax); EditText emailET = (EditText) view.findViewById(R.id.editText_com_email); EditText addressET = (EditText) view.findViewById(R.id.editText_com_addr); CheckBox ckBox = (CheckBox) view.findViewById(R.id.checkBox_is_default); nameET.setText(""); phoneET.setText(""); faxET.setText(""); emailET.setText(""); addressET.setText(""); ckBox.setChecked(false); } }); }
From source file:ru.orangesoftware.financisto2.db.MyEntityManager.java
public void deleteProject(long id) { SQLiteDatabase db = db(); db.beginTransaction();/*from w w w .j av a2s .c o m*/ try { delete(Project.class, id); ContentValues values = new ContentValues(); values.put("project_id", 0); db.update("transactions", values, "project_id=?", new String[] { String.valueOf(id) }); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
From source file:heartware.com.heartware_master.DBAdapter.java
public int updateMeetup(final String note, final String userId, HashMap<String, String> queryValues) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(USER_ID, queryValues.get(USER_ID)); values.put(NOTE, queryValues.get(NOTE)); values.put(EXERCISE, queryValues.get(EXERCISE)); values.put(LOCATION, queryValues.get(LOCATION)); values.put(DATE, queryValues.get(DATE)); values.put(PEOPLE, queryValues.get(PEOPLE)); // update(TableName, ContentValueForTable, WhereClause, ArgumentForWhereClause) return database.update(MEETUPS_TABLE, values, NOTE + " = '" + note + "' AND " + USER_ID + " = " + userId, null);/* ww w .ja v a2 s . c o m*/ }
From source file:org.jsharkey.oilcan.ScriptDatabase.java
/** * Toggle the enabled state of the given script. *//*ww w .j a va 2 s. c o m*/ public void toggleEnabled(long id) { SQLiteDatabase db = this.getWritableDatabase(); // first read the existing status Cursor cur = db.query(TABLE_SCRIPTS, new String[] { FIELD_SCRIPT_ENABLED }, "_id = ?", new String[] { Long.toString(id) }, null, null, null); if (cur == null || !cur.moveToFirst()) return; int value = cur.getInt(cur.getColumnIndex(FIELD_SCRIPT_ENABLED)); cur.close(); // update to have the opposite value ContentValues values = new ContentValues(); values.put(FIELD_SCRIPT_ENABLED, (value == 0) ? 1 : 0); db.update(TABLE_SCRIPTS, values, "_id = ?", new String[] { Long.toString(id) }); }
From source file:com.fan3cn.fishrecorder.ContentFragment.java
/** * ??// w w w . j av a2 s. c o m * @param view */ private void handleShipEvent(final View view) { Button addButton = (Button) view.findViewById(R.id.button_add); addButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText nameET = (EditText) view.findViewById(R.id.editText_ship_name); EditText nationET = (EditText) view.findViewById(R.id.editText_ship_nation); EditText registerET = (EditText) view.findViewById(R.id.editText_ship_register); EditText emailET = (EditText) view.findViewById(R.id.editText_ship_email); EditText ffaET = (EditText) view.findViewById(R.id.editText_ship_ffa); EditText wcpfcET = (EditText) view.findViewById(R.id.editText_ship_wcpfc); EditText radioET = (EditText) view.findViewById(R.id.editText_ship_radio); EditText licenseET = (EditText) view.findViewById(R.id.editText_ship_license); CheckBox ckBox = (CheckBox) view.findViewById(R.id.checkBox_is_default); int isDefault = ckBox.isChecked() ? 1 : 0; String name = nameET.getText().toString(); String nation = nationET.getText().toString(); String register = registerET.getText().toString(); String email = emailET.getText().toString(); String ffa = ffaET.getText().toString(); String wcpfc = wcpfcET.getText().toString(); String radio = radioET.getText().toString(); String license = licenseET.getText().toString(); if (name.isEmpty() || nation.isEmpty() || register.isEmpty() || email.isEmpty() || ffa.isEmpty() || wcpfc.isEmpty() || radio.isEmpty() || license.isEmpty()) { new AlertDialog.Builder(getActivity()).setTitle("??").setPositiveButton("", null) .setMessage("?").show(); return; } SQLiteDatabase db = MainActivity.getDbHelper().getWritableDatabase(); if (isDefault == 1) { Cursor cursor = db.query(Constants.table.get(menuId), null, "is_default=?", new String[] { 1 + "" }, null, null, null); if (cursor.getCount() > 0) { //? ContentValues cv1 = new ContentValues(); cv1.put("is_default", 0); db.update(Constants.table.get(menuId), cv1, "is_default=?", new String[] { 1 + "" }); } } int companyId = 0; //? Cursor cursor = db.query("company", null, "is_default=?", new String[] { 1 + "" }, null, null, null); if (cursor.getCount() > 0) { while (cursor.moveToNext()) { companyId = cursor.getInt(cursor.getColumnIndex("id")); break; } } ContentValues cv = new ContentValues(); cv.put("name", name); cv.put("company_id", companyId); cv.put("nation", nation); cv.put("resgiter_no", register); cv.put("email", email); cv.put("ffa_no", ffa); cv.put("wcpfc_no", wcpfc); cv.put("radio_tel", radio); cv.put("license", license); cv.put("is_default", isDefault); db.insert(Constants.table.get(menuId), null, cv); //?? db.close(); Toast.makeText(getActivity(), "?!", Toast.LENGTH_SHORT).show(); } }); Button clearButton = (Button) view.findViewById(R.id.button_clear); clearButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub EditText nameET = (EditText) view.findViewById(R.id.editText_ship_name); EditText nationET = (EditText) view.findViewById(R.id.editText_ship_nation); EditText registerET = (EditText) view.findViewById(R.id.editText_ship_register); EditText emailET = (EditText) view.findViewById(R.id.editText_ship_email); EditText ffaET = (EditText) view.findViewById(R.id.editText_ship_ffa); EditText wcpfcET = (EditText) view.findViewById(R.id.editText_ship_wcpfc); EditText radioET = (EditText) view.findViewById(R.id.editText_ship_radio); EditText licenseET = (EditText) view.findViewById(R.id.editText_ship_license); CheckBox ckBox = (CheckBox) view.findViewById(R.id.checkBox_is_default); nameET.setText(""); nationET.setText(""); registerET.setText(""); emailET.setText(""); ffaET.setText(""); emailET.setText(""); radioET.setText(""); wcpfcET.setText(""); licenseET.setText(""); ckBox.setChecked(false); } }); }
From source file:syncthing.android.settings.AppSettings.java
public void saveCredentials(Credentials creds) { SQLiteDatabase _db = db.getWritableDatabase(); Cursor c = null;/* w w w . java 2 s . co m*/ try { ContentValues cv = new ContentValues(); cv.put(CredentialsDB.SCHEMA.ALIAS, creds.alias); cv.put(CredentialsDB.SCHEMA.URL, creds.url); cv.put(CredentialsDB.SCHEMA.API_KEY, creds.apiKey); cv.put(CredentialsDB.SCHEMA.CERT, creds.caCert); String[] sel = new String[] { creds.id }; _db.beginTransaction(); c = _db.query(CredentialsDB.SCHEMA.TABLE, idCols, credentialsDeviceIdSel, sel, null, null, null); if (c != null && c.getCount() > 0) { _db.update(CredentialsDB.SCHEMA.TABLE, cv, credentialsDeviceIdSel, sel); } else { cv.put(CredentialsDB.SCHEMA.DEVICE_ID, creds.id); _db.insert(CredentialsDB.SCHEMA.TABLE, null, cv); } _db.setTransactionSuccessful(); } finally { _db.endTransaction(); if (c != null) c.close(); } }