Sunday, 15 February 2015

Complex queries with SQLite in Android -



Complex queries with SQLite in Android -

i have table 3 columns "id", "name" & "status". execute query on database can 1 entry of "id" located @ top row. have working sql query,

"select top 1 id sample_table status='pending' order id asc;"

this far implemented in android,

// getting pending items public int pendingcontact() { sqlitedatabase db = this.getwritabledatabase(); cursor mcount = db.query( table_contacts , new string[] { "id" } , "status = ?" , new string[] { "pending" } , null , null , null ); mcount.movetofirst(); int count = mcount.getint(0); mcount.close(); homecoming count; }

al through gives desired output know if there other way of doing more efficiently.

you can utilize limit

public cursor query (string table, string[] columns, string selection, string[] selectionargs, string groupby, string having, string orderby, string limit)

limit - limits number of rows returned query, formatted limit clause. passing null denotes no limit clause.

you can this:

cursor mcount = db.query(table_contacts, new string[] { "id" }, "status = ?", new string[] { "pending" }, null, null, "id asc", "1");

this maintain acquiring more info need.

android sqlite

No comments:

Post a Comment