Raised This Month: $32 Target: $400
 8% 

Sql syntax error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 01-14-2012 , 16:39   Sql syntax error
Reply With Quote #1

I get this with the plugin:

Quote:
L 01/14/2012 - 22:147: [Untitled.amxx] SQL error: near "auto_increment": syntax error
L 01/14/2012 - 22:147: [Untitled.amxx] Error while creating steamid table. Pausing plugin.
PHP Code:
#define CREATE_TABLE_STEAMIDS        "CREATE TABLE IF NOT EXISTS steamids (steamid varchar(40) NOT NULL default '',  id int(11) NOT NULL auto_increment,  PRIMARY KEY  (id),  UNIQUE KEY STEAMID (steamid)) TYPE=MyISAM;"

bool:create_tables()
{
    new 
Sql:sql
    
    
if (!connect(sql))
    {
        
log_amx("[%s] Failed connecting to database. Pausing plugin."PLUGINNAME)
        
pause("ad")
        return 
false
    
}

    new 
Result:result

    format
(g_queryQSIZE"%s"CREATE_TABLE_STEAMIDS)

    
result dbi_query(sqlg_query)

    if (
result <= RESULT_FAILED && dbi_check_error(sql))
    {
        
log_amx("Error while creating steamid table. Pausing plugin.")
        
disconnect(sql)
        
pause("ad")
        return 
false
    
}
    
    
jghg_free_result(result)

    
format(g_queryQSIZE"%s"CREATE_TABLE_NAMES)

    
result dbi_query(sqlg_query)

    if (
result <= RESULT_FAILED && dbi_check_error(sql))
    {
        
log_amx("Error while creating names table. Pausing plugin.")
        
disconnect(sql)
        
pause("ad")
        return 
false
    
}
    
    
jghg_free_result(result)

    
disconnect(sql)

    return 
true
}

jghg_free_result(Result:result)
{
    if(
result RESULT_NONE)
    {
        
dbi_free_result(result)
    }
}

dbi_check_error(&Sql:sql)
{
    new 
error[256] = ""
    
dbi_error(sqlerror255)
    
    if(
error[0] && !equal(error"Not an error"))
    {
        
log_amx("SQL error: %s"error)

        return 
true
    
}
    return 
false
}

disconnect(&Sql:sql)
{
    if(
sql SQL_FAILED)
    {
        
dbi_close(sql)
        
sql SQL_FAILED
    
}

__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-14-2012 , 17:10   Re: Sql syntax error
Reply With Quote #2

It should work fine with mysql. If you are trying to use it with sqlite, then you need to change query:
Code:
CREATE TABLE IF NOT EXISTS steamids (steamid varchar(40) UNIQUE NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT);
__________________
Impossible is Nothing
Sylwester is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-14-2012 , 17:26   Re: Sql syntax error
Reply With Quote #3

Mhmm... very weird. I am running actually mysql, on a friend it runs perfect. However, it is a sign, I get the same for the other table now, would be really appreciated:

PHP Code:
"CREATE TABLE IF NOT EXISTS names (  timestamp int(10) unsigned NOT NULL default '0',  counter int(10) unsigned NOT NULL default '1',  id int(11) NOT NULL default '0',  name varchar(32) binary NOT NULL default '',  PRIMARY KEY  (id,name)) TYPE=MyISAM; " 
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-14-2012 , 18:07   Re: Sql syntax error
Reply With Quote #4

I just updated my mysql (v5.5.20) and now I get syntax error caused by "TYPE=MyISAM" (you can remove it). The rest of the query should work fine, so if you get syntax errors then maybe you are connecting to sqlite without even knowing about it...
__________________
Impossible is Nothing
Sylwester is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-15-2012 , 05:29   Re: Sql syntax error
Reply With Quote #5

Code:
CREATE TABLE IF NOT EXISTS names (  timestamp int(10) unsigned NOT NULL default '0',  counter int(10) unsigned NOT NULL default '1',  id int(11) NOT NULL default '0',  name varchar(32) binary NOT NULL default '',  PRIMARY KEY  (id,name))
I get this now:

Quote:
SQL error: near "unsigned": syntax error
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-15-2012 , 06:22   Re: Sql syntax error
Reply With Quote #6

You get this error because your plugin is using sqlite, not mysql. This query will work with sqlite:
Code:
CREATE TABLE IF NOT EXISTS names (  timestamp integer unsigned NOT NULL default '0',  counter integer unsigned NOT NULL default '1',  id integer NOT NULL default '0',  name varchar(32) NOT NULL default '',  PRIMARY KEY  (id,name));
__________________
Impossible is Nothing
Sylwester is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-15-2012 , 07:13   Re: Sql syntax error
Reply With Quote #7

How can I change it to mysql then? I see there are no tables in the mysql server but the plugin however works now.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu 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 06:53.


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