Saving Data on Android


ALTER TABLE  statement that adds a  category



Download 19,28 Mb.
Pdf ko'rish
bet190/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   186   187   188   189   190   191   192   193   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

ALTER TABLE
 statement that adds a 
category
 column of 
type text with a default value of 
android
.
Open the 
QuizDatabase
 class and modify it like this
@Database(entities = [(Question::class)
, (Answer::
class
)], 
version = 3) //change version to version 3 
 
abstract
 
class
 
QuizDatabase
 : 
RoomDatabase
() {
Saving Data on Android
Chapter 10: Migrations with Room
raywenderlich.com
180


  
companion
 
object

    
val
 MIGRATION_1_TO_2 = Migration1To2() 
    
val
 MIGRATION_2_TO_3 = Migration2To3() 
//adds migration
 
  } 
  
abstract
 
fun
 
questionsDao
()
: QuestionDao 
}
The above code changes the database version to 3 and creates a reference to your 
new migration.
Now, open the 
QuizApplication.kt
 file and add the migration you just created to 
your database builder inside 
onCreate()
:
database = 
Room
.databaseBuilder(this, 
QuizDatabase
::
class
.
java

"
question_database
") 
    .
addMigrations
(
QuizDatabase
.
MIGRATION_1_TO_2

QuizDatabase
.
MIGRATION_2_TO_3

    .
build
()
Build and run your app, then press 
START
:
Sweet! It looks like your migration works as expected.
Until now, the changes that you've made to your database schema have been really 
simple, since you only needed to add a new column to your tables.
But what happens if you need to modify a previously-created column?
Saving Data on Android
Chapter 10: Migrations with Room
raywenderlich.com
181


Well, it turns out that the 
ALTER TABLE
 statement is very limited; the only 
operations that you can perform with it are 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   186   187   188   189   190   191   192   193   ...   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