Store icons into their own separate table
This commit is contained in:
parent
8d6b282862
commit
9f4a5baebb
3 changed files with 24 additions and 7 deletions
|
@ -44,7 +44,7 @@ OriginsDB::OriginsDB (std::string_view path) :
|
||||||
|
|
||||||
OriginsDB::~OriginsDB() noexcept = default;
|
OriginsDB::~OriginsDB() noexcept = default;
|
||||||
|
|
||||||
void OriginsDB::overwrite (const Items& items) {
|
void OriginsDB::update (const Items& items) {
|
||||||
Database db(m_db_mutex, m_path);
|
Database db(m_db_mutex, m_path);
|
||||||
|
|
||||||
db.exec("DROP TABLE IF EXISTS items");
|
db.exec("DROP TABLE IF EXISTS items");
|
||||||
|
@ -57,7 +57,17 @@ void OriginsDB::overwrite (const Items& items) {
|
||||||
// "type":"IT_HEALING",
|
// "type":"IT_HEALING",
|
||||||
// "npc_price":50
|
// "npc_price":50
|
||||||
//}
|
//}
|
||||||
db.exec("CREATE TABLE items (item_id INTEGER PRIMARY KEY, unique_name TEXT, name TEXT, type INTEGER, subtype INTEGER, npc_price INTEGER, slots INTEGER, icon TEXT)");
|
db.exec(
|
||||||
|
"CREATE TABLE items ("
|
||||||
|
"item_id INTEGER PRIMARY KEY NOT NULL"
|
||||||
|
", unique_name TEXT"
|
||||||
|
", name TEXT"
|
||||||
|
", type TINYINT"
|
||||||
|
", subtype TINYINT"
|
||||||
|
", npc_price INTEGER"
|
||||||
|
", slots TINYINT"
|
||||||
|
")"
|
||||||
|
);
|
||||||
|
|
||||||
SQLite::Statement query(db, "INSERT INTO items(item_id, unique_name, name, type, subtype, npc_price, slots) VALUES(?, ?, ?, ?, ?, ?, ?)");
|
SQLite::Statement query(db, "INSERT INTO items(item_id, unique_name, name, type, subtype, npc_price, slots) VALUES(?, ?, ?, ?, ?, ?, ?)");
|
||||||
for (const auto& item : items.items) {
|
for (const auto& item : items.items) {
|
||||||
|
@ -88,11 +98,18 @@ void OriginsDB::update (const Icons& icons) {
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Database db(m_db_mutex, m_path);
|
Database db(m_db_mutex, m_path);
|
||||||
SQLite::Statement query(db, "UPDATE items SET icon = ? WHERE item_id = ?");
|
db.exec("DROP TABLE IF EXISTS icons");
|
||||||
|
db.exec(
|
||||||
|
"CREATE TABLE icons("
|
||||||
|
"item_id INTEGER PRIMARY KEY NOT NULL"
|
||||||
|
", icon TEXT"
|
||||||
|
")"
|
||||||
|
);
|
||||||
|
SQLite::Statement query(db, "INSERT INTO icons(item_id, icon) VALUES(?, ?)");
|
||||||
|
|
||||||
for (const auto& ico : icons.icons) {
|
for (const auto& ico : icons.icons) {
|
||||||
query.bind(1, ico.icon);
|
query.bind(1, ico.item_id);
|
||||||
query.bind(2, ico.item_id);
|
query.bind(2, ico.icon);
|
||||||
query.exec();
|
query.exec();
|
||||||
query.reset();
|
query.reset();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
explicit OriginsDB(std::string_view path);
|
explicit OriginsDB(std::string_view path);
|
||||||
~OriginsDB() noexcept;
|
~OriginsDB() noexcept;
|
||||||
|
|
||||||
void overwrite (const Items& items);
|
void update (const Items& items);
|
||||||
void update (const Icons& icons);
|
void update (const Icons& icons);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace duck {
|
||||||
set_timer(static_cast<double>(next_timer));
|
set_timer(static_cast<double>(next_timer));
|
||||||
}
|
}
|
||||||
|
|
||||||
db().overwrite(items.second);
|
db().update(items.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace duck
|
} //namespace duck
|
||||||
|
|
Loading…
Add table
Reference in a new issue