Skip to content
Permalink
Browse files

0004064: Allow zero date on MySQL or convert to null otherwise

  • Loading branch information...
erilong committed Aug 8, 2019
1 parent 1e42f88 commit 8d6d47609289086cfe0bf2b4978aa936a9e414ea
@@ -76,6 +76,7 @@

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.
*/
@@ -868,6 +869,9 @@ public boolean canColumnBeUsedInWhereClause(Column column) {
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) {
@@ -275,6 +275,8 @@

private boolean notNullColumnsSupported = true;

private boolean zeroDateAllowed;

/**
* Creates a new platform info object.
*/
@@ -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;
}

}
@@ -38,7 +38,6 @@
import org.jumpmind.db.model.Database;
import org.jumpmind.db.model.ForeignKey;
import org.jumpmind.db.model.IIndex;
import org.jumpmind.db.model.IndexColumn;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.AbstractDdlBuilder;
import org.jumpmind.db.platform.DatabaseNamesConstants;
@@ -65,6 +64,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");

0 comments on commit 8d6d476

Please sign in to comment.
You can’t perform that action at this time.