Skip to content

Commit

Permalink
DB: Remove trailing ;'s from internal queries
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Mar 31, 2024
1 parent e7062b9 commit 2462885
Show file tree
Hide file tree
Showing 51 changed files with 320 additions and 320 deletions.
14 changes: 7 additions & 7 deletions src/common/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void SqlConnection::SetupKeepalive()
void SqlConnection::CheckCharset()
{
// Check that the SQL charset is what we require
auto ret = QueryStr("SELECT @@character_set_database, @@collation_database;");
auto ret = QueryStr("SELECT @@character_set_database, @@collation_database");
if (ret != SQL_ERROR && NumRows())
{
bool foundError = false;
Expand Down Expand Up @@ -559,7 +559,7 @@ bool SqlConnection::GetAutoCommit()
TracyZoneScoped;
if (self)
{
int32 ret = Query("SELECT @@autocommit;");
int32 ret = Query("SELECT @@autocommit");

if (ret != SQL_ERROR && NumRows() > 0 && NextRow() == SQL_SUCCESS)
{
Expand All @@ -575,7 +575,7 @@ bool SqlConnection::GetAutoCommit()
bool SqlConnection::TransactionStart()
{
TracyZoneScoped;
if (self && Query("START TRANSACTION;") != SQL_ERROR)
if (self && Query("START TRANSACTION") != SQL_ERROR)
{
return true;
}
Expand All @@ -601,7 +601,7 @@ bool SqlConnection::TransactionCommit()
bool SqlConnection::TransactionRollback()
{
TracyZoneScoped;
if (self && Query("ROLLBACK;") != SQL_ERROR)
if (self && Query("ROLLBACK") != SQL_ERROR)
{
return true;
}
Expand All @@ -617,7 +617,7 @@ bool SqlConnection::TransactionRollback()
void SqlConnection::StartProfiling()
{
TracyZoneScoped;
if (self && QueryStr("SET profiling = 1;") != SQL_ERROR)
if (self && QueryStr("SET profiling = 1") != SQL_ERROR)
{
return;
}
Expand All @@ -639,7 +639,7 @@ void SqlConnection::FinishProfiling()
}

auto lastQuery = self->buf;
if (QueryStr("SHOW PROFILE;") != SQL_ERROR && NumRows() > 0)
if (QueryStr("SHOW PROFILE") != SQL_ERROR && NumRows() > 0)
{
std::string outStr = "SQL SHOW PROFILE:\n";
outStr += fmt::format("Query: {}\n", lastQuery);
Expand All @@ -652,7 +652,7 @@ void SqlConnection::FinishProfiling()
auto measurement = GetStringData(1);
outStr += fmt::format("| {:<31}| {:<8} |\n", category, measurement);
}
QueryStr("SET profiling = 0;");
QueryStr("SET profiling = 0");
ShowInfo(outStr);
return;
}
Expand Down
16 changes: 8 additions & 8 deletions src/login/auth_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void auth_session::read_func()
// clang-format off
auto passHash = [&]() -> std::string
{
auto ret = _sql->Query("SELECT accounts.password FROM accounts WHERE accounts.login = '%s';", username);
auto ret = _sql->Query("SELECT accounts.password FROM accounts WHERE accounts.login = '%s'", username);
if (ret != SQL_ERROR && _sql->NumRows() != 0 && _sql->NextRow() == SQL_SUCCESS)
{
return _sql->GetStringData(0);
Expand Down Expand Up @@ -208,7 +208,7 @@ void auth_session::read_func()
else
{
passHash = BCrypt::generateHash(password);
_sql->Query("UPDATE accounts SET accounts.password = '%s' WHERE accounts.login = '%s';", passHash.c_str(), username);
_sql->Query("UPDATE accounts SET accounts.password = '%s' WHERE accounts.login = '%s'", passHash.c_str(), username);

if (!BCrypt::validatePassword(password, passHash))
{
Expand Down Expand Up @@ -236,7 +236,7 @@ void auth_session::read_func()
ret = _sql->Query("SELECT charid, server_addr, server_port \
FROM accounts_sessions JOIN accounts \
ON accounts_sessions.accid = accounts.id \
WHERE accounts.id = %d;",
WHERE accounts.id = %d",
accountID);

if (ret != SQL_ERROR && _sql->NumRows() == 1)
Expand Down Expand Up @@ -267,7 +267,7 @@ void auth_session::read_func()

/* fmtQuery = "SELECT charid \
FROM accounts_sessions \
WHERE accid = %u LIMIT 1;";
WHERE accid = %u LIMIT 1";
if (_sql->Query(fmtQuery, accountID) != SQL_ERROR && _sql->NumRows() != 0 && _sql->NextRow() == SQL_SUCCESS)
{
Expand Down Expand Up @@ -343,7 +343,7 @@ void auth_session::read_func()
// creating new account_id
uint32 accid = 0;

if (_sql->Query("SELECT max(accounts.id) FROM accounts;") != SQL_ERROR && _sql->NumRows() != 0)
if (_sql->Query("SELECT max(accounts.id) FROM accounts") != SQL_ERROR && _sql->NumRows() != 0)
{
_sql->NextRow();

Expand All @@ -369,7 +369,7 @@ void auth_session::read_func()
strftime(strtimecreate, sizeof(strtimecreate), "%Y:%m:%d %H:%M:%S", &timecreateinfo);

if (_sql->Query("INSERT INTO accounts(id,login,password,timecreate,timelastmodify,status,priv) \
VALUES(%d,'%s','%s','%s',NULL,%d,%d);",
VALUES(%d,'%s','%s','%s',NULL,%d,%d)",
accid, username, BCrypt::generateHash(escaped_pass), strtimecreate, ACCOUNT_STATUS_CODE::NORMAL, ACCOUNT_PRIVILEGE_CODE::USER) == SQL_ERROR)
{
ref<uint8>(data_, 0) = LOGIN_ERROR_CREATE;
Expand Down Expand Up @@ -434,7 +434,7 @@ void auth_session::read_func()
else
{
passHash = BCrypt::generateHash(password);
_sql->Query("UPDATE accounts SET accounts.password = '%s' WHERE accounts.login = '%s';", passHash.c_str(), username);
_sql->Query("UPDATE accounts SET accounts.password = '%s' WHERE accounts.login = '%s'", passHash.c_str(), username);

if (!BCrypt::validatePassword(password, passHash))
{
Expand All @@ -448,7 +448,7 @@ void auth_session::read_func()

int32 ret = _sql->Query("SELECT accounts.id, accounts.status \
FROM accounts \
WHERE accounts.login = '%s';",
WHERE accounts.login = '%s'",
username);
if (ret == SQL_ERROR || _sql->NumRows() == 0)
{
Expand Down
16 changes: 8 additions & 8 deletions src/login/data_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void data_session::read_func()

auto _sql = std::make_unique<SqlConnection>();
uint32 numContentIds = 0;
int32 ret = _sql->Query("SELECT content_ids FROM accounts WHERE id = %u;", session.accountID);
int32 ret = _sql->Query("SELECT content_ids FROM accounts WHERE id = %u", session.accountID);

numContentIds = _sql->NumRows();

Expand Down Expand Up @@ -89,7 +89,7 @@ void data_session::read_func()
INNER JOIN char_look USING(charid) \
INNER JOIN char_jobs USING(charid) \
WHERE accid = %i \
LIMIT %u;";
LIMIT %u";

ret = _sql->Query(pfmtQuery, session.accountID, numContentIds);
if (ret == SQL_ERROR)
Expand Down Expand Up @@ -273,7 +273,7 @@ void data_session::read_func()

if (_sql->Query("SELECT zoneip, zoneport, zoneid, pos_prevzone, gmlevel, accid, charname \
FROM zone_settings, chars \
WHERE IF(pos_zone = 0, zoneid = pos_prevzone, zoneid = pos_zone) AND charid = %u AND accid = %u;",
WHERE IF(pos_zone = 0, zoneid = pos_prevzone, zoneid = pos_zone) AND charid = %u AND accid = %u",
charid, session.accountID) != SQL_ERROR &&
_sql->NumRows() != 0)
{
Expand Down Expand Up @@ -314,7 +314,7 @@ void data_session::read_func()

if (_sql->Query("SELECT COUNT(client_addr) \
FROM accounts_sessions \
WHERE client_addr = %u;",
WHERE client_addr = %u",
accountIP) != SQL_ERROR &&
_sql->NumRows() != 0)
{
Expand All @@ -326,7 +326,7 @@ void data_session::read_func()

if (_sql->Query("SELECT * \
FROM accounts_sessions \
WHERE accid = %u AND client_port != '0';",
WHERE accid = %u AND client_port != '0'",
session.accountID) != SQL_ERROR &&
_sql->NumRows() != 0)
{
Expand All @@ -338,7 +338,7 @@ void data_session::read_func()

if (_sql->Query("SELECT UNIX_TIMESTAMP(exception) \
FROM ip_exceptions \
WHERE accid = %u;",
WHERE accid = %u",
session.accountID) != SQL_ERROR &&
_sql->NumRows() != 0)
{
Expand Down Expand Up @@ -374,7 +374,7 @@ void data_session::read_func()
{
if (PrevZone == 0)
{
_sql->Query("UPDATE chars SET pos_prevzone = %d WHERE charid = %u;", ZoneID, charid);
_sql->Query("UPDATE chars SET pos_prevzone = %d WHERE charid = %u", ZoneID, charid);
}
auto searchPort = settings::get<uint16>("network.SEARCH_PORT");
characterSelectionResponse.cache_ip = session.serverIP; // search-server ip
Expand Down Expand Up @@ -452,7 +452,7 @@ void data_session::read_func()
strftime(timeAndDate, sizeof(timeAndDate), "%Y:%m:%d %H:%M:%S", &convertedTime);

if (_sql->Query("INSERT INTO account_ip_record(login_time,accid,charid,client_ip) \
VALUES ('%s', %u, %u, '%s');",
VALUES ('%s', %u, %u, '%s')",
timeAndDate, session.accountID, charid, loginHelpers::ip2str(accountIP)) == SQL_ERROR)
{
ShowError("data_session: Could not write info to account_ip_record.");
Expand Down
22 changes: 11 additions & 11 deletions src/login/login_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,58 +148,58 @@ namespace loginHelpers
{
auto _sql = std::make_unique<SqlConnection>();

if (_sql->Query("INSERT INTO chars(charid,accid,charname,pos_zone,nation) VALUES(%u,%u,'%s',%u,%u);",
if (_sql->Query("INSERT INTO chars(charid,accid,charname,pos_zone,nation) VALUES(%u,%u,'%s',%u,%u)",
charid, accid, str(createchar->m_name), createchar->m_zone, createchar->m_nation) == SQL_ERROR)
{
ShowDebug(fmt::format("lobby_ccsave: char<{}>, accid: {}, charid: {}", str(createchar->m_name), accid, charid));
return -1;
}

if (_sql->Query("INSERT INTO char_look(charid,face,race,size) VALUES(%u,%u,%u,%u);",
if (_sql->Query("INSERT INTO char_look(charid,face,race,size) VALUES(%u,%u,%u,%u)",
charid, createchar->m_look.face, createchar->m_look.race, createchar->m_look.size) == SQL_ERROR)
{
ShowDebug(fmt::format("lobby_cLook: char<{}>, charid: {}", str(createchar->m_name), charid));
return -1;
}

if (_sql->Query("INSERT INTO char_stats(charid,mjob) VALUES(%u,%u);",
if (_sql->Query("INSERT INTO char_stats(charid,mjob) VALUES(%u,%u)",
charid, createchar->m_mjob) == SQL_ERROR)
{
ShowDebug(fmt::format("lobby_cStats: charid: {}", charid));
return -1;
}

if (_sql->Query("INSERT INTO char_exp(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid;",
if (_sql->Query("INSERT INTO char_exp(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid",
charid, createchar->m_mjob) == SQL_ERROR)
{
return -1;
}

if (_sql->Query("INSERT INTO char_jobs(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid;",
if (_sql->Query("INSERT INTO char_jobs(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid",
charid, createchar->m_mjob) == SQL_ERROR)
{
return -1;
}

if (_sql->Query("INSERT INTO char_points(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid;",
if (_sql->Query("INSERT INTO char_points(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid",
charid, createchar->m_mjob) == SQL_ERROR)
{
return -1;
}

if (_sql->Query("INSERT INTO char_unlocks(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid;",
if (_sql->Query("INSERT INTO char_unlocks(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid",
charid, createchar->m_mjob) == SQL_ERROR)
{
return -1;
}

if (_sql->Query("INSERT INTO char_profile(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid;",
if (_sql->Query("INSERT INTO char_profile(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid",
charid, createchar->m_mjob) == SQL_ERROR)
{
return -1;
}

if (_sql->Query("INSERT INTO char_storage(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid;",
if (_sql->Query("INSERT INTO char_storage(charid) VALUES(%u) ON DUPLICATE KEY UPDATE charid = charid",
charid, createchar->m_mjob) == SQL_ERROR)
{
return -1;
Expand All @@ -210,14 +210,14 @@ namespace loginHelpers
return -1;
}

if (_sql->Query("INSERT INTO char_inventory(charid) VALUES(%u);", charid, createchar->m_mjob) == SQL_ERROR)
if (_sql->Query("INSERT INTO char_inventory(charid) VALUES(%u)", charid, createchar->m_mjob) == SQL_ERROR)
{
return -1;
}

if (settings::get<bool>("main.NEW_CHARACTER_CUTSCENE"))
{
if (_sql->Query("INSERT INTO char_vars(charid, varname, value) VALUES(%u, '%s', %u);",
if (_sql->Query("INSERT INTO char_vars(charid, varname, value) VALUES(%u, '%s', %u)",
charid, "HQuest[newCharacterCS]notSeen", 1) == SQL_ERROR)
{
return -1;
Expand Down
6 changes: 3 additions & 3 deletions src/login/view_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void view_session::read_func()
auto _sql = std::make_unique<SqlConnection>();

uint32 accountID = 0;
int32 ret = _sql->Query("SELECT accid FROM chars WHERE charid = %u AND charname = '%s' LIMIT 1;",
int32 ret = _sql->Query("SELECT accid FROM chars WHERE charid = %u AND charname = '%s' LIMIT 1",
requestedCharacterID, requestedCharacter);
if (ret != SQL_ERROR && _sql->NumRows() != 0 && _sql->NextRow() == SQL_SUCCESS)
{
Expand Down Expand Up @@ -120,7 +120,7 @@ void view_session::read_func()
CharID, ipAddress));

uint32 accountID = 0;
int32 ret = _sql->Query("SELECT accid FROM chars WHERE charid = %u LIMIT 1;", CharID);
int32 ret = _sql->Query("SELECT accid FROM chars WHERE charid = %u LIMIT 1", CharID);

if (ret != SQL_ERROR && _sql->NumRows() != 0 && _sql->NextRow() == SQL_SUCCESS)
{
Expand Down Expand Up @@ -237,7 +237,7 @@ void view_session::read_func()
" UNION "
" SELECT packet_name AS `name` FROM mob_pools "
") "
"SELECT * FROM results WHERE REPLACE(REPLACE(UPPER(`name`), '-', ''), '_', '') LIKE REPLACE(REPLACE(UPPER('%s'), '-', ''), '_', '');";
"SELECT * FROM results WHERE REPLACE(REPLACE(UPPER(`name`), '-', ''), '_', '') LIKE REPLACE(REPLACE(UPPER('%s'), '-', ''), '_', '')";

if (_sql->Query(query, nameStr) == SQL_ERROR)
{
Expand Down
2 changes: 1 addition & 1 deletion src/map/ability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ namespace ability
}
}

const char* Query2 = "SELECT recastId, job, level, maxCharges, chargeTime, meritModId FROM abilities_charges ORDER BY job, level ASC;";
const char* Query2 = "SELECT recastId, job, level, maxCharges, chargeTime, meritModId FROM abilities_charges ORDER BY job, level ASC";

ret = _sql->Query(Query2);

Expand Down
4 changes: 2 additions & 2 deletions src/map/ai/controllers/automaton_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ namespace automaton

void LoadAutomatonSpellList()
{
const char* Query = "SELECT spellid, skilllevel, heads, enfeeble, immunity, removes FROM automaton_spells;";
const char* Query = "SELECT spellid, skilllevel, heads, enfeeble, immunity, removes FROM automaton_spells";

int32 ret = _sql->Query(Query);

Expand Down Expand Up @@ -1724,7 +1724,7 @@ namespace automaton

void LoadAutomatonAbilities()
{
const char* Query = "SELECT abilityid, abilityname, reqframe, skilllevel FROM automaton_abilities;";
const char* Query = "SELECT abilityid, abilityname, reqframe, skilllevel FROM automaton_abilities";

int32 ret = _sql->Query(Query);

Expand Down
Loading

0 comments on commit 2462885

Please sign in to comment.