SQLiteOpenHelper子類

用於操縱資料庫,本例中操縱資料庫的類名為DBService.該類中的onCreate和onUpgrade方法的代碼如下:。

用於操縱資料庫,本例中操縱資料庫的類名為DBService.該類中的OnCreate和onUpgrade方法的代碼如下:

public void onCreate(SQLiteDatabase db)

{

String sql = "CREATE TABLE[t_contacts]("

+ "[id]AUTOINC,"

+ "[name]VARCHAR(20) NOT NULL ON CONFLICT FAIL,"

+ "[telephone]VARCHAR(20) NOT NULL ON CONFLICT FAIL,"

+ "[email]VARCHAR(20),"

+ "[photo] BINARY,"

+ "CONSTRAINT [sqlite_autoindex_t_contacts_1] PRIMARY KEY ([id]))";

db.execSQL(sql);

}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

{

String sql = " drop table if exists [t_contacts]";

db.execSQL(sql);

//此處應該是新的SQL語句

sql = "CREATE TABLE[t_contacts]("

+ "[id]AUTOINC,"

+ "[name] VARCHAR(20) NOT NULL ON CONFLICT FAIL,"

+"[email]VARCHAR(20),"

+"[photo]BINARY,"

+"CONSTRAINT[sqlite_autoindex_t_contacts_1]PRIMARY KEY ([id]))";

db.execSQL(sql);

}

相關詞條

相關搜尋

熱門詞條

聯絡我們