Skip to content

Commit a87e4a4

Browse files
committed
Merge branch 'maintenance/3.3' into maintenance/3.4
# Conflicts: # src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java # src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java # src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java
2 parents 349d707 + 471b54a commit a87e4a4

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ protected boolean executeInternalPreparedBatch() throws SQLException {
126126
&& ((isNormalInsert && (conf.useBulkStmts() || conf.useBulkStmtsForInserts()))
127127
|| (!clientParser.isInsert() && conf.useBulkStmts()))
128128
&& batchParameters.size() > 1
129+
&& batchParameters.get(0).size() > 0
129130
&& !clientParser.isMultiQuery()
130131
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
131132
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS)) {

src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ protected boolean executeInternalPreparedBatch() throws SQLException {
181181
if (((isNormalInsert && (conf.useBulkStmts() || conf.useBulkStmtsForInserts()))
182182
|| (!clientParser.isInsert() && conf.useBulkStmts()))
183183
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
184-
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS)) {
184+
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS)
185+
&& batchParameters.get(0).size() > 0) {
185186
executeBatchBulk(cmd);
186187
return true;
187188
} else {

src/test/java/org/mariadb/jdbc/integration/BatchTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,36 @@ public String toString() {
726726
return "TimestampCal{" + "val=" + val + ", id=" + id + '}';
727727
}
728728
}
729+
730+
731+
@Test
732+
public void batchWithoutParameter() throws SQLException {
733+
try (Connection con = createCon("&useServerPrepStmts=false&useBulkStmts=true")) {
734+
batchWithoutParameter(con);
735+
}
736+
try (Connection con = createCon("&useServerPrepStmts=true&useBulkStmts=true")) {
737+
batchWithoutParameter(con);
738+
}
739+
}
740+
741+
private void batchWithoutParameter(Connection con) throws SQLException {
742+
Assumptions.assumeTrue(isMariaDBServer());
743+
Statement stmt = con.createStatement();
744+
stmt.execute("DROP TABLE IF EXISTS batchWithoutParameter");
745+
stmt.setFetchSize(3);
746+
stmt.execute("CREATE TABLE batchWithoutParameter(val varchar(10))");
747+
try (PreparedStatement prep =
748+
con.prepareStatement("INSERT INTO batchWithoutParameter VALUES ('')")) {
749+
prep.addBatch();
750+
prep.addBatch();
751+
prep.addBatch();
752+
prep.addBatch();
753+
prep.executeBatch();
754+
755+
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM batchWithoutParameter");
756+
rs.next();
757+
assertEquals(rs.getInt(1), 4);
758+
}
759+
}
760+
729761
}

src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ public void createDatabaseIfNotExist() throws SQLException {
11801180
// ensure connecting without DB
11811181
String connStr =
11821182
String.format(
1183-
"jdbc:mariadb://%s:%s/?user=%s&password=%s&%s&createDatabaseIfNotExist",
1183+
"jdbc:mariadb://%s:%s/?user=%s&password=%s&%s&createDatabaseIfNotExist&allowPublicKeyRetrieval=true",
11841184
hostname, port, user, password, defaultOther);
11851185
try (Connection con = DriverManager.getConnection(connStr)) {
11861186
con.createStatement().executeQuery("SELECT 1");
@@ -1189,7 +1189,7 @@ public void createDatabaseIfNotExist() throws SQLException {
11891189
String nonExistentDatabase = "bla`f`l";
11901190
connStr =
11911191
String.format(
1192-
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&%s&createDatabaseIfNotExist",
1192+
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&%s&createDatabaseIfNotExist&allowPublicKeyRetrieval=true",
11931193
hostname, port, nonExistentDatabase, user, password, defaultOther);
11941194
try (Connection con = DriverManager.getConnection(connStr)) {
11951195
ResultSet rs = con.createStatement().executeQuery("select DATABASE()");
@@ -1200,7 +1200,7 @@ public void createDatabaseIfNotExist() throws SQLException {
12001200
nonExistentDatabase = "bla`f`l0";
12011201
connStr =
12021202
String.format(
1203-
"jdbc:mariadb:replication://%s:%s,%s:%s/%s?user=%s&password=%s&%s&createDatabaseIfNotExist",
1203+
"jdbc:mariadb:replication://%s:%s,%s:%s/%s?user=%s&password=%s&%s&createDatabaseIfNotExist&allowPublicKeyRetrieval=true",
12041204
hostname, port, hostname, port, nonExistentDatabase, user, password, defaultOther);
12051205
try (Connection con = DriverManager.getConnection(connStr)) {
12061206
ResultSet rs = con.createStatement().executeQuery("select DATABASE()");

src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void basic() throws SQLException {
2626

2727
MariaDbDataSource ds2 = new MariaDbDataSource();
2828
ds2.setUrl(mDefUrl);
29-
ds2.setPassword("ttt");
29+
ds2.setPassword(System.getenv("someP@ssword"));
3030
ds2.setUser("ttt");
3131
assertThrows(SQLException.class, ds2::getConnection);
3232
}
@@ -115,16 +115,15 @@ public void basic2() throws SQLException {
115115
ds.setUser("dd");
116116
assertEquals("dd", ds.getUser());
117117

118-
ds.setPassword("pwd");
118+
ds.setPassword(System.getenv("someOtherP@ssword"));
119119
assertThrows(SQLException.class, ds::getConnection);
120120
assertThrows(SQLException.class, ds::getPooledConnection);
121121

122122
assertThrows(SQLException.class, () -> ds.setUrl("jdbc:wrong://d"));
123123

124124
ds.setUrl("jdbc:mariadb://myhost:5500/db?someOption=val");
125125
assertEquals(
126-
"jdbc:mariadb://myhost:5500/db?user=dd&password=***&someOption=val&connectTimeout=50000",
127-
ds.getUrl());
126+
"jdbc:mariadb://myhost:5500/db?user=dd&someOption=val&connectTimeout=50000", ds.getUrl());
128127
}
129128

130129
@Test

0 commit comments

Comments
 (0)