Reputation: 4214
I'm dealing with an sqlite db in android application. To update a row in the db I use method of SQLiteDatabase object "update"
SQLiteDatabase.update(String table, ContentValues values, String whereClause, String[] whereArgs)
But here a confusion, how "whereClause" should look like? Assume I have these values for update.
values.put("name", appInfo.getName());
values.put("package_name", appInfo.getPackageName());
values.put("version_name", appInfo.getVersionName());
I want to update a row where package_mane column equal to "com.mynamespace.db". How "whereClause" should be written here? Thanks.
Upvotes: 1
Views: 4117
Reputation: 5945
db.update(TABLE_NAME, values, "package_name=com.mynamespase.db", null);
// or
String[] args = { "com.mynamespase.db" };
db.update(TABLE_NAME, values, "package_name=?", args);
Upvotes: 2
Reputation: 69198
You should use it like this:
SQLiteDatabase.update(table, "package_name=?", new String[] { "com.mynamespace.db" });
and prevent other problems and cache inefficiencies if you concat the string.
Upvotes: 3
Reputation: 3341
db.update("table", values, "package_name = ?", new String[]{"com.mynamespase.db"});
Another example:
db.update("table", values, "package_name = ? and other_field = ?", new String[]{"com.mynamespase.db", "test"});
Upvotes: 8
Reputation: 9743
You whereClause
should look like this:
String whereClause = "package_mane = ?"; // package_name perhaps?
String[] whereArgs = new String[]{"com.mynamespase.db"};
String from whereArgs
are used to substitute ?
in whereClause
.
Upvotes: 4