AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   MySQL query Question/Problem (https://forums.alliedmods.net/showthread.php?t=184516)

Spriite 05-06-2012 03:53

MySQL query Question/Problem
 
[EN]
During the query the players lose their connection to the server, and only returned when the query is completed. How do I fix this?

Obs: I'm using the SQLx.

[BP]
Durante a consulta os jogadores perdem a conexão com o servidor, e só voltam quando a consulta é concluída. Como eu conserto isso?

Obs: Eu estou usando o SQLx.

hornet 05-06-2012 04:12

Re: MySQL query Question/Problem
 
I've only experienced this issue when I tried to connect to the database during gameplay, instead of during plugin_init().

Show your code.

Spriite 05-06-2012 12:00

Re: MySQL query Question/Problem
 
PHP Code:

new const g_sqlTable[] = "DataTable";
new const 
g_DataBase[] = "DataBase_test";
public 
plugin_init()
{
     ...
     
sql_init();
     ...
}
sql_init()

     
SQL_SetAffinity("mysql");
 
     
g_SqlTuple SQL_MakeDbTuple("???.???.???.???""xxxx""zzzz"g_DataBase);
 
     new 
Sql_Cache[400];
     
formatex(Sql_Cachecharsmax(Sql_Cache), "CREATE TABLE `%s` \
     (`Index` INTEGER(20) AUTO_INCREMENT PRIMARY KEY , \
     `Conta` VARCHAR( 64 ) NOT NULL , \
     `Senha` VARCHAR( 64 ) NOT NULL , \
     `AmmoPacks` INT( 20 ) NOT NULL DEFAULT '0' , \
     `Blocked` INT( 20 ) NOT NULL DEFAULT '0' )"
g_sqlTable);
 
     
SQL_ThreadQuery(g_SqlTuple"handle_create_table"Sql_Cache);
}
public 
handle_create_table(FailStateHandle:Query,Error[], ErrcodeData[], DataSize)
{
     new 
fail_msg[300];
     if(
Error[0] && Errcode != 1050)
     {
          
formatex(fail_msgcharsmax(fail_msg), "MySQL Error: %s (%d)"ErrorErrcode);
          
set_fail_state(fail_msg);
          return;
     }
     new 
errcodeerror[100];
     
g_SqlCon SQL_Connect(g_SqlTupleerrcodeerrorcharsmax(error));
 
     if(
error[0])
     {
          
formatex(fail_msgcharsmax(fail_msg), "MySQL Error: %s (%d)"errorerrcode);
          
set_fail_state(fail_msg);
          return;
     }
 
     if(
Errcode == 1050)
          return;
     else
     {
          
SQL_FreeHandle(Query);
          
Query SQL_PrepareQuery(g_SqlCon"INSERT INTO `%s` ( `Index` , `Conta` , `Senha` , `Blocked` ) VALUES ( 1 , 'null' , %d , 1 )"g_sqlTableget_gametime());
          
SQL_Execute(Query);
          
SQL_QueryError(Queryerror99);
          
SQL_FreeHandle(Query);
 
          if(
error[0])
          
server_print("SQL Error: %s (%d)"errorerrcode);
     }


[EN]
Obs: Most of my queries and I do using SQL_PrepareQuery and SQL_Execute.

[BP]
Obs: A maioria das minhas consultas eu faço utilizando SQL_PrepareQuery e SQL_Execute.

Neeeeeeeeeel.- 05-06-2012 18:23

Re: MySQL query Question/Problem
 
Thats because when you use SQL_PrepareQuery the native waits from de mysql answer.... Change your MySQL system and replace SQL_PrepareQuery with SQL_ThreadQuery

The link in my signature is a register system using MySQL, it use SQL_ThreadQuery if you want an example.


All times are GMT -4. The time now is 00:31.

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