Code example for ContentValues

Methods: getAsString

0
        throw new SQLException("Failed to insert row into " + uri);
    } 
 
    private long tryUpdateWithConstrain(String table, String constrain, ContentValues values) {
        long rowId = -1;
        int update = dbHelper.getWritableDatabase().update(table, values, constrain + "=?",
                new String[] {
                values.getAsString(constrain)
        }); 
 
        if (Log.Provider.verboseLoggingEnabled()) { 
            Log.Provider.v("Constrain " + constrain + " yield " + update);
        } 
        if (update > 0) {
            rowId = getRowIdForUpdate(table, constrain, values);
        } 
        return rowId;
    } 
 
    /** 
     * Will get the Row id from the latest update. 
     * 
     * @param table 
     * @param constrain 
     * @param values 
     * @return 
     */ 
    private long getRowIdForUpdate(String table, String constrain, ContentValues values) {
        final Cursor cur = dbHelper.getReadableDatabase().query(table, new String[] {
                "_id" 
        }, constrain + "=?", new String[] {
                values.getAsString(constrain)
        }, null, null, null); 
        if (!cur.moveToFirst()) {
            return -1; 
        } 
        try {