Skip to content

Commit

Permalink
Remove current date and time from ColumnDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jun 9, 2023
1 parent 6c1ea4b commit fca3ee5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/mysql/def/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ pub enum ColumnDefault {
Double(f64),
String(String),
Null,
CurrentDate,
CurrentTime,
CurrentTimestamp,
}

Expand Down
21 changes: 3 additions & 18 deletions src/mysql/parser/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,8 @@ pub fn parse_column_default(
}

pub fn parse_mysql_5_default(default: String, col_type: &Type) -> ColumnDefault {
let is_date_time_col = matches!(
col_type,
Type::Date | Type::DateTime(_) | Type::Timestamp(_)
);
if is_date_time_col && default == "CURRENT_DATE" {
ColumnDefault::CurrentDate
} else if is_date_time_col && default == "CURRENT_TIME" {
ColumnDefault::CurrentTime
} else if is_date_time_col && default == "CURRENT_TIMESTAMP" {
let is_date_time_col = matches!(col_type, Type::Timestamp(_));
if is_date_time_col && default == "CURRENT_TIMESTAMP" {
ColumnDefault::CurrentTimestamp
} else if let Ok(int) = default.parse::<i32>() {
ColumnDefault::Int(int)
Expand All @@ -309,11 +302,7 @@ pub fn parse_mysql_5_default(default: String, col_type: &Type) -> ColumnDefault

pub fn parse_mysql_8_default(default: String, extra: &str) -> ColumnDefault {
let is_expression = extra == "DEFAULT_GENERATED";
if is_expression && default == "CURRENT_DATE" {
ColumnDefault::CurrentDate
} else if is_expression && default == "CURRENT_TIME" {
ColumnDefault::CurrentTime
} else if is_expression && default == "CURRENT_TIMESTAMP" {
if is_expression && default == "CURRENT_TIMESTAMP" {
ColumnDefault::CurrentTimestamp
} else if let Ok(int) = default.parse::<i32>() {
ColumnDefault::Int(int)
Expand All @@ -331,10 +320,6 @@ pub fn parse_mariadb_10_default(default: String) -> ColumnDefault {
ColumnDefault::Int(int)
} else if let Ok(double) = default.parse::<f64>() {
ColumnDefault::Double(double)
} else if default == "current_date()" {
ColumnDefault::CurrentDate
} else if default == "current_time()" {
ColumnDefault::CurrentTime
} else if default == "current_timestamp()" {
ColumnDefault::CurrentTimestamp
} else if default == "NULL" {
Expand Down
2 changes: 0 additions & 2 deletions src/mysql/writer/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ impl ColumnInfo {
ColumnDefault::Double(double) => (*double).into(),
ColumnDefault::String(string) => string.into(),
ColumnDefault::Null => Option::<bool>::None.into(),
ColumnDefault::CurrentDate => Keyword::CurrentDate.into(),
ColumnDefault::CurrentTime => Keyword::CurrentTime.into(),
ColumnDefault::CurrentTimestamp => Keyword::CurrentTimestamp.into(),
};
col_def.default(default_expr);
Expand Down

0 comments on commit fca3ee5

Please sign in to comment.