简体   繁体   English

Android:具有频繁更改订单记录的表上的SQLite一对多关系

[英]Android: SQLite One-To-Many relationship on a table that has records changing orders frequently

Relevant question: Android: SQLite one-to-many design 相关问题: Android:SQLite一对多设计

This is my first post on here, and it's also my first time dealing with databases. 这是我在这里的第一篇文章,也是我第一次处理数据库。 If there are any clarifications, or corrections I can make, please let me know. 如果我可以做出任何澄清或更正,请告诉我。

I'm trying to set up an SQLite database to better store items collected from an RSS Feed. 我正在尝试建立一个SQLite数据库,以更好地存储从RSS Feed中收集的项目。 I'm trying to have a 3 table set-up. 我正在尝试设置3张桌子。 It looks like this: 看起来像这样:

Table 1: The Channel Table (items stay in constant order) 表1:通道表(项目保持不变)

_id | _id | Feed Location | 提要位置| Channel Title | 频道标题| Channel Description | 频道说明| ... ...


Table 2: The Item Table (The items should be stored in chronological order for ease of access and deletion) 表2:项目表(项目应按时间顺序存储,以便于访问和删除)

_id | _id | Item Title |...| 项目标题| ... | Channel ID | 频道编号| ... ...

Where Channel ID has the row number that the Channel the item is part of is located. 渠道ID所在的行编号是该项目所属的渠道所在的位置。

That part is pretty simple, but here's my problem. 这部分非常简单,但这是我的问题。 I want to be able to query items by the categories that are relevant to them. 我希望能够通过与它们相关的类别来查询项目。 They're included in the XML that'll be parsed, and it'd be great to sort by those values. 它们包含在将要解析的XML中,按这些值进行排序将是很棒的。 So I started to set up another table, and implement the same one-to-many relationship described above, but then I ran into a problem. 因此,我开始建立另一个表,并实现与上述相同的一对多关系,但是随后遇到了一个问题。 Because the id's of those items are likely to change when more items are parsed, the id's aren't static, and I can't have the categories link the way I did earlier. 由于在解析更多项目时这些项目的ID可能会发生变化,因此ID并非是静态的,并且我无法像以前那样将类别链接起来。 Also, another challenge I found was the fact that each category might've ideally needed to point to many different items because the Items' could've been relevant to the same Category. 另外,我发现的另一个挑战是,每个类别可能理想地需要指向许多不同的项目,因为“项目”可能与同一个类别相关。

And that's where I'm stuck. 那就是我被困住的地方。

Now I'm not sure I understand your situation correctly: are the id's of the Category's non-static? 现在,我不确定我是否正确理解了您的情况:类别的ID是非静态的吗? That seems a bit strange, since the entire idea of an id is that it stays constant through out it's life time. 这似乎有点奇怪,因为id的整个概念是在生命周期中保持不变。

If that still is the case, I would try to implement my own id structure and assure that it's constant. 如果仍然如此,我将尝试实现自己的id结构并确保其不变。 You could perhaps calculate an id based on the category name (use a md5 or sha1 sum as id, overkill but guaranteed to stay static and unique). 您也许可以根据类别名称计算一个id(使用md5或sha1 sum作为id,使用过大但可以保证保持静态和唯一性)。 Having a unique id structure for your categories would then allow you to use the same table structure as before (on the items and channels). 为您的类别使用唯一的ID结构将使您能够使用与以前相同的表结构(在项目和渠道上)。

It would perhaps even be an idea to make all letters in the category name lowercase and remove non-alpha/numeric values before calculating the id. 甚至可以将类别名称中的所有字母都转换为小写字母,并在计算ID之前删除非字母/数字值。 This way you'd get rid of Categories that are most likely the same ("Category" would then equal "Cat-e-gory"). 这样,您就可以摆脱最有可能相同的类别(“类别”将等于“类别猫”)。

I'm not sure I actually answered your question, but I hope you can make some use of it :-) 我不确定我是否真的回答了您的问题,但是希望您可以使用它:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM