Code example for SQLiteDatabase

Methods: execSQLinsert

0
     * Called when a new database is created. 
     * @param db The database to initialize. 
     */ 
    @Override 
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(
            "CREATE TABLE identity(" + 
                "_id INTEGER," + 
                "category TEXT NOT NULL," + 
                "type TEXT NOT NULL," + 
                "lang TEXT NOT NULL DEFAULT ''," + 
                "name TEXT NOT NULL DEFAULT ''," + 
                "jid TEXT," + 
                "PRIMARY KEY(_id)" + 
            ")" 
        ); 
        db.execSQL("CREATE INDEX lookup_identity ON identity(" +
                   "category ASC, type ASC, lang ASC, name ASC, _id ASC" + 
                   ")"); 
        db.execSQL(
            "CREATE TABLE feature(" + 
                "_id INTEGER," + 
                "ver TEXT NOT NULL," + 
                "jid TEXT," + 
                "PRIMARY KEY(_id)" + 
            ")" 
        ); 
        db.execSQL("CREATE INDEX lookup_feature ON feature(" +
                   "ver ASC, _id ASC)"); 
 
        // insert a default identity 
        ContentValues values = new ContentValues();
        values.put("category", "client");
        values.put("type", "phone");
        values.put("name", "asmack service");
        db.insert("identity", "_id", values);
 
        // and support caps/disco#info. 
        // we can't reach this block otherwise :-) 
        values.clear();
        values.put("ver", "http://jabber.org/protocol/caps");
        db.insert("feature", "_id", values);
        values.put("ver", "http://jabber.org/protocol/disco#info");
        db.insert("feature", "_id", values);
    } 
 
    /** 
     * Called when there is a database update. 
     * @param db The database in need of an update.