Use BIT(1) for fields with only 2 possible non-NULL values.

This commit is contained in:
pentarctagon 2019-09-27 23:13:14 -05:00 committed by Gunter Labes
parent 7cb6482b32
commit 2cd4273192
5 changed files with 13 additions and 13 deletions

View file

@ -427,10 +427,10 @@ void fuh::db_insert_game_info(const std::string& uuid, int game_id, const std::s
}
}
void fuh::db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, bool reload){
void fuh::db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload){
try {
prepared_statement<void>("UPDATE `" + db_game_info_table_ + "` SET START_TIME = CURRENT_TIMESTAMP, MAP_NAME = ?, ERA_NAME = ?, RELOAD = ? WHERE INSTANCE_UUID = ? AND GAME_ID = ?",
map_name, era_name, std::string(reload?"Y":"N"), uuid, game_id);
map_name, era_name, reload, uuid, game_id);
} catch (const sql_error& e) {
ERR_UH << "Could not update the game's starting information on table `" + db_game_info_table_ + "`:" << e.message << std::endl;
}
@ -445,7 +445,7 @@ void fuh::db_update_game_end(const std::string& uuid, int game_id, const std::st
}
}
void fuh::db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, const std::string& is_host, const std::string& faction){
void fuh::db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction){
try {
prepared_statement<void>("INSERT INTO `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+db_users_table_+"` WHERE username = ?), -1), ?, ?, ?)",
uuid, game_id, username, side_number, is_host, faction);
@ -465,7 +465,7 @@ void fuh::db_insert_modification_info(const std::string& uuid, int game_id, cons
void fuh::db_set_oos_flag(const std::string& uuid, int game_id){
try {
prepared_statement<void>("UPDATE `" + db_game_info_table_ + "` SET OOS = 'Y' WHERE INSTANCE_UUID = ? AND GAME_ID = ?",
prepared_statement<void>("UPDATE `" + db_game_info_table_ + "` SET OOS = 1 WHERE INSTANCE_UUID = ? AND GAME_ID = ?",
uuid, game_id);
} catch (const sql_error& e) {
ERR_UH << "Could not update the game's OOS flag on table `" + db_game_info_table_ + "`:" << e.message << std::endl;

View file

@ -71,9 +71,9 @@ class fuh : public user_handler {
std::string get_uuid();
void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name);
void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, bool reload);
void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload);
void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location);
void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, const std::string& is_host, const std::string& faction);
void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction);
void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name);
void db_set_oos_flag(const std::string& uuid, int game_id);

View file

@ -1620,7 +1620,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
const simple_wml::node::child_list& sides = g.get_sides_list();
for(unsigned side_index = 0; side_index < sides.size(); ++side_index) {
const simple_wml::node& side = *sides[side_index];
user_handler_->db_insert_game_player_info(uuid_, g.id(), side["player_id"].to_string(), side["side"].to_int(), side["is_host"].to_string(), side["faction"].to_string());
user_handler_->db_insert_game_player_info(uuid_, g.id(), side["player_id"].to_string(), side["side"].to_int(), side["is_host"].to_bool(), side["faction"].to_string());
}
const std::string mods = multiplayer["active_mods"].to_string();

View file

@ -136,9 +136,9 @@ class user_handler {
virtual std::string get_uuid() =0;
virtual void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name) =0;
virtual void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, bool reload) =0;
virtual void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload) =0;
virtual void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location) =0;
virtual void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, const std::string& is_host, const std::string& faction) =0;
virtual void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction) =0;
virtual void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name) =0;
virtual void db_set_oos_flag(const std::string& uuid, int game_id) =0;
};

View file

@ -38,7 +38,7 @@ CREATE TABLE extra
(
username varchar(100) NOT NULL,
user_lastvisit int(10) unsigned NOT NULL DEFAULT '0',
user_is_moderator tinyint(4) NOT NULL DEFAULT '0',
user_is_moderator bit(1) NOT NULL DEFAULT '0',
PRIMARY KEY (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@ -66,8 +66,8 @@ create table game_info
MAP_NAME VARCHAR(255),
ERA_NAME VARCHAR(255),
REPLAY_NAME VARCHAR(255),
OOS CHAR(1) NOT NULL DEFAULT 'N',
RELOAD CHAR(1),
OOS BIT(1) NOT NULL DEFAULT 0,
RELOAD BIT(1),
primary key (INSTANCE_UUID, GAME_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@ -84,7 +84,7 @@ create table game_player_info
GAME_ID INT UNSIGNED NOT NULL,
USER_ID INT NOT NULL,
SIDE_NUMBER SMALLINT UNSIGNED NOT NULL,
IS_HOST VARCHAR(255) NOT NULL,
IS_HOST BIT(1) NOT NULL,
FACTION VARCHAR(255) NOT NULL,
primary key (INSTANCE_UUID, GAME_ID, SIDE_NUMBER)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;