Thread: getMoreResults() returns false incorrectly
I tried to search the list archives, but the search engine appears to be broken (comes back with an http 404 error). Using the Postgresql JDBC driver (I'm testing with jdbc7.0-1.1.jar) it appears that Statement.getMoreResults() returns false even if there is a result set from the query just executed. Statement stmt = conn.createStatement(); stmt.execute("SELECT * FROM t"); if (stmt.getMoreResults()) { ResultSetrs = stmt.getResultSet(); while (rs.next()) { // process row .... } } The call to getMoreResults() returns false consistently. If the call is replaced with 'if (true) ...' then the code to get the result set and process the rows works fine. Accoring to the JDBC docs, this method should return "true if the next result is a ResultSet; false if it is an update count or there are no more results." There is no update count (as confirmed by getUpdateCount()). Is this a known problem? If this method doesn't work as documented, it's impossible to "work with an unknown SQL string" as the documentation for execute() indicates we should be able to (without parsing the SQL query). -- Bob Kline mailto:bkline@rksystems.com http://www.rksystems.com
I'll look into this, as the psql example included with the source uses this method in this way. Peter -- Peter Mount Enterprise Support Maidstone Borough Council Any views stated are my own, and not those of Maidstone Borough Council -----Original Message----- From: Bob Kline [mailto:bkline@rksystems.com] Sent: Tuesday, June 20, 2000 11:25 AM To: pgsql-interfaces@postgresql.org Subject: [INTERFACES] getMoreResults() returns false incorrectly [Second submission; first seems to have disappeared.] I tried to search the list archives, but the search engine appears to be broken (comes back with an http 404 error). Using the Postgresql JDBC driver (I'm testing with jdbc7.0-1.1.jar) it appears that Statement.getMoreResults() returns false even if there is a result set from the query just executed. Statement stmt = conn.createStatement(); stmt.execute("SELECT * FROM t"); if (stmt.getMoreResults()) { ResultSetrs = stmt.getResultSet(); while (rs.next()) { // process row .... } } The call to getMoreResults() returns false consistently. If the call is replaced with 'if (true) ...' then the code to get the result set and process the rows works fine. Accoring to the JDBC docs, this method should return "true if the next result is a ResultSet; false if it is an update count or there are no more results." There is no update count (as confirmed by getUpdateCount()). Is this a known problem? If this method doesn't work as documented, it's impossible to "work with an unknown SQL string" as the documentation for execute() indicates we should be able to (without parsing the SQL query). -- Bob Kline mailto:bkline@rksystems.com http://www.rksystems.com
I believe I've figured out what the problem is. The JDBC API documentation doesn't say so explicitly, but the example code in Sun's JDBC tutorial implies that you can only call getMoreResults() after you have retrieved either the first update count (with getUpdateCount()) or the first result set. So the version of the code below which works would be: Statement stmt = conn.createStatement(); stmt.execute(queryString); for (;;) { int updateCount = stmt.getUpdateCount(); if (updateCount >= 0) { // report update count ... } else { ResultSet rs = stmt.getResultSet(); if (rs == null) break; // process resultset .... } stmt.getMoreResults(); } Bob On Mon, 26 Jun 2000, Peter Mount wrote: > I'll look into this, as the psql example included with the source > uses this method in this way. > > Peter > > -----Original Message----- > From: Bob Kline [mailto:bkline@rksystems.com] > Sent: Tuesday, June 20, 2000 11:25 AM > To: pgsql-interfaces@postgresql.org > Subject: [INTERFACES] getMoreResults() returns false incorrectly > > > [Second submission; first seems to have disappeared.] > > I tried to search the list archives, but the search engine appears to be > broken (comes back with an http 404 error). > > Using the Postgresql JDBC driver (I'm testing with jdbc7.0-1.1.jar) it > appears that Statement.getMoreResults() returns false even if there is a > result set from the query just executed. > > Statement stmt = conn.createStatement(); > stmt.execute("SELECT * FROM t"); > if (stmt.getMoreResults()) { > ResultSet rs = stmt.getResultSet(); > while (rs.next()) { > // process row .... > } > } > > The call to getMoreResults() returns false consistently. If the call is > replaced with 'if (true) ...' then the code to get the result set and > process the rows works fine. > > Accoring to the JDBC docs, this method should return "true if the next > result is a ResultSet; false if it is an update count or there are no > more results." There is no update count (as confirmed by > getUpdateCount()). > > Is this a known problem? If this method doesn't work as documented, > it's impossible to "work with an unknown SQL string" as the > documentation for execute() indicates we should be able to (without > parsing the SQL query). >
This sounds correct. If you think about it, getMoreResults() does seem to imply it get's another ResultSet, implying that one already exists. Peter -- Peter Mount Enterprise Support Maidstone Borough Council Any views stated are my own, and not those of Maidstone Borough Council -----Original Message----- From: Bob Kline [mailto:bkline@rksystems.com] Sent: Monday, June 26, 2000 5:13 PM To: Peter Mount Cc: pgsql-interfaces@postgresql.org Subject: RE: [INTERFACES] getMoreResults() returns false incorrectly I believe I've figured out what the problem is. The JDBC API documentation doesn't say so explicitly, but the example code in Sun's JDBC tutorial implies that you can only call getMoreResults() after you have retrieved either the first update count (with getUpdateCount()) or the first result set. So the version of the code below which works would be: Statement stmt = conn.createStatement(); stmt.execute(queryString); for (;;) { int updateCount = stmt.getUpdateCount(); if (updateCount >= 0) { // report update count ... } else { ResultSet rs = stmt.getResultSet(); if (rs == null) break; // process resultset .... } stmt.getMoreResults(); } Bob On Mon, 26 Jun 2000, Peter Mount wrote: > I'll look into this, as the psql example included with the source > uses this method in this way. > > Peter > > -----Original Message----- > From: Bob Kline [mailto:bkline@rksystems.com] > Sent: Tuesday, June 20, 2000 11:25 AM > To: pgsql-interfaces@postgresql.org > Subject: [INTERFACES] getMoreResults() returns false incorrectly > > > [Second submission; first seems to have disappeared.] > > I tried to search the list archives, but the search engine appears to be > broken (comes back with an http 404 error). > > Using the Postgresql JDBC driver (I'm testing with jdbc7.0-1.1.jar) it > appears that Statement.getMoreResults() returns false even if there is a > result set from the query just executed. > > Statement stmt = conn.createStatement(); > stmt.execute("SELECT * FROM t"); > if (stmt.getMoreResults()) { > ResultSet rs = stmt.getResultSet(); > while (rs.next()) { > // process row .... > } > } > > The call to getMoreResults() returns false consistently. If the call is > replaced with 'if (true) ...' then the code to get the result set and > process the rows works fine. > > Accoring to the JDBC docs, this method should return "true if the next > result is a ResultSet; false if it is an update count or there are no > more results." There is no update count (as confirmed by > getUpdateCount()). > > Is this a known problem? If this method doesn't work as documented, > it's impossible to "work with an unknown SQL string" as the > documentation for execute() indicates we should be able to (without > parsing the SQL query). >
I agree (though -- according to Sun's sample code I was referring to -- the thing that "already exists" need not be a result set, but could instead be an update count). Thanks very much for taking the time to investigate and respond. Bob On Tue, 27 Jun 2000, Peter Mount wrote: > This sounds correct. If you think about it, getMoreResults() does > seem to imply it get's another ResultSet, implying that one already > exists. > > Peter > > -- > Peter Mount > Enterprise Support > Maidstone Borough Council > Any views stated are my own, and not those of Maidstone Borough Council > > > -----Original Message----- > From: Bob Kline [mailto:bkline@rksystems.com] > Sent: Monday, June 26, 2000 5:13 PM > To: Peter Mount > Cc: pgsql-interfaces@postgresql.org > Subject: RE: [INTERFACES] getMoreResults() returns false incorrectly > > > I believe I've figured out what the problem is. The JDBC API > documentation doesn't say so explicitly, but the example code in Sun's > JDBC tutorial implies that you can only call getMoreResults() after you > have retrieved either the first update count (with getUpdateCount()) or > the first result set. > > So the version of the code below which works would be: > > Statement stmt = conn.createStatement(); > stmt.execute(queryString); > for (;;) { > int updateCount = stmt.getUpdateCount(); > if (updateCount >= 0) { > // report update count ... > } > else { > ResultSet rs = stmt.getResultSet(); > if (rs == null) > break; > // process resultset .... > } > stmt.getMoreResults(); > } > > Bob > > On Mon, 26 Jun 2000, Peter Mount wrote: > > > I'll look into this, as the psql example included with the source > > uses this method in this way. > > > > Peter > > > > -----Original Message----- > > From: Bob Kline [mailto:bkline@rksystems.com] > > Sent: Tuesday, June 20, 2000 11:25 AM > > To: pgsql-interfaces@postgresql.org > > Subject: [INTERFACES] getMoreResults() returns false incorrectly > > > > > > [Second submission; first seems to have disappeared.] > > > > I tried to search the list archives, but the search engine appears to be > > broken (comes back with an http 404 error). > > > > Using the Postgresql JDBC driver (I'm testing with jdbc7.0-1.1.jar) it > > appears that Statement.getMoreResults() returns false even if there is a > > result set from the query just executed. > > > > Statement stmt = conn.createStatement(); > > stmt.execute("SELECT * FROM t"); > > if (stmt.getMoreResults()) { > > ResultSet rs = stmt.getResultSet(); > > while (rs.next()) { > > // process row .... > > } > > } > > > > The call to getMoreResults() returns false consistently. If the call is > > replaced with 'if (true) ...' then the code to get the result set and > > process the rows works fine. > > > > Accoring to the JDBC docs, this method should return "true if the next > > result is a ResultSet; false if it is an update count or there are no > > more results." There is no update count (as confirmed by > > getUpdateCount()). > > > > Is this a known problem? If this method doesn't work as documented, > > it's impossible to "work with an unknown SQL string" as the > > documentation for execute() indicates we should be able to (without > > parsing the SQL query). > > > -- Bob Kline mailto:bkline@rksystems.com http://www.rksystems.com