java - How do I check if a "name" value exists in a SQLLite Database? -
i have sqllite database of sites name field. have save , create buttons. want run addrecord() or updaterecord() depending on whether or not value in name field exists.
i have method in dbadapter:
public cursor getrow(long rowid) { string = key_rowid + "=" + rowid; cursor c = db.query(true, database_table, all_keys, where, null, null, null, null, null); if (c != null) { c.movetofirst(); } return c; }
how can create similar method rowid based on name string supplied?
ie
public cursor getrowid(string _name) { ... }
search name instead of id in clause.
public cursor getrowid(string _name) { string = "name = '" + _name + "'"; cursor c = db.query(true, database_table, all_keys, where, null, null, null, null, null); if (c != null) { c.movetofirst(); } return c; }
get rowid cursor this:
cursor c = getrowid("john"); int rowid = c.getint(c.getcolumnindex(key_rowid));
Comments
Post a Comment