Added SQL_QuoteString to include/tests

This commit is contained in:
David Anderson 2007-04-25 13:45:15 +00:00
parent 359b7e25dd
commit c957a9db0f
2 changed files with 53 additions and 0 deletions

View File

@ -62,6 +62,34 @@ native Handle:SQL_Connect(Handle:cn_tuple, &errcode, error[], maxlength);
native Handle:SQL_PrepareQuery(Handle:db, const fmt[], {Float,_}:...); native Handle:SQL_PrepareQuery(Handle:db, const fmt[], {Float,_}:...);
/**
* Back-quotes characters in a string for database querying.
* Note: The buffer's maximum size should be 2*strlen(string) to catch
* all scenarios.
*
* @param db Database handle, for localization.
* @param buffer Buffer to copy to.
* @param buflen Maximum size of the buffer.
* @param string String to backquote (should not overlap buffer).
* @return Length of new string, or -1 on failure.
*/
native SQL_QuoteString(Handle:db, buffer[], buflen, const string[]);
/**
* Back-quotes characters in a string for database querying.
* Note: The buffer's maximum size should be 2*strlen(string) to catch
* all scenarios.
*
* @param db Database handle, for localization.
* @param buffer Buffer to copy to.
* @param buflen Maximum size of the buffer.
* @param fmt Format of string to backquote (should not overlap buffer).
* @param ... Format arguments.
* @return Length of new string, or -1 on failure.
*/
native SQL_QuoteStringFmt(Handle:db, buffer[], buflen, const fmt[], any:...);
#define TQUERY_CONNECT_FAILED -2 #define TQUERY_CONNECT_FAILED -2
#define TQUERY_QUERY_FAILED -1 #define TQUERY_QUERY_FAILED -1
#define TQUERY_SUCCESS 0 #define TQUERY_SUCCESS 0

View File

@ -16,6 +16,7 @@ public plugin_init()
register_srvcmd("sqlx_test_old2", "SqlxTest_Old2") register_srvcmd("sqlx_test_old2", "SqlxTest_Old2")
register_srvcmd("sqlx_test_thread_end", "SqlxTest_ThreadEnd") register_srvcmd("sqlx_test_thread_end", "SqlxTest_ThreadEnd")
register_srvcmd("sqlx_test_bad", "SqlxTest_Bad") register_srvcmd("sqlx_test_bad", "SqlxTest_Bad")
register_srvcmd("sqlx_test_quote", "SqlxTest_Quote")
new configsDir[64] new configsDir[64]
get_configsdir(configsDir, 63) get_configsdir(configsDir, 63)
@ -163,6 +164,30 @@ public SqlxTest_Thread()
g_QueryNum++ g_QueryNum++
} }
/**
* Tests string quoting
*/
public SqlxTest_Quote()
{
DoBasicInfo(1)
new errno, error[255]
new Handle:db = SQL_Connect(g_DbInfo, errno, error, sizeof(error)-1)
if (!db)
{
server_print("Query failure: [%d] %s", errno, error)
return
}
new buffer[500], num
num = SQL_QuoteString(buffer, sizeof(buffer)-1, "Hi y'all! C\lam")
server_print("num: %d str: %s", num, buffer)
SQL_FreeHandle(db)
}
/** /**
* Does a normal query. * Does a normal query.
*/ */