简体   繁体   中英

How to reference blob column of array from other table in sqlite

I've been playing around sqlite for android studio while making a RPG game app until I came to these two questions:

  1. Can I save an array as blob data in a table?
  2. Is it possible to reference the array values in that blob column from other tables? If so, how?

Here's are the details of the problem:

There's a table called, 'monster', which is a table of enemy NPCs that has columns mon_ID, HP, MP, mon_str, mon_con, mon_dex, mon_int, drop_items.

It's the drop_items column that I'm trying to solve.

Some monsters have different number of drop items dropped after battle and I want to save them in the database, somehow.

Also, there is a table called, 'items', that has all the information about the items used in my game.

The drop_items column needs to be referenced from this 'items' table via item_ID.

So that's how I came up with trying to save an array list of drop items in the monster table.

If the above method is not really a good choice, can I have some other suggestions?

You should use a third table that links the monsters and the items. This table will just contain mon_Id and item_ID.
With this table, a monster can have several items and an item several owners.

mon_ID1   item_ID1
mon_ID1   item_ID2
mon_ID1   item_ID3
mon_ID2   item_ID1
mon_ID3   item_ID4
mon_ID4   item_ID5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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