Skip to content

Commit

Permalink
Set max fractional timestamp digits to 12 for all DB2 editions (fix #…
Browse files Browse the repository at this point in the history
…2880) (#2892)

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

Co-authored-by: ctg <ctg@LAPTOP-50VTJSGN>
  • Loading branch information
ctgnz and ctg committed Jul 28, 2022
1 parent bf60120 commit 7e825f5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
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());
}

}

0 comments on commit 7e825f5

Please sign in to comment.