public static void upsertVariables(final String geocode, final List<VariableList.VariableEntry> variables) {
        withAccessLock(() -> {
            init();
            database.beginTransaction();
            try {
                final Set<Long> idsToRemain = new HashSet<>();
                int varidx = 0;
                for (VariableList.VariableEntry row : variables) {
                    final ContentValues cv = new ContentValues();
                    cv.put("geocode", geocode);
                    cv.put("varname", row.varname);
                    cv.put("varorder", varidx++);
                    cv.put("formula", row.formula);
                    final boolean updated = row.id >= 0 &&
                            database.update(dbTableVariables, cv, "geocode = ? and _id = ?", new String[]{geocode, "" + row.id}) > 0;
                    if (updated) {
                        idsToRemain.add(row.id);
                    } else {
                        final long newId = database.insert(dbTableVariables, null, cv);
                        if (newId < 0) {
                            throw new SQLiteException("Exception on inserting row in table " + dbTableVariables);
                        }
                        idsToRemain.add(newId);
                    }
                }
                database.delete(dbTableVariables, "geocode = ? AND _id NOT IN (" + StringUtils.join(idsToRemain, ",") + ")", new String[]{geocode});
                database.setTransactionSuccessful();
            } finally {
                database.endTransaction();
            }
        });
    }
method should solely be used by class {@Link CacheVariables}
main/src/main/java/cgeo/geocaching/storage/DataStore.java