Public void Delete (integer... IDS) {If (IDs. length> 0) {stringbuilder sb = new stringbuilder (); string [] strids = new string [IDs. length]; for (INT I = 0; I <IDs. length; I ++) {sb. append ('? '). Append (','); strids [I] = string. valueof (IDs [I]);} sb. deletecharat (sb. length ()-1); sqlitedatabase database = dbmanger. getwritabledatabase (); // parameter table name specifies the condition placeholder value database. delete ("person", "personid in (" + Sb + ")", strids) ;}} public list getscrolldata (INT startresult, int maxresult) {list persons = new arraylist (); sqlitedatabase database = dbmanger. getwritabledatabase (); // parameter table name returned field specified condition ing value whether grouping condition sorting paging condition cursor = database. query ("person", new string [] {"personid", "name", "Age"}, null, "personid DESC ", startresult + "," + maxresult); While (cursor. movetonext () {persons. add (new person (cursor. getint (0), cursor. getstring (1), cursor. getshort (2);} return persons;} public long getcount () {sqlitedatabase database = dbmanger. getwritabledatabase (); cursor = database. query ("person", new string [] {"count (*)"}, null); If (cursor. movetonext () {return cursor. getlong (0) ;}return 0 ;}}
Test code
Package EOE. demo; import Java. util. list; import it. bean. person; import it. service. personservice; import android. test. androidtestcase; import android. util. log;/***** run the personservice test **/public class personservicetest extends androidtestcase {Private Static final string tag = "personservicetest"; Public void testsave () throws exception {personservice = new personservice (this. getcontext (); For (INT I = 0; I <10; I ++) {personservice. save (new person ("huhuanhuan", (short) 33) ;}} public void testfindbyid () {personservice = new personservice (this. getcontext (); person P = personservice. findbyid (1); log. I (TAG, P. tostring ();} public void testupdate () {person = new person (1, "Chun", (short) 20); personservice = new personservice (this. getcontext (); personservice. update (person); person P = personservice. findbyid (1); log. I (TAG, P. tostring ();} public void testgetdateperson () {person P = new person (); personservice = new personservice (this. getcontext (); List list = personservice. getdateperson (0, 10); For (INT I = 0; I <p> P = (person) list. get (I); log. I (TAG, P. tostring () ;}} public void testgetcount () {personservice = new personservice (this. getcontext (); long l = personservice. getcount (); log. I (TAG, String. valueof (l);} public void testdelete () {personservice = new personservice (this. getcontext (); personservice. delete (1, 2, 3 );}}