Saving Data on Android


DELETE FROM  query in  your  questions  table. Since there is no  WHERE



Download 19,28 Mb.
Pdf ko'rish
bet149/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   145   146   147   148   149   150   151   152   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

DELETE FROM
 query in 
your 
questions
 table. Since there is no 
WHERE
 clause, this will just delete all the 
records in your 
questions
 table, which is what you will need later.
Note
: Notice how, if you examine the query 
String
, there's some degree of 
autocomplete available. Room knows which entity definitions you've created 
and which fields exist within. You can use this to write queries, and to easily 
connect to those definitions, knowing that autocomplete is here to help you 
write them.
Room also offers the 
@Delete
 annotation to automatically create 
DELETE FROM
 
querys. A method annotated with 
@Delete
 will delete its parameter objects from the 
database. For example, if you wanted to delete a single question from your database, 
you could do something like this:
@Delete
 
fun
 
deleteQuestion
(question: Question)
Note
: If you want to learn more about 
@Delete
, you can check out the official 
documentation here: 
https://developer.android.com/reference/android/arch/
persistence/room/Delete.html
.
Finally, add the following methods:
@Query("SELECT * FROM questions ORDER BY question_id")
 
// 1
 
fun
 
getAllQuestions
()
: List 
 
@Transaction
 
// 2
 
@Query("SELECT * FROM questions")
 
// 3
 
fun
 
getQuestionAndAllAnswers
()
: List
Just like 
deleteQuestion()
, the above methods use 
@Query
 to create SQL 
statements. Taking each commented section in turn:
1. This statement is retrieving all the question records in your database and 
ordering
 them by 
question_id
. The response is returned as a 
List
 of 
Question
 
objects.
Saving Data on Android
Chapter 8: The DAO Pattern
raywenderlich.com
135


2.
@Transaction
 tells Room that the following SQL statements should be executed 
in a 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   145   146   147   148   149   150   151   152   ...   292




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish