vendredi 18 décembre 2015

Android Sqlite - updating multiple table

anyone can help me fix the problem in my query?

i'm trying to call a function to update multiple table which has a value of "1" from column "col" but it's not working,

my_function

public long updateNow() {
        mDbHelper = new DatabaseHelper(mContext);
        mDb = mDbHelper.getWritableDatabase();

        int doneClear = 0;
        String base_value = "1"; // update all column "col" where value of 1

        ContentValues initialValues = new ContentValues();
        initialValues.put("col", "0"); // Update all column "col" with 0

        doneClear = mDb.update(SQLITE_TABLE_ONE, initialValues, "col=" + base_value, null);
        doneClear = mDb.update(SQLITE_TABLE_TWO, initialValues, "col=" + base_value, null);
        doneClear = mDb.update(SQLITE_TABLE_THREE, initialValues, "col=" + base_value, null);
        doneClear = mDb.update(SQLITE_TABLE_FOUR, initialValues, "col=" + base_value, null);
        doneClear = mDb.update(SQLITE_TABLE_FIVE, initialValues, "col=" + base_value, null);
        doneClear = mDb.update(SQLITE_TABLE_SIX, initialValues, "col=" + base_value, null);
        Log.w(TAG, Integer.toString(doneClear));
        return doneClear;
    }

this code is not working, i'm confused of why, nothing's happen in column col. anyway, that code is based on my previous query which is working fine.

working_update_query

public long updates(String recent_value, String _id, String table_name) {
        ContentValues initialValues = new ContentValues();
        initialValues.put("recent_value", recent_value);
        Log.w(TAG, String.valueOf(initialValues) + " WITH ID OF " + _id + " IN TABLE OF " + table_name);
        return mDb.update(table_name, initialValues, "_id=" + _id, null);
    }

i'm stock here of almost 1 hour, can't figureout the problem. anyone can help me please?? Thank You!!

Aucun commentaire:

Enregistrer un commentaire