aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-11-07 01:49:31 +0000
committerstuconnolly <stuart02@gmail.com>2009-11-07 01:49:31 +0000
commit021ed107a07064cb5e0f1988b778fa0cfe4ffa37 (patch)
tree06f4589e997ed36ae95790552d7ad8c953de9e66 /Source
parent563809382aa8dd0ae3f4fe877fe9fdc6986171ba (diff)
downloadsequelpro-021ed107a07064cb5e0f1988b778fa0cfe4ffa37.tar.gz
sequelpro-021ed107a07064cb5e0f1988b778fa0cfe4ffa37.tar.bz2
sequelpro-021ed107a07064cb5e0f1988b778fa0cfe4ffa37.zip
When creating a new field of type BIT, allowing default values in BIT notation. For example b'1'. Fixes #340.
Diffstat (limited to 'Source')
-rw-r--r--Source/TableSource.m26
1 files changed, 14 insertions, 12 deletions
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];