sqlite - Android upgrading a DB with a NOT NULL column - what happens to old users -
sqlite - Android upgrading a DB with a NOT NULL column - what happens to old users -
i have app released in app store want add together new column user table in sqlite db , want not null want old users able utilize app
what happen if old user updates app new version? @ login, info server , insert in db. db insertion stop when there no value new column
also, how do upgrade itself?
in onupgrade "alter table user..." in constructor of sqlite helper add together new db versionwhat else?
also, i've added 3-4 totally new tables needed new features. i've called create queries in oncreate method of sqlite helper. should else in add-on this?
in constructor of sqlite helper add together new db version
that trigger onupgrade(), good.
however, cannot utilize alter table add together column not null.
here's can in onupgrade() preserve user data:
rename old table temporary name
recreate table new column , not null
populate new table old temp table , supply new column reasonable non-null default value
drop temporary table
can give me illustration lets table called user fields name , email , want add together new field age?
here's example:
sqlite> create table user(name, email); sqlite> insert user select 'foo','bar'; sqlite> alter table user rename user_temp; sqlite> create table user(name, email, age not null); sqlite> insert user select name,email,-1 user_temp; sqlite> drop table user_temp; sqlite> select * user; name|email|age foo|bar|-1 also, i've added 3-4 totally new tables needed new features. i've called create queries in oncreate method of sqlite helper. should else in add-on this?
should set new creates new tables in both oncreate , onupgrade or in onupgrade?
make sure same new tables created in onupgrade().
oncreate() run when database created first time, not on upgrade.
after both oncreate() , onupgrade() database schema (table structure) should compatible. how implement you. putting create tables there in onupgrade() option. people prefer phone call oncreate() insinde onupgrade(), can cause headache when trying migrate old data.
android sqlite
Comments
Post a Comment