Populate slotted_cards table
It contains the list of cards inserted into the slots of the items in the shop_items table I can't enable the foreign key on card_id because the items table gets razed periodically - need to find a solution to this
This commit is contained in:
parent
b76a2f22a4
commit
bc0de0cf8b
1 changed files with 19 additions and 0 deletions
|
@ -37,6 +37,7 @@ namespace {
|
|||
std::unique_lock<std::mutex>(mtx),
|
||||
SQLite::Database(path, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE)
|
||||
{
|
||||
SQLite::Database::exec("PRAGMA foreign_keys = ON");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -216,9 +217,19 @@ void OriginsDB::update (const Shops& shops) {
|
|||
", FOREIGN KEY(shop_id) REFERENCES shops(id)"
|
||||
")"
|
||||
);
|
||||
db.exec("CREATE TABLE IF NOT EXISTS slotted_cards("
|
||||
"id INTEGER PRIMARY KEY NOT NULL"
|
||||
", item_id INTEGER NOT NULL"
|
||||
", card_id INTEGER NOT NULL"
|
||||
", FOREIGN KEY(item_id) REFERENCES shop_items(id)"
|
||||
//", FOREIGN KEY(card_id) REFERENCES items(item_id)"
|
||||
")"
|
||||
);
|
||||
|
||||
SQLite::Statement ins_shop(db, "INSERT INTO shops(title, owner, creation_date, loc_map, loc_x, loc_y, type) VALUES(?, ?, ?, ?, ?, ?, ?)");
|
||||
SQLite::Statement ins_item(db, "INSERT INTO shop_items(shop_id, item_id, amount, price, refine, star_crumbs, element, creator, beloved) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
SQLite::Statement ins_card(db, "INSERT INTO slotted_cards(item_id, card_id) VALUES(?, ?)");
|
||||
|
||||
SQLite::Transaction transaction(db);
|
||||
for (const auto& shop : shops.shops) {
|
||||
std::optional<oro::Shop> old_shop = fetch_shop(db, shop.owner, shop.creation_date);
|
||||
|
@ -249,6 +260,14 @@ void OriginsDB::update (const Shops& shops) {
|
|||
bind<int>(ins_item, 9, item.beloved);
|
||||
ins_item.exec();
|
||||
ins_item.reset();
|
||||
|
||||
const auto item_id = db.getLastInsertRowid();
|
||||
for (unsigned int card_id : item.cards) {
|
||||
ins_card.bind(1, item_id);
|
||||
ins_card.bind(2, card_id);
|
||||
ins_card.exec();
|
||||
ins_card.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
transaction.commit();
|
||||
|
|
Loading…
Reference in a new issue