Android SqliteDatabase Command updateTable(SQLiteDatabase database, String table, String id, String[] newValues)

Here you can find the source of updateTable(SQLiteDatabase database, String table, String id, String[] newValues)

Description

update Table

Declaration

public static void updateTable(SQLiteDatabase database, String table,
            String id, String[] newValues) 

Method Source Code

//package com.java2s;
import android.content.ContentValues;

import android.database.sqlite.SQLiteDatabase;

public class Main {
    public final static String NESTLE_TABLE_NAME = "Nescafe";
    public final static String NESTLE_PRIMARY_KEY = "_id";
    public final static String NESTLE_COLUMN_1 = "date";
    public final static String NESTLE_COLUMN_2 = "first";
    public final static String NESTLE_COLUMN_3 = "last";
    public final static String NESTLE_COLUMN_4 = "difference";
    public final static String TIPS_TABLE_NAME = "Tips";

    public static void updateTable(SQLiteDatabase database, String table,
            String id, String[] newValues) {
        ContentValues cv = new ContentValues();
        if (table.equals(NESTLE_TABLE_NAME)) {
            try {
                cv.put(NESTLE_COLUMN_1, newValues[0]);
            } catch (ArrayIndexOutOfBoundsException e) {
            }/*from   w  w  w . j  a  v a 2  s  . com*/
            try {
                cv.put(NESTLE_COLUMN_2, newValues[1]);
            } catch (ArrayIndexOutOfBoundsException e) {
            }
            try {
                cv.put(NESTLE_COLUMN_3, newValues[2]);
            } catch (ArrayIndexOutOfBoundsException e) {
            }
            try {
                cv.put(NESTLE_COLUMN_4, newValues[3]);
            } catch (ArrayIndexOutOfBoundsException e) {
            }
            database.update(table, cv, NESTLE_PRIMARY_KEY + " ="
                    + quote(id), null);
        } else if (table.equals(TIPS_TABLE_NAME)) {

        }
    }

    public static String quote(String s) {
        return "\'" + s + "\'";
    }
}

Related

  1. executeSqlStatements(SQLiteDatabase db, String[] statements)
  2. executeSqlStatementsInTx(SQLiteDatabase db, String[] statements)
  3. getListOfDays(SQLiteDatabase db)
  4. insertIntoTable(SQLiteDatabase database, String table, String[] data)
  5. selectFromTable(SQLiteDatabase db, String table, String sample)
  6. getTaskCursor(SQLiteDatabase database, String name)
  7. SQLiteSanitize(String input)
  8. getFreeTourName(SQLiteDatabase db, String tourName)
  9. getNewTourPointPosition(SQLiteDatabase db, long tourId)