Saturday 16 October 2010

SQLite, Create View Example

I've been having some issues with SQLite. I'm a confident SQL programmer and use it day to day. But some things are just different with SQLite and for some reason it's been taking me ages to find examples on such simple things such as views. I could find any good material for creating a view... correct me if there is something out there that I've missed.

Views are simple but need to be done in the correct place with the correct syntax.

This is a VERY basic view.. No INNER JOINS or anything. Ensure that the CREATE VIEW ect is in capitals otherwise it won't work! unlike the create table which does...




private static final String VIEW1 =
"CREATE VIEW inventoryview AS SELECT items.item, items.category, " +
"items.price, lists.listname, listitem.status, inventory.bbf, " +
"listitem.listid, listitem.itemid, listitem.quantity " +
"FROM items, lists, listitem, inventory " +
"WHERE " +
"listitem.itemid=items._id AND " +
"listitem.itemid=inventory.itemid AND " +
"listitem.listid=lists._id;";


@Override
public void onCreate(SQLiteDatabase db)
{ try{

db.execSQL(VIEW1);
}catch (Exception e)
{
Log.e("Create Error", e.toString());
e.printStackTrace();

}}


Easy Peasy

No comments:

Post a Comment