Error ID: 2014, Commands out of sync; you can't run this command now
#1

I can't tell in which function the problem is

Code:
[19:22:18] CMySQLHandler::Query(SELECT * FROM characters WHERE faction = '1') - An error has occured. (Error ID: 2014, Commands out of sync; you can't run this command now)

[19:22:18] >> mysql_store_result( Connection handle: 1 )

[19:22:18] CMySQLHandler::StoreResult() - Result was stored.

[19:22:18] >> mysql_fetch_row_format( Connection handle: 1 )

[19:22:18] CMySQLHandler::FetchRow() - An error has occured. (Error ID: 2014, Commands out of sync; you can't run this command now)

[19:22:18] >> mysql_free_result( Connection handle: 1 )

[19:22:18] CMySQLHandler::FreeResult() - Result was successfully free'd.

[19:22:21] >> mysql_query( Connection hand
pawn Code:
{
    new  message[128];
    new  Date[25];
    new  CharacterIDs;
    new  mSQLID;
    new  messagescount = 0;
   
    format(string, sizeof(string), "SELECT * FROM offline_messages WHERE characterID = '%d'", AccountData[playerid][characterID]);
    mysql_query(string);
    mysql_store_result();

    AddDListItem(playerid, "Message type\t\t\t Date", 10001, 0);
   
    string = " ";
    ProductList = " ";
   
    while(mysql_fetch_row_format(line,"|")) {
        sscanf(line, "p<|>iis[128]s[25]", mSQLID, CharacterIDs , message, Date );


        messagescount ++;
       
        //SendFormattedMessage(playerid, COLOR_YELLOW, "[Offline Message:] Date: %i %s Message: %s", Date, month, message);
        format(ProductList, sizeof(ProductList), "Offline Message\t\t %s", Date);

     
    }


    if(messagescount == 0)
    {
        ShowPlayerDialog(playerid, 99999, DIALOG_STYLE_MSGBOX, "No Messages", "You have no messages", "Okay", "Cancel");
        return 1;
    }


    format(string, sizeof(string), "New messages: %i", messagescount);
   
    mysql_free_result();
}
pawn Code:
stock ShowFactionMembers(playerid, factionid)
{

    string = " ";
    ProductList = " ";
   
    new LastSeen[20];
    new Rankk;
    new MemberCount;
    new CharacterName[24];
    new RankkName[24];
    new MemberID;
   
    format(string, sizeof(string), "SELECT * FROM characters WHERE faction = '%d'", factionid);
    mysql_query(string);
    mysql_store_result();
   
    AddDListItem(playerid, "Member Name\t\tRank\t\t\tLast Seen", 10000, 0);

   
    while(mysql_fetch_row_format(line,"|"))
    {
       MemberCount ++;
       
       sscanf(line, "p<|>{iffiiiiiii}i{ii}s[24]i{ffffii}s[20]", Rankk, CharacterName, MemberID, LastSeen );

       switch(Rankk)
       {
         case 1: format(RankkName, 24, "%s", FactionInfo[factionid][Rank1]);
         case 2: format(RankkName, 24, "%s", FactionInfo[factionid][Rank2]);
         case 3: format(RankkName, 24, "%s", FactionInfo[factionid][Rank3]);
         case 4: format(RankkName, 24, "%s", FactionInfo[factionid][Rank4]);
         case 5: format(RankkName, 24, "%s", FactionInfo[factionid][Rank5]);
       }
       
       
       format(ProductList, sizeof(ProductList), "%s\t\t%s\t\t%s", CharacterName, RankkName, LastSeen);
       
       printf("Prod: %s string: %s", ProductList, string);
       
   }
   
   format(string, sizeof(string), "Members: %i", MemberCount);
   
   mysql_free_result();
}
Reply
#2

bump....
Reply
#3

I suggest using threaded queries, and OnQueryFinish.
Perhaps try putting the connection handle in your commands where appropriate ( long shot ).
Also try putting print statements in both functions before and after the queries to see which order they are being processed in.
Reply
#4

I already debuged(printf()) - everything is alright and can you show me an example of threaded query, of this case
Reply
#5

Basically, you take everything after your query ( in your posted example ) and put it under OnQueryFinish(), that way if two queries are being performed close together they will not overlap ( I think this is the idea ). It also means your script wont "hang" while the queries are being processed.

pawn Code:
#define THREAD_FUNCTION1    1
#define THREAD_FUNCTION2    2

public YourFunction(playerid)
{
//format query here..
     mysql_query(string,THREAD_FUNCTION1,playerid,connection);
//playerid is extraid in the callback
//connection is the result of the mysql_connect function ( usually 1 )
     return 1;
}
//I put this in a function to simulate you putting it in your script

public OnQueryFinish(query[], resultid, extraid, connectionhandle)
{
     if(connectionhandle == connection) //precaution in case of multiple sql connections
     {
          switch(resultid)
          {
                case THREAD_FUNCTION1:
                {
                      mysql_store_result(query);
                      //put the rest of your code here
                      mysql_free_result(query); //im not sure if you need this line
                }
          }
     }
      return 1;
}
[edit] I'm new to sql, so I'm not 100% sure that this will fix your problem, however I am pretty sure its a good way to script sql queries.
more info here:
http://forum.sa-mp.com/showthread.ph...ght=sql+plugin
Reply
#6

Quote:
Originally Posted by Rachael
View Post
Basically, you take everything after your query ( in your posted example ) and put it under OnQueryFinish(), that way if two queries are being performed close together they will not overlap ( I think this is the idea ). It also means your script wont "hang" while the queries are being processed.

pawn Code:
#define THREAD_FUNCTION1    1
#define THREAD_FUNCTION2    2

public YourFunction(playerid)
{
//format query here..
     mysql_query(string,THREAD_FUNCTION1,playerid,connection);
//playerid is extraid in the callback
//connection is the result of the mysql_connect function ( usually 1 )
     return 1;
}
//I put this in a function to simulate you putting it in your script

public OnQueryFinish(query[], resultid, extraid, connectionhandle)
{
     if(connectionhandle == connection) //precaution in case of multiple sql connections
     {
          switch(resultid)
          {
                case THREAD_FUNCTION1:
                {
                      mysql_store_result(query);
                      //put the rest of your code here
                      mysql_free_result(query); //im not sure if you need this line
                }
          }
     }
      return 1;
}
[edit] I'm new to sql, so I'm not 100% sure that this will fix your problem, however I am pretty sure its a good way to script sql queries.
more info here:
http://forum.sa-mp.com/showthread.ph...ght=sql+plugin
Thank you,
Code:
stock GetUserDBName(userid)
{
    new UserName[24];
    
    format(string, sizeof(string), "SELECT `CharacterName` FROM characters WHERE cSQLID = '%d'", userid);
    mysql_query(string);
    
    
    mysql_fetch_row_format(UserName);
    
    printf("Query: %s Name: %s ID: %i", string, UserName, userid);
    mysql_free_result();
    
    return UserName;
}
I'm worrying that this could cause the error, because it should get the CharacterName field but it fetches nothing
Reply
#7

did you forget mysql_store_result()?
Reply
#8

Quote:
Originally Posted by Rachael
View Post
did you forget mysql_store_result()?
Yes, thanks!

pawn Code:
stock OfflineMessage(cid, text[])
{
   
    format(string, sizeof(string), "INSERT INTO offline_messages (Message, CharacterID) VALUES('%s', '%i')", text, cid);
    mysql_query(string);
    mysql_query("SELECT MAX(SQLID) FROM offline_messages");
   
    new onlineplayer = IsOnline(cid);
   
    if(onlineplayer != INVALID_PLAYER_ID)
    {
       SendClientMessage(onlineplayer, SERVER_COLOR, "SERVER: You have received a new message, /messages to read it.");
    }

}
Everything after this function use starts to bug, i mean showing command out of sync error.

pawn Code:
[15:47:53] CMySQLHandler::Query(INSERT INTO offline_messages (Message, CharacterID) VALUES('Lol', '62')) - Successfully executed.

[15:47:53] >> mysql_query( Connection handle: 1 )

//use of the function
[15:47:53] CMySQLHandler::Query(SELECT MAX(SQLID) FROM offline_messages) - Successfully executed.

[15:47:54] >> mysql_query( Connection handle: 1 )

// and here it shows the sync error
[15:47:54] CMySQLHandler::Query(SELECT `CharacterName` FROM characters WHERE cSQLID = '62') - An error has occured. (Error ID: 2014, Commands out of sync; you can't run this command now)

[15:47:54] >> mysql_store_result( Connection handle: 1 )

[15:47:54] CMySQLHandler::StoreResult() - Result was stored.

[15:47:54] >> mysql_fetch_row_format( Connection handle: 1 )

[15:47:54] CMySQLHandler::FetchRow() - Return: 29

[15:47:54] >> mysql_free_result( Connection handle: 1 )

[15:47:54] CMySQLHandler::FreeResult() - Result was successfully free'
d.
Look in comments!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)