9-Amaliy mashgʻulot: Matni maydon komponenetalari bilan ishlash


Download 68.95 Kb.
bet1/5
Sana23.12.2022
Hajmi68.95 Kb.
#1048135
  1   2   3   4   5
Bog'liq
9-Amaliy mashgʻulot

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

Download 68.95 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2025
ma'muriyatiga murojaat qiling