From: paul vudmaska Date: 2003-10-12T06:01:15+09:00 Subject: Re: mysql_num_rows equivalent for DBI? --- 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 > 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? > > Ben > Certainly, it seems misleading...the page at kitebird is up now and below is a snip that explains this. >> For statements that return no result set, such as INSERT or DELETE, do returns a count of the number of rows processed.>>PLV _ this is what i thot you were looking for<< For statements that return rows, such as SELECT, you can use the statement handle after invoking execute to get row and column counts or information about each of the columns in the result set: The row and column counts are not available directly. To get the row count, either count the rows as you fetch them, or fetch them into a data structure and see how many elements it contains... << sa = $db.select_all('Select * from person') p sa.size #> think this returns what you are looking for. Paul __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com