Skip to content

SPR-16556 - Incorrect isGetGeneratedKeysSimulated() return value logic in PostgresTableMetaDataProvider.java #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,49 @@ public PostgresTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws S

@Override
public boolean isGetGeneratedKeysSimulated() {
boolean ret = false;
String version = getDatabaseVersion();
if (version != null && version.compareTo("8.2.0") >= 0) {
return true;

if (version != null) {
String[] versionParts = version.split(".");

int majorVersion = -1;
int minorVersion = -1;

if (versionParts.length > 0) {
try {
majorVersion = Integer.valueOf(versionParts[0]);
if (majorVersion > 8) {
ret = true;
}
else if (majorVersion == 8) {
if (versionParts.length > 1) {
minorVersion = Integer.valueOf(versionParts[1]);
ret = (minorVersion >= 2);
}
else {
ret = false;
}
}
else {
ret = false;
}
}
catch (NumberFormatException e) {
if (logger.isWarnEnabled()) {
logger.warn("Invalid PostgreSQL version format: " + version);
}
ret = false;
}
}
}
else {
if (logger.isWarnEnabled()) {
logger.warn("PostgreSQL does not support getGeneratedKeys or INSERT ... RETURNING in version " +
version);
}
return false;
}
return ret;
}

@Override
Expand Down