From: Michael Neumann Date: 2003-10-13T00:08:26+09:00 Subject: Re: mysql_num_rows equivalent for DBI? On Sun, Oct 12, 2003 at 05:17:19AM +0900, Ben Giddings wrote: > paul vudmaska wrote: > >What i think you are looking for is recordset#rows - > >Returns the RPC (Row Processed Count) of the last > >executed statement, or nil if no such exists. > > That's what I thought I should be using, but it is always zero: > > irb(main):097:0> dbh.execute("SELECT Username FROM Users").fetch_all > [["ben"], ["harry"]] > irb(main):098:0> dbh.execute("SELECT Username FROM Users").rows > 0 Try this one: dbh.execute("SELECT Username FROM Users")['pg_row_count'] This is a Postgres-specific function, but should return what you except. Alternatively you can always use SELECT COUNT(Username). > irb(main):099:0> sth = dbh.prepare("SELECT Username FROM Users") > ... > irb(main):100:0> sth.execute > [nil] > irb(main):101:0> sth.rows > 0 > irb(main):102:0> sth.fetch_all > [["ben"], ["harry"]] > > This appears to be a bug, doesn't it? What exactly should be a bug? That sth.execute returns [nil]? That's not a bug, but even so should be changed to nil or self. Regards, Michael