[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
{
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();
}
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();
}
#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;
}
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:
more info here: http://forum.sa-mp.com/showthread.ph...ght=sql+plugin |
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; }
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.");
}
}
[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.