mercredi 22 avril 2015

How to implement an SQLite Update command properly

I am looking to use an update command to change all my users details, depending on the users email address. I have been told to use an update command, but I don't properly understand how to use one, and the online documentation is pretty poor. Can anyone help me out? Here is my code:

public class DatabaseOperations extends SQLiteOpenHelper {

    public static int database_version = 1;
    public String CREATE_QUERY = "CREATE TABLE " + TableData.TableInfo.TABLE_NAME + "(" + TableData.TableInfo.USER_NAME + " TEXT," + TableData.TableInfo.USER_PASS + " TEXT," + TableData.TableInfo.USER_EMAIL + " TEXT," + TableData.TableInfo.USER_WEIGHT + " INTEGER," + TableData.TableInfo.USER_GOAL + " INTEGER );";

    public DatabaseOperations(Context context) {
        super(context, TableData.TableInfo.DATABASE_NAME, null, database_version);
        Log.d("Database Operations", "Database Created");

    public void onCreate(SQLiteDatabase sdb) {
        Log.d("Database Operations", "Table Created");

    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {


    public void putInformation(DatabaseOperations dop, String name, String pass, String email, int weight, int goal) {
        SQLiteDatabase SQ = dop.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(TableData.TableInfo.USER_NAME, name);
        cv.put(TableData.TableInfo.USER_PASS, pass);
        cv.put(TableData.TableInfo.USER_EMAIL, email);
        cv.put(TableData.TableInfo.USER_WEIGHT, weight);
        cv.put(TableData.TableInfo.USER_GOAL, goal);
        long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
        Log.d("Database Operations", "One Row Inserted");

    public Cursor getInformation(DatabaseOperations dop) {
        SQLiteDatabase SQ = dop.getReadableDatabase();
        String[] columns = {TableData.TableInfo.USER_NAME, TableData.TableInfo.USER_PASS, TableData.TableInfo.USER_EMAIL, TableData.TableInfo.USER_WEIGHT, TableData.TableInfo.USER_GOAL};
        Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME, columns, null, null, null, null, null);
        return CR;

Aucun commentaire:

Enregistrer un commentaire