SA-MP Forums Archive
it says there is 0 raw but there is 1 raw - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: it says there is 0 raw but there is 1 raw (/showthread.php?tid=625896)



it says there is 0 raw but there is 1 raw - fastayko - 07.01.2017

it always create new user when there is already an user with the same name ( it give me 0 raw )
Код HTML:
new queryy[200] ;
format(queryy, 128, "SELECT * users WHERE username = '%s'", PlayerName(playerid) );
new row_count;
mysql_query(g_Sql, queryy);
cache_get_row_count(row_count) ;
if(row_count == 1)
{
    SendClientMessage(playerid, COLOR_PURPLE, "[MYSQL] Your account found in the mysql");
}
if(row_count == 0)
{
    format(string,sizeof(string),"INSERT INTO `users` (`username`) VALUES ('%s')",PlayerName(playerid));
    mysql_query(g_Sql, string);
    SendClientMessage(playerid, COLOR_PURPLE, "[MYSQL] Your account added to the mysql");
}



Re: it says there is 0 raw but there is 1 raw - GoldenLion - 07.01.2017

The query has to be like this:
Код:
SELECT * FROM users WHERE username = '%s'
You forgot "FROM".

Also you should use threaded queries, but if you still want to use non-threaded queries then you will need to delete the cache after you finish doing the stuff with it. Another thing: you should always escape the strings if you set something. Also you don't need 200 cells for that query, 70 would be enough for the both queries and also you can do sizeof(...) when you format something. I suggest you using mysql_format for formatting queries though because you can escape strings easily by using %e.

Код:
new query[70], row_count, Cache:cache;

mysql_format(g_Sql, query, sizeof(query), "SELECT * FROM users WHERE username = '%s'", PlayerName(playerid));
cache = mysql_query(g_Sql, query);
cache_get_row_count(row_count);

if (row_count)
{
    SendClientMessage(playerid, COLOR_PURPLE, "[MYSQL] Your account found in the mysql");
}
else
{
    mysql_format(g_Sql, query, sizeof(query), "INSERT INTO users (username) VALUES ('%e')", PlayerName(playerid));
    mysql_tquery(g_Sql, string);
    SendClientMessage(playerid, COLOR_PURPLE, "[MYSQL] Your account added to the mysql");
}
cache_delete(cache);
I used a threaded query in the insert query because you don't need a callback for it at this case so it's easy to use.


Re: it says there is 0 raw but there is 1 raw - Jefff - 07.01.2017

Check native
pawn Код:
native cache_get_row_count(connectionHandle = 1);
pawn Код:
if(cache_get_row_count(g_Sql))
{
// found
}
else
{
// not found
}