aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableData.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-10-03 23:40:50 +0000
committerrowanbeentje <rowan@beent.je>2009-10-03 23:40:50 +0000
commit33318efe01aa815a6d607b530c7e727aa5b3a6d0 (patch)
treed518d81a2d84d05b1919cc5dd9690eebaa247f8a /Source/SPTableData.m
parentd794d105545e92a75bdaf697580ee7f12b566531 (diff)
downloadsequelpro-33318efe01aa815a6d607b530c7e727aa5b3a6d0.tar.gz
sequelpro-33318efe01aa815a6d607b530c7e727aa5b3a6d0.tar.bz2
sequelpro-33318efe01aa815a6d607b530c7e727aa5b3a6d0.zip
- When moving or editing table columns, preserve comments and any column details which are currently unhandled (column formats, storage, references). This addresses the data loss part of Issue #180.
- Parse out column comments in SPTableData to allow displaying or editing comments in future
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r--Source/SPTableData.m19
1 files changed, 16 insertions, 3 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 083de094..66224529 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -410,7 +410,7 @@
// Store the column.
[tableColumns addObject:[NSDictionary dictionaryWithDictionary:tableColumn]];
- // TODO: Otherwise it's a key definition, constraint, check, or other 'metadata'. Would be useful to parse/display these!
+ // TODO: Otherwise it's a key definition, check, or other 'metadata'. Would be useful to parse/display these!
} else {
NSArray *parts = [fieldsParser splitStringByCharacter:' ' skippingBrackets:YES ignoringQuotedStrings:YES];
@@ -866,6 +866,8 @@
[fieldDetails setValue:[NSNumber numberWithBool:NO] forKey:@"zerofill"];
[fieldDetails setValue:[NSNumber numberWithBool:NO] forKey:@"autoincrement"];
[fieldDetails setValue:[NSNumber numberWithBool:NO] forKey:@"onupdatetimestamp"];
+ [fieldDetails setValue:@"" forKey:@"comment"];
+ [fieldDetails setValue:[NSMutableString string] forKey:@"unparsed"];
// Walk through the remaining column definition parts storing recognised details
partsArrayLength = [definitionParts count];
@@ -931,10 +933,21 @@
&& [[[definitionParts objectAtIndex:definitionPartsIndex+2] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) {
[fieldDetails setValue:[NSNumber numberWithBool:YES] forKey:@"onupdatetimestamp"];
definitionPartsIndex += 2;
+
+ // Column comments
+ } else if ([detailString isEqualToString:@"COMMENT"] && (definitionPartsIndex + 1 < partsArrayLength)) {
+ detailParser = [[SPSQLParser alloc] initWithString:[definitionParts objectAtIndex:definitionPartsIndex+1]];
+ [fieldDetails setValue:[detailParser unquotedString] forKey:@"comment"];
+ [detailParser release];
+ definitionPartsIndex++;
+
+ // Preserve unhandled details to avoid losing information when rearranging columns etc
+ // TODO: Currently unhandled: [UNIQUE | PRIMARY] KEY | COLUMN_FORMAT bar | STORAGE q | REFERENCES...
+ } else {
+ [[fieldDetails objectForKey:@"unparsed"] appendString:@" "];
+ [[fieldDetails objectForKey:@"unparsed"] appendString:[definitionParts objectAtIndex:definitionPartsIndex]];
}
- // TODO: Currently unhandled: [UNIQUE | PRIMARY] KEY | COMMENT 'foo' | COLUMN_FORMAT bar | STORAGE q | REFERENCES...
-
[detailString release];
}