rdbms: move assertOpen() call near the top of Database::query