mysql_query return value.
#1

I'm only just learning how to do MySQL, so I'm making a few mistakes.

I've converted my accounts system from SQLite to MySQL, or am attempting to. In the wiki page on the mysql plugin it says that mysql_query returns 1 if successful and 0 if unsuccessful.

I made some defines for multi threading, and when I perform a query, it returns the value of the define rather than returning 1 or 0.

Here is a small piece of the code.

pawn Код:
#define THREAD_CHECKGANG 39
pawn Код:
new query[256];

    format(query, sizeof(query), "SELECT `GangName` FROM `Gangs` WHERE `GangName`='%s'", gangname);

        if(mysql_query(query, THREAD_CHECKGANG) == 1)
        return -1;//gang already exists
        else
        {
          //Create Gang Here
        }
}
and under OnQueryFinish i have
pawn Код:
case THREAD_CHECKGANG:
{
      mysql_store_result();

       if(mysql_num_rows() > 0)
       {
             mysql_free_result();
         return true;
       }
       else
       {
             mysql_free_result();
         return false;
       }
}
Ok, the problem is the query is returning the value of the thread define (39) when its supposed to return 1 or 0. What have i done wrong?
Reply
#2

Anyone have any solution?
Reply
#3

pawn Код:
format(query, sizeof(query), "SELECT `GangName` FROM `Gangs` WHERE `GangName`='%s'", gangname);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows()!=0)
{
//do something,when the row exists
}else
{
//do something,when the row don't exists
}
mysql_free_result();
https://sampwiki.blast.hk/wiki/MySQL#mysql_query
mysql_query return 1 on success, 0 on fail.
Reply
#4

Thanks, but I'm wanting to do it as a threaded query, which is why i had defined THREAD_CHECKGANG.

I just cant figure out why it's returning the value of the define / thread rather than 0 or 1
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)