diff options
author | rowanbeentje <rowan@beent.je> | 2011-10-05 00:39:05 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2011-10-05 00:39:05 +0000 |
commit | 31f17d3c4b1be994b647c133196c82c11db4328f (patch) | |
tree | 0f6a50f5b86fe912b6f0e325a89726279a2e3f44 /Source/SPCopyTable.m | |
parent | c9aad8326e53f9544bc10e9bae6bb2a7697cbffa (diff) | |
download | sequelpro-31f17d3c4b1be994b647c133196c82c11db4328f.tar.gz sequelpro-31f17d3c4b1be994b647c133196c82c11db4328f.tar.bz2 sequelpro-31f17d3c4b1be994b647c133196c82c11db4328f.zip |
- Rework table data saving to ensure that cells that should be edited via the edit sheet aren't then overwritten by the cell value, potentially causing data truncation in 10.5. This addresses Issue 1196.
- Consolidate field editing in sheet logic
Diffstat (limited to 'Source/SPCopyTable.m')
-rw-r--r-- | Source/SPCopyTable.m | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index c2cadf59..857b45c3 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -1155,6 +1155,45 @@ static const NSInteger kBlobAsImageFile = 4; } #pragma mark - +#pragma mark Field editing checks + +/** + * Determine whether to use the sheet for editing; do so if the multipleLineEditingButton is enabled, + * or if the column was a blob or a text, or if it contains linebreaks. + */ +- (BOOL)shouldUseFieldEditorForRow:(NSUInteger)rowIndex column:(NSUInteger)colIndex +{ + + // Retrieve the column definition + NSDictionary *columnDefinition = [[[self delegate] dataColumnDefinitions] objectAtIndex:colIndex]; + NSString *columnType = [columnDefinition objectForKey:@"typegrouping"]; + + // Return YES if the multiple line editing button is enabled - triggers sheet editing on all cells. +#ifndef SP_REFACTOR + if ([prefs boolForKey:SPEditInSheetEnabled]) return YES; +#endif + + // If the column is a BLOB or TEXT column, and not an enum, trigger sheet editing + BOOL isBlob = ([columnType isEqualToString:@"textdata"] || [columnType isEqualToString:@"blobdata"]); + if (isBlob && ![columnType isEqualToString:@"enum"]) return YES; + + // Otherwise, check the cell value for newlines. + id cellValue = [tableStorage cellDataAtRow:rowIndex column:colIndex]; + if ([cellValue isKindOfClass:[NSData class]]) { + cellValue = [[[NSString alloc] initWithData:cellValue encoding:[mySQLConnection stringEncoding]] autorelease]; + } + if (![cellValue isNSNull] + && [columnType isEqualToString:@"string"] + && [cellValue rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:NSLiteralSearch].location != NSNotFound) + { + return YES; + } + + // Otherwise, use standard editing + return NO; +} + +#pragma mark - #pragma mark Bundle Command Support - (IBAction)executeBundleItemForDataTable:(id)sender |