什么是在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提供了的SQLiteOpenHelper类,应使用它。 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)
在这里看到一个很好的教程:http://www.$c$cproject.com/KB/android/AndroidSQLite.aspx
See here for a good tutorial: http://www.codeproject.com/KB/android/AndroidSQLite.aspx