From 3bf49ee7d4458c51bafdb5581c288fbd0f71d532 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 9 Sep 2023 23:10:03 -0400 Subject: Support the new dump format with locked attribute. --- mapman/src/library.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'mapman/src/library.cpp') diff --git a/mapman/src/library.cpp b/mapman/src/library.cpp index 2361441..4a51272 100644 --- a/mapman/src/library.cpp +++ b/mapman/src/library.cpp @@ -5,7 +5,7 @@ #include #include -const int MAPDB_VERSION = 1; +const int MAPDB_VERSION = 2; map_library::map_library() : db(nullptr) {} @@ -45,18 +45,20 @@ void map_library::set_map(const map_t &map) sqlite3_stmt *st = nullptr; if (has_map(map.id)) { - sqlite3_prepare_v2(db, "update maps set custom_name = ?, data = ? where id = ?;", -1, &st, 0); + sqlite3_prepare_v2(db, "update maps set custom_name = ?, locked = ?, data = ? where id = ?;", -1, &st, 0); sqlite3_bind_text(st, 1, map.custom_name.c_str(), map.custom_name.length(), SQLITE_STATIC); - sqlite3_bind_blob(st, 2, map.map_data.data(), map.map_data.size(), SQLITE_STATIC); - sqlite3_bind_int(st, 3, map.id); + sqlite3_bind_int(st, 2, map.locked); + sqlite3_bind_blob(st, 3, map.map_data.data(), map.map_data.size(), SQLITE_STATIC); + sqlite3_bind_int(st, 4, map.id); sqlite3_step(st); } else { - sqlite3_prepare_v2(db, "insert into maps (id, custom_name, data) values(?, ?, ?);", -1, &st, 0); + sqlite3_prepare_v2(db, "insert into maps (id, custom_name, locked, data) values(?, ?, ?, ?);", -1, &st, 0); sqlite3_bind_int(st, 1, map.id); sqlite3_bind_text(st, 2, map.custom_name.c_str(), map.custom_name.length(), SQLITE_STATIC); - sqlite3_bind_blob(st, 3, map.map_data.data(), map.map_data.size(), SQLITE_STATIC); + sqlite3_bind_int(st, 3, map.locked); + sqlite3_bind_blob(st, 4, map.map_data.data(), map.map_data.size(), SQLITE_STATIC); sqlite3_step(st); } sqlite3_finalize(st); @@ -65,13 +67,14 @@ void map_library::set_map(const map_t &map) map_t map_library::get_map(int id) const { sqlite3_stmt *st = nullptr; - sqlite3_prepare_v2(db, "select custom_name, data from maps where id = ?;", -1, &st, 0); + sqlite3_prepare_v2(db, "select custom_name, locked, data from maps where id = ?;", -1, &st, 0); sqlite3_bind_int(st, 1, id); - map_t ret{id, std::string(), map_data_t()}; + map_t ret{id, std::string(), false, map_data_t()}; if (sqlite3_step(st) == SQLITE_ROW) { ret.custom_name = std::string((char*)sqlite3_column_text(st, 0)); - memcpy(ret.map_data.data(), sqlite3_column_blob(st, 1), ret.map_data.size()); + ret.locked = sqlite3_column_int(st, 1) ? true : false; + memcpy(ret.map_data.data(), sqlite3_column_blob(st, 2), ret.map_data.size()); } sqlite3_finalize(st); return ret; @@ -298,6 +301,7 @@ void map_library::init_db() create table maps( id integer primary key, custom_name text, + locked integer, data blob ); )sql", nullptr, nullptr, nullptr); -- cgit v1.2.3