From f9837de31479152d8c29f06222bac3f5541b60b3 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 19 Mar 2014 19:51:00 +0100 Subject: Add basic support for CURRENT_TIMESTAMP in DATETIME columns (MySQL 5.6.5) See #1867 --- Source/SPSQLExporter.m | 2 +- Source/SPTableData.m | 2 +- Source/SPTableStructure.m | 4 ++-- Source/SPTableStructureLoading.m | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'Source') diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m index 03958f32..649e4ac3 100644 --- a/Source/SPSQLExporter.m +++ b/Source/SPSQLExporter.m @@ -884,7 +884,7 @@ [fieldString appendString:@" DEFAULT NULL"]; } } - else if ([[column objectForKey:@"type"] isEqualToString:@"TIMESTAMP"] && [column objectForKey:@"default"] != [NSNull null] && [[[column objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) { + else if (([[column objectForKey:@"type"] isEqualToString:@"TIMESTAMP"] || [[column objectForKey:@"type"] isEqualToString:@"DATETIME"]) && [column objectForKey:@"default"] != [NSNull null] && [[[column objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) { [fieldString appendString:@" DEFAULT CURRENT_TIMESTAMP"]; } else { diff --git a/Source/SPTableData.m b/Source/SPTableData.m index e4945305..5158d4be 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -1343,7 +1343,7 @@ [detailParser release]; definitionPartsIndex++; - // Special timestamp case - Whether fields are set to update the current timestamp + // Special timestamp/datetime case - Whether fields are set to update the current timestamp } else if ([detailString isEqualToString:@"ON"] && (definitionPartsIndex + 2 < partsArrayLength) && [[NSArrayObjectAtIndex(definitionParts, definitionPartsIndex+1) uppercaseString] isEqualToString:@"UPDATE"] && [[NSArrayObjectAtIndex(definitionParts, definitionPartsIndex+2) uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) { diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index b2675271..807ff1ae 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -856,8 +856,8 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey"; [queryString appendString:@"\n DEFAULT NULL"]; } } - // Otherwise, if CURRENT_TIMESTAMP was specified for timestamps, use that - else if ([theRowType isEqualToString:@"TIMESTAMP"] && + // Otherwise, if CURRENT_TIMESTAMP was specified for timestamps/datetimes, use that + else if (([theRowType isEqualToString:@"TIMESTAMP"] || [theRowType isEqualToString:@"DATETIME"]) && [[[theRow objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) { [queryString appendString:@"\n DEFAULT CURRENT_TIMESTAMP"]; diff --git a/Source/SPTableStructureLoading.m b/Source/SPTableStructureLoading.m index 399176c2..07656155 100644 --- a/Source/SPTableStructureLoading.m +++ b/Source/SPTableStructureLoading.m @@ -247,8 +247,9 @@ [theField setObject:@"auto_increment" forKey:@"Extra"]; } - // For timestamps check to see whether "on update CURRENT_TIMESTAMP" and set Extra accordingly - else if ([type isEqualToString:@"TIMESTAMP"] && [[theField objectForKey:@"onupdatetimestamp"] integerValue]) { + // For timestamps/datetime check to see whether "on update CURRENT_TIMESTAMP" and set Extra accordingly + else if (([type isEqualToString:@"TIMESTAMP"] || [type isEqualToString:@"DATETIME"]) && + [[theField objectForKey:@"onupdatetimestamp"] integerValue]) { [theField setObject:@"on update CURRENT_TIMESTAMP" forKey:@"Extra"]; } } -- cgit v1.2.3