AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [AMXX]Run time error 10(native "SQL_PrepareQuery") (https://forums.alliedmods.net/showthread.php?t=277187)

MASKED 01-04-2016 11:17

[AMXX]Run time error 10(native "SQL_PrepareQuery")
 
Code:

L 01/04/2016 - 10:43:34: Start of error session.
L 01/04/2016 - 10:43:34: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20160104.log")
L 01/04/2016 - 10:43:34: [MySQL] Invalid database handle: 0
L 01/04/2016 - 10:43:34: [AMXX] Run time error 10 (plugin "ncodmodmysql.amxx") (native "SQL_PrepareQuery") - debug

PHP Code:

public Load(id)
    {
            new 
Name[32];
    
get_user_name(idName31);
    new 
error[128], errno;
    new 
Handle:info SQL_MakeStdTuple();
    new 
Handle:sql SQL_Connect(infoerrnoerror127);
 
    new 
Handle:query SQL_PrepareQuery(sql"SELECT * FROM `oles_szam` WHERE `username` = '%s'"Name);
 
 
    if (!
SQL_Execute(query))
        
server_print("[NiCE skin] Hiba tortent a lekeres soran. #1");
    else if (!
SQL_NumResults(query)) {
        
Kills[id] = 0;
        
Rang[id] = 0;
        
m4a1_oles[id] = 0;
        
ak47_oles[id] = 0;
        
awp_oles[id] = 0;
        
kes_oles[id] = 0;
    } else {        
        new 
qcol_oles SQL_FieldNameToNum(query"oles");
        new 
qcol_rang SQL_FieldNameToNum(query"rang");
        new 
qcol_m4a1 SQL_FieldNameToNum(query"m4a1");
        new 
qcol_ak47 SQL_FieldNameToNum(query"ak47");
        new 
qcol_awp SQL_FieldNameToNum(query"awp")    ;    
        new 
qcol_kes SQL_FieldNameToNum(query"kes");
 
        
Kills[id]= SQL_ReadResult(query,    qcol_oles);
        
Rang[id]= SQL_ReadResult(query,    qcol_rang);
        
m4a1_oles[id]= SQL_ReadResult(query,    qcol_m4a1);
        
ak47_oles[id]= SQL_ReadResult(query,    qcol_ak47);
        
awp_oles[id] = SQL_ReadResult(query,    qcol_awp);
        
kes_oles[id] = SQL_ReadResult(query,    qcol_kes);
 
        
SQL_FreeHandle(query);
        
SQL_FreeHandle(sql);
        
SQL_FreeHandle(info);
    }
 
    return 
PLUGIN_CONTINUE;
    }
    public 
Save(id)
    {
    new 
Name[32];
    
get_user_name(idName31);
    new 
error[128], errno;
    new 
Handle:info SQL_MakeStdTuple();
    new 
Handle:sql SQL_Connect(infoerrnoerror127);
 
     new 
Handle:query SQL_PrepareQuery(sql"INSERT INTO `oles_szam`  (`username`, `oles`, `rang`, `m4a1`, `ak47`, `awp`, `kes`) VALUES  ('%s',%d,%d,%d,%d,%d,%d) ON DUPLICATE KEY UPDATE `oles`=VALUES(`oles`),  `rang`=VALUES(`rang`), `m4a1`=VALUES(`m4a1`), `ak47`=VALUES(`ak47`),  `awp`=VALUES(`awp`), `kes`=VALUES(`kes`)",  sqlesc(Name),Kills[id],Rang[id],m4a1_oles[id],ak47_oles[id],awp_oles[id],kes_oles[id]);
 
 
    if (!
SQL_Execute(query))
        
server_print("[NiCE skin] Hiba tortent a lekeres soran. #2");
    return 
PLUGIN_CONTINUE;
    }
    
#define SECURE_NAME_LEN 31 * 2 + 1
    
sqlesc(const name[])
    {
    new 
secureName[SECURE_NAME_LEN];
    
copy(secureNamecharsmax(secureName), name);
    
replace_all(secureNamecharsmax(secureName), "\", "\\");
    replace_all(secureName, charsmax(secureName), "
`", "\`");
    replace_all(secureName, charsmax(secureName), "'", "\'");
 
    return secureName;
    } 

Hello, guys!
can you tell me that, why is my server shutting down about every 16th hour?
I get this error from time to time, and i dont know what the problem is...

MASKED 01-04-2016 11:26

Re: [AMXX]Run time error 10(native "SQL_PrepareQuery")
 
PHP Code:

CREATE TABLE IF NOT EXISTS `oles_szam` (
  `
usernamevarchar(20NOT NULL,
  `
olesint(10NOT NULL DEFAULT '0',
  `
rangint(10NOT NULL DEFAULT '0',
  `
m4a1int(10NOT NULL DEFAULT '0',
  `
ak47int(10NOT NULL DEFAULT '0',
  `
awpint(10NOT NULL DEFAULT '0',
  `
kesint(10NOT NULL DEFAULT '0',
  
UNIQUE KEY `username` (`username`)
ENGINE=MyISAM DEFAULT CHARSET=latin1

This is the Sql code

klippy 01-04-2016 11:29

Re: [AMXX]Run time error 10(native "SQL_PrepareQuery")
 
Looks like SQL_Connect() returned an invalid handle, meaning that connection couldn't be made. You should check if the returned handle ("sql" variable) is valid before doing anything with it. You can also print the error that's stored into "error" variable.

siriusmd99 01-04-2016 11:30

Re: [AMXX]Run time error 10(native "SQL_PrepareQuery")
 
Use diferent handle names for every query.
Like Handle1, Handle2 ...

MASKED 01-04-2016 13:41

Re: [AMXX]Run time error 10(native "SQL_PrepareQuery")
 
Ok ty guys, i'll try these options..


All times are GMT -4. The time now is 09:28.

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