Skip to content

Commit

Permalink
fix "WITH SQL" compile errors for Visual Studio 2015 (continuation of #…
Browse files Browse the repository at this point in the history
  • Loading branch information
HarpyWar committed Sep 21, 2015
1 parent 5f9d7d6 commit bd08cc8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
16 changes: 8 additions & 8 deletions src/bnetd/sql_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ namespace pvpgn
return 0;
}

snprintf(query, sizeof(query), "SELECT max("SQL_UID_FIELD") FROM %sBNET", tab_prefix);
snprintf(query, sizeof(query), "SELECT max(" SQL_UID_FIELD ") FROM %sBNET", tab_prefix);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if ((result = sql->query_res(query)) == NULL) {
eventlog(eventlog_level_error, __FUNCTION__, "error trying query: \"SELECT max("SQL_UID_FIELD") FROM %sBNET\"", tab_prefix);
eventlog(eventlog_level_error, __FUNCTION__, "error trying query: \"SELECT max(" SQL_UID_FIELD ") FROM %sBNET\"", tab_prefix);
return 0;
}

Expand Down Expand Up @@ -286,7 +286,7 @@ namespace pvpgn
/* don't actually load anything here if ST_FORCE is not set as SQL is indexed */
if (!FLAG_ISSET(flag, ST_FORCE)) return 1;

snprintf(query, sizeof(query), "SELECT DISTINCT("SQL_UID_FIELD") FROM %sBNET", tab_prefix);
snprintf(query, sizeof(query), "SELECT DISTINCT(" SQL_UID_FIELD ") FROM %sBNET", tab_prefix);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if ((result = sql->query_res(query)) != NULL)
{
Expand Down Expand Up @@ -404,7 +404,7 @@ namespace pvpgn
clan->channel_type = prefs_get_clan_channel_default_private();
clan->members = list_create();

snprintf(query, sizeof(query), "SELECT "SQL_UID_FIELD", status, join_time FROM %sclanmember WHERE cid='%u'", tab_prefix, clan->clanid);
snprintf(query, sizeof(query), "SELECT " SQL_UID_FIELD ", status, join_time FROM %sclanmember WHERE cid='%u'", tab_prefix, clan->clanid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if ((result2 = sql->query_res(query)) != NULL)
{
Expand Down Expand Up @@ -519,7 +519,7 @@ namespace pvpgn
if (member->modified)
{
uid = account_get_uid(member->memberacc);
snprintf(query, sizeof(query), "SELECT count(*) FROM %sclanmember WHERE "SQL_UID_FIELD"='%u'", tab_prefix, uid);
snprintf(query, sizeof(query), "SELECT count(*) FROM %sclanmember WHERE " SQL_UID_FIELD "='%u'", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if ((result = sql->query_res(query)) != NULL)
{
Expand All @@ -533,9 +533,9 @@ namespace pvpgn
num = std::atol(row[0]);
sql->free_result(result);
if (num < 1)
snprintf(query, sizeof(query), "INSERT INTO %sclanmember (cid, "SQL_UID_FIELD", status, join_time) VALUES('%u', '%u', '%d', '%u')", tab_prefix, clan->clanid, uid, member->status, (unsigned)member->join_time);
snprintf(query, sizeof(query), "INSERT INTO %sclanmember (cid, " SQL_UID_FIELD ", status, join_time) VALUES('%u', '%u', '%d', '%u')", tab_prefix, clan->clanid, uid, member->status, (unsigned)member->join_time);
else
snprintf(query, sizeof(query), "UPDATE %sclanmember SET cid='%u', status='%d', join_time='%u' WHERE "SQL_UID_FIELD"='%u'", tab_prefix, clan->clanid, member->status, (unsigned)member->join_time, uid);
snprintf(query, sizeof(query), "UPDATE %sclanmember SET cid='%u', status='%d', join_time='%u' WHERE " SQL_UID_FIELD "='%u'", tab_prefix, clan->clanid, member->status, (unsigned)member->join_time, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if (sql->query(query) < 0)
{
Expand Down Expand Up @@ -613,7 +613,7 @@ namespace pvpgn
return -1;
}

snprintf(query, sizeof(query), "DELETE FROM %sclanmember WHERE "SQL_UID_FIELD"='%u'", tab_prefix, uid);
snprintf(query, sizeof(query), "DELETE FROM %sclanmember WHERE " SQL_UID_FIELD "='%u'", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if (sql->query(query) != 0)
{
Expand Down
28 changes: 14 additions & 14 deletions src/bnetd/storage_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,43 +165,43 @@ namespace pvpgn

info = xmalloc(sizeof(t_sql_info));
*((unsigned int *)info) = uid;
snprintf(query, sizeof(query), "DELETE FROM %sBNET WHERE "SQL_UID_FIELD" = '%u'", tab_prefix, uid);
snprintf(query, sizeof(query), "DELETE FROM %sBNET WHERE " SQL_UID_FIELD " = '%u'", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
sql->query(query);
snprintf(query, sizeof(query), "INSERT INTO %sBNET ("SQL_UID_FIELD",username) VALUES('%u','%s')", tab_prefix, uid, user);
snprintf(query, sizeof(query), "INSERT INTO %sBNET (" SQL_UID_FIELD ",username) VALUES('%u','%s')", tab_prefix, uid, user);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if (sql->query(query))
{
eventlog(eventlog_level_error, __FUNCTION__, "user insert failed (query: '%s')", query);
goto err_info;
}

snprintf(query, sizeof(query), "DELETE FROM %sprofile WHERE "SQL_UID_FIELD" = '%u'", tab_prefix, uid);
snprintf(query, sizeof(query), "DELETE FROM %sprofile WHERE " SQL_UID_FIELD " = '%u'", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
sql->query(query);
snprintf(query, sizeof(query), "INSERT INTO %sprofile ("SQL_UID_FIELD") VALUES('%u')", tab_prefix, uid);
snprintf(query, sizeof(query), "INSERT INTO %sprofile (" SQL_UID_FIELD ") VALUES('%u')", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if (sql->query(query))
{
eventlog(eventlog_level_error, __FUNCTION__, "user insert failed (query: '%s')", query);
goto err_info;
}

snprintf(query, sizeof(query), "DELETE FROM %sRecord WHERE "SQL_UID_FIELD" = '%u'", tab_prefix, uid);
snprintf(query, sizeof(query), "DELETE FROM %sRecord WHERE " SQL_UID_FIELD " = '%u'", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
sql->query(query);
snprintf(query, sizeof(query), "INSERT INTO %sRecord ("SQL_UID_FIELD") VALUES('%u')", tab_prefix, uid);
snprintf(query, sizeof(query), "INSERT INTO %sRecord (" SQL_UID_FIELD ") VALUES('%u')", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if (sql->query(query))
{
eventlog(eventlog_level_error, __FUNCTION__, "user insert failed (query: '%s')", query);
goto err_info;
}

snprintf(query, sizeof(query), "DELETE FROM %sfriend WHERE "SQL_UID_FIELD" = '%u'", tab_prefix, uid);
snprintf(query, sizeof(query), "DELETE FROM %sfriend WHERE " SQL_UID_FIELD " = '%u'", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
sql->query(query);
snprintf(query, sizeof(query), "INSERT INTO %sfriend ("SQL_UID_FIELD") VALUES('%u')", tab_prefix, uid);
snprintf(query, sizeof(query), "INSERT INTO %sfriend (" SQL_UID_FIELD ") VALUES('%u')", tab_prefix, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);
if (sql->query(query))
{
Expand Down Expand Up @@ -255,7 +255,7 @@ namespace pvpgn
if (strcmp(ktab, *tab) != 0)
continue;

snprintf(query, sizeof(query), "SELECT * FROM %s%s WHERE "SQL_UID_FIELD"='%u'", tab_prefix, *tab, uid);
snprintf(query, sizeof(query), "SELECT * FROM %s%s WHERE " SQL_UID_FIELD "='%u'", tab_prefix, *tab, uid);
eventlog(eventlog_level_trace, __FUNCTION__, query);

if ((result = sql->query_res(query)) != NULL && sql->num_rows(result) == 1 && sql->num_fields(result) > 1)
Expand Down Expand Up @@ -460,7 +460,7 @@ namespace pvpgn
}

/* FIRST TIME UPDATE EACH ATTRIBUTE IN A SINGLE QUERY AND SAVE ATTRIBUTE NAME IN `knownattributes` */
snprintf(query, sizeof(query), "UPDATE %s%s SET `%s` = '%s' WHERE "SQL_UID_FIELD" = '%u'", tab_prefix, tab, col, escape, uid);
snprintf(query, sizeof(query), "UPDATE %s%s SET `%s` = '%s' WHERE " SQL_UID_FIELD " = '%u'", tab_prefix, tab, col, escape, uid);
eventlog(eventlog_level_trace, "db_set", query);

if (sql->query(query) || !sql->affected_rows()) {
Expand All @@ -476,7 +476,7 @@ namespace pvpgn
// eventlog(eventlog_level_trace, "db_set", "retry insert query: %s", query);
if (sql->query(query) || !sql->affected_rows()) {
// Tried everything, now trying to insert that user to the table for the first time
snprintf(query2, sizeof(query2), "INSERT INTO %s%s ("SQL_UID_FIELD",`%s`) VALUES ('%u','%s')", tab_prefix, tab, col, uid, escape);
snprintf(query2, sizeof(query2), "INSERT INTO %s%s (" SQL_UID_FIELD ",`%s`) VALUES ('%u','%s')", tab_prefix, tab, col, uid, escape);
eventlog(eventlog_level_trace, __FUNCTION__, query2);
// eventlog(eventlog_level_error, __FUNCTION__, "update failed so tried INSERT for the last chance");
if (sql->query(query2))
Expand All @@ -502,7 +502,7 @@ namespace pvpgn
{
query_s = "UPDATE " + std::string(tab_prefix) + q->first + " SET ";
query_s += q->second.substr(0, q->second.size() - 2); // remove last reduntant comma at the end of the string with parameters
query_s += " WHERE "SQL_UID_FIELD" = '" + std_to_string(uid) + "'";
query_s += " WHERE " SQL_UID_FIELD " = '" + std_to_string(uid) + "'";

if (!sql->query(query_s.c_str()))
{
Expand Down Expand Up @@ -536,11 +536,11 @@ namespace pvpgn
char *user = xstrdup(name);
strtolower(user);

snprintf(query, sizeof(query), "SELECT "SQL_UID_FIELD" FROM %sBNET WHERE username='%s'", tab_prefix, user);
snprintf(query, sizeof(query), "SELECT " SQL_UID_FIELD " FROM %sBNET WHERE username='%s'", tab_prefix, user);
xfree(user);
}
else
snprintf(query, sizeof(query), "SELECT "SQL_UID_FIELD" FROM %sBNET WHERE "SQL_UID_FIELD" = '%u'", tab_prefix, uid);
snprintf(query, sizeof(query), "SELECT " SQL_UID_FIELD " FROM %sBNET WHERE " SQL_UID_FIELD " = '%u'", tab_prefix, uid);

eventlog(eventlog_level_trace, __FUNCTION__, query);

Expand Down

0 comments on commit bd08cc8

Please sign in to comment.