X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9042253B65 for ; Thu, 21 Apr 2005 20:38:38 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14638-10 for ; Thu, 21 Apr 2005 23:38:33 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 3A28E542E2 for ; Thu, 21 Apr 2005 19:16:37 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1DOjyQ-0005WR-BF; Fri, 22 Apr 2005 10:16:38 +1200 Message-ID: <42682645.4030104@opencloud.com> Date: Fri, 22 Apr 2005 10:16:37 +1200 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ruediger Herrmann Cc: pgsql-jdbc@postgresql.org Subject: Re: isLast() and empty ResultSet References: <6626.1114117809@www66.gmx.net> In-Reply-To: <6626.1114117809@www66.gmx.net> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/124 X-Sequence-Number: 12731 Ruediger Herrmann wrote: > Hello, > > I implemented an Iterator interface iterating over a ResultSet. Therefore > I rely on isLast() to implement the Iterator#hasNext() method. This works > fine unless the whole ResultSet is empty. > For empty RresultSets, isLast always returns true. > Stepping through the code I found the reason therefore. Line 544 of > AbstractJdbc2ResultSet says > if (rows_size == 0) > return false; // No rows. > At least to me this is suspicious as I would return the opposite. Might that > be a bug or is there any other reason to behave like this? It's not a bug, AFAIK. isLast() returns true if the resultset is positioned *on* the last row of the resultset. This means that if you have a 5-row resultset, isLast() is true when the 5th row is the currently active row (and you can retrieve data from that row at that point). For a 0-row resultset, we can never be on the last row as there are no rows at all. You could try something like this for your hasNext() condition: rs.isBeforeFirst() || (rs.getRow() != 0 && !rs.isLast()) (note that isBeforeFirst() returns false on an empty resultset, per javadoc) -O