Android ????????? SQLite ?????
???????????? ???????[ 2013/11/20 14:16:30 ] ????????
????update????????????????????????????????????????? ContentValues ????????? WHERE ????????????? WHERE ?????????????Щ????????滻 WHERE ?????е?“??”????update() ??????????????????е?????????? execSQL() ??????????????????
????WHERE ??????????????ù??????? SQL APIs ????????磺
????String[] parms=new String[] {"this is a string"};
????db.update("widgets"?? replacements?? "name=?"?? parms);
????delete() ????????ú? update() ?????????????????? WHERE ?????????????? WHERE ?????????????
????????????
???????? INSERT?? UPDATE?? DELETE?????????????? SELECT ?? SQLite ?????????????
????1 ????? rawQuery() ?????? SELECT ???
??????? query() ????????????????
????Raw Queries
???????? API ?????rawQuery() ??????????????????????????????? SQL SELECT ??????磺
????Cursor c=db.rawQuery(
????"SELECT name FROM sqlite_master WHERE type='table' AND name='mytable'"?? null);
???????????????У??????? SQLite ?????sqlite_master????? table ??????????????????? cursor ??????????????????????????????
???????????????????????????????????????磬????????????????????????????????????????? query() ??????????
????Regular Queries
????query() ?????? SELECT ???ι????????SELECT ?????????? query() ??????????????磺????????????????????????WHERE ???????????????λ?ò????????? WHERE ??????λ?ò????????GROUP BY ??????HAVING ??????
??????????????????????????? null???????????????ο????д???
String[] columns={"ID"?? "inventory"};
String[] parms={"snicklefritz"};
Cursor result=db.query("widgets"?? columns?? "name=?"??parms?? null?? null?? null);
|
????????α?
???????????????в????????????? Cursor?????? Android ?? SQLite ??????α?????α???????
?????????? getCount() ???????????????ж???????
??????? moveToFirst()?? moveToNext()?? ?? isAfterLast() ???????????м????
??????? getColumnNames() ??????????
??????? getColumnIndex() ???????κ??
??????? getString()??getInt() ??????????????ε??????????
??????? requery() ??????????в??????α?
??????? close() ????????α??????
???????磬?????????? mytable ??
Cursor result=db.rawQuery("SELECT ID?? name?? inventory FROM mytable");
result.moveToFirst();
while (!result.isAfterLast()) {
int id=result.getInt(0);
String name=result.getString(1);
int inventory=result.getInt(2);
// do something useful with these
result.moveToNext();
}
result.close();
|
?????? Android ????? SQLite ???????????
??????????????????????????????ù????????????????????????????????????????? API????? Android ?????????????????????????????????
?????????????????? sqlite3 ???????????????? adb shell ?????????????????????????????? shell??????????·????? sqlite3 ??????????????????????????
????/data/data/your.app.package/databases/your-db-name
????????????????????????????????????????????????????? SQLite-aware ????????????????????????????????????????????????????????????????????豸?????????????????????
?????????????豸????????????????? adb pull ?????????? IDE ????????????????洢???????????????豸?????? adb push ???
??????
???·???
??????????????????
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