sqlite3 - Query doesnt work on android, column '_id' does not exist? -


i hope can me this.

i'm using sqlite3 on android app. i'm trying query:

mcursor = conexion.getdatabase().rawquery("select employee.name, company.name employee "                                                + " inner join company "                                                + " on (employee.idcompany=company._id) order employee.name", null); 

this schema:

create table company ("_id integer primary key autoincrement, "                     + "name text not null);";  create table employee ("_id integer primary key autoincrement, "                      + "name text not null, "                      + "fullname text not null, "                      + "idcompany integer not null, "                      + "foreign key(idcompany) references company (_id));"; 

when run query on android app following error:

05-09 22:35:23.170: e/androidruntime(10920): fatal exception: main 05-09 22:35:23.170: e/androidruntime(10920): java.lang.runtimeexception: unable start activity componentinfo{com.ej.ej/com.ej.ej.controlador.aplicacionactivity}: java.lang.illegalargumentexception: column '_id' not exist 

if run same query select *:

mcursor = conexion.getdatabase().rawquery("select * employee "                                                + " inner join company "                                                + " on (employee.idemployee=company._id) order employee.name", null); 

no problem get, works fine. since in schema have name company , name employee need differentiate both.

i tried doing query using cmd , adb commands , works. don't why error!!

edited: made work, @halr suggested in query (dont know why) have retrieve ids. have:

mcursor = conexion.getdatabase().rawquery("select company._id, employee.name employee, company.name company employee "                                            + " inner join company "                                            + " on (employee.idcompany=company._id) order employee.name", null); 

but had 1 more issue , wasnt in query, on activityfragment (thanks @hoan nguyen, made me see part of code again): listing employees, getting name of employee , idcompany. don't know why, looking _id of company instead of idcompany of employee.

string[] = new string[] { "name", "idcompany"}; int[] = new int[] { r.id.textviewnombreizq,  r.id.textviewnombrecent };  listview lvemployee = (listview) view.findviewbyid (android.r.id.list);  listclientscursoradapter notes = new listclientscursoradapter(context, r.layout.activity_file_client, mcursoremployee, from, to, 0); lvemployee .setadapter(notes); 

i changed:

string[] = new string[] { "name", "idcompany"};  

for:

string[] = new string[] { "employee", "company"}; 

and fine. all, apreciated :).

i think want this:

mcursor = conexion.getdatabase().rawquery("select employee.idcompany, employee.name, company.name employee "                                                + " inner join company "                                                + " on (employee.idcompany=company._id) order employee.name", null); 

note: need make sure specify column name comparing in section after select.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -