9-Amaliy mashgʻulot: Matni maydon komponenetalari bilan ishlash.
ContentValues values = new ContentValues();
values.put(PostDatabase.COL_TITLE, "Second title changed");
// Which row to update, based on the ID
String whereClause = PostDatabase.ID + " LIKE ?"; String[] whereArgs = { "2" }; int affectedRows = sqlDB.update( PostDatabase.TABLE_POSTS, values, whereClause, whereArgs );
// Dumps 1
Log.d(TAG, String.valueOf(affectedRows));
Ma`lumotlarni o`chirish (DELETE)
| Qaysi joyini o`zgartirmoqchi bo`lsak o`sh yerni tanlab olishimiz kerak:
String whereClause = PostDatabase.ID + " = ?"; // Specify arguments in placeholder order.
String[] whereArgs = { "1" }; // Issue SQL statement.
sqlDB.delete(PostDatabase.TABLE_POSTS, whereClause, whereArgs);
|
Qaysi joyini o`chirmoqchi bo`lsak o`sh yerni tanlab olishimiz kerak:
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(PostDatabase.TABLE_POSTS); queryBuilder.appendWhere("id = 1");
// Dumps "SELECT * FROM posts WHERE (id = 1)"
Log.d(TAG, queryBuilder.buildQuery(null, null, null, null, null, null));
// queryBuilder.query(DB.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder)
Here’s how you could build a JOIN (between posts and comments table): queryBuilder.setTables(
PostDatabase.TABLE_POSTS
+ " INNER JOIN "
+ PostDatabase.TABLE_COMMENTS
+ " ON "
+ PostDatabase.ID
+ " = "
+ (PostDatabase.TABLE_COMMENTS + "." + PostDatabase.COMMENT_POST_ID)
);
// queryBuilder.query(...)
|
SQLiteQueryBuilder
Do'stlaringiz bilan baham: |