有人“删除表笔记”吗? Android Notepadv3 教程?
我刚刚完成 Notepadv# 教程。然后,我通过控制台(adb shell)连接“数据”文件 Notepadv3 教程。我尝试了一些东西。
- 删除notes表,然后重新运行。
- 不工作。
- 删除数据文件(db文件),然后重新运行。
- 工作。
如果您学习过 Notepadv# 教程,您可能了解 NotesDbAdapter 类中的一些预处理。在该代码位置,我发现在构造函数上“选择数据库”,在 onCreate 方法上“创建表”,在 onUpgrade 方法上“更新表”。
通过这种方法,数据库(名为 data 的文件)在构造函数之后调用 onCreate 时创建表。没办法,这没用。以上2个类似白痴的测试都是由这种废话引起的。有人把笔记表放在控制台上吗?我不明白为什么创建不起作用。
ps - 对愚蠢的英语感到抱歉。
I've just finished Notepadv# tutorials. And then, I connect through console(adb shell) the 'data' file Notepadv3 tutorial. I tried something.
- Delete notes table, and re-run.
- Do not work.
- Delete data file(db file), and re-run.
- Work.
If you worked Notepadv# tutorials, you may know about some pre-processing in NotesDbAdapter class. At that code position, I found "selecting db" on constructor, "creating table" on onCreate method and "update table" on onUpgrade method.
By that method, database(file named data) create table when onCreate called after constructor. No way, that didn't work. Above 2 like-moron test caused by that nonsense. Does anyone drop the notes table on console? I can't find why create doesn't work.
ps - So sorry about stupid English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果数据库不存在,您的数据库 onCreate 方法只会创建该数据库。如果它已损坏(即您已删除 Notes 表),或存在但为空,则由应用程序来检测并恢复。
这就是为什么当您删除表时记事本示例会失败(数据库存在,因此不会调用 onCreate 并且您的数据库已损坏),但当您删除数据库时它会起作用,因为调用了 onCreate 并重新创建了数据库。
所以基本上,不要这样做:-)
请参阅 SQLiteOpenHelper 文档以获取更详细的描述。
Your database onCreate method will only create the database if it does not exist. If it is corrupt (i.e. you've dropped the Notes table), or exists but is empty, then it is up to the application to detect that and recover.
This is why the notepad example fails when you drop the table (the database exists, so onCreate is not called and your database is corrupt), but when you delete the database it does work because onCreate is called and it recreates the database.
So basically, don't do that :-)
See the SQLiteOpenHelper documentation for a more detailed description.
尝试卸载应用程序或从“设置”->“管理应用程序”中删除应用程序数据?
Tried to uninstall the application or deleting the application data from Settings->manage application?