Raised This Month: $51 Target: $400
 12% 

SQL_NumResults() returns 0


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nikol4u
Member
Join Date: Jan 2007
Location: Burgas
Old 04-03-2015 , 13:18   SQL_NumResults() returns 0
Reply With Quote #1

I have created a rather very simple sql ban plugin.
Whenever a player connects I run the cmdCheckPlayer() to see if he is banned or not.

Connection to the database is fine, however I get SQL_NumResults(query) to be 0

This is what I log:

Quote:
L 04/03/2015 - 17:13:58: [sqlbans.amxx] SELECT * FROM `e107_server_bans` WHERE (`sb_steam`='STEAM_0:0xxxxxx' OR `sb_ip` = 'xx.xx.xx.xx') AND (`sb_date` + `sb_time` > '1428081238' OR `sb_time` = '0')
L 04/03/2015 - 17:13:59: [sqlbans.amxx] number of rows 0
L 04/03/2015 - 17:13:59: [sqlbans.amxx] user is not banned
And when I run the same query through phpMyAdmin I am getting 1 result.

Have I done something wrong?

Code:
public cmdCheckPlayer( plr )
{
	static query[256], authid[36], ip[16], playerId[1];
	playerId[0] = plr;

	get_user_authid( plr, authid, sizeof authid - 1 );
	get_user_ip( plr, ip, sizeof ip - 1, 1 );

	formatex( query, 256, "SELECT `sb_reason` FROM `%s` WHERE (`sb_steam`='%s' OR `sb_ip` = '%s') AND (`sb_date` +  `sb_time` > '%d' OR `sb_time` = '0')", g_SqlTable, authid, ip, get_systime() );
	log_amx(query);
	SQL_ThreadQuery( g_SqlTuple, "fnSqlBanSearch", query, playerId, 1 );
	
	log_amx(query);
}

public fnSqlBanSearch( failstate, Handle:query, error[], errorcode, data[], size, Float:queuetime )
{	
	if( !query_failed( failstate, error, errorcode ) )
	{
		static plr;
		plr = data[0];
		
		static te[256];
		
		formatex(te, 256, "number of rows %i", SQL_NumResults( query ) );
		log_amx(te);
		
		if( SQL_NumResults( query ) )
		{
			static reason[192];
			
			SQL_ReadResult( query, 0, reason, sizeof reason - 1 );
			
			client_print( plr, print_console, "[%s] You are banned from this server",g_ServerName );
			plr += 200;
			set_task( 0.1, "delayed_kick", plr );
		}
		else
		{
			log_amx("user is not banned");
		}
	}
	
	return PLUGIN_HANDLED;
}

public query_failed( failstate, error[], errornum )
{
	if( failstate == TQUERY_CONNECT_FAILED )
	{
		log_amx( "[SQL] Could not connect to database: %s", error );
		return 1;
	}
	else if( failstate == TQUERY_QUERY_FAILED )
	{
		log_amx( "[SQL] Query failed: %s", error );
		return 1;
	}
   
	if( errornum )
	{
		log_amx( "[SQL] Query Error: %s", error );
		return 1;
	}
	
	return 0;
}
__________________
www.cosy-climbing.net - The official Kreedz community for non-official Kreedz maps

Cosy-Climbing's server IP: 108.61.254.236:27015

Last edited by Nikol4u; 04-03-2015 at 13:19.
Nikol4u is offline
Send a message via ICQ to Nikol4u Send a message via Skype™ to Nikol4u
Nikol4u
Member
Join Date: Jan 2007
Location: Burgas
Old 04-06-2015 , 10:12   Re: SQL_NumResults() returns 0
Reply With Quote #2

bump?
__________________
www.cosy-climbing.net - The official Kreedz community for non-official Kreedz maps

Cosy-Climbing's server IP: 108.61.254.236:27015
Nikol4u is offline
Send a message via ICQ to Nikol4u Send a message via Skype™ to Nikol4u
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-06-2015 , 22:32   Re: SQL_NumResults() returns 0
Reply With Quote #3

When I write queries I do not wrap anything but strings in quotes. The below (to me) is comparing a numerical value against a string of numbers, not a numerical value. I'm not sure if the SQL processor can interpret this properly, but try what I posted below and see if you get a different result:

`sb_date` + `sb_time` > '1428081238'

Mind you, I use MS Access 2010 so I'm not sure if MySQL\SQLite differ in this regard, but worth a try.

See if this works
Code:
SELECT * 
FROM e107_server_bans 
WHERE (sb_steam='STEAM_0:0xxxxxx' OR sb_ip='xx.xx.xx.xx') AND 
((sb_date + sb_time) > 1428081238 OR sb_time = 0);
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode