Android ????????? SQLite ?????
???????????? ???????[ 2013/11/20 14:16:30 ] ????????
?????????????????????μ?? 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);
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11