MySQL error handling
#1

Just a quickie,
does anyone know a method to handle mysql errors correctly in SAMP in such a case the errors aren't logged (cluttering up the log file)?

Example,

1. A key field is set to being distinct values in MySQL.
2. Imagine we have some voting system (may contain errors),
Код:
CMD:vote(playerid, params[]) {
      new votedfor;
     if(sscanf(params, "d", votedfor)) { return; }
     if votedfor is valid...
     
     new query[200];
     mysql_format(sqlGameConnection, query, sizeof(query), "INSERT INTO votes SET pID = %d, for = %d;", PlayerInfo[playerid][pID], votedfor);
     mysql_pquery(sqlGameConnection, query, "OnVotedError", "i", playerid);
}

forward OnVotedError(playerid);
public OnVotedError(playerid) {
     if(mysql_errno() == 1062) { //duplicate record, player has already voted
            SendClientMessage(playerid, COLOR_GREY, "You have already voted");
     }
     return;
}
I'd much prefer this to having to send two queries: one SELECT & followed by an INSERT. Is there a way to avoid writing to mysql_log.txt in this situation? Going to take a quick looksy at the source.


Hmm perhaps mysql_log(none); then set it to default.
#define mysql_pquery_e(%0) mysql_log(LOG_NONE); \
mysql_pquery(%0); \
mysql_log(...); //... = default
...but this could fail seemingly queries are threaded.

I'm aware we can create sql routines which except errors but surely there's a much simpler approach in samp
Reply


Messages In This Thread
MySQL error handling - by iiNzTicTx - 11.11.2017, 07:53
Re: MySQL error handling - by woot - 11.11.2017, 08:11
Re: MySQL error handling - by iiNzTicTx - 11.11.2017, 08:17
Re: MySQL error handling - by Juvanii - 11.11.2017, 08:38
Re: MySQL error handling - by iiNzTicTx - 11.11.2017, 09:06

Forum Jump:


Users browsing this thread: 1 Guest(s)