On Oct 14, 11:02 am, Michael Bayer <mike...@zzzcomputing.com> wrote: > On Oct 14, 2011, at 10:38 AM, Lloyd Kvam wrote: > > > Would it make sense to add a __nonzero__ method to ResultProxy that > > was tied to the rowcount? > > > def __nonzero__(self): > > return bool(self.rowcount) > > > This would allow code like > > > if results: > > process(results) > > > I was surprised when this did not work. > > this is because .rowcount is not related to the count of rows in a result > set. Some DBAPI's may do this, but this is not the intent of .rowcount and > is not supported on most. .rowcount is only intended to describe the number > of rows matched by an UPDATE or DELETE statement. > > The only way to know if there are any rows in a result set are to fetch them. > The cursor itself, based on backend, doesn't even know there's a row until > it sends a message to the database to get the first row. > > Therefore you have to use fetchone() to check for a row.
I apologize for not reading the documentation. http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engine.base.ResultProxy.rowcount Thanks for being so kind in setting me straight. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.