?????????????????????μ?? SQLiteOpenHelper ?????????

 

public class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context?? String name?? CursorFactory cursorFactory?? int version)
{
super(context?? name?? cursorFactory?? version);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO ?????????????????????
}
@Override
public void onUpgrade(SQLiteDatabase db?? int oldVersion?? int newVersion) {
// TODO ?????????汾?????
}
@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
// TODO ??γ??????????????????
}
}

???????????????????δ??????????????????????????? getReadableDatabase() ?? getWriteableDatabase() ????????????? SQLiteDatabase ????????????????????????????????????????????????
????db=(new DatabaseHelper(getContext())).getWritableDatabase();
????return (db == null) ? false : true;
??????????δ????????? SQLiteDatabase ?????????????????????????????????????
???????????????????????????????? Activity ???????????????? SQLiteDatabase ?? Close() ????????????????????
???????????????
?????????????????????????? SQLiteDatabase ?? execSQL() ????????? DDL ??????????????????????з??????
???????磬???????????′???
????db.execSQL("CREATE TABLE mytable (_id INTEGER PRIMARY KEY
????AUTOINCREMENT?? title TEXT?? value REAL);");
???????????????????? mytable ???????????????? _id?????????????????е???????????????????????磬?????????????SQLite ??????????????????????????У?title( ??? ) ?? value( ?????? )?? SQLite ???????????д?????????
???????????£?????δ???????????????????????????????????? schema????????????????? . ?????????????????? execSQL() ???????? DROP INDEX ?? DROP TABLE ???
???????????????
????????????????????????????????????????????????????????????????????????
?????????洴????????????????? execSQL() ??????? INSERT?? UPDATE?? DELETE ??????????±???????execSQL() ?????????????в????????? SQL ??????磺
????db.execSQL("INSERT INTO widgets (name?? inventory)"+
????"VALUES ('Sprocket'?? 5)");
????????????????? SQLiteDatabase ????? insert()?? update()?? delete() ????????Щ?????? SQL ????????????????????????£?

 

ContentValues cv=new ContentValues();
cv.put(Constants.TITLE?? "example title");
cv.put(Constants.VALUE?? SensorManager.GRAVITY_DEATH_STAR_I);
db.insert("mytable"?? getNullColumnHack()?? cv);