Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-812] DatabaseMetadata getBestRowIdentifier pseudo code correcti…
…on for server without IS_GENERATED column in INFORMATION_SCHEMA.COLUMNS
  • Loading branch information
rusher committed Sep 2, 2020
1 parent f3055c7 commit 0954159
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/mariadb/jdbc/MariaDbDatabaseMetaData.java
Expand Up @@ -1068,6 +1068,10 @@ public ResultSet getBestRowIdentifier(
throw new SQLException("'table' parameter cannot be null in getBestRowIdentifier()");
}

boolean hasIsGeneratedCol =
(connection.isServerMariaDb() && connection.versionGreaterOrEqual(10,2, 0))
|| (!connection.isServerMariaDb() && connection.versionGreaterOrEqual(8,0, 0));

String sql =
"SELECT "
+ bestRowSession
Expand All @@ -1076,11 +1080,9 @@ public ResultSet getBestRowIdentifier(
+ " DATA_TYPE, DATA_TYPE TYPE_NAME,"
+ " IF(NUMERIC_PRECISION IS NULL, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION) COLUMN_SIZE, 0 BUFFER_LENGTH,"
+ " NUMERIC_SCALE DECIMAL_DIGITS,"
+ " if(IS_GENERATED='NEVER',"
+ bestRowNotPseudo
+ ","
+ bestRowPseudo
+ ") PSEUDO_COLUMN"
+ ( hasIsGeneratedCol ? ("IF(IS_GENERATED='NEVER'," + bestRowNotPseudo + "," + bestRowPseudo + ")") :
bestRowNotPseudo )
+ " PSEUDO_COLUMN"
+ " FROM INFORMATION_SCHEMA.COLUMNS"
+ " WHERE (COLUMN_KEY = 'PRI'"
+ " OR (COLUMN_KEY = 'UNI' AND NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_KEY = "
Expand Down

0 comments on commit 0954159

Please sign in to comment.