Skip to content

Commit

Permalink
Fixed #3971: "SAP SQL Anywhere 17.0.11: Liquibase incorrectly reports…
Browse files Browse the repository at this point in the history
… that TIMESTAMP requested precision is longer than TIMESTAMP supported precision" (#4422)

* Fixed #3971: SAP SQL Anywhere 17.0.11: Liquibase incorrectly reports that TIMESTAMP requested precision is longer than TIMESTAMP supported precision

* Fixed Typo

There was a closing angle missing when fixing the merge conflict.
  • Loading branch information
mkarg committed Jul 6, 2023
1 parent b38b059 commit 25ad76a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<runningAs username="${loginUser}"/>
</preConditions>

<changeSet id="test-timestamp-with-timezone" author="mkarg">
<createTable tableName="SomeTableWithSomeTimezonedColumn">
<column defaultValueComputed="CURRENT UTC TIMESTAMP" name="someTimezonedColumn" type="TIMESTAMP WITH TIME ZONE" />
</createTable>
</changeSet>

<changeSet id="1" author="nvoxland">
<comment>
You can add comments to changeSets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@
</changeSet>

<changeSet id="timestamp_column_precision9" author="abuschka"
dbms="db2,derby,firebird,h2,hsqldb,informix,mssql,oracle,sqlite,asany,sybase">
dbms="db2,derby,firebird,h2,hsqldb,informix,mssql,oracle,sqlite,sybase">
<comment>Test if we (and the JDBC driver) correctly support TIMESTAMP columns with a extra-large precision
of 9 for supported DBMS.
</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,13 @@ public boolean requiresExplicitNullForColumns() {
*/
return true;
}

@Override
public int getMaxFractionalDigitsForTimestamp() {
/*
* SQL Anywhere statically uses exactly 6 decimal places for the fraction.
* See: https://help.sap.com/docs/SAP_SQL_Anywhere/93079d4ba8e44920ae63ffb4def91f5b/81fe344c6ce21014a4f29d9e0af358b9.html
*/
return 6;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public DatabaseDataType toDatabaseDataType(Database database) {
*/
DatabaseDataType type;

if (getParameters().length > 0) {
if (getParameters().length > 0 && !(database instanceof SybaseASADatabase)) {
int fractionalDigits = 0;
String fractionalDigitsInput = getParameters()[0].toString();
try {
Expand Down Expand Up @@ -130,9 +130,12 @@ public DatabaseDataType toDatabaseDataType(Database database) {
&& (database instanceof PostgresDatabase
|| database instanceof OracleDatabase
|| database instanceof H2Database
|| database instanceof HsqlDatabase)) {
|| database instanceof HsqlDatabase
|| database instanceof SybaseASADatabase)) {

if (database instanceof PostgresDatabase || database instanceof H2Database) {
if (database instanceof PostgresDatabase
|| database instanceof H2Database
|| database instanceof SybaseASADatabase) {
type.addAdditionalInformation("WITH TIME ZONE");
} else {
type.addAdditionalInformation("WITH TIMEZONE");
Expand All @@ -145,12 +148,14 @@ public DatabaseDataType toDatabaseDataType(Database database) {
&& (database instanceof PostgresDatabase
|| database instanceof OracleDatabase)
|| database instanceof H2Database
|| database instanceof HsqlDatabase){
|| database instanceof HsqlDatabase
|| database instanceof SybaseASADatabase){
String additionalInformation = this.getAdditionalInformation();

if (additionalInformation != null) {
String additionInformation = additionalInformation.toUpperCase(Locale.US);
if ((database instanceof PostgresDatabase || database instanceof H2Database) && additionInformation.toUpperCase(Locale.US).contains("TIMEZONE")) {
if ((database instanceof PostgresDatabase || database instanceof H2Database || database instanceof SybaseASADatabase)
&& additionInformation.toUpperCase(Locale.US).contains("TIMEZONE")) {
additionalInformation = additionInformation.toUpperCase(Locale.US).replace("TIMEZONE", "TIME ZONE");
}
// CORE-3229 Oracle 11g doesn't support WITHOUT clause in TIMESTAMP data type
Expand All @@ -163,6 +168,11 @@ public DatabaseDataType toDatabaseDataType(Database database) {
// http://www.h2database.com/html/datatypes.html
additionalInformation = null;
}

if ((database instanceof SybaseASADatabase) && additionInformation.startsWith("WITHOUT")) {
// https://help.sap.com/docs/SAP_SQL_Anywhere/93079d4ba8e44920ae63ffb4def91f5b/81fe3e6b6ce2101487d8acce02f6aba5.html
additionalInformation = null;
}
}

type.addAdditionalInformation(additionalInformation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ protected DataType readDataType(CachedRow columnMetadataResultSet, Column column
*/
int jdbcType = columnMetadataResultSet.getInt("DATA_TYPE");

// Java 8 compatibility notes: When upgrading this project to JDK8 and beyond, also execute this if-branch
// if jdbcType is TIMESTAMP_WITH_TIMEZONE (does not exist yet in JDK7)
if (jdbcType == Types.TIMESTAMP) {
if (jdbcType == Types.TIMESTAMP || jdbcType == Types.TIMESTAMP_WITH_TIMEZONE
// SQL Anywhere incorrectly reports type VARCHAR for TIMESTAMP_WITZH_TIMEZONE columns
|| (database instanceof SybaseASADatabase && "timestamp with time zone".equalsIgnoreCase(columnTypeName))) {

if (decimalDigits == null) {
type.setColumnSize(null);
Expand Down

0 comments on commit 25ad76a

Please sign in to comment.