当前位置:网站首页>Android sqliteopenhelper data table structure upgrade
Android sqliteopenhelper data table structure upgrade
2022-04-23 01:30:00 【Jianren Yinkou】
Recently, I met a new requirement in the project , You need to add a field in the local cache , Because the user cache is saved in tables according to the group , When updating database upgrade , Finding the to be modified indicates that it is dynamically generated , After continuous efforts and online reference , Finally a solution has been found .
The main logic is still put in customization SQLiteOpenHelper Class onUpgrade In the method , We according to the db Parameters can get all the data tables , Because the table names have certain rules when dividing tables , Therefore, it can be modified uniformly according to this rule . The following is the author's implementation logic , For reference .
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Different database versions should have different processing logic , At present, only this upgrade is available
if (oldVersion == 1) {
// Query all data table names
Cursor cursor = db.rawQuery("select name from sqlite_master where type='table' order by name", null);
while (cursor.moveToNext()) {
String name = cursor.getString(0);
if (!TextUtils.isEmpty(name) && name.startsWith("users_")) {
// Get the target data table according to the matching rules , Then perform the corresponding operation , This is just a new field
db.execSQL("ALTER TABLE " + name + " ADD COLUMN aliasName text");
}
}
// Finally, don't forget to close cursor
cursor.close();
}
}
版权声明
本文为[Jianren Yinkou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220942099531.html
边栏推荐
- Gbase 8s存儲結構簡介及空間管理
- 光猫超级帐号密码,重置光猫获取超级帐号密码
- Text justify, orientation, combine text attributes
- Slow response of analysis API
- Gbase 8s客户端与服务器的通信
- What is the legal basis and procedure for Tami dog sharing | state owned equity transfer?
- Qingyan environment and Shenzhen Stock Exchange listing: annual revenue of 180 million and market value of 4.1 billion
- Examples of branch and loop statements
- What kind of project is suitable for automated testing?
- 代码实现发邮件---sendemails
猜你喜欢
How to introduce SPI into a project
10月24号是什么?中国的高级程序员为什么没有五六十岁的,而国外人、、、,玉念聿辉带你过1024程序员节日
代码实现发邮件---sendemails
Unrelated interprocess communication -- creation and use of named pipes
全排列(DFS和next_permutation解法)
ai2022新功能,illustrator 2022 新功能介绍
Full Permutation (DFS and next_permutation solution)
Basic knowledge of software testing (detailed version) collection of this article is enough
Use Charles to grab app package
Google developer tool preserve log
随机推荐
Analysis of uboot directory structure
engine. Post() handles post requests
四级城市地区表 xlsx, sql文件,国内,中国省市县街道乡镇四级地址 (名称,联动ID,层级,是否末级(1-是))
计蒜客家谱(dfs求直系后代数)
10月24号是什么?中国的高级程序员为什么没有五六十岁的,而国外人、、、,玉念聿辉带你过1024程序员节日
Find number (DFS)
Android本地数据库基础操作|多线程操作数据库|数据库的增删改查|批量插入数据库|线程池基础使用|玉念聿辉
Level 4 city area table xlsx, SQL file, domestic, provincial, county, street, township level 4 address in China (name, linkage ID, level, end level or not (1-yes))
世界读书日:18本豆瓣评分9.0以上的IT书值得收藏
New functions of ai2022, introduction to new functions of illustrator 2022
Is the stable currency a super opportunity to accelerate the death of the public chain or replace BTC?
Introduction to granularity locking of gbase 8s concurrency control
2022 penetration job interview (thinking)
iTextSharp 基础结构
VRF in Mina
计蒜客(踏青)(染色块问题的DFS和BFS解法)
Gbase 8s shared memory segment deletion
Abused "architect"!
GBASE 8s 共享内存缓冲池介绍
Garlic customer: equilateral triangle (DFS)