Skip to content
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

Set max fractional timestamp digits to 12 for all DB2 editions (fix #2880) #2892

Merged
merged 2 commits into from Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,7 +24,9 @@

public abstract class AbstractDb2Database extends AbstractJdbcDatabase {

public AbstractDb2Database() {
private static final int MAX_DB2_TIMESTAMP_FRACTIONAL_DIGITS = 12;

public AbstractDb2Database() {
super.setCurrentDateTimeFunction("CURRENT TIMESTAMP");
super.sequenceNextValueFunction = "NEXT VALUE FOR %s";
super.sequenceCurrentValueFunction = "PREVIOUS VALUE FOR %s";
Expand Down Expand Up @@ -235,4 +237,19 @@ protected boolean mustQuoteObjectName(String objectName, Class<? extends Databas
public CatalogAndSchema.CatalogAndSchemaCase getSchemaAndCatalogCase() {
return CatalogAndSchema.CatalogAndSchemaCase.ORIGINAL_CASE;
}

@Override
public int getMaxFractionalDigitsForTimestamp() {
try {
// See https://www.ibm.com/docs/en/db2/9.7?topic=enhancements-timestamp-data-type-allows-parameterized-precision
// Max precision for timestamp is 12 digits in all editions of DB from version 9.7 onwards
if (getDatabaseMajorVersion() > 9 || getDatabaseMajorVersion() == 9 && getDatabaseMinorVersion() >= 7) {
return MAX_DB2_TIMESTAMP_FRACTIONAL_DIGITS;
} else {
return super.getMaxFractionalDigitsForTimestamp();
}
} catch (Exception e) {
return super.getMaxFractionalDigitsForTimestamp();
}
}
}
Expand Up @@ -9,11 +9,7 @@

public class Db2zDatabase extends AbstractDb2Database {

// See https://www.ibm.com/support/knowledgecenter/en/SSEPEK_11.0.0/sqlref/src/tpc/db2z_limits.html#db2z_limits__limdt,
// may not apply to older versions, caveat emptor
private static final int MAX_DB2Z_TIMESTAMP_FRACTIONAL_DIGITS = 12;

public Db2zDatabase() {
public Db2zDatabase() {
super.setCurrentDateTimeFunction("CURRENT TIMESTAMP");
super.sequenceNextValueFunction = "NEXT VALUE FOR %s";
super.sequenceCurrentValueFunction = "PREVIOUS VALUE FOR %s";
Expand Down Expand Up @@ -51,9 +47,4 @@ public boolean isSystemObject(DatabaseObject example) {
protected String getDefaultDatabaseProductName() {
return "DB2/z";
}

@Override
public int getMaxFractionalDigitsForTimestamp() {
return MAX_DB2Z_TIMESTAMP_FRACTIONAL_DIGITS;
}
}
Expand Up @@ -16,4 +16,10 @@ public void testGetDefaultDriver() throws DatabaseException {
}
}

public void testMaxFractionDigits() {
Database database = new DB2Database();
assertEquals(12, database.getMaxFractionalDigitsForTimestamp());
}


}
Expand Up @@ -16,4 +16,9 @@ public void testGetDefaultDriver() throws DatabaseException {
}
}

public void testMaxFractionDigits() {
Database database = new Db2zDatabase();
assertEquals(12, database.getMaxFractionalDigitsForTimestamp());
}

}