Example #1
0
static cell AMX_NATIVE_CALL SQL_SetCharset(AMX *amx, cell *params)
{
	SQL_Connection *sql = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
	if (!sql)
	{
		IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
		if (!pDb)
		{
			MF_LogError(amx, AMX_ERR_NATIVE, "Invalid info tuple or database handle: %d", params[1]);
			return 0;
		}

		int len;
		return pDb->SetCharacterSet(MF_GetAmxString(amx, params[2], 0, &len));
	}
	else
	{
		int len;
		const char *charset = MF_GetAmxString(amx, params[2], 0, &len);

		if (!sql->charset || stricmp(charset, sql->charset))
		{
			sql->charset = strdup(charset);
		}

		return 1;
	}

	return 0;
}
Example #2
0
static cell_t SQL_SetCharset(IPluginContext *pContext, const cell_t *params)
{
	IDatabase *db = NULL;
	HandleError err;

	if ((err = g_DBMan.ReadHandle(params[1], DBHandle_Database, (void **)&db))
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid database Handle %x (error: %d)", params[1], err);
	}

	char *characterset;
	pContext->LocalToString(params[2], &characterset);

	return db->SetCharacterSet(characterset);
}