spadefoot / kohana-orm-leap

An ORM module for the Kohana PHP framework that is designed to work with all major databases.
http://spadefoot.github.io/kohana-orm-leap/
100 stars 25 forks source link

Ability to count rows without fetching all data ... #73

Closed ghost closed 11 years ago

ghost commented 11 years ago

Hey guys,

again my 800 rows table. To create a pagination i need to know how many rows my database has exactly. i dont see a possible solution in leap orm without fetching all data from the table...

the problem is, the table is large and fetching all data needs some seconds. i dont need these seconds because i will only fetch 25 entrys at once, but for pagination i need the count of all rows...

is there a possibility in leap?

kind regards

taai commented 11 years ago

Yeah, the problem is that Leap ORM fetches all rows into memory. I hate that too. This should be optional, but it isn't. :(

bluesnowman commented 11 years ago

@viperneo Yes, this is a known issue. This happens because all results are buffered in DB_ResultSet. As I am sure @taai would agree, LEAP should also offer the ability to query results using the SqlDataReader paradigm (e.g. http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx). However, there are a few challenges to implementing this paradigm so that all database dialects follow the same contract and act alike.

As for a count method, the challenge here is that not all database dialect drivers offers functions like mysql_num_rows(). Have you tried (see http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html):

$result = $connection->query('SELECT COUNT(*) AS `TblSize` FROM `TblName`;');