为未来的更新的Andr​​oid数据库的方法 [英] Android database approach for future updates

查看:152
本文介绍了为未来的更新的Andr​​oid数据库的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是在Android的SQLite数据库工作的最佳方法是什么?

What is the best way to work with the sqlite database in android?

SQLite数据库文件(复制它第一次进入应用环境)

创建表code(在数据库助手的onCreate())

我的数据库中有6张桌子,这是空的第一次。我问这个,因为我想在未来的更新我的数据库,并想知道这是最好的方法。

My database has 6 tables and it is empty for the first time. I ask this because I want to update my database in the future and would want to know the best approach for this.

感谢您!

推荐答案

您应该创建(在code)它的第一次使用。 Android提供了的<一个href="http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html">SQLiteOpenHelper类,应使用它。 <一href="http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html">SQLiteOpenHelper定义了以下方法:

You should create (in code) it the first time it is used. Android offers the SQLiteOpenHelper class that should be used for it. SQLiteOpenHelper defines the following methods:

的onCreate(SQLiteDatabase DB):调用创建数据库时,这是你可以创建表和列给他们,创建视图或触发器

onCreate(SQLiteDatabase db): invoked when the database is created, this is where you can create tables and columns to them, create views or triggers.

onUpgrade(SQLiteDatabse分贝,INT oldVersion,INT动态网页):如果调用所使用的数据库是早于当前版本。这里处理升级的东西(数据迁移,表的创建/删除)

onUpgrade(SQLiteDatabse db, int oldVersion, int newVersion): Invoked if the used database is older than the current version. Handle here the upgrade stuff (data migration, table creation/deletion)

在这里看到一个很好的教程:<一href="http://www.$c$cproject.com/KB/android/AndroidSQLite.aspx">http://www.$c$cproject.com/KB/android/AndroidSQLite.aspx

See here for a good tutorial: http://www.codeproject.com/KB/android/AndroidSQLite.aspx

这篇关于为未来的更新的Andr​​oid数据库的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