mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-24 13:55:36 +03:00
implemented SQL_QuoteString and SQL_QuoteStringFmt
fixed sqlx test script not working on first load
This commit is contained in:
parent
58ad23186b
commit
82c3807bd5
@ -489,6 +489,52 @@ static cell AMX_NATIVE_CALL SQL_Rewind(AMX *amx, cell *params)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL SQL_QuoteString(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
||||||
|
if (!pDb)
|
||||||
|
{
|
||||||
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str = MF_GetAmxString(amx, params[4], 0, &len);
|
||||||
|
size_t newsize;
|
||||||
|
static char buffer[8192];
|
||||||
|
|
||||||
|
if (pDb->QuoteString(str, buffer, sizeof(buffer)-1, &newsize) == 0)
|
||||||
|
{
|
||||||
|
MF_SetAmxString(amx, params[2], buffer, params[3]);
|
||||||
|
return newsize;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL SQL_QuoteStringFmt(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
||||||
|
if (!pDb)
|
||||||
|
{
|
||||||
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str = MF_FormatAmxString(amx, params, 4, &len);
|
||||||
|
size_t newsize;
|
||||||
|
static char buffer[8192];
|
||||||
|
|
||||||
|
if (pDb->QuoteString(str, buffer, sizeof(buffer)-1, &newsize) == 0)
|
||||||
|
{
|
||||||
|
MF_SetAmxString(amx, params[2], buffer, params[3]);
|
||||||
|
return newsize;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
||||||
{
|
{
|
||||||
{"SQL_MakeDbTuple", SQL_MakeDbTuple},
|
{"SQL_MakeDbTuple", SQL_MakeDbTuple},
|
||||||
@ -511,6 +557,8 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
|||||||
{"SQL_GetInsertId", SQL_GetInsertId},
|
{"SQL_GetInsertId", SQL_GetInsertId},
|
||||||
{"SQL_GetQueryString", SQL_GetQueryString},
|
{"SQL_GetQueryString", SQL_GetQueryString},
|
||||||
{"SQL_Rewind", SQL_Rewind},
|
{"SQL_Rewind", SQL_Rewind},
|
||||||
|
{"SQL_QuoteString", SQL_QuoteString},
|
||||||
|
{"SQL_QuoteStringFmt", SQL_QuoteStringFmt},
|
||||||
|
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
@ -69,12 +69,16 @@ int MysqlDatabase::QuoteString(const char *str, char buffer[], size_t maxlen, si
|
|||||||
unsigned long size = static_cast<unsigned long>(strlen(str));
|
unsigned long size = static_cast<unsigned long>(strlen(str));
|
||||||
unsigned long needed = size*2 + 1;
|
unsigned long needed = size*2 + 1;
|
||||||
|
|
||||||
if (size < needed)
|
if (maxlen < needed)
|
||||||
|
{
|
||||||
return (int)needed;
|
return (int)needed;
|
||||||
|
}
|
||||||
|
|
||||||
needed = mysql_real_escape_string(m_pMysql, buffer, str, size);
|
needed = mysql_real_escape_string(m_pMysql, buffer, str, size);
|
||||||
if (newsize)
|
if (newsize)
|
||||||
|
{
|
||||||
*newsize = static_cast<size_t>(needed);
|
*newsize = static_cast<size_t>(needed);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -489,6 +489,51 @@ static cell AMX_NATIVE_CALL SQL_Rewind(AMX *amx, cell *params)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL SQL_QuoteString(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
||||||
|
if (!pDb)
|
||||||
|
{
|
||||||
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str = MF_GetAmxString(amx, params[4], 0, &len);
|
||||||
|
size_t newsize;
|
||||||
|
static char buffer[8192];
|
||||||
|
|
||||||
|
if (pDb->QuoteString(str, buffer, sizeof(buffer)-1, &newsize) == 0)
|
||||||
|
{
|
||||||
|
MF_SetAmxString(amx, params[2], buffer, params[3]);
|
||||||
|
return newsize;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL SQL_QuoteStringFmt(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
||||||
|
if (!pDb)
|
||||||
|
{
|
||||||
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str = MF_FormatAmxString(amx, params, 4, &len);
|
||||||
|
size_t newsize;
|
||||||
|
static char buffer[8192];
|
||||||
|
|
||||||
|
if (pDb->QuoteString(str, buffer, sizeof(buffer)-1, &newsize) == 0)
|
||||||
|
{
|
||||||
|
MF_SetAmxString(amx, params[2], buffer, params[3]);
|
||||||
|
return newsize;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
||||||
{
|
{
|
||||||
@ -512,6 +557,8 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
|||||||
{"SQL_GetInsertId", SQL_GetInsertId},
|
{"SQL_GetInsertId", SQL_GetInsertId},
|
||||||
{"SQL_GetQueryString", SQL_GetQueryString},
|
{"SQL_GetQueryString", SQL_GetQueryString},
|
||||||
{"SQL_Rewind", SQL_Rewind},
|
{"SQL_Rewind", SQL_Rewind},
|
||||||
|
{"SQL_QuoteString", SQL_QuoteString},
|
||||||
|
{"SQL_QuoteStringFmt", SQL_QuoteStringFmt},
|
||||||
|
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
@ -68,13 +68,12 @@ IQuery *SqliteDatabase::PrepareQueryFmt(const char *fmt, ...)
|
|||||||
|
|
||||||
int SqliteDatabase::QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newsize)
|
int SqliteDatabase::QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newsize)
|
||||||
{
|
{
|
||||||
unsigned long size = static_cast<unsigned long>(strlen(str));
|
char *res = sqlite3_snprintf(static_cast<int>(maxlen), buffer, "%q", str);
|
||||||
unsigned long needed = size*2 + 1;
|
|
||||||
|
|
||||||
if (size < needed)
|
if (res != NULL && newsize != NULL)
|
||||||
return (int)needed;
|
{
|
||||||
|
*newsize = strlen(buffer);
|
||||||
sqlite3_snprintf(static_cast<int>(maxlen), buffer, "%q", str);
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,8 @@ public plugin_init()
|
|||||||
get_configsdir(configsDir, 63)
|
get_configsdir(configsDir, 63)
|
||||||
|
|
||||||
server_cmd("exec %s/sql.cfg", configsDir)
|
server_cmd("exec %s/sql.cfg", configsDir)
|
||||||
server_exec()
|
|
||||||
|
set_task(2.0, "start_map")
|
||||||
}
|
}
|
||||||
|
|
||||||
DoBasicInfo(affinities=0)
|
DoBasicInfo(affinities=0)
|
||||||
@ -55,12 +56,12 @@ DoBasicInfo(affinities=0)
|
|||||||
wanted_type,
|
wanted_type,
|
||||||
res ? "Success" : "Failed")
|
res ? "Success" : "Failed")
|
||||||
SQL_GetAffinity(affinity, 11)
|
SQL_GetAffinity(affinity, 11)
|
||||||
plugin_cfg()
|
start_map()
|
||||||
server_print("Verification: %s", affinity)
|
server_print("Verification: %s", affinity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public plugin_cfg()
|
public start_map()
|
||||||
{
|
{
|
||||||
new host[64]
|
new host[64]
|
||||||
new user[64]
|
new user[64]
|
||||||
@ -181,7 +182,7 @@ public SqlxTest_Quote()
|
|||||||
}
|
}
|
||||||
|
|
||||||
new buffer[500], num
|
new buffer[500], num
|
||||||
num = SQL_QuoteString(buffer, sizeof(buffer)-1, "Hi y'all! C\lam")
|
num = SQL_QuoteString(db, buffer, sizeof(buffer)-1, "Hi y'all! C\lam")
|
||||||
|
|
||||||
server_print("num: %d str: %s", num, buffer)
|
server_print("num: %d str: %s", num, buffer)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user