←  Problemy

AMXX.pl: Support AMX Mod X i SourceMod

»

Problem z zapytaniem do bazy danych, błąd...


Best Answer Puchate 02.11.2015 15:24

Nawet nie raczyłeś zdebugować tego błędu... ani przyjrzeć się zapytaniu, eh :)

 

Wystarczyło zapisać zapytanie do pliku (bądź usunąć z pluginowego znaki \) i wykonać zapytanie do bazy danych przez narzędzie co lepiej zaraportuje błąd, np. phpmyadmin.

#1064 - 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 'DATETIME NOT NULL,
            date_ungag DATETIME NOT NULL,
            gag_seconds INT NOT NUL' at line 8 

Mianowicie...

 

 

player_ip VARCHAR(15) NOT NULL, PRIMARY KEY\

 

 

nie w tym miejscu, nieprawdaż?

 

Go to the full post

  • +
  • -
Rivit's Photo Rivit 31.10.2015

Witam, przerabiam sobie admin_gag, tak aby gagi szły na IP

 

Jednak na chwilę obecną wyrzuca mi takie błędy:

Failed create table query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to us

 

 

Kod:

enum _:GagData
{
	GAG_AUTHID[ 35 ],
	GAG_NAME[33], 
	GAG_TIME,
	GAG_START,
	GAG_FLAGS
};

new g_szAuthid[ MAX_PLAYERS + 1 ][ 15 ];

public plugin_init( )
{
	// set server's SteamID to "SERVER"
	copy( g_szAuthid[ 0 ], charsmax( g_szAuthid[ ] ), "SERVER" );
}

InitSQL( )
{
	// init SQL after configs were executed
	if( get_pcvar_num( g_pCvarSQL ) )
	{
		new szHost[ 64 ], szUser[ 64 ], szPass[ 64 ], szDb[ 64 ];
		get_pcvar_string( g_pCvarSQLHost, szHost, charsmax( szHost ) );
		get_pcvar_string( g_pCvarSQLUser, szUser, charsmax( szUser ) );
		get_pcvar_string( g_pCvarSQLPass, szPass, charsmax( szPass ) );
		get_pcvar_string( g_pCvarSQLDb,   szDb,   charsmax( szDb   ) );
		
		g_hSqlTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDb );
		
		if( g_hSqlTuple == Empty_Handle ) return;
		
		// TABLE STRUCTURE
		// admin_name VARCHAR(32) NOT NULL
		// admin_steamid VARCHAR(35) NOT NULL
		// admin_ip VARCHAR(15) NOT NULL
		// player_name VARCHAR(32) NOT NULL
		// player_steamid VARCHAR(35) NOT NULL PRIMARY KEY
		// player_ip VARCHAR(15) NOT NULL
		// date_gagged DATETIME NOT NULL
		// date_ungag DATETIME NOT NULL
		// gag_seconds INT NOT NULL
		// gag_flags VARCHAR(3) NOT NULL
		
		new iError, szError[ 128 ];
		new Handle:hDb = SQL_Connect( g_hSqlTuple, iError, szError, charsmax( szError ) );
		
		if( hDb == Empty_Handle )
		{
			log_amx( "Failed to connect to database: (%d) %s", iError, szError );
			return;
		}
		
		new Handle:hQuery = SQL_PrepareQuery( hDb, "CREATE TABLE IF NOT EXISTS gagged_players2 (\
			admin_name VARCHAR(32) NOT NULL,\
			admin_steamid VARCHAR(35) NOT NULL,\
			admin_ip VARCHAR(15) NOT NULL,\
			player_name VARCHAR(32) NOT NULL,\
			player_steamid VARCHAR(35) NOT NULL,\
			player_ip VARCHAR(15) NOT NULL, PRIMARY KEY\
			date_gagged DATETIME NOT NULL,\
			date_ungag DATETIME NOT NULL,\
			gag_seconds INT NOT NULL,\
			gag_flags VARCHAR(3) NOT NULL);" );
		
		if( !SQL_Execute( hQuery ) )
		{
			SQL_QueryError( hQuery, szError, charsmax( szError ) );
			log_amx( "Failed create table query: %s", szError ); //tu blad
		}
		else
		{
			//kod
		}
	}
}

