在Android SQLite中使用类来表示外键/连接表?
我需要使用类来表示数据库中的实体,这里有一些信息:
=== TABLEs ===
SHOP shop_id(主要) 姓名 所有者
收藏夹列表 fav_id(主要) list_name
(加入)FAV_SHOPS fav_id(主要) shop_id(primary)
如果我使用 Shop 类来表示商店实体,并使用 FavShops 来表示 fav_shops,FavShops 的写法如下:
class FavShop {
int fav_id;
String list_name;
NSSet<Shop> shops;
}
那么如何在 SQLite(Android) 中从数据库中检索 fav_shops ?如果有人可以提供一些SQL语句,我将不胜感激,我还需要将列表保存到数据库,比如说,我在FavShop“我的最爱”中添加了另一家商店,我如何将其保存回数据库?
谢谢!
I need to use classes to represent entities in database, here are some information:
=== TABLEs ===
SHOP
shop_id(primary)
name
owner
FAVOURITES LIST
fav_id(primary)
list_name
(JOIN)FAV_SHOPS
fav_id(primary)
shop_id(primary)
If I use a class Shop to represent shop entity, and FavShops to represent fav_shops, FavShops is written as below:
class FavShop {
int fav_id;
String list_name;
NSSet<Shop> shops;
}
Then how do I retrieve fav_shops from database in SQLite(Android)? I'll be appreciated if any one can provide some SQL statement, I also need to save the list to database, say, I added another shop to FavShop "My Favourites", how do I save it back to database?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 JOIN 来获取您的 FavShops 表。
您可以在 WHERE 中放置您需要的任何子句(shop_id = ?, list_name = ?等..)
并在 fav_shops 表中插入新行
You can use JOIN to get your FavShops table..
You can put whatever clause you need in your WHERE (shop_id = ?, list_name = ?, etc..)
And to insert a new row in the fav_shops table