Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-263] Exception must be throwing exception if exception append i…
…n multiple query
  • Loading branch information
rusher committed Mar 7, 2016
1 parent 6634fa5 commit c02b379
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/mariadb/jdbc/MariaDbStatement.java
Expand Up @@ -196,7 +196,7 @@ void executeQueryProlog() throws SQLException {
}
}

protected void cacheMoreResults() {
protected void cacheMoreResults() throws SQLException {
if (isStreaming()) {
return;
}
Expand All @@ -210,8 +210,7 @@ protected void cacheMoreResults() {
break;
}
} catch (QueryException e) {
cachedResultSets.add(ExceptionMapper.createException(e, connection, this));
break;
throw ExceptionMapper.createException(e, connection, this);
}
}
queryResult = saveResult;
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/mariadb/jdbc/CallableStatementTest.java
Expand Up @@ -25,6 +25,11 @@ public static void initClass() throws SQLException {
createProcedure("inoutParam", "(INOUT p1 INT) begin set p1 = p1 + 1; end\n");
createProcedure("testGetProcedures", "(INOUT p1 INT) begin set p1 = p1 + 1; end\n");
createProcedure("withStrangeParameter", "(IN a DECIMAL(10,2)) begin select a; end");
createProcedure("TEST_SP1", "() BEGIN\n"
+ "SELECT @Something := 'Something';\n"
+ "SIGNAL SQLSTATE '70100'\n"
+ "SET MESSAGE_TEXT = 'Test error from SP'; \n"
+ "END");
}

@Before
Expand Down Expand Up @@ -137,4 +142,24 @@ public void withStrangeParameter() throws SQLException {
rs.close();
stmt.close();
}

/**
* CONJ-263: Error in stored procedure or SQL statement with allowMultiQueries does not raise Exception
* when there is a result returned prior to erroneous statement.
*
* @throws SQLException exception
*/
@Test
public void testCallExecuteErrorBatch() throws SQLException {
CallableStatement cStmt = sharedConnection.prepareCall("{call TEST_SP1()}");
try {
cStmt.execute();
fail("Must have thrown error");
} catch (SQLException sqle) {
//must have thrown error.
assertTrue(sqle.getMessage().contains("Test error from SP"));
}
}


}
19 changes: 19 additions & 0 deletions src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
Expand Up @@ -151,4 +151,23 @@ public void testExecuteBatch() throws SQLException {
}

}


/**
* CONJ-263: Exception must be throwing exception if exception append in multiple query
*
* @throws SQLException exception
*/
@Test
public void testCallExecuteErrorBatch() throws SQLException {
PreparedStatement pstmt = sharedConnection.prepareStatement("SELECT 1;INSERT INTO INCORRECT_QUERY ;");
try {
pstmt.execute();
fail("Must have thrown error");
} catch (SQLException sqle) {
//must have thrown error.
assertTrue(sqle.getMessage().contains("INSERT INTO INCORRECT_QUERY"));
}
}

}

0 comments on commit c02b379

Please sign in to comment.