From cae0a084e52ea3e2e4c1ac92908f41920d9cbbdc Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 24 Jun 2009 20:51:25 +0000 Subject: - Fix default values behaviour - previously, default values weren't being saved. They are now. --- Source/TableSource.m | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'Source') diff --git a/Source/TableSource.m b/Source/TableSource.m index 130f9d54..3ead57ac 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -690,31 +690,31 @@ fetches the result as an array with a dictionary for each row in it if ([[theRow objectForKey:@"Null"] isEqualToString:@"NO"]) { [queryString appendString:@" NOT NULL"]; - } - else { + } else { [queryString appendString:@" NULL"]; } - - if ((![[theRow objectForKey:@"Extra"] isEqualToString:@"auto_increment"]) && - ([[theRow objectForKey:@"Default"] isEqualToString:@"NULL"])) - { + + // Don't provide any defaults for auto-increment fields + if ([[theRow objectForKey:@"Extra"] isEqualToString:@"auto_increment"]) { + [queryString appendString:@" "]; + } else { + + // If a null value has been specified, and null is allowed, specify DEFAULT NULL if ([[theRow objectForKey:@"Default"] isEqualToString:[prefs objectForKey:@"NullValue"]]) { if ([[theRow objectForKey:@"Null"] isEqualToString:@"YES"]) { [queryString appendString:@" DEFAULT NULL "]; } - } - else if ([[theRow objectForKey:@"Type"] isEqualToString:@"timestamp"] && - ([[theRow objectForKey:@"Default"] isEqualToString:@"CURRENT_TIMESTAMP"] || - [[theRow objectForKey:@"Default"] isEqualToString:@"current_timestamp"]) ) + + // 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 "]; - } - else { + + // Otherwise, use the provided default + } else { [queryString appendString:[NSString stringWithFormat:@" DEFAULT '%@' ", [mySQLConnection prepareString:[theRow objectForKey:@"Default"]]]]; } - } - else { - [queryString appendString:@" "]; } if (!( -- cgit v1.2.3