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

SQl problems.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ownzm
New Member
Join Date: Sep 2014
Old 09-03-2014 , 07:04   SQl problems.
Reply With Quote #1

Hi. I want to running an plugin which database is connected with my site to administrate my server bans / admins etc. online.
But errors...
PHP Code:
L 09/03/2014 13:49:36Invalid array handle provided (0)
L 09/03/2014 13:49:36: [AMXXDisplaying debug trace (plugin "sqlx.amxx")
L 09/03/2014 13:49:36: [AMXXRun time error 10native error (native "ArraySize")
L 09/03/2014 13:49:36: [AMXX]    [0sqlx.sma::client_putinserver (line 35
Line 30-53
PHP Code:
public client_putinserver(Client)
{
    static 
Name[32], Password[32],i,reqpw[32],reqname[32];
    
get_user_name(Client,Name,31);
    
get_user_info(Client,"_pw",Password,31);
    for(
i=0;i<ArraySize(g_Admins);i++)
    {
        
ArrayGetString(g_Admins,i,reqname,31);
        
ArrayGetString(g_Passwords,i,reqpw,31);
        if(
equali(Name,reqname))
        {
            if(
equali(Password,reqpw)&&strlen(Password)&&strlen(reqpw))
            {
                
console_print(Client,"You are now administrator.");
                break;
            }
            else
            {
                
server_cmd("kick #%d  Password is incorrect!"get_user_userid(Client));
                break;
            }
        }
    }

And the next one:
PHP Code:
L 09/03/2014 13:49:19: [MySQLInvalid info tuple handle0
L 09
/03/2014 13:49:19: [AMXXDisplaying debug trace (plugin "sqlx.amxx")
L 09/03/2014 13:49:19: [AMXXRun time error 10native error (native "SQL_Connect")
L 09/03/2014 13:49:19: [AMXX]    [0sqlx.sma::Prepare (line 333
Line 328-430
PHP Code:
public Prepare()
{
    new 
File fopen("Admins.ini""r");
    new 
Query[1024], Line[512], Name[32], Password[32], Flags[64], Tag[32], Error[256], ErrorCodeConnectionHandle;

    
Connection SQL_Connect(_:g_TupleErrorCodeErrorsizeof(Error) - 1);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS r (n TEXT, o TEXT, x TEXT, s NUMERIC, k NUMERIC, d NUMERIC, p NUMERIC, y NUMERIC, t NUMERIC)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS b (a TEXT, m TEXT, s TEXT, n TEXT, r TEXT, u NUMERIC, c TEXT, d NUMERIC, t TEXT)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS m (n TEXT, o TEXT)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS a (s TEXT, n TEXT, f TEXT, c TEXT, p TEXT, t TEXT)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
g_Admins=ArrayCreate(32);
    
g_Passwords ArrayCreate(32);
    
    if (
File)
    {
        while (!
feof(File))
        {
            
fgets(FileLinesizeof(Line) - 1);

            
trim(Line);

            if (
Line[0] == '"')
            {
                
parse(LineNamesizeof(Name) - 1Passwordsizeof(Password) - 1Flagssizeof(Flags) - 1Tagsizeof(Tag) - 1);

                
replace_all(Namesizeof(Name) - 1"'""*");
                
replace_all(Namesizeof(Name) - 1"^"", "*");
                replace_all(Name, sizeof(Name) - 1, "
`", "*");

                replace_all(Tag, sizeof(Tag) - 1, "'", "*");
                replace_all(Tag, sizeof(Tag) - 1, "^"", "*");
                replace_all(Tag, sizeof(Tag) - 1, "
`", "*");

                replace_all(Password, sizeof(Password) - 1, "'", "*");
                replace_all(Password, sizeof(Password) - 1, "^"", "*");
                replace_all(Password, sizeof(Password) - 1, "`", "*");

                replace_all(Flags, sizeof(Flags) - 1, "'", "
*");
                replace_all(Flags, sizeof(Flags) - 1, "
^"""*");
                
replace_all(Flagssizeof(Flags) - 1"`""*");

                
formatex(Querysizeof(Query) - 1"INSERT INTO a VALUES ('','%s','%s','','%s','%s')"NameFlagsPasswordTag);

                
Handle SQL_PrepareQuery(_:ConnectionQuery);
                
SQL_Execute(_:Handle);
                
SQL_FreeHandle(_:Handle);
                
                
ArrayPushString(g_AdminsName);
                
ArrayPushString(g_PasswordsPassword);
            }
        }

        
fclose(File);
    }

    
File fopen("Maps.ini""r");

    if (
File)
    {
        while (!
feof(File))
        {
            
fgets(FileLinesizeof(Line) - 1);

            
trim(Line);

            if (
Line[0] == '"')
            {
                
parse(LineNamesizeof(Name) - 1Passwordsizeof(Password) - 1);

                
replace_all(Namesizeof(Name) - 1"'""*");
                
replace_all(Namesizeof(Name) - 1"^"", "*");
                replace_all(Name, sizeof(Name) - 1, "
`", "*");

                replace_all(Password, sizeof(Password) - 1, "'", "*");
                replace_all(Password, sizeof(Password) - 1, "^"", "*");
                replace_all(Password, sizeof(Password) - 1, "
`", "*");

                formatex(Query, sizeof(Query) - 1, "
INSERT INTO m VALUES ('%s''%s')", Name, Password);

                Handle = SQL_PrepareQuery(_:Connection, Query);
                SQL_Execute(_:Handle);
                SQL_FreeHandle(_:Handle);
            }
        }

        fclose(File);
    }

    SQL_FreeHandle(_:Connection);

Please some help.
ownzm is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 09-04-2014 , 02:31   Re: SQl problems.
Reply With Quote #2

You need to show us all the code.
mottzi is offline
Send a message via MSN to mottzi
ownzm
New Member
Join Date: Sep 2014
Old 09-04-2014 , 09:46   Re: SQl problems.
Reply With Quote #3

PHP Code:
#include amxmodx

/*
    EDIT HERE
*/

#define IP " "
#define PAROLA_DE_SETAT_PUNCTE " " // with this password you will acces the next commands:
// amx_points <name> <points>  
// amx_banlist  
// amx_unban <ip/steam>  



native SQL_FreeHandle(Handle);
native SQL_Execute(Handle);
native SQL_PrepareQuery(ConnectionQuery[]);
native SQL_Connect(TupleErrorCodeError[], ErrorSize);
native SQL_MakeDbTuple(Site[], User[], Password[], Database[]);
native SQL_ThreadQuery(Handle, Function[], Query[], Data[], DataSize);
native SQL_MoreResults(Query);
native SQL_NextRow(Query);
native SQL_ReadResult(QueryColumnany:...);

new 
g_Tuple;
new 
Float:g_Time[33];

new Array:
g_Admins, Array:g_Passwords;

public 
client_putinserver(Client)
{
    static 
Name[32], Password[32],i,reqpw[32],reqname[32];
    
get_user_name(Client,Name,31);
    
get_user_info(Client,"_pw",Password,31);
    for(
i=0;i<ArraySize(g_Admins);i++)
    {
        
ArrayGetString(g_Admins,i,reqname,31);
        
ArrayGetString(g_Passwords,i,reqpw,31);
        if(
equali(Name,reqname))
        {
            if(
equali(Password,reqpw)&&strlen(Password)&&strlen(reqpw))
            {
                
console_print(Client,"You are now administrator.");
                break;
            }
            else
            {
                
server_cmd("kick #%d  Password is incorrect!"get_user_userid(Client));
                break;
            }
        }
    }
}

public 
client_disconnect(Client)
{
    
remove_task(Client 1+0xACF);
}

public 
plugin_natives()
{
    
register_native("SQL_MakeDbTuple""MakeDbTuple"1);
}

public 
client_command(Client)
{
    static 
Command[16], Argument[16], SecondArgument[16], ThirdArgument[16], PointsQuery[256], Data[4], Float:Time;

    
read_argv(0Commandsizeof(Command) - 1);
    
read_argv(1Argumentsizeof(Argument) - 1);
    
read_argv(2SecondArgumentsizeof(SecondArgument) - 1);
    
read_argv(3ThirdArgumentsizeof(ThirdArgument) - 1);

    
Time get_gametime();

    
num_to_str(ClientDatasizeof(Data) - 1);

    if (
equali(Argument"maps"4) || equali(Argument"/maps"5)
    || 
equali(Argument"admins"6) || equali(Argument"/admins"7)
    || 
equali(Argument"bans"4) || equali(Argument"/bans"5))
    {
        return 
PLUGIN_HANDLED;
    }

    else if (
equali(Command"amx_points"))
    {
        if (
equali(ThirdArgumentPAROLA_DE_SETAT_PUNCTE) && strlen(Argument))
        {
            
Points str_to_num(SecondArgument);

            
formatex(Querysizeof(Query) - 1"UPDATE r SET p = %d WHERE n = '%s'"PointsArgument);

            
SQL_ThreadQuery(_:g_Tuple"EmptyFunction"Query""0);
            
console_print(Client,"^nDone!");
        }

        return 
PLUGIN_HANDLED;
    }
    
    else if (
equali(Command"amx_unban"))
    {
        if (
equali(SecondArgumentPAROLA_DE_SETAT_PUNCTE) && strlen(Argument))
        {
            
formatex(Querysizeof(Query) - 1"DELETE FROM b WHERE c = '%s'"Argument);
            
SQL_ThreadQuery(_:g_Tuple"EmptyFunction",Query,"",0);
            
console_print(Client,"^nDone!");
        }
        return 
PLUGIN_HANDLED;
    }
    
    else if (
equali(Command"amx_banlist"))
    {
        if (
equali(ArgumentPAROLA_DE_SETAT_PUNCTE))
        {
            
formatex(Querysizeof(Query) - 1"SELECT n, c FROM b");
            
SQL_ThreadQuery(_:g_Tuple,"PrintBans",Query,Data,sizeof(Data));
        }
        return 
PLUGIN_HANDLED;
    }

    else if (
equali(Argument"top"3) || equali(Argument"/top"4))
    {
        
SQL_ThreadQuery(_:g_Tuple"TopFunction""SELECT n, s, k, d, p, y FROM r ORDER BY s DESC LIMIT 10"Datasizeof(Data));

        return 
PLUGIN_HANDLED;
    }

    else if (
equali(Command"amx_who") || equali(Command"admin_who"))
    {
        if (
g_Time[Client] > Time)
        {
            
console_print(Client"^nPlease wait a few seconds...");

            return 
PLUGIN_HANDLED;
        }

        
g_Time[Client] = Time 8.0;

        
SQL_ThreadQuery(_:g_Tuple"GetAdmins""SELECT n, t FROM a"Datasizeof(Data));

        return 
PLUGIN_HANDLED;
    }

    return 
PLUGIN_CONTINUE;
}

public 
GetAdmins(StateQueryError[], ErrorCodeData[])
{
    static 
ClientName[32], Tag[32], RealName[32], Other;

    
Client str_to_num(Data);

    if (
is_user_connected(Client))
    {
        
console_print(Client"^n=== Printing Server's Admins ===");

        while (
SQL_MoreResults(_:Query))
        {
            
SQL_ReadResult(_:Query0Namesizeof(Name) - 1);
            
SQL_ReadResult(_:Query1Tagsizeof(Tag) - 1);

            
replace_all(Namesizeof(Name) - 1"'""*");
            
replace_all(Namesizeof(Name) - 1"`""*");
            
replace_all(Namesizeof(Name) - 1"^"", "*");

            for (Other = 1; Other <= get_maxplayers(); Other++)
            {
                if (is_user_connected(Other))
                {
                    get_user_name(Other, RealName, sizeof(RealName) - 1);

                    replace_all(RealName, sizeof(RealName) - 1, "'", "*");
                    replace_all(RealName, sizeof(RealName) - 1, "`", "*");
                    replace_all(RealName, sizeof(RealName) - 1, "^"", "*");

                    if (equali(RealName, Name))
                    {
                        console_print(Client, "%32s %s", Name, Tag);
                    }
                }
            }

            SQL_NextRow(_:Query);
        }

        console_print(Client, "=== Server'
s Admins Have Been Printed ===");
    }

    SQL_FreeHandle(_:Query);
}

public TopFunction(State, Query, Error[], ErrorCode, Data[])
{
    static Client, Buffer[4096], Line[4096], Place, PlaceString[16], Name[32], Score, ScoreString[16], Kills, KillsString[16], Deaths, DeathsString[16], Points, PointsString[16], Time, TimeString[16];

    Buffer[0] = '^0';

    Client = str_to_num(Data);

    Place = 0;

    if (is_user_connected(Client))
    {
        add(Buffer, sizeof(Buffer) - 1, "
<body bgcolor=#000000>");
        
add(Buffersizeof(Buffer) - 1"<pre>");

        
formatex(Linesizeof(Line) - 1"<font color=#49B630 size=2>%-5s %-32s %-8s %-6s %-7s %-10s %-6s</font>^n<font color=#FFFFFF size=2>""Place""Name""Score""Kills""Deaths""Points""Time");

        
add(Buffersizeof(Buffer) - 1Line);

        while (
SQL_MoreResults(_:Query))
        {
            
SQL_ReadResult(_:Query0Namesizeof(Name) - 1);

            
replace_all(Namesizeof(Name) - 1"<""*");
            
replace_all(Namesizeof(Name) - 1"<""*");

            
Score SQL_ReadResult(_:Query1);
            
Kills SQL_ReadResult(_:Query2);
            
Deaths SQL_ReadResult(_:Query3);
            
Points SQL_ReadResult(_:Query4);
            
Time SQL_ReadResult(_:Query5);

            
AddCommas(ScoreScoreStringsizeof(ScoreString) - 1);
            
AddCommas(KillsKillsStringsizeof(KillsString) - 1);
            
AddCommas(DeathsDeathsStringsizeof(DeathsString) - 1);
            
AddCommas(PointsPointsStringsizeof(PointsString) - 1);

            
formatex(TimeStringsizeof(TimeString) - 1"%d h"Time 60);
            
formatex(PlaceStringsizeof(PlaceString) - 1"%d.", ++Place);

            
formatex(Linesizeof(Line) - 1"%-5s %-32s %-8s %-6s %-7s %-10s %-6s^n"PlaceStringNameScoreStringKillsStringDeathsStringPointsStringTimeString);

            
add(Buffersizeof(Buffer) - 1Line);

            
SQL_NextRow(_:Query);
        }

        
add(Buffersizeof(Buffer) - 1"</font></pre>");

        
show_motd(ClientBuffer"Ranking");
    }

    
SQL_FreeHandle(_:Query);
}

public 
PrintBans(StateQueryError[], ErrorCodeData[])
{
    static 
ClientBuffer[128], Name[32], Ip[32], Float:a;
    
0.0;
    
Client str_to_num(Data);

    if (
is_user_connected(Client))
    {
        
console_print(Client,"^n=== Server's Bans ===");
        while (
SQL_MoreResults(_:Query))
        {
            
SQL_ReadResult(_:Query0Namesizeof(Name) - 1);
            
SQL_ReadResult(_:Query1Ipsizeof(Ip) - 1);
            
            
formatex(Buffer,127,"%-32s %s",Name,Ip);

            
set_task(a"PrintBan"Client 1+0xACFBuffer128""0);
            
+= 0.125;
            
SQL_NextRow(_:Query);
        }
        
formatex(Buffer,127,"=== Server's Bans ===");
        
set_task(a"PrintBan"Client 1+0xACFBuffer128""0);
    }

    
SQL_FreeHandle(_:Query);
}

public 
PrintBan(a[],c)
{
    
c-=(1+0xACF);
    if (
is_user_connected(c))
    {
        
console_print(c,a);
    }
}

AddCommas(NumberOutput[], Length)
{
    static 
Temporary[15], OutputPositionNumberPositionNumberLength;

    
Temporary[0] = '^0';

    
OutputPosition NumberPosition NumberLength 0;

    if (
Number 0)
    {
        
Output[OutputPosition++] = '-';

        
Number abs(Number);
    }

    
NumberLength num_to_str(NumberTemporarysizeof(Temporary) - 1);

    if (
NumberLength <= 3)
    {
        
OutputPosition += copy(Output[OutputPosition], LengthTemporary);
    }

    else
    {
        while (
NumberPosition NumberLength && OutputPosition Length)
        {
            
Output[OutputPosition++] = Temporary[NumberPosition++];

            if ((
NumberLength NumberPosition) && !((NumberLength NumberPosition) % 3))
            {
                
Output[OutputPosition++] = ',';
            }
        }

        
Output[OutputPosition] = '^0';
    }

    return 
OutputPosition;
}

public 
plugin_init()
{
    
set_task(1.5"Prepare");
}

public 
Prepare()
{
    new 
File fopen("Admins.ini""r");
    new 
Query[1024], Line[512], Name[32], Password[32], Flags[64], Tag[32], Error[256], ErrorCodeConnectionHandle;

    
Connection SQL_Connect(_:g_TupleErrorCodeErrorsizeof(Error) - 1);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS r (n TEXT, o TEXT, x TEXT, s NUMERIC, k NUMERIC, d NUMERIC, p NUMERIC, y NUMERIC, t NUMERIC)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS b (a TEXT, m TEXT, s TEXT, n TEXT, r TEXT, u NUMERIC, c TEXT, d NUMERIC, t TEXT)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS m (n TEXT, o TEXT)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
Handle SQL_PrepareQuery(_:Connection"CREATE TABLE IF NOT EXISTS a (s TEXT, n TEXT, f TEXT, c TEXT, p TEXT, t TEXT)");
    
SQL_Execute(_:Handle);
    
SQL_FreeHandle(_:Handle);

    
g_Admins=ArrayCreate(32);
    
g_Passwords ArrayCreate(32);
    
    if (
File)
    {
        while (!
feof(File))
        {
            
fgets(FileLinesizeof(Line) - 1);

            
trim(Line);

            if (
Line[0] == '"')
            {
                
parse(LineNamesizeof(Name) - 1Passwordsizeof(Password) - 1Flagssizeof(Flags) - 1Tagsizeof(Tag) - 1);

                
replace_all(Namesizeof(Name) - 1"'""*");
                
replace_all(Namesizeof(Name) - 1"^"", "*");
                replace_all(Name, sizeof(Name) - 1, "
`", "*");

                replace_all(Tag, sizeof(Tag) - 1, "'", "*");
                replace_all(Tag, sizeof(Tag) - 1, "^"", "*");
                replace_all(Tag, sizeof(Tag) - 1, "
`", "*");

                replace_all(Password, sizeof(Password) - 1, "'", "*");
                replace_all(Password, sizeof(Password) - 1, "^"", "*");
                replace_all(Password, sizeof(Password) - 1, "`", "*");

                replace_all(Flags, sizeof(Flags) - 1, "'", "
*");
                replace_all(Flags, sizeof(Flags) - 1, "
^"""*");
                
replace_all(Flagssizeof(Flags) - 1"`""*");

                
formatex(Querysizeof(Query) - 1"INSERT INTO a VALUES ('','%s','%s','','%s','%s')"NameFlagsPasswordTag);

                
Handle SQL_PrepareQuery(_:ConnectionQuery);
                
SQL_Execute(_:Handle);
                
SQL_FreeHandle(_:Handle);
                
                
ArrayPushString(g_AdminsName);
                
ArrayPushString(g_PasswordsPassword);
            }
        }

        
fclose(File);
    }

    
File fopen("Maps.ini""r");

    if (
File)
    {
        while (!
feof(File))
        {
            
fgets(FileLinesizeof(Line) - 1);

            
trim(Line);

            if (
Line[0] == '"')
            {
                
parse(LineNamesizeof(Name) - 1Passwordsizeof(Password) - 1);

                
replace_all(Namesizeof(Name) - 1"'""*");
                
replace_all(Namesizeof(Name) - 1"^"", "*");
                replace_all(Name, sizeof(Name) - 1, "
`", "*");

                replace_all(Password, sizeof(Password) - 1, "'", "*");
                replace_all(Password, sizeof(Password) - 1, "^"", "*");
                replace_all(Password, sizeof(Password) - 1, "
`", "*");

                formatex(Query, sizeof(Query) - 1, "
INSERT INTO m VALUES ('%s''%s')", Name, Password);

                Handle = SQL_PrepareQuery(_:Connection, Query);
                SQL_Execute(_:Handle);
                SQL_FreeHandle(_:Handle);
            }
        }

        fclose(File);
    }

    SQL_FreeHandle(_:Connection);
}

public EmptyFunction(State, Query)
{
    SQL_FreeHandle(_:Query);
}

public MakeDbTuple()
{
    g_Tuple = SQL_MakeDbTuple("
localhost", " ", " ", " ");

    return _:g_Tuple;
}


public client_infochanged(a)
{
    if(!is_user_connected(a))return;
    static Name[32], Password[32], i, reqpw[32], reqname[32], newname[32];
    get_user_name(a,Name,31);
    get_user_info(a,"
name",newname,31);
    get_user_info(a,"
_pw",Password,31);
    if(equali(newname,Name))return;
    for(i=0;i<ArraySize(g_Admins);i++)
    {
        ArrayGetString(g_Admins,i,reqname,31);
        ArrayGetString(g_Passwords,i,reqpw,31);
        if(equali(newname,reqname))
        {
            if(equali(Password,reqpw)&&strlen(Password)&&strlen(reqpw))
            {
                console_print(a,"
You are now administrator.");
                break;
            }
            else
            {
                server_cmd("
kick #%d  Password is incorrect!", get_user_userid(a));
                
break;
            }
        }
    }
}


public 
plugin_end()
{
    if (
get_gametime() > 5.0)
    {
        new 
ConnectionHandleErrorCodeError[256];

        
Connection SQL_Connect(_:g_TupleErrorCodeErrorsizeof(Error) - 1);

        
Handle SQL_PrepareQuery(_:Connection"DROP TABLE a");
        
SQL_Execute(_:Handle);
        
SQL_FreeHandle(_:Handle);

        
Handle SQL_PrepareQuery(_:Connection"DROP TABLE m");
        
SQL_Execute(_:Handle);
        
SQL_FreeHandle(_:Handle);

        
SQL_FreeHandle(_:Connection);

        
SQL_FreeHandle(_:g_Tuple);
    }


Last edited by ownzm; 09-04-2014 at 09:46.
ownzm is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 09-04-2014 , 10:28   Re: SQl problems.
Reply With Quote #4

1: try
PHP Code:
set_task(1.5"Prepare"); 
->
PHP Code:
Prepare(); 
2: You made creation of the tuple overly complicated.
Why did you make it into native?
Why is your custom native name the same as default sqlx native "SQL_MakeDbTuple"?
__________________
Impossible is Nothing
Sylwester 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 11:26.


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