src/main/java/de/blau/android/resources/KeyDatabaseHelper.java
/**
     * Add or replace an entry in the keys table
     * 
     * @param db writable database
     * @param name the key name
     * @param type type of the entry
     * @param key the key value
     * @param custom if set this is a custom entry that will be protected against overwriting
     * @param overwrite overwrite entry even if custom flag is set
     * @param add1 1st additional value to store
     * @param add2 2nd additional value to store
     */
Add or replace an entry in the keys table


Add or replace an entry in the keys table
public static void replaceKey(@NonNull SQLiteDatabase db, @NonNull String name, @NonNull EntryType type, @Nullable String key, boolean custom,
            boolean overwrite, @Nullable String add1, @Nullable String add2) {
        ContentValues values = new ContentValues();
        values.put(NAME_FIELD, name);
        values.put(TYPE_FIELD, type.toString());
        values.put(KEY_FIELD, key);
        values.put(ADD1_FIELD, add1);
        values.put(ADD2_FIELD, add2);
        values.put(CUSTOM_FIELD, custom ? 1 : 0);
        try {
            int count = db.update(KEYS_TABLE, values, NAME_FIELD + "=? AND " + TYPE_FIELD + "=?" + (!overwrite ? AND + CUSTOM_FIELD + "=0" : ""),
                    new String[] { name, type.toString() });
            if (count == 0) {
                db.insert(KEYS_TABLE, null, values);
            }
        } catch (SQLException e) {
            Log.e(DEBUG_TAG, "replaceKey " + e.getMessage());
        }
    }
public static void replaceKey ( @ NonNull SQLiteDatabase db , @ NonNull String name , @ NonNull EntryType type , @ Nullable String key , boolean custom , boolean overwrite , @ Nullable String add1 , @ Nullable String add2 ) { ContentValues values = new ContentValues ( ) ; values . put ( NAME_FIELD , name ) ; values . put ( TYPE_FIELD , type . toString ( ) ) ; values . put ( KEY_FIELD , key ) ; values . put ( ADD1_FIELD , add1 ) ; values . put ( ADD2_FIELD , add2 ) ; values . put ( CUSTOM_FIELD , custom ? 1 : 0 ) ; try { int count = db . update ( KEYS_TABLE , values , NAME_FIELD + "=? AND " + TYPE_FIELD + "=?" + ( ! overwrite ? AND + CUSTOM_FIELD + "=0" : "" ) , new String [ ] { name , type . toString ( ) } ) ; if ( count == 0 ) { db . insert ( KEYS_TABLE , null , values ) ; } } catch ( SQLException e ) { Log . e ( DEBUG_TAG , "replaceKey " + e . getMessage ( ) ) ; } }
Add or replace an entry in the keys table
Add or replace an entry in the keys table