android - SQLite no such column even though everything spelled right and there is correct spacing -


this question has answer here:

i learning android programming , sqlite @ same time. creating table like:

    private static final string database_create = "create table " + book_table + " ("         + bookcontract._id + " integer primary key autoincrement, "         + bookcontract.title + " text not null, "         + bookcontract.authors + " text not null, "         + bookcontract.isbn + " text not null, "         + bookcontract.price + " text not null );"; 

in function fetches books in database, query is:

string query =  "select " +             book_table + "." + bookcontract._id + ", " +             bookcontract.title + ", " +             bookcontract.price + ", " +             bookcontract.isbn + ", " +             "group_concat(" + authorcontract.name + ", ',') " + bookcontract.authors +             " " + book_table + " left outer join " + author_table + " on " +             book_table + "." + bookcontract._id + "=" +             author_table + "." + authorcontract.book_foreign_key +             " group " + book_table + "." + bookcontract._id + ", " +             bookcontract.title + ", " + bookcontract.price + ", " + bookcontract.isbn; 

here how string looks table creation:

create table booktable (_id integer primary key autoincrement, title text not null, authors text not null, isbn text not null, price text not null ); 

and query:

 select booktable._id, title, price, isbn, group_concat(name, ',') authors booktable left outer join authortable on booktable._id = authortable.book_fk group booktable._id, title, price, isbn 

i swear going insane on because similar stackoverflow posts asking similar problem have minor spelling mistakes or missing spaces, mine seems work correctly on online sql simulator!

when database.rawquery(query, null), error saying there no such column: price appears in log.

edit:

there author table has missing name column mentioned in comments, here clarity:

 string author_table_create = "create table " + author_table + " ("         + authorcontract._id + " integer primary key autoincrement, "         + authorcontract.book_foreign_key + " integer not null, "         + authorcontract.name  + " text not null, "         + "foreign key ("+ authorcontract.book_foreign_key+") " +         "references "+book_table+"("+bookcontract._id+") on delete cascade);"; 

which gives string:

create table authortable (_id integer primary key autoincrement, book_fk integer not null, name text not null, foreign key (book_fk) references booktable(_id) on delete cascade); 

just uninstall app mobile , re-run. hope works if there no problem in code.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -