Fixed check for empty queries to use the SQLAlchemy.engine.ResultProxy.rowcount attribute rather than a simple truthiness check