public client_authorized( id )
	get_user_ip( id, g_szAuthid[ id ], charsmax(g_szAuthid[ ]), 1);

public client_disconnect( id )
	g_szAuthid[ id ][ 0 ] = '^0';

AddGag( admin, player, iGagTime, iFlags )
{
	new szAdminName[ 32 ], adminsid[ 35 ];
	
	if( admin )
		get_user_name( admin, szAdminName, charsmax( szAdminName ) );
	else
		copy( szAdminName, charsmax( szAdminName ), "SERVER" );
	
	get_user_authid( admin, adminsid, charsmax( adminsid ));
	
	new szPlayerName[ 32 ], playersid[ 35 ];
	get_user_name( player, szPlayerName, charsmax( szPlayerName ) );
	get_user_authid( player, playersid, charsmax( playersid ));
	
	new szDateNow[ DATE_SIZE ], szDateUngag[ DATE_SIZE ];
	get_time( DATETIME_FORMAT, szDateNow, charsmax( szDateNow ) );
	format_time( szDateUngag, charsmax( szDateUngag ), DATETIME_FORMAT, get_systime( ) + iGagTime );
	
	new szFlags[ 4 ];
	get_flags( iFlags, szFlags, charsmax( szFlags ) );
	
	new szQuery[ 256 ];
	formatex( szQuery, charsmax( szQuery ), "REPLACE INTO gagged_players2 \
		(admin_name, admin_steamid, admin_ip, player_name, player_steamid, player_ip, date_gagged, date_ungag, gag_seconds, gag_flags) \
		VALUES \
		(^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", %d, ^"%s^");",\
		szAdminName, adminsid, g_szAuthid[ admin  ],\
		szPlayerName, playersid, g_szAuthid[ player ],\
		szDateNow, szDateUngag, iGagTime, szFlags );
	
	SQL_ThreadQuery( g_hSqlTuple, "QueryAdd", szQuery );
}

public QueryAdd( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:flQueueTime )
{
	switch( iFailState )
	{
		case TQUERY_CONNECT_FAILED: log_amx( "Failed to connect to database: (%d) %s", iError, szError );
		case TQUERY_QUERY_FAILED:   log_amx( "Failed add gag query: (%d) %s", iError, szError ); //tu tez blad
	}
}
Quote

  • +
  • -
Ogen Dogen's Photo Ogen Dogen 01.11.2015


gag_seconds INT NOT NULL,\

 

Z tego co pamiętam do inta też trzeba podać rozmiar ;)

Quote

  • +
  • -
sebul's Photo sebul 01.11.2015

gag_seconds INT NOT NULL,\

 
Z tego co pamiętam do inta też trzeba podać rozmiar ;)

Jak nie podasz, to ustawi standardowo, czyli 11.


Co do błędu, może spróbuj bez tego załamywania stringa przy pomocy \, może podaj engine, nie wiem, musisz popróbować.
sebul (01.11.2015 14:46):
A chyba jednak coś z "PRIMARY KEY" masz nie tak ^ ^
Quote

  • +
  • -
Asiap's Photo Asiap 01.11.2015

usun , PRIMARY KEY

Quote

  • +
  • -
sebul's Photo sebul 02.11.2015

usun , PRIMARY KEY

Jak już - zmień sposób jego ustawienia na poprawny (a jak to zrobić, to jest tego dużo w necie), bo zawsze powinno się określać unikalny klucz dla tabeli.
Quote

  • +
  • -
Best Answer Puchate's Photo Puchate 02.11.2015

Nawet nie raczyłeś zdebugować tego błędu... ani przyjrzeć się zapytaniu, eh :)

 

Wystarczyło zapisać zapytanie do pliku (bądź usunąć z pluginowego znaki \) i wykonać zapytanie do bazy danych przez narzędzie co lepiej zaraportuje błąd, np. phpmyadmin.

#1064 - 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 'DATETIME NOT NULL,
            date_ungag DATETIME NOT NULL,
            gag_seconds INT NOT NUL' at line 8 

Mianowicie...

 

 

player_ip VARCHAR(15) NOT NULL, PRIMARY KEY\

 

 

nie w tym miejscu, nieprawdaż?

 

Quote