Android数据库方法以供将来更新 [英] Android database approach for future updates

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

问题描述

在android中使用sqlite数据库的最佳方式是什么?



sqlite数据库文件(首次复制到应用程序环境中)





在代码中创建表格(在数据库助手的onCreate

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



谢谢!

解决方案

您应该在第一次使用时创建(在代码中)。 Android提供应该使用的 SQLiteOpenHelper 类。 SQLiteOpenHelper 定义了以下方法:



onCreate(SQLiteDatabase db):在创建数据库时调用,可以在其中为其创建表和列, 。



onUpgrade(SQLiteDatabse db,int oldVersion,int newVersion):如果使用的数据库比当前版本。在这里处理升级内容(数据迁移,表创建/删除)



在这里查看一个好的教程: http://www.codeproject.com/KB/android/AndroidSQLite.aspx


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

The sqlite database file (copy it for the first time into the application environment)

OR

Creating the tables in code (in database helper's onCreate())

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.

Thank you!

解决方案

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): invoked when the database is created, this is where you can create tables and columns to them, create views or triggers.

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)

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

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

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