PDA

View Full Version : Faction, MySQL


BigGroter
22/02/2014, 12:56 PM
CMD:factions(playerid, params[])
{
new string[128];
for(new i=0;i<MAX_FACTIONS;i++)
{
if(strlen(fInfo[i][fName]) == 0) continue;
format(string, sizeof(string), "MySQL ID: %d (ID: %d) "#DIALOG_GREEN#" %s", fInfo[i][fID], i, fInfo[i][fName]);
SCM(playerid, -1, string);
}
return 1;
}

CMD:deletefaction(playerid, params[])
{
new facID, szQuery[128];
if(sscanf(params, "d", facID)) return SCM(playerid, -1, "Usage: /deletefaction <faction ID>");
format(szQuery, sizeof(szQuery), "DELETE FROM `factions` WHERE `fID` = %d", fInfo[facID][fID]);
mysql_pquery(dbHandle, szQuery);
format(fInfo[facID][fName], 0, "");
fInfo[facID][fID] = 0;

LoadFactions();
return 1;
}

When I delete a faction it is removed from the MySQL database, it's still listed IG via /factions however, how do I fix this?

Vince
22/02/2014, 01:00 PM
Most likely due to the fact that you're executing concurrent queries (DELETE vs the SELECT in the LoadFactions function) resulting in a race condition. Create a callback for the DELETE query and execute the reset procedure and the LoadFactions in there. This way you'll be sure that the query has been completed.

BigGroter
22/02/2014, 01:31 PM
forward thread_DeleteFaction(facID);
public thread_DeleteFaction(facID)
{
format(fInfo[facID][fName], 0, "");
LoadFactions();
return 1;
}


I added that, still not working. Again, the faction is removed from the MySQL database, but not IG when you use /factions. It's probably something simple, I got back into MySQL today.

S4t3K
22/02/2014, 01:48 PM
Look at the query, be sure that it takes an existing variable to save in an existing column

BigGroter
22/02/2014, 01:53 PM
Hmm? The MySQL part works, it's just messing up in game.

S4t3K
22/02/2014, 02:13 PM
Ah, my fault.

What's wrong ? Can you still be in the faction/using the faction's commands after deleting it ?
Or is the faction still remaining on the list but nobody can use faction's features ?

BigGroter
22/02/2014, 02:31 PM
Yes you can still use the commands. It exists IG, not in the MySQL DB though.

S4t3K
22/02/2014, 02:35 PM
When you use the commands, do you check the database or the stats ?

If you check the stats, be sure that they update enough often

If you use the database (a mysql_get_field or the macro), don't know ;3

BigGroter
22/02/2014, 02:47 PM
Okay, I almost solved the problem.

Say I have three factions, and I delete the number 2, number 3 takes its place but also keeps the third slot, why? Remember that this is all visual IG, nothing is wrong with the tables or the database.

Faction 1
Faction 2 - Delete this
Faction 3

Ends up looking like this.

Faction 1
Faction 3
Faction 3



Read the original post for the /factions and /deletefaction command.

EDIT:
Added for(new i=0;i<MAX_FACTIONS;i++)
{
strdel(fInfo[i][fName], 0, 65);
}
before loading, now I have to type /deletefaction <faction id> twice to delete a faction, then after I have deleted one faction I can continue deleting with /deletefaction, not needing to use it twice. :S