android中使用sqlite动态创建表
所以我创建和操作数据库的基础知识有点混乱。我的目标是,每当应用程序启动时,用户都可以指定一个表名称,然后收集的任何数据都会放入该表中。
但是,我对如何做到这一点感到困惑。我是否只需将用户输入的变量的值作为我的 contentprovider 类中的表名传递并执行 sqlite 语句来创建它?
我已经阅读/阅读了文档,所以如果有人有任何见解或清晰度,甚至更好的代码片段,那就太好了。
So my fundamentals of creating and manipulating databases are a bit messed up. My aim here is that whenever the app is launched, the user is allowed to specify a table name, and whatever data is then collected is put into that table.
However, I'm confused as to how to do this. Do I simply pass the value of a user entered variable as the table name in my contentprovider class and execute sqlite statements to create it?
I've read/reading the documentation already, so if anyone has any insight or clarity, or even better, code snippets, it would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不简单地使用一个表,并创建一个代表当前应用程序会话的值,然后将该值插入到每一行中。这将使您的代码更简单,并且仍然允许您分离/过滤掉特定应用程序会话中的值。如果您想让用户能够输入值(因为您让他们能够选择表名称),您只需检查该值是否已被使用,就像您必须这样做一样查看表名是否已被使用。
Why not simply use one table, and create a value that stands for the current app-session, and insert that value with each row. This would make your code simpler, and would still allow you to segregate/filter out the values from a particular app-session. If you want to give the user the ability to enter the value (as you are giving them the ability to choose the table name) you'd just want to check to see if that value had already been used, just as you would have to see if the table-name had already been used.