Skip to content

Commit b89d115

Browse files
authored
Merge pull request #105 from karimcambridge/issue-54
Add query to debug logs in the most places where (assumed) that peopl…
2 parents 5fd3535 + 807485c commit b89d115

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/CMySQLQuery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool CMySQLQuery::Execute(MYSQL *mysql_connection)
6565
int error_id = mysql_errno(mysql_connection);
6666
string error_str(mysql_error(mysql_connection));
6767

68-
CLog::Get()->LogFunction(LOG_ERROR, log_funcname, "(error #%d) %s", error_id, error_str.c_str());
68+
CLog::Get()->LogFunction(LOG_ERROR, log_funcname, "(error #%d) %s (Query: \"%s\")", error_id, error_str.c_str(), Query.c_str());
6969

7070
if (!Unthreaded)
7171
{

src/CMySQLResult.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const char *CMySQLResult::GetFieldName(unsigned int idx)
1414
}
1515
else
1616
{
17-
CLog::Get()->LogFunction(LOG_WARNING, "CMySQLResult::GetFieldName", "invalid field index ('%d')", idx);
17+
CLog::Get()->LogFunction(LOG_WARNING, "CMySQLResult::GetFieldName", "invalid field index ('%d') (Query: \"%s\")", idx, m_Query.c_str());
1818
return NULL;
1919
}
2020
}
@@ -36,7 +36,7 @@ const char *CMySQLResult::GetRowData(unsigned int row, unsigned int fieldidx)
3636
}
3737
else
3838
{
39-
CLog::Get()->LogFunction(LOG_WARNING, "CMySQLResult::GetRowData", "invalid row ('%d') or field index ('%d')", row, fieldidx);
39+
CLog::Get()->LogFunction(LOG_WARNING, "CMySQLResult::GetRowData", "invalid row ('%d') or field index ('%d') (Query: \"%s\")", row, fieldidx, m_Query.c_str());
4040
return NULL;
4141
}
4242
}
@@ -45,13 +45,13 @@ const char *CMySQLResult::GetRowDataByName(unsigned int row, const char *field)
4545
{
4646
if(row >= m_Rows || m_Fields == 0)
4747
{
48-
CLog::Get()->LogFunction(LOG_ERROR, "CMySQLResult::GetRowDataByName()", "invalid row index ('%d')", row);
48+
CLog::Get()->LogFunction(LOG_ERROR, "CMySQLResult::GetRowDataByName()", "invalid row index ('%d') (Query: \"%s\")", row, m_Query.c_str());
4949
return NULL;
5050
}
5151

5252
if(field == NULL)
5353
{
54-
CLog::Get()->LogFunction(LOG_ERROR, "CMySQLResult::GetRowDataByName()", "empty field name specified");
54+
CLog::Get()->LogFunction(LOG_ERROR, "CMySQLResult::GetRowDataByName()", "empty field name specified (Query: \"%s\")", m_Query.c_str());
5555
return NULL;
5656
}
5757

@@ -70,7 +70,7 @@ const char *CMySQLResult::GetRowDataByName(unsigned int row, const char *field)
7070
return m_Data[row][i];
7171
}
7272
}
73-
CLog::Get()->LogFunction(LOG_WARNING, "CMySQLResult::GetRowDataByName", "field not found (\"%s\")", field);
73+
CLog::Get()->LogFunction(LOG_WARNING, "CMySQLResult::GetRowDataByName", "field not found (\"%s\") (Query: \"%s\")", field, m_Query.c_str());
7474
return NULL;
7575
}
7676

src/CScripting.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ AMX_DECLARE_NATIVE(Native::mysql_pquery)
855855
return ERROR_INVALID_CONNECTION_HANDLE("mysql_pquery", connection_id);
856856

857857
if (cb_format != NULL && strlen(cb_format) != ((params[0] / 4) - ConstParamCount))
858-
return CLog::Get()->LogFunction(LOG_ERROR, "mysql_pquery", "callback parameter count does not match format specifier length");
858+
return CLog::Get()->LogFunction(LOG_ERROR, "mysql_pquery", "callback parameter count does not match format specifier length (Query: \"%s\")", query_str ? query_str : "");
859859

860860

861861
CMySQLHandle *Handle = CMySQLHandle::GetHandle(connection_id);
@@ -898,7 +898,7 @@ AMX_DECLARE_NATIVE(Native::mysql_tquery)
898898
return ERROR_INVALID_CONNECTION_HANDLE("mysql_tquery", connection_id);
899899

900900
if (cb_format != NULL && strlen(cb_format) != ((params[0] / 4) - ConstParamCount))
901-
return CLog::Get()->LogFunction(LOG_ERROR, "mysql_tquery", "callback parameter count does not match format specifier length");
901+
return CLog::Get()->LogFunction(LOG_ERROR, "mysql_tquery", "callback parameter count does not match format specifier length (Query: \"%s\")", query_str ? query_str : "");
902902

903903

904904
CMySQLHandle *Handle = CMySQLHandle::GetHandle(connection_id);
@@ -1300,7 +1300,7 @@ AMX_DECLARE_NATIVE(Native::mysql_escape_string)
13001300
if(source_str != NULL)
13011301
{
13021302
if(strlen(source_str) >= max_size)
1303-
return CLog::Get()->LogFunction(LOG_ERROR, "mysql_escape_string", "destination size is too small (must be at least as big as source)");
1303+
return CLog::Get()->LogFunction(LOG_ERROR, "mysql_escape_string", "destination size is too small (must be at least as big as source) (Query: \"%s\")", source_str);
13041304

13051305
CMySQLHandle::GetHandle(connection_id)->GetMainConnection()->EscapeString(source_str, escaped_str);
13061306
}
@@ -1338,8 +1338,6 @@ AMX_DECLARE_NATIVE(Native::mysql_errno)
13381338
ERROR_INVALID_CONNECTION_HANDLE("mysql_errno", connection_id);
13391339
return -1; //don't return 0 since it means that there are no errors
13401340
}
1341-
1342-
13431341
return static_cast<cell>(mysql_errno(CMySQLHandle::GetHandle(connection_id)->GetMainConnection()->GetMysqlPtr()));
13441342
}
13451343

0 commit comments

Comments
 (0)