diff --git a/common/version.h b/common/version.h index b667db189..e6fd74e00 100644 --- a/common/version.h +++ b/common/version.h @@ -35,7 +35,7 @@ */ #define CURRENT_BINARY_DATABASE_VERSION 9217 -#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9036 +#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9037 #define COMPILE_DATE __DATE__ #define COMPILE_TIME __TIME__ diff --git a/utils/sql/git/bots/bots_db_update_manifest.txt b/utils/sql/git/bots/bots_db_update_manifest.txt index c67c33969..f0c0a78ee 100644 --- a/utils/sql/git/bots/bots_db_update_manifest.txt +++ b/utils/sql/git/bots/bots_db_update_manifest.txt @@ -35,6 +35,7 @@ 9034|2022_12_02_bot_spell_settings.sql|SHOW COLUMNS FROM `bot_data` LIKE 'enforce_spell_settings'|empty| 9035|2022_12_04_bot_archery.sql|SHOW COLUMNS FROM `bot_data` LIKE 'archery_setting'|empty| 9036|2023_01_19_drop_bot_views.sql|SHOW TABLES LIKE 'vw_groups'|not_empty| +9037|2023_01_22_add_name_index.sql||show index from bot_data WHERE key_name = 'name`|empty| # Upgrade conditions: # This won't be needed after this system is implemented, but it is used database that are not diff --git a/utils/sql/git/bots/required/2023_01_22_add_name_index.sql b/utils/sql/git/bots/required/2023_01_22_add_name_index.sql new file mode 100644 index 000000000..d4e3cca14 --- /dev/null +++ b/utils/sql/git/bots/required/2023_01_22_add_name_index.sql @@ -0,0 +1 @@ +create index `name` on bot_data(`name`); \ No newline at end of file diff --git a/zone/bot_database.cpp b/zone/bot_database.cpp index fe3d39e62..1bac31359 100644 --- a/zone/bot_database.cpp +++ b/zone/bot_database.cpp @@ -173,13 +173,23 @@ bool BotDatabase::QueryNameAvailablity(const std::string& bot_name, bool& availa query = fmt::format( "SELECT b.bot_id FROM bot_data b " - "INNER JOIN character_data c ON b.`name` = c.`name` " - "WHERE b.`name` LIKE '{0}' OR c.`name` LIKE '{0}' " + "WHERE b.`name` LIKE '{}' " "LIMIT 1", bot_name ); auto results = database.QueryDatabase(query); + + if (!results.RowCount()) { + query = fmt::format( + "SELECT c.id FROM character_data c " + "WHERE c.`name` LIKE '{}' " + "LIMIT 1", + bot_name + ); + results = database.QueryDatabase(query); + } + if (!results.Success()) { return false; }