From 33318efe01aa815a6d607b530c7e727aa5b3a6d0 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sat, 3 Oct 2009 23:40:50 +0000 Subject: - 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 --- Source/TableSource.m | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'Source/TableSource.m') diff --git a/Source/TableSource.m b/Source/TableSource.m index a2b62787..bc4a9810 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -754,6 +754,22 @@ fetches the result as an array with a dictionary for each row in it [queryString appendString:[theRow objectForKey:@"Extra"]]; } + if (!isEditingNewRow) { + + // Add details not provided via the SHOW COLUMNS query from the table data cache so column details aren't lost + NSDictionary *originalColumnDetails = [[tableDataInstance columns] objectAtIndex:currentlyEditingRow]; + + // Any column comments + if ([originalColumnDetails objectForKey:@"comment"] && [[originalColumnDetails objectForKey:@"comment"] length]) { + [queryString appendString:[NSString stringWithFormat:@" COMMENT '%@'", [mySQLConnection prepareString:[originalColumnDetails objectForKey:@"comment"]]]]; + } + + // Unparsed details - column formats, storage, reference definitions + if ([originalColumnDetails objectForKey:@"unparsed"]) { + [queryString appendString:[originalColumnDetails objectForKey:@"unparsed"]]; + } + } + // Asks the user to add an index to query if auto_increment is set and field isn't indexed if ([[theRow objectForKey:@"Extra"] isEqualToString:@"auto_increment"] && ([[theRow objectForKey:@"Key"] isEqualToString:@""] || @@ -1184,6 +1200,19 @@ would result in a position change. [queryString appendString:[NSString stringWithFormat:@" DEFAULT '%@'", [mySQLConnection prepareString:[originalRow objectForKey:@"Default"]]]]; } + // Add details not provided via the SHOW COLUMNS query from the table data cache so column details aren't lost + NSDictionary *originalColumnDetails = [[tableDataInstance columns] objectAtIndex:originalRowIndex]; + + // Any column comments + if ([originalColumnDetails objectForKey:@"comment"] && [[originalColumnDetails objectForKey:@"comment"] length]) { + [queryString appendString:[NSString stringWithFormat:@" COMMENT '%@'", [mySQLConnection prepareString:[originalColumnDetails objectForKey:@"comment"]]]]; + } + + // Unparsed details - column formats, storage, reference definitions + if ([originalColumnDetails objectForKey:@"unparsed"]) { + [queryString appendString:[originalColumnDetails objectForKey:@"unparsed"]]; + } + // Add the new location if ( destinationRowIndex == 0 ){ [queryString appendString:@" FIRST"]; -- cgit v1.2.3