Skip to content

Commit

Permalink
0004065: Allow zero date on MySQL or convert to null otherwise (3.10)
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Aug 8, 2019
1 parent e74334b commit ffa2568
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Expand Up @@ -84,6 +84,7 @@ public abstract class AbstractDatabasePlatform implements IDatabasePlatform {

public static final String REQUIRED_FIELD_NULL_SUBSTITUTE = " ";

public static final String ZERO_DATE_STRING = "0000-00-00 00:00:00";
/*
* The default name for models read from the database, if no name as given.
*/
Expand Down Expand Up @@ -926,6 +927,9 @@ public java.util.Date parseTimestamp(int type, String value) {
try {
return Timestamp.valueOf(value);
} catch (IllegalArgumentException ex) {
if (!getDatabaseInfo().isZeroDateAllowed() && value != null && value.startsWith(ZERO_DATE_STRING)) {
return null;
}
try {
return new Timestamp(FormatUtils.parseDate(value, FormatUtils.TIMESTAMP_PATTERNS).getTime());
} catch (Exception e) {
Expand Down
Expand Up @@ -275,6 +275,8 @@ public class DatabaseInfo {

private boolean notNullColumnsSupported = true;

private boolean zeroDateAllowed;

/**
* Creates a new platform info object.
*/
Expand Down Expand Up @@ -1357,5 +1359,12 @@ public void setNotNullColumnsSupported(boolean notNullColumnsSupported) {
this.notNullColumnsSupported = notNullColumnsSupported;
}


public boolean isZeroDateAllowed() {
return zeroDateAllowed;
}

public void setZeroDateAllowed(boolean zeroDateAllowed) {
this.zeroDateAllowed = zeroDateAllowed;
}

}
Expand Up @@ -65,6 +65,7 @@ public MySqlDdlBuilder() {
// Double quotes are only allowed for delimiting identifiers if the
// server SQL mode includes ANSI_QUOTES
databaseInfo.setDelimiterToken("`");
databaseInfo.setZeroDateAllowed(true);

databaseInfo.addNativeTypeMapping(Types.ARRAY, "LONGBLOB", Types.LONGVARBINARY);
databaseInfo.addNativeTypeMapping(Types.BIT, "BIT");
Expand Down

0 comments on commit ffa2568

Please sign in to comment.