Getting SUM and AVG from SQLite DB - 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: Getting SUM and AVG from SQLite DB (
/showthread.php?tid=416123)
Getting SUM and AVG from SQLite DB -
Minokon - 16.02.2013
Hello
I got one problem - I can't select field with SUM or AVG from my sqlite database. Function "db_get_field" simply crashes (yes, i debugged it with print).
My code:
Код:
new query[128], rating[10];
formatt(query, "SELECT AVG(Rate) FROM `raceratings` WHERE `RaceID`='%d'", raceid);
new DBResult:rateCheck = db_query(servDB, query);
new numRows = db_num_rows(rateCheck);
if(numRows > 0)
{
db_get_field(rateCheck, 0, rating, sizeof(rating));
avg = floatstr(rating);
}
else
avg = 0.0;
db_free_result(rateCheck);
When there isn't any rows, "numRows" still is bigger than 0, and server crashes at db_get_field.
Thanks for any help!