From 021ed107a07064cb5e0f1988b778fa0cfe4ffa37 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 7 Nov 2009 01:49:31 +0000 Subject: When creating a new field of type BIT, allowing default values in BIT notation. For example b'1'. Fixes #340. --- Source/TableSource.m | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'Source') diff --git a/Source/TableSource.m b/Source/TableSource.m index 3eb87932..d6e0af75 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -676,12 +676,12 @@ fetches the result as an array with a dictionary for each row in it } else { // CHANGE syntax - if (([[theRow objectForKey:@"Length"] isEqualToString:@""]) || (![theRow objectForKey:@"Length"]) || ([[theRow objectForKey:@"Type"] isEqualToString:@"datetime"])) { - + if (([[theRow objectForKey:@"Length"] isEqualToString:@""]) || + (![theRow objectForKey:@"Length"]) || + ([[theRow objectForKey:@"Type"] isEqualToString:@"datetime"])) + { // If the old row and new row dictionaries are equal then the user didn't actually change anything so don't continue - if ([oldRow isEqualToDictionary:theRow]) { - return YES; - } + if ([oldRow isEqualToDictionary:theRow]) return YES; queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ CHANGE %@ %@ %@", [selectedTable backtickQuotedString], @@ -691,9 +691,7 @@ fetches the result as an array with a dictionary for each row in it } else { // If the old row and new row dictionaries are equal then the user didn't actually change anything so don't continue - if ([oldRow isEqualToDictionary:theRow]) { - return YES; - } + if ([oldRow isEqualToDictionary:theRow]) return YES; queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ CHANGE %@ %@ %@(%@)", [selectedTable backtickQuotedString], @@ -728,20 +726,24 @@ fetches the result as an array with a dictionary for each row in it [queryString appendString:@" "]; } else { - // If a null value has been specified, and null is allowed, specify DEFAULT NULL + // If a NULL value has been specified, and NULL is allowed, specify DEFAULT NULL if ([[theRow objectForKey:@"Default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { if ([[theRow objectForKey:@"Null"] intValue] == 1) { [queryString appendString:@" DEFAULT NULL "]; } - - // Otherwise, if current_timestamp was specified for timestamps, use that } + // Otherwise, if CURRENT_TIMESTAMP was specified for timestamps, use that else if ([[theRow objectForKey:@"Type"] isEqualToString:@"timestamp"] && [[[theRow objectForKey:@"Default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) { [queryString appendString:@" DEFAULT CURRENT_TIMESTAMP "]; } + // 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. + else if ([[theRow objectForKey:@"Type"] isEqualToString:@"bit"]) { + [queryString appendString:[NSString stringWithFormat:@" DEFAULT %@ ", [theRow objectForKey:@"Default"]]]; + } // Otherwise, use the provided default else { [queryString appendString:[NSString stringWithFormat:@" DEFAULT '%@' ", [mySQLConnection prepareString:[theRow objectForKey:@"Default"]]]]; @@ -815,7 +817,7 @@ fetches the result as an array with a dictionary for each row in it else if (isEditingNewRow) { [queryString appendString:[NSString stringWithFormat:@" AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"Field"] backtickQuotedString]]]; } - + // Execute query [mySQLConnection queryString:queryString]; -- cgit v1.2.3