mercredi 16 septembre 2015

SQLite Asset Helper - can't write into my database

I'm trying to get familiar with the SQLite Asset Helper to manage data inside my Android app.

Until now, I've been able to read perfectly from it by using

public Cursor getParameters()
    {

    SQLiteDatabase db = getReadableDatabase();
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    String [] sqlSelect = { 

            /*0*/ "params0",
            /*1*/ "params1"
            /*2*/ "params2"
            /*3*/ "params3"
    };

    String sqlTables = "settings";

    qb.setTables(sqlTables);
    Cursor c = qb.query(db, sqlSelect, null, null,
            null, null, null);

    c.moveToFirst();
    return c;

    }

calling it from the Fragment:

Cursor parameters;
SettingsDataBase db;

// Load the Parameters Database
db = new SettingsDataBase(getActivity());
db.writeData();
parameters = db.getParameters(); // you would not typically call this on the main thread

Problem : I can't write into my database (update data).

Here's what I've done so far:

public void writeData()
    {
        SQLiteDatabase db = getWritableDatabase();
        db.execSQL("REPLACE INTO settings (params0, params1, params2, params3) VALUES ('0', '1', '2','3')");
    }

Obviously, no success.

The execSQL is running fine, no crashes, but nothing is written inside the database.

Any hints?

Aucun commentaire:

Enregistrer un commentaire