SQLite db_num_rows VS count
#3

Using SELECT COUNT(*) will count itself the number of rows that the table "players" contains and return it:
Код:
new DBResult:result = db_query(db, "SELECT COUNT(*) FROM players");
new count = db_get_field_int(result); //I think you don't really need this since SELECT COUNT(*) already returns an int
db_free_result(result);
Also replace SELECT NULL with SELECT *
Код:
new DBResult:result = db_query(db, "SELECT * FROM players"); //this gets every record of the table players
new count = db_num_rows(result); //counts the number of rows as int
db_free_result(result);
Between this two I'd personally use SELECT COUNT(*), instead of selecting everything from the table and then counting each row.
Quote:
Originally Posted by Quis
Посмотреть сообщение
And another question: what, if I only want to know if a record just exists?
Yes, you can check if a record exists without actually displaying it. For example, if you want to know if a player called John_Cena exists in the database:
Код:
SELECT 1 FROM players WHERE name = 'John_Cena'
This will return 1 if the record exists.
Reply


Messages In This Thread
SQLite db_num_rows VS count - by Quis - 23.11.2017, 20:43
Re: SQLite db_num_rows VS count - by BlackBank - 23.11.2017, 23:02
Re: SQLite db_num_rows VS count - by L97 - 23.11.2017, 23:11
Re: SQLite db_num_rows VS count - by Quis - 24.11.2017, 15:10
Re: SQLite db_num_rows VS count - by BlackBank - 24.11.2017, 17:55
Re: SQLite db_num_rows VS count - by L97 - 24.11.2017, 22:59

Forum Jump:


Users browsing this thread: 1 Guest(s)