Android 中使用“替换”进行意外 SQL 查询结果
我正在为 Android 编写一个应用程序,它会定期下载游戏排行榜。结果存储在数据库中。为了使下载与实时结果分开,我下载到一个表中,然后复制到另一个表中。排行榜表存储当前排名和先前排名。在将下载的版本复制到实时版本之前,我会从当前的 ie 中更新以前的评级:
mDb.execSQL(
"update " + mTableName + " set last_rank = rank, last_world = world;");
然后,我从下载表中选择适当的列并替换到实时表中:
mDb.execSQL(
"replace into " + mTableName + " (world, _id, victories, owned_regions, rank,
clan_name) select world, _id, victories, owned_regions, rank, clan_name
from " + mTableName + "_dl;");
如果我在更新之后但在更新之前获得数据库的副本替换然后运行 Android 外部的替换查询(我使用 SQLite Expert 进行测试),然后我得到预期的结果 - last_rank 和 last_world 字段被保留,但如果我在 Android 中运行查询,则 _dl 的所有字段表被复制,并且last_rank 和last_world 被用tehir 默认值覆盖。这是 Android SQLite 实现中的错误还是我做错了什么?
任何帮助将不胜感激。谢谢。
I am writing an application for Android that downloads a games leaderboard at frequent intervals. The results are stored in a database. To keep a download seperate from the live results I download into one table then copy over to another. The leaderboard table stores a current ranking and a previous ranking. Before copying the downloaded version into the live version I update the previous rating from the current i.e.:
mDb.execSQL(
"update " + mTableName + " set last_rank = rank, last_world = world;");
Then I select the appropriate columns from the download table and replace into the live table:
mDb.execSQL(
"replace into " + mTableName + " (world, _id, victories, owned_regions, rank,
clan_name) select world, _id, victories, owned_regions, rank, clan_name
from " + mTableName + "_dl;");
If I get a copy of the database after the update but before the replace then run the replace query external to Android (I use SQLite Expert for my tests), then I get the expected results - the last_rank and last_world fields are preserved, but if I run the query in Android, then all the fields of the _dl table are copied over and last_rank and last_world are over-written with tehir default values. Is this a bug in the Android SQLite implementation or am I doing something very wrong?
Any help would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
再次回答我自己的问题,尽管这与其说是答案,不如说是解决方法。解决方案是对现有记录集进行外部联接。
我希望其他人发现这很有用。
Answering my own question again, although this isn't so much an answer as a workaround. The solution was to do an outer join with the existing record set.
I hope someone else finds this useful.