Changeset: bac87d4ed683 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bac87d4ed683 Modified Files: java/ChangeLog.Apr2011 java/src/nl/cwi/monetdb/jdbc/MonetStatement.java java/tests/Test_Smoreresults.java java/tests/build.xml Branch: Apr2011 Log Message:
Statement: fix getMoreResults() NullPointerException on unitialised Statement Return false from Statement.getMoreResults() instead of a NullPointerException when no query has been performed on the Statement yet, bug #2833 diffs (124 lines): diff --git a/java/ChangeLog.Apr2011 b/java/ChangeLog.Apr2011 --- a/java/ChangeLog.Apr2011 +++ b/java/ChangeLog.Apr2011 @@ -1,6 +1,11 @@ # ChangeLog file for java # This file is updated with Maddlog +* Fri Jul 8 2011 Fabian Groffen <[email protected]> +- Return false from Statement.getMoreResults() instead of a + NullPointerException when no query has been performed on the Statement + yet, bug #2833 + * Mon Jun 6 2011 Fabian Groffen <[email protected]> - Fixed read-only interpretation. Connection.isReadOnly now always returns false, setReadOnly now generates a warning when called with diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java b/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java @@ -766,6 +766,12 @@ * @throws SQLException if a database access error occurs */ public boolean getMoreResults(int current) throws SQLException { + // protect against people calling this on an unitialised state + if (lastResponseList == null) { + header = null; + return(false); + } + if (current == CLOSE_CURRENT_RESULT) { lastResponseList.closeCurrentResponse(); } else if (current == CLOSE_ALL_RESULTS) { diff --git a/java/tests/Test_Smoreresults.java b/java/tests/Test_Smoreresults.java new file mode 100644 --- /dev/null +++ b/java/tests/Test_Smoreresults.java @@ -0,0 +1,64 @@ +/* + * The contents of this file are subject to the MonetDB Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is the MonetDB Database System. + * + * The Initial Developer of the Original Code is CWI. + * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. + * Copyright August 2008-2011 MonetDB B.V. + * All Rights Reserved. + */ + +import java.sql.*; + +public class Test_Smoreresults { + public static void main(String[] args) throws Exception { + Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); + Connection con = DriverManager.getConnection(args[0]); + Statement stmt = con.createStatement(); + ResultSet rs = null; + //DatabaseMetaData dbmd = con.getMetaData(); + + // >> true: auto commit should be on by default + System.out.println("0. true\t" + con.getAutoCommit()); + + try { + System.out.print("1. more results?..."); + if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) + throw new SQLException("more results on an unitialised Statement, how can that be?"); + System.out.println(" nope :)"); + + System.out.print("2. SELECT 1..."); + if (stmt.execute("SELECT 1;") == false) + throw new SQLException("SELECT 1 returns update or no results"); + System.out.println(" ResultSet :)"); + + System.out.print("3. more results?..."); + if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) + throw new SQLException("more results after SELECT 1 query, how can that be?"); + System.out.println(" nope :)"); + + System.out.print("4. even more results?..."); + if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) + throw new SQLException("more results after SELECT 1 query, how can that be?"); + System.out.println(" nope :)"); + + } catch (SQLException e) { + // this means we failed (table not there perhaps?) + System.out.println("FAILED :( " + e.getMessage()); + System.out.println("ABORTING TEST!!!"); + } + + if (rs != null) rs.close(); + + con.close(); + } +} diff --git a/java/tests/build.xml b/java/tests/build.xml --- a/java/tests/build.xml +++ b/java/tests/build.xml @@ -120,6 +120,7 @@ <antcall target="Test_Rpositioning" /> <antcall target="Test_Rtimedate" /> <antcall target="Test_Sbatching" /> + <antcall target="Test_Smoreresults" /> <antcall target="BugConcurrent_clients_SF_1504657" /> <antcall target="BugConcurrent_sequences" /> </target> @@ -186,6 +187,12 @@ </antcall> </target> + <target name="Test_Smoreresults"> + <antcall target="test_class"> + <param name="test.class" value="Test_Smoreresults" /> + </antcall> + </target> + <target name="Test_PSgeneratedkeys"> <antcall target="test_class"> <param name="test.class" value="Test_PSgeneratedkeys" /> _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
