Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-238] PrepareStatement prepare exception handling when using tem…
…porary tables.
  • Loading branch information
rusher committed Dec 31, 2015
1 parent 008c6e7 commit 8cb011c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/org/mariadb/jdbc/MariaDbConnection.java
Expand Up @@ -372,7 +372,12 @@ public PreparedStatement prepareStatement(final String sql, final String[] colum
public PreparedStatement internalPrepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
checkConnection();
if (!options.allowMultiQueries && !options.rewriteBatchedStatements && options.useServerPrepStmts && checkIfPreparable(sql)) {
return new MariaDbServerPreparedStatement(this, sql, autoGeneratedKeys);
try {
return new MariaDbServerPreparedStatement(this, sql, autoGeneratedKeys);
} catch (SQLException e) {
//on some specific case, server cannot prepared data (CONJ-238)
return new MariaDbClientPreparedStatement(this, sql, autoGeneratedKeys);
}
}
return new MariaDbClientPreparedStatement(this, sql, autoGeneratedKeys);
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
Expand Up @@ -30,6 +30,7 @@ public static void initClass() throws SQLException {
+ "`Seems:LikeParam?` bit(1) DEFAULT NULL,"
+ "`Webinar10-TM/ProjComp` text",
"ENGINE=InnoDB DEFAULT CHARSET=utf8");
createTable("test_insert_select","`field1` varchar(20)");
}

@Test
Expand All @@ -40,6 +41,19 @@ public void testClosingError() throws Exception {

}

/**
* Conj-238.
*
* @throws SQLException exception
*/
@org.junit.Test
public void insertSelect() throws Exception {
PreparedStatement stmt = sharedConnection.prepareStatement(
"insert into test_insert_select ( field1) (select TMP.field1 from (select ? `field1` from dual) TMP)");
stmt.setString(1, "test");
stmt.executeUpdate();
}

/**
* Conj-90.
*
Expand Down

0 comments on commit 8cb011c

Please sign in to comment.