Skip to content

Commit 7811fae

Browse files
committed
fix dialect detection
1 parent b50c060 commit 7811fae

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

wrapper/src/main/java/software/amazon/jdbc/dialect/GlobalAuroraMysqlDialect.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class GlobalAuroraMysqlDialect extends AuroraMysqlDialect {
3232
"SELECT 1 AS tmp FROM information_schema.tables WHERE"
3333
+ " upper(table_schema) = 'INFORMATION_SCHEMA' AND upper(table_name) = 'AURORA_GLOBAL_DB_STATUS'";
3434

35+
protected final String globalDbStatusQuery =
36+
"SELECT count(1) FROM information_schema.aurora_global_db_status";
37+
3538
protected final String globalDbInstanceStatusTableExistQuery =
3639
"SELECT 1 AS tmp FROM information_schema.tables WHERE"
3740
+ " upper(table_schema) = 'INFORMATION_SCHEMA' AND upper(table_name) = 'AURORA_GLOBAL_DB_INSTANCE_STATUS'";
@@ -59,7 +62,18 @@ public boolean isDialect(final Connection connection) {
5962
stmt = connection.createStatement();
6063
rs = stmt.executeQuery(this.globalDbInstanceStatusTableExistQuery);
6164

62-
return rs.next();
65+
if (rs.next()) {
66+
rs.close();
67+
stmt.close();
68+
69+
stmt = connection.createStatement();
70+
rs = stmt.executeQuery(this.globalDbStatusQuery);
71+
72+
if (rs.next()) {
73+
int awsRegionCount = rs.getInt(1);
74+
return awsRegionCount > 1;
75+
}
76+
}
6377
}
6478
return false;
6579
} catch (final SQLException ex) {

wrapper/src/main/java/software/amazon/jdbc/dialect/GlobalAuroraPgDialect.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class GlobalAuroraPgDialect extends AuroraPgDialect {
4242
+ "VISIBILITY_LAG_IN_MSEC, AWS_REGION "
4343
+ "FROM aurora_global_db_instance_status()";
4444

45+
protected final String globalDbStatusQuery =
46+
"SELECT count(1) FROM aurora_global_db_status()";
47+
4548
protected final String regionByNodeIdQuery =
4649
"SELECT AWS_REGION FROM aurora_global_db_instance_status() WHERE SERVER_ID = ?";
4750

@@ -72,7 +75,18 @@ public boolean isDialect(final Connection connection) {
7275
stmt = connection.createStatement();
7376
rs = stmt.executeQuery(this.globalDbInstanceStatusFuncExistQuery);
7477

75-
return rs.next();
78+
if (rs.next()) {
79+
rs.close();
80+
stmt.close();
81+
82+
stmt = connection.createStatement();
83+
rs = stmt.executeQuery(this.globalDbStatusQuery);
84+
85+
if (rs.next()) {
86+
int awsRegionCount = rs.getInt(1);
87+
return awsRegionCount > 1;
88+
}
89+
}
7690
}
7791
return false;
7892
} catch (final SQLException ex) {

0 commit comments

Comments
 (0)