????????????????????????????????????????????????SQL????????????????????????????????????????????д???????????????????????????????????????????????SQL???????????????????executeSQLScript?????У?????????????????????????????????????????????????????

????(????????????????????????????DB????????????DB??????????????????????????????????????ü???????????ù?SQLite???????С???????????????????

????DB db = new DB(this);

????SQLiteDatabase qdb = db.getReadableDatabase();

????????????getWritableDatabase(); ???????д????????????Android???????????????????????????????????????????????????????????????????????Android?????????????????е?version?????DB???????д????Version??????????????????????????????onUpgrade()????????????????onCreate??????onUpgrade????????????????????????

?????????仰???????Activity??onCreate?????У?????onResume???????????????????????仰????Android????/data/data/package_name/databases?????????????????????????????????????????е?DB_NAME???????DDMS?ó?????????????λ??????????????λ????????????????????sqliteman????http://sqliteman.com/page/4.html????;??????firefox??????sqlite manager???????)

?????????????

???????????????????????????????????????н??????????????????裺

????????????????????????????????????????getReadableDatabase()????????getWritableDatabase()????????????????????????????????????д?????????????????????в???;?????????????insert?? update???????

??????Android???У???????????????Cursor??????????????query()????rawQuery()?????????β???????磬????????????????????????????
 
DB db = new DB(this);
SQLiteDatabase qdb = db.getReadableDatabase();
Cursor recordset1 = 
qdb.query("mytable"?? null?? null?? null?? null?? null?? null);
Cursor recordset2 = qdb.rawQuery("SELECT * FROM mytable"?? null);

?????????????????????????????????????????????????????????飬 WHERE????????????飬GROUP BY???HAVING??????ORDER BY?????????????????????????????null???????ú???????????????Щ??????Ч??????????????????????Щ??????????????????????????????????????

???????????????????????SQL?????????????????????????????????????????????????????????????飬?????????У?WHERE????п??????‘?’??????????????????????α????????????е???滻?????????????????е???????滻??WHERE????е????‘?’??

?????????rawQuery()?????????????????????????????SQL???????????????????????-???????ú?query?????е??????????????????????????????????????????JOIN?????????(???????????????????????????????????????sqlite?????????????????left join???????????????where????У????????????select x1?? x2 from tables1?? tables 2 where table1.?=tables2.? ?????????????????????????????????????????????????β?????????????????????????д??select * from tablename where name = ??? ??????β?????????????????????????????????е?????滻????????????ζ?”select * from tablename where name = ‘“+Michael+”’” ??????????????Java???????????????????????????????????????????????????????+???????????String????)??

????????????(Upgrades)

?????????????????????????????????е?С????????????????????????????????ú????????ó????????????仯??????????μ?????????????Щ???????Щ?仯?????????????????仯???????????????′????У?????????汾?????????????θ????

????????????????и?????????????п??????????汾?????????????????????????????e汾???????????????????????????????????????μ??μ?汾?????????????????汾??version3.0???????????????????????????μ?version2.0??????????????2?????????????????汾???μ???????汾??

???????????????????????????????????????????°汾?????????onUpgrade()??????????????????????????????????????????ж??????汾???????????λ????θ???????

????????????????????????У???2.0?汾???????Щ???:

?????綽???????????(???????????)?????綽????浽????????“numbers”??????

??????????????????????н???Ρ?

??????汾1?????????μ?????????????SQL????????????????????????????汾?е?????????°汾??????С?

CREATE TABLE numbers (
   _id INTEGER PRIMARY KEY AUTOINCREMENT??
   employid INTEGER NOT NULL??
   number TEXT NOT NULL??
   ntype INTEGER NOT NULL DEFAULT '0'
);
CREATE INDEX employid ON numbers(employid);
 
INSERT INTO numbers (employid?? number?? ntype) SELECT _id?? ext?? 0
   FROM employees;
INSERT INTO numbers (employid?? number?? ntype) SELECT _id?? mob?? 1
   FROM employees;
 
CREATE TABLE temp (
     _id INTEGER PRIMARY KEY AUTOINCREMENT??
     name TEXT NOT NULL??
     salary INTEGER NOT NULL DEFAULT '0'
);
INSERT INTO temp (_id?? name) SELECT _id?? name FROM employees;
 
DROP TABLE employees;
ALTER TABLE temp RENAME TO employees;