Android SQLite??????????
???????????? ???????[ 2015/3/16 13:36:41 ] ????????Android ????? SQLite ???? ???????
????SQLite??Android??????????л?????????????????????????????????SQLite????????????????????????????????????????????????????????????????????????豸?У?????????????K????湻??????????????????????Android????SQlite 3????á?
???????????????Android????SQlite?????μ????
????????????????
????SQlite?????????????????????????????????
???????????????????????
??????????????????????????
?????????????????????
?????????ζ????????????
??????????????????????
????????????????????????????????????????????????????ζ??????????SQlite?У?????????????????????????????????????????????????????????????????????????SQL??????????????
????Android??????????????
????SQLiteOpenHelper?????????????????????????????????????????????????
????SQLiteDatabase????????????ж???????????????????????????
????SQLiteCursor?????????????????????????е?????
?????????????
???????????????????洢??????????б???????????????????????3????Σ???????ID??name??age????SQLiteOpenHelper??????????????ж?????????????????????С?
????????????
????public DbHelper(Context context??String name??CursorFactory factory??int version){
????super(context??name??factory??version);
????}
??????????е????name???????????????????????????version???1????????????????????????η????仯??????????????version?????????onUpgrade()??????????????Ч????
??????onCreate?????д??????
????public void onCreate(SQLiteDatabase db){
????StringBuilder sql=new StringBuilder();
????sql.append("CREATE TABLE");
????sql.append(TBL_NAME);
????sql.append("(");
????sql.append(FIELD_ID+"TEXT PRIMARY KEY NOT NULL??");
????sql.append(FIELD_NAME+"TEXT??");
????sql.append(FIELD_AGE+"INTEGER");
????sql.append(");");
????db.execSQL(sql.toString());
????}
????onCreate?????????????????δ?????????????????????Щ???????????????
???????????????????Ч?????????SQL???
????CREATE TABLE mytable(id TEXT PRIMARY KEY NOT NULL??name TEXT??age INTEGER);
?????????????????
??????????????????????????????????????SQLiteDatabase????execSQL??????????SQL???????????SQLiteDatabase????insert?????????????SQL???????????????????á?
???????execSQL(“INSERT INTO mytable VALUES(‘idStr’??’nameStr’??20);”);???????????????????????????????????????????
???????insert??????insert??????????ContentValues????????????????????hashmap?????key?????????????key?????????
????ContentValues v=new ContentValues();
????v.put("id"??"101");
????v.put("name"??"user 101");
????v.put("age"??44);
????mDb.insert("mytable"??"null"??v);
???????v?е?key?????????????????Σ???????name??????id???????????????????????????????????????????????????name?????????????????name??ε???NULL???????id?????????????????????????????NOT NULL.
???????????????????????????
????adb shell??к????shell??
????cd/data/data/cn.demo.sql
????sqlite3 database.db??????sqlite???????檔
????.help????????????????
????.dump?????????????е??????
??????????????????????????insert??????????????????????ContentValues??????????????????
????public void insert(String id??String name??int age){
????if(mDb==null)mDb=getWritableDatabase();
????ContentValues v=new ContentValues();
????v.put("id"??id);
????v.put("name"??name);
????if(age>0)v.put("age"??age);
????mDb.insert(TBL_NAME??"null"??v);
?????????в?????
????SQL???SELECT column list FROM table WHERE expr ORDER BY column list;???SQLiteDatabase???query()??????
????Cursor SQLiteDatabase.query(String table??
????String[]columns??String selection??String[]selectionArgs??
????String groupBy??String having??String orderBy);
????Parameters:
????table????μ?????????????
????values????μ???????
????whereClause Where?????????Щ?????
????whereArgs Where????е?’?'?滻????
???????update???????????????????θ???????update????и????????????????????????
??????????????????
????int SQLiteDatabase.delete(String table??String whereClause??String[]whereArgs);
??????SQLite????????????????????????????????Android????????SQLite????????????????????????????????????????????????????????????????SQL????????????????????????????Android??????SQLite???????SQLiteOpenHelper??????SQLiteDatabase?????????????SQLiteCursor???????????
??????
???·???
??????????????????
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