diff options
author | Max <post@wickenrode.com> | 2015-11-03 17:46:12 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-11-03 17:49:22 +0100 |
commit | 945f6c56aa6a8cb10be924cc3331789c10e53e57 (patch) | |
tree | 8db0f277be0b9c9984cf0c9672dbe1000f3efccc /Source | |
parent | 7c7660b66d4c47a43de8b1a42dba6c787b44c0cc (diff) | |
download | sequelpro-945f6c56aa6a8cb10be924cc3331789c10e53e57.tar.gz sequelpro-945f6c56aa6a8cb10be924cc3331789c10e53e57.tar.bz2 sequelpro-945f6c56aa6a8cb10be924cc3331789c10e53e57.zip |
Support fractional seconds for CURRENT_TIMESTAMP in the default column (part of #2315)
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPTableStructure.m | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index 319e74ec..5594934b 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -852,7 +852,7 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey"; // Don't provide any defaults for auto-increment fields if (![theRowExtra isEqualToString:@"AUTO_INCREMENT"]) { - + NSArray *matches; // If a NULL value has been specified, and NULL is allowed, specify DEFAULT NULL if ([[theRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { @@ -862,10 +862,15 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey"; } // 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"]) + [(matches = [[[theRow objectForKey:@"default"] uppercaseString] captureComponentsMatchedByRegex:@"^\\s*CURRENT_TIMESTAMP(?:\\s*\\(\\s*(\\d+)\\s*\\))?\\s*$"]) count]) { [queryString appendString:@"\n DEFAULT CURRENT_TIMESTAMP"]; - + NSString *userLen = [matches objectAtIndex:1]; + //mysql 5.6.4+ allows DATETIME(n) for fractional seconds, which in turn requires CURRENT_TIMESTAMP(n). + // Also, if the user explicitly added one we should never ignore that. + if([userLen length] || fieldDefIncludesLen) { + [queryString appendFormat:@"(%@)",([userLen length]? userLen : [theRow objectForKey:@"length"])]; + } } // If the field is of type BIT, permit the use of single qoutes and also don't quote the default value. // For example, use DEFAULT b'1' as opposed to DEFAULT 'b\'1\'' which results in an error. |