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

[SQL] result help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mulan
Senior Member
Join Date: Jul 2005
Location: [GER]Worbis
Old 08-12-2010 , 13:58   [SQL] result help
Reply With Quote #1

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


Last edited by Mulan; 08-12-2010 at 14:18.
Mulan is offline
Send a message via ICQ to Mulan
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-12-2010 , 14:32   Re: [SQL] result help
Reply With Quote #2

formatex( query, 1023, "create table if not exists map_names (map varchar(32))", mapname)

Remove this : , mapname
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 08-12-2010 , 14:44   Re: [SQL] result help
Reply With Quote #3

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.

Last edited by platzpatrone; 08-12-2010 at 14:51.
platzpatrone is offline
Mulan
Senior Member
Join Date: Jul 2005
Location: [GER]Worbis
Old 08-12-2010 , 15:01   Re: [SQL] result help
Reply With Quote #4

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
Mulan is offline
Send a message via ICQ to Mulan
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 08-12-2010 , 15:15   Re: [SQL] result help
Reply With Quote #5

sorry, try this:

formatex( query, 33, "INSERT INTO `map_names` (`map`) VALUES ('%s') ON DUPLICATE KEY UPDATE map=map", mapname )
platzpatrone is offline
Mulan
Senior Member
Join Date: Jul 2005
Location: [GER]Worbis
Old 08-12-2010 , 15:22   Re: [SQL] result help
Reply With Quote #6

don't work too. self problem... any ideas? -.-
Mulan is offline
Send a message via ICQ to Mulan
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 17:06.


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