Android sqlite 有什么作用?
我正在我的 Android 应用程序中开发一个 sqlite 数据库。我需要它可以轻松增长,所以我需要在将来的升级中,我可以更改数据库等。
我想知道当我在sqlite创建方法中更改数据库版本时,它是否会创建一个新的数据库文件。如果确实如此,那么在 onUpgrade 中我应该迁移所有数据,不是吗?
总之,onCreate 到底做了什么?它会创建数据库的新文件吗?还是它修改了实际的内容?
我问这个是因为我不希望 onCreate 创建一个新文件...我只想更改实际的数据库。
谢谢
I'm developing a sqlite database in my android application. I need it can grow easily, so I need that in future upgrades, I could change the database, etc.
I want to know if when I change the data base version in the sqlite creation method, it creates a new file of the database. If it does, then, in the onUpgrade I should migrate all the data, isn't it?
In conclusion, what onCreate does exactly? Does it create a new file of the database? Or does it modify the actually one?
I'm asking this because I dont want that the onCreate creates a new file... I want to alter the actual data base only.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OnCreate仅在第一次需要创建数据库时调用。
如果数据库已存在且版本号不匹配,则调用 OnUpgrade。您应该使用 OnUpgrade 将数据库从旧版本更改为新版本。
OnCreate is only called when a database needs to be created for the first time.
OnUpgrade is called if the database already exists and the version numbers do not match. You should use OnUpgrade to alter your database from the old version to the new version.
我假设您指的是 SQLiteOpenHelper 中的 OnCreate 方法。当您请求可写或可读数据库并且需要创建数据库时,它会被调用。我们不直接调用oncreate方法。因此,如果数据库已经存在并且我们请求可写或可读的数据库——则不会创建新的数据库。
请参阅这些链接以获取更多信息
http://developer.android.com/参考/android/database/sqlite/SQLiteOpenHelper.html
http://developer.android.com/resources/tutorials/notepad/index.html
I am assuming you are referring to OnCreate method in SQLiteOpenHelper. It gets called when you request for a writable or readable database and the the database needs to be created. We do not call the oncreate method directly. So if a database is already existing and we request for a writeable or readable database --- no new database gets created.
Refer to these links for more information
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
http://developer.android.com/resources/tutorials/notepad/index.html