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

Plugins to database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Axons
Junior Member
Join Date: Feb 2011
Old 08-11-2015 , 12:40   Plugins to database
Reply With Quote #1

Hello everyone,

i need help for codding i dont know c# codding.. Years ago i was using it and Exolent helped me but now its giving error..

Code :
Code:
#include <amxmodx>
#include <sqlx>

#define SQL_HOST "localhost"
#define SQL_USER "*****"
#define SQL_PASS "*****"
#define SQL_DB "*******"
public plugin_init()
{
    register_plugin("Plugin List to SQL", "0.0.1", "Exolent");
    register_concmd("amx_musti", "musti", ADMIN_CFG, "asdas")
}

public plugin_cfg()
{
    new Handle:tuple = SQL_MakeDbTuple(SQL_HOST, SQL_USER, SQL_PASS, SQL_DB);
    
    if(tuple == Empty_Handle) return log_amx("Failed to make SQL tuple");
    
    new errcode, error[128];
    new Handle:db = SQL_Connect(tuple, errcode, error, charsmax(error));
    
    if(db == Empty_Handle) return log_amx("Failed connecting to db (%d): %s", errcode, error);
    
    new Handle:query = SQL_PrepareQuery(db,
        "CREATE TABLE IF NOT EXISTS plugin_list \
        (filename VARCHAR(64) NOT NULL, \
        name VARCHAR(64) NOT NULL, \
        author VARCHAR(64) NOT NULL, \
        version VARCHAR(32) NOT NULL);");
    
    if(!SQL_Execute(query))
    {
        SQL_QueryError(query, error, charsmax(error));
        log_amx("Error on create table: %s", error);
    }
    
    SQL_FreeHandle(query);

    query = SQL_PrepareQuery(db, "DELETE FROM plugin_list;");
    
    if(!SQL_Execute(query))
    {
        SQL_QueryError(query, error, charsmax(error));
        log_amx("Error on emptying table: %s", error);
    }
    
    SQL_FreeHandle(query);
    
    new filename[64], name[64], author[64], version[32];
    new pluginsnum = get_pluginsnum();
    
    static query_all[1024];
    new len = copy(query_all, charsmax(query_all),
        "INSERT INTO plugin_list \
        (filename, name, author, version) \
        VALUES");
    
    for(new i = 0; i < pluginsnum; i++)
    {
        get_plugin(i, filename, charsmax(filename), name, charsmax(name), version, charsmax(version), author, charsmax(author));
        
        len += formatex(query_all[len], charsmax(query_all) - len, "%s (^"%s^", ^"%s^", ^"%s^", ^"%s^")", i ? "," : "", filename, name, author, version);
    }
    
    query = SQL_PrepareQuery(db, "%s;", query_all);
    
    if(!SQL_Execute(query))
    {
        SQL_QueryError(query, query_all, charsmax(query_all));
        log_amx("Error on adding plugins: %s", query_all);
    }
    
    SQL_FreeHandle(query);
    
    SQL_FreeHandle(db);
    
    return 1;
}  

public musti()
{
    new Handle:tuple = SQL_MakeDbTuple(SQL_HOST, SQL_USER, SQL_PASS, SQL_DB);
    
    if(tuple == Empty_Handle) return log_amx("Failed to make SQL tuple");
    
    new errcode, error[128];
    new Handle:db = SQL_Connect(tuple, errcode, error, charsmax(error));
    
    if(db == Empty_Handle) return log_amx("Failed connecting to db (%d): %s", errcode, error);
    
    new Handle:query = SQL_PrepareQuery(db,
        "CREATE TABLE IF NOT EXISTS plugin_list \
        (filename VARCHAR(64) NOT NULL, \
        name VARCHAR(64) NOT NULL, \
        author VARCHAR(64) NOT NULL, \
        version VARCHAR(32) NOT NULL);");
    
    if(!SQL_Execute(query))
    {
        SQL_QueryError(query, error, charsmax(error));
        log_amx("Error on create table: %s", error);
    }
    
    SQL_FreeHandle(query);
    
    query = SQL_PrepareQuery(db, "DELETE FROM plugin_list;");
    
    if(!SQL_Execute(query))
    {
        SQL_QueryError(query, error, charsmax(error));
        log_amx("Error on emptying table: %s", error);
    }
    
    SQL_FreeHandle(query);
    
    new filename[64], name[64], author[64], version[32];
    new pluginsnum = get_pluginsnum();
    
    static query_all[1024];
    new len = copy(query_all, charsmax(query_all),
        "INSERT INTO plugin_list \
        (filename, name, author, version) \
        VALUES");
    
    for(new i = 0; i < pluginsnum; i++)
    {
        get_plugin(i, filename, charsmax(filename), name, charsmax(name), version, charsmax(version), author, charsmax(author));
        
        len += formatex(query_all[len], charsmax(query_all) - len, "%s (^"%s^", ^"%s^", ^"%s^", ^"%s^")", i ? "," : "", filename, name, author, version);
 }
    
    query = SQL_PrepareQuery(db, "%s;", query_all);
    
    if(!SQL_Execute(query))
    {
        SQL_QueryError(query, query_all, charsmax(query_all));
        log_amx("Error on adding plugins: %s", query_all);
    }
    

    SQL_FreeHandle(query);
    
    SQL_FreeHandle(db);
    
    return 1;
}

And Error giving at console is ;

Code:
 [musti.amxx] Error on adding plugins: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"adminvote.a' at line 1
I tried to diffrent version of MYSQL on Cpanel, it doesnt work..

Thank you
Regards
Axons is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-11-2015 , 13:40   Re: Plugins to database
Reply With Quote #2

Add semicolon (;) at the end of the each query.
Try to put %s formatting rules between (') and not (").

Escape all strings. Make sure plug-in's (name, author, version) do not contain (', `, \ or ").

Last edited by claudiuhks; 08-11-2015 at 13:42.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-11-2015 , 14:34   Re: Plugins to database
Reply With Quote #3

Do this:
Code:
        SQL_QueryError(query, query_all, charsmax(query_all));         log_amx("Error on adding plugins: %s", query_all);
-->
Code:
        log_amx("Error on adding plugins: %s", query_all);         SQL_QueryError(query, query_all, charsmax(query_all));         log_amx("Error on adding plugins: %s", query_all);
It will then print out the query so you can see which query is the problem and you can easily identify the problem.
__________________

Last edited by Black Rose; 08-11-2015 at 14:41.
Black Rose 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 00:13.


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