jeudi 27 août 2015

update sqlite row android

Hi guys I'm in trouble updating specific row in sqlite database.

here's my databaseHandler :

    private static final String COLUMN_ID = "_id";
    private static final String COLUMN_NUMBER = "stardinumber";
    private static final String COLUMN_NAME = "nimi";
    private static final String COLUMN_SPRINT = "sprint";
    private static final String COLUMN_LONG_JUMP = "kaugushüpe";
    private static final String COLUMN_BALL = "pallivise";
    private static final String COLUMN_MEDICINE_BALL = "toppispallijänn";
    private static final String COLUMN_RUN = "pikkjooks";
    private static final String COLUMN_FOOTBALL = "jalgpall";
    private static final String COLUMN_BASKETBALL = "korvpall";
    private static final String COLUMN_VOLLEYBALL = "võrkpall";
    private static final String COLUMN_BOXES = "kastironimine";
    private static final String COLUMN_BIKE = "jalgratas";
    private static final String DATABASE_NAME = "LasteMV.db";


public void createTable(String tableName) {
        SQLiteDatabase database = getWritableDatabase();
        String drop = "DROP TABLE IF EXISTS " + tableName;
        database.execSQL(drop);
        String query = "CREATE  TABLE  IF NOT EXISTS " + tableName + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + COLUMN_NUMBER + " INTEGER, " + COLUMN_NAME + " TEXT, " + COLUMN_SPRINT + " FLOAT, " + COLUMN_LONG_JUMP + " FLOAT, "
                + COLUMN_BALL + " FLOAT, " + COLUMN_MEDICINE_BALL + " FLOAT, " + COLUMN_RUN + " FLOAT, "
                + COLUMN_FOOTBALL + " FLOAT, " + COLUMN_BASKETBALL + " FLOAT, " + COLUMN_VOLLEYBALL + " FLOAT, "
                + COLUMN_BOXES + " FLOAT, " + COLUMN_BIKE + " FLOAT " + ");";
        database.execSQL(query);

public void addResult(int id, Result result, String tableName, String dicipline) {
        SQLiteDatabase database = getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(dicipline ,result.getResult());
        database.update(tableName,values,"_id" + "='" + id + "'",null);

This I have tried:

added quotes to values.put("'" dicipline "'",...). removed "'" from update method. result.getResult() returns float.

Aucun commentaire:

Enregistrer un commentaire