sqlite - using several query in cursor in android -
i want go information in sqllite database in android.but dont know what. code is:
public cursor getdata() { string mypath = db_path + db_name; db = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly); cursor c = db.rawquery("select text,_id tbl_laws parent_id = 0",null); // note: master 1 table in external db. here trying access records of table external db. cursor c1 = db.rawquery("select text,_id tbl_nokte parent_id = 0",null); // note: master 1 table in external db. here trying access records of table external db. return c; return c1; }
can me?
the solution adjust sql-select-query.
you use rawquery information, 2 different cusors. not work.
the solution needed information single cursor be:
public cursor getdata() { string mypath = db_path + db_name; db = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly); string query = "select laws._id, laws.text," + " nokt._id,nokt.text" + " tbl_laws laws, tbl_nokte nokt" + " laws.parent_id = 0 , nokt.parent_id = 0"; cursor c = db.rawquery(query, null); return c; }
the usage be:
public list<yourobject> getdataforyourobjects(cursor c){ list<yourobject> yourobjects = new arraylist<>(); if(c != null){ while(c.movetonext(){ //law results long lawsid = c.getlong(0); string lawstext = c.getstring(1); //nokt results long noktid = c.getlong(2); string nokttext = c.getstring(3); yourobject yo = new yourobject(); yo.addlaw(lawid, lawtext); yo.addnokt(noktid, nokttext); yourobjects.add(yo); } c.close(); } return yourobjects; }
(the example code above not tested!)
hope helps.
additonal, can sqlite tutorial like: http://www.tutorialspoint.com/sqlite/ mor familiar sqlite.
also have in android sqlite tutorial like: https://www.tutorialspoint.com/android/android_sqlite_database.htm more information possible anroids-sqlite , cursor object.
Comments
Post a Comment