AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SQL] result help (https://forums.alliedmods.net/showthread.php?t=135092)

Mulan 08-12-2010 13:58

[SQL] result help
 
I have a problem with my script.
This script put mapnames in my Mysql-Database. The Problem is, comes the map again, the script write the map in the Database again -.-

PHP Code:

#include <amxmodx> 
#include <amxmisc> 
#include <sqlx> 

#define PLUGIN    "Web_mapnames" 
#define AUTHOR    "by me" 
#define VERSION    "1.0 beta" 

new Handle:DB_TUPLE 
new error[512
new 
error_code 
new Handle:DB_CONNECT 

public plugin_cfg()
{
    
server_cmd("make_map")


public 
plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR
    
    
register_srvcmd"make_map""selectfrom_map_table" )
    
    
register_cvar"js_db_host""xxx" 
    
register_cvar"js_db_user""xxx" 
    
register_cvar"js_db_pass""xxx" 
    
register_cvar"js_db_name""xxx" 
    
    static 
host[32], user[32], pass[32], name[32
    
    
get_cvar_string"js_db_host"host31 
    
get_cvar_string"js_db_user"user31 
    
get_cvar_string"js_db_pass"pass31 
    
get_cvar_string"js_db_name"name31 
    
    
DB_TUPLE=SQL_MakeDbTuple(host,user,pass,name
    
DB_CONNECT=SQL_Connect(DB_TUPLEerror_codeerror516); 
    
    if(
DB_CONNECT == Empty_Handle
        
set_fail_state(error
    
    new 
query[1024
    
    
formatexquery1023"create table if not exists map_names (map varchar(32))"mapname
    
SQL_ThreadQueryDB_TUPLE"db_generic_handler"query 
}

public 
selectfrom_map_table()
{
    new 
query[34
    
    
formatexquery33"SELECT * FROM map_names"
    
SQL_ThreadQueryDB_TUPLE"map_handler"query 
}

public 
map_handler(failstateHandle:queryerror[], errnumdata[], sizeFloat:queuetime
{
        if(!
SQL_MoreResults(query))    
            {  
                new 
query[34
                
get_mapname(mapname32
                
formatexquery33"INSERT INTO `map_names` VALUES ('%s')"mapname )
                
SQL_ThreadQuery(DB_TUPLE,"db_save_handler",query)
            }
            else
            {
                
log_amx("[MAPHANDLER] %s schon vorhanden!"mapname
            } 
}

public 
db_generic_handler(failstateHandle:queryerror[], errnumdata[], sizeFloat:queuetime

    return 
query_failedfailstateerrorerrnum 


public 
db_save_handlerfailstateHandle:queryerror[], errnumdata[], sizeFloat:queuetime 

    return 
query_failedfailstateerrorerrnum 


public 
query_failedfailstateerror[], errnum 

    if( 
failstate == TQUERY_CONNECT_FAILED 
    { 
        
log_amx"Couldn't connect to database: %s"error 
        return 

    

    else if( 
failstate == TQUERY_QUERY_FAILED 
    { 
        
log_amx"Query failed: %s"error 
        return 

    

    
    if( 
errnum 
    { 
        
log_amx"Query Error: %s"error 
        return 

    

    
    return 



public 
plugin_end() 

    
SQL_FreeHandle(DB_TUPLE



ConnorMcLeod 08-12-2010 14:32

Re: [SQL] result help
 
formatex( query, 1023, "create table if not exists map_names (map varchar(32))", mapname)

Remove this : , mapname

platzpatrone 08-12-2010 14:44

Re: [SQL] result help
 
formatex( query, 33, "INSERT IGNORE INTO `map_names` VALUES ('%s')", mapname )

or

formatex( query, 33, "INSERT IGNORE INTO `map_names` SET map = '%s'", mapname )


while if u only insert each map, the maps are double counted in the database. with ignore it will be skipped.
there are just other methods they may useful if u want to catch more things as the mapnames, so u can use
replace into.

Mulan 08-12-2010 15:01

Re: [SQL] result help
 
dont work ):

with this code the script write 1 map in database, if mapchange, no more map added

PHP Code:

public selectfrom_map_table()
{
    new 
query[34
    
get_mapname(mapname32
    
    
formatexquery33"SELECT * FROM map_names"
    
SQL_ThreadQueryDB_TUPLE"map_handler"query 


and with this the maps are added again if he comes

PHP Code:

public selectfrom_map_table()
{
    new 
query[34
    
get_mapname(mapname32
    
    
formatexquery33"SELECT %s FROM map_names"mapname
    
SQL_ThreadQueryDB_TUPLE"map_handler"query 


Quote:

formatex( query, 33, "INSERT IGNORE INTO `map_names` VALUES ('%s')", mapname )

or

formatex( query, 33, "INSERT IGNORE INTO `map_names` SET map = '%s'", mapname )
dont work, self problem :(

platzpatrone 08-12-2010 15:15

Re: [SQL] result help
 
sorry, try this:

formatex( query, 33, "INSERT INTO `map_names` (`map`) VALUES ('%s') ON DUPLICATE KEY UPDATE map=map", mapname )

Mulan 08-12-2010 15:22

Re: [SQL] result help
 
don't work too. self problem... any ideas? -.-


All times are GMT -4. The time now is 21:52.

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