Permalink
Browse files

Small changes to PR #2807 and surrounding code

  • Loading branch information...
dmoagx committed May 29, 2017
1 parent 35b8b4a commit c83f7b115e9cb41f7c92212434096515ac8e6909
View
@@ -184,6 +184,7 @@ - (NSString *)rowsAsTabStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex];
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
for (NSUInteger c = 0; c < numColumns; c++ ) {
id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
@@ -197,13 +198,12 @@ - (NSString *)rowsAsTabStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[result appendFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")];
else if ([cellData isKindOfClass:[NSData class]]) {
if(withBlobHandling == kBlobInclude) {
BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex];
NSString *displayString;
if (hexBlobs)
displayString = [[NSString alloc] initWithFormat:@"0x%@", [cellData dataToHexString]];
else
displayString = [[NSString alloc] initWithData:cellData encoding:[mySQLConnection stringEncoding]];
if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSASCIIStringEncoding];
if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSISOLatin1StringEncoding];
if (displayString) {
[result appendFormat:@"%@\t", displayString];
[displayString release];
@@ -320,6 +320,7 @@ - (NSString *)rowsAsCsvStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex];
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
for (NSUInteger c = 0; c < numColumns; c++ ) {
id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
@@ -333,8 +334,12 @@ - (NSString *)rowsAsCsvStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[result appendFormat:@"\"%@\",", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")];
else if ([cellData isKindOfClass:[NSData class]]) {
if(withBlobHandling == kBlobInclude) {
NSString *displayString = [[NSString alloc] initWithData:cellData encoding:[mySQLConnection stringEncoding]];
if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSASCIIStringEncoding];
NSString *displayString;
if (hexBlobs)
displayString = [[NSString alloc] initWithFormat:@"0x%@", [cellData dataToHexString]];
else
displayString = [[NSString alloc] initWithData:cellData encoding:[mySQLConnection stringEncoding]];
if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSISOLatin1StringEncoding];
if (displayString) {
[result appendFormat:@"\"%@\",", displayString];
[displayString release];
@@ -625,6 +630,7 @@ - (NSString *) draggedRowsAsTabString
Class nsDataClass = [NSData class];
Class spmysqlGeometryData = [SPMySQLGeometryData class];
NSStringEncoding connectionEncoding = [mySQLConnection stringEncoding];
BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex];
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
for (NSUInteger c = 0; c < numColumns; c++ ) {
id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
@@ -637,10 +643,15 @@ - (NSString *) draggedRowsAsTabString
else if ([cellData isSPNotLoaded])
[result appendFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")];
else if ([cellData isKindOfClass:nsDataClass]) {
NSString *displayString = [[NSString alloc] initWithData:cellData encoding:connectionEncoding];
if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSASCIIStringEncoding];
NSString *displayString;
if (hexBlobs)
displayString = [[NSString alloc] initWithFormat:@"0x%@", [cellData dataToHexString]];
else
displayString = [[NSString alloc] initWithData:cellData encoding:connectionEncoding];
if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSISOLatin1StringEncoding];
if (displayString) {
[result appendString:displayString];
[result appendString:@"\t"];
[displayString release];
}
}
@@ -754,7 +765,6 @@ - (NSDictionary *) autodetectColumnWidths
- (NSUInteger)autodetectWidthForColumnDefinition:(NSDictionary *)columnDefinition maxRows:(NSUInteger)rowsToCheck
{
CGFloat columnBaseWidth;
id contentString;
NSUInteger cellWidth, maxCellWidth, i;
NSRange linebreakRange;
double rowStep;
@@ -767,6 +777,7 @@ - (NSUInteger)autodetectWidthForColumnDefinition:(NSDictionary *)columnDefinitio
NSUInteger columnIndex = (NSUInteger)[[columnDefinition objectForKey:@"datacolumnindex"] integerValue];
NSDictionary *stringAttributes = @{NSFontAttributeName : tableFont};
Class spmysqlGeometryData = [SPMySQLGeometryData class];
BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex];
// Check the number of rows available to check, sampling every n rows
if ([tableStorage count] < rowsToCheck)
@@ -784,7 +795,7 @@ - (NSUInteger)autodetectWidthForColumnDefinition:(NSDictionary *)columnDefinitio
for (i = 0; i < rowsToCheck; i += rowStep) {
// Retrieve part of the cell's content to get widths, topping out at a maximum length
contentString = SPDataStoragePreviewAtRowAndColumn(tableStorage, i, columnIndex, 500);
id contentString = SPDataStoragePreviewAtRowAndColumn(tableStorage, i, columnIndex, 500);
// If the cell hasn't loaded yet, skip processing
if (!contentString)
@@ -806,7 +817,10 @@ - (NSUInteger)autodetectWidthForColumnDefinition:(NSDictionary *)columnDefinitio
// Otherwise, ensure the cell is represented as a short string
if ([contentString isKindOfClass:[NSData class]]) {
contentString = [contentString shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]];
if (hexBlobs)
contentString = [[NSString alloc] initWithFormat:@"0x%@", [(NSData *)contentString dataToHexString]];
else
contentString = [contentString shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]];
} else if ([(NSString *)contentString length] > 500) {
contentString = [contentString substringToIndex:500];
}
View
@@ -31,6 +31,7 @@
#import "SPTableContent.h"
#import "SPTableContentFilter.h"
#import "SPTableContentDataSource.h"
#import "SPDatabaseDocument.h"
#import "SPTableStructure.h"
#import "SPTableInfo.h"
@@ -2382,15 +2383,15 @@ - (NSArray *)currentDataResultWithNULLs:(BOOL)includeNULLs hideBLOBs:(BOOL)hide
[currentResult addObject:[NSArray arrayWithArray:tempRow]];
BOOL hexBlobs = [prefs boolForKey: SPDisplayBinaryDataAsHex];
// Add rows
for (i = 0; i < [self numberOfRowsInTableView:tableContentView]; i++)
{
[tempRow removeAllObjects];
for (NSTableColumn *aTableColumn in tableColumns)
{
id o = SPDataStorageObjectAtRowAndColumn(tableValues, i, [[aTableColumn identifier] integerValue]);
NSUInteger columnIndex = [[aTableColumn identifier] integerValue];
id o = SPDataStorageObjectAtRowAndColumn(tableValues, i, columnIndex);
if ([o isNSNull]) {
[tempRow addObject:includeNULLs ? [NSNull null] : [prefs objectForKey:SPNullValue]];
@@ -2442,15 +2443,16 @@ - (NSArray *)currentDataResultWithNULLs:(BOOL)includeNULLs hideBLOBs:(BOOL)hide
}
else {
NSString *str;
if (hide)
if (hide) {
str = @"&lt;BLOB&gt;";
else if (hexBlobs) {
str = [NSString stringWithFormat: @"0x%@", [o dataToHexString]];
}
else if ([self cellValueIsDisplayedAsHexForColumn:columnIndex]) {
str = [NSString stringWithFormat:@"0x%@", [o dataToHexString]];
}
else {
str = [o stringRepresentationUsingEncoding:[mySQLConnection stringEncoding]];
}
[tempRow addObject: str];
[tempRow addObject:str];
}
if(image) [image release];
@@ -32,4 +32,6 @@
@interface SPTableContent (SPTableContentDataSource)
- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex;
@end
@@ -120,7 +120,7 @@ - (id)tableView:(SPCopyTable *)tableView objectValueForTableColumn:(NSTableColum
if ([self cellValueIsDisplayedAsHexForColumn:columnIndex]) {
if ([(NSData *)value length] > 255) {
return [NSString stringWithFormat:@"0x%@...", [[(NSData *)value subdataWithRange:NSMakeRange(0, 255)] dataToHexString]];
return [NSString stringWithFormat:@"0x%@", [[(NSData *)value subdataWithRange:NSMakeRange(0, 255)] dataToHexString]];
}
return [NSString stringWithFormat:@"0x%@", [(NSData *)value dataToHexString]];
}
@@ -30,6 +30,7 @@
#import "SPTableContentDelegate.h"
#import "SPTableContentFilter.h"
#import "SPTableContentDataSource.h"
#ifndef SP_CODA /* headers */
#import "SPAppController.h"
#endif
@@ -54,7 +55,6 @@
@interface SPTableContent (SPDeclaredAPI)
- (BOOL)cancelRowEditing;
- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex;
@end

0 comments on commit c83f7b1

Please sign in to comment.