Code example for SQLiteStatement

Methods: bindLong, bindString, executeInsert

0
    AdAwayDatabase(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    } 
 
    public long insertHostsSource(SQLiteStatement insertStmt, String url) {
        insertStmt.bindString(1, url);
        insertStmt.bindLong(2, 0); // last_modified_local starts at 0
        insertStmt.bindLong(3, 0); // last_modified_online starts at 0
        insertStmt.bindString(4, "1"); // default is enabled
        return insertStmt.executeInsert();
    } 
 
    private void insertDefaultHostsSources(SQLiteDatabase db) {
        // fill default hosts sources 
        SQLiteStatement insertStmt;
        String insertHostsSources = "INSERT OR IGNORE INTO " + Tables.HOSTS_SOURCES
                + "(url, last_modified_local, last_modified_online, enabled) VALUES (?, ?, ?, ?)"; 
        insertStmt = db.compileStatement(insertHostsSources);
 
        // http://winhelp2002.mvps.org/hosts.htm 
        insertHostsSource(insertStmt, "http://winhelp2002.mvps.org/hosts.txt");