[Commits] Rev 409: CONJ-24 - first() is not legal to use with streaming result set, throw exception if it used in file:///H:/bzr/mariadb-java-client/

Vladislav Vaintroub wlad at montyprogram.com
Thu Feb 14 00:05:36 EET 2013


At file:///H:/bzr/mariadb-java-client/

------------------------------------------------------------
revno: 409
revision-id: wlad at montyprogram.com-20130213220529-3nt9agupszq2cufk
parent: wlad at montyprogram.com-20130213162801-tfmiw1lova983zr3
fixes bug: https://mariadb.atlassian.net/browse/CONJ-24
committer: Vladislav Vaintroub <wlad at montyprogram.com>
branch nick: mariadb-java-client
timestamp: Wed 2013-02-13 23:05:29 +0100
message:
  CONJ-24  - first() is not legal to use with streaming result set, throw exception if it used
-------------- next part --------------
=== modified file 'src/main/java/org/mariadb/jdbc/MySQLResultSet.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLResultSet.java	2013-02-13 16:28:01 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLResultSet.java	2013-02-13 22:05:29 +0000
@@ -562,7 +562,8 @@ public class MySQLResultSet implements R
      * @since 1.2
      */
     public boolean isBeforeFirst() throws SQLException {
-        return (queryResult.getResultSetType() == ResultSetType.SELECT  && ((SelectQueryResult) queryResult).isBeforeFirst());
+        return (queryResult.getResultSetType() == ResultSetType.SELECT  
+                && ((SelectQueryResult) queryResult).isBeforeFirst());
     }
 
     /**
@@ -669,12 +670,15 @@ public class MySQLResultSet implements R
      * @since 1.2
      */
     public boolean first() throws SQLException {
-        if (queryResult.getResultSetType() == ResultSetType.SELECT && queryResult.getRows() > 0) {
-             if (!(queryResult instanceof CachedSelectResult)) {
+        if (queryResult.getResultSetType() == ResultSetType.SELECT) {
+            if (!(queryResult instanceof CachedSelectResult)) {
               throw new SQLException("Invalid operation for result set type TYPE_FORWARD_ONLY");
             }
-            ((SelectQueryResult) queryResult).moveRowPointerTo(0);
-            return true;
+             
+            if (queryResult.getRows() > 0) {
+                ((SelectQueryResult) queryResult).moveRowPointerTo(0);
+                return true;
+            }
         }
         return false;
     }

=== modified file 'src/test/java/org/mariadb/jdbc/DriverTest.java'
--- a/src/test/java/org/mariadb/jdbc/DriverTest.java	2013-02-13 16:28:01 +0000
+++ b/src/test/java/org/mariadb/jdbc/DriverTest.java	2013-02-13 22:05:29 +0000
@@ -16,7 +16,6 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import static junit.framework.Assert.*;
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -124,7 +123,21 @@ public class DriverTest extends BaseTest
         assertEquals(2, prepStmt.getParameterMetaData().getParameterCount());
     }
 
-   
+    
+    @Test
+    public void streamingResultSet() throws Exception {
+        Statement stmt = connection.createStatement();
+        stmt.setFetchSize(Integer.MIN_VALUE);
+        ResultSet rs = stmt.executeQuery("SELECT 1");
+        assertTrue(rs.isBeforeFirst());
+        try {
+            rs.first();
+            assertFalse("should not get there", true);
+        }
+        catch (SQLException sqle) {
+            assertTrue(sqle.getMessage().toLowerCase().contains("invalid operation"));
+        }
+    }
     @Test
     public void preparedTest2() throws SQLException {
         Statement stmt = connection.createStatement();



More information about the commits mailing list