aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-07-24 19:39:41 +0000
committerstuconnolly <stuart02@gmail.com>2011-07-24 19:39:41 +0000
commitdf3c269342bcfb6fa343f16e10ad0b56f4b20852 (patch)
tree82dd1db55e7de22f46d7ec53d71de033f891af8f /Source
parenta6b8cd46677d517b2aad5e8bf7543a8d307b211e (diff)
downloadsequelpro-df3c269342bcfb6fa343f16e10ad0b56f4b20852.tar.gz
sequelpro-df3c269342bcfb6fa343f16e10ad0b56f4b20852.tar.bz2
sequelpro-df3c269342bcfb6fa343f16e10ad0b56f4b20852.zip
Fix for NULL values in CSV export (same as last commit, but this one actually works).
Diffstat (limited to 'Source')
-rw-r--r--Source/SPCSVExporter.m8
-rw-r--r--Source/SPExportInitializer.m3
-rw-r--r--Source/SPPrintController.m2
-rw-r--r--Source/SPTableContent.h4
-rw-r--r--Source/SPTableContent.m50
5 files changed, 42 insertions, 25 deletions
diff --git a/Source/SPCSVExporter.m b/Source/SPCSVExporter.m
index 17f6fb40..6e0fa715 100644
--- a/Source/SPCSVExporter.m
+++ b/Source/SPCSVExporter.m
@@ -31,8 +31,6 @@
#import "SPExportUtilities.h"
#import "SPExportFile.h"
-static NSString *SPDatabaseNULLString = @"NULL";
-
@implementation SPCSVExporter
@synthesize delegate;
@@ -294,12 +292,8 @@ static NSString *SPDatabaseNULLString = @"NULL";
[csvCellString setString:[csvCell description]];
}
- // Handle NULL values according to what the user specified
- if ([csvCellString isEqualToString:SPDatabaseNULLString]) {
- [csvString appendString:[self csvNULLString]];
- }
// Add empty strings as a pair of enclosing characters.
- else if ([csvCellString length] == 0) {
+ if ([csvCellString length] == 0) {
[csvString appendString:[self csvEnclosingCharacterString]];
[csvString appendString:[self csvEnclosingCharacterString]];
}
diff --git a/Source/SPExportInitializer.m b/Source/SPExportInitializer.m
index df615495..15ab192d 100644
--- a/Source/SPExportInitializer.m
+++ b/Source/SPExportInitializer.m
@@ -33,6 +33,7 @@
#import "SPDatabaseDocument.h"
#import "SPCustomQuery.h"
#import "SPAlertSheets.h"
+#import "SPTableContent.h"
#import "SPCSVExporter.h"
#import "SPSQLExporter.h"
@@ -98,7 +99,7 @@
switch (exportSource)
{
case SPFilteredExport:
- dataArray = [tableContentInstance currentResult];
+ dataArray = [tableContentInstance currentDataResultWithNULLs:YES];
break;
case SPQueryExport:
dataArray = [customQueryInstance currentResult];
diff --git a/Source/SPPrintController.m b/Source/SPPrintController.m
index 425c1247..80d3c068 100644
--- a/Source/SPPrintController.m
+++ b/Source/SPPrintController.m
@@ -253,7 +253,7 @@
// Table content view
else if (view == 1) {
- NSArray *data = [tableContentInstance currentDataResult];
+ NSArray *data = [tableContentInstance currentDataResultWithNULLs:NO];
heading = NSLocalizedString(@"Table Content", @"table content print heading");
diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h
index 4b7def6f..fcde1f6b 100644
--- a/Source/SPTableContent.h
+++ b/Source/SPTableContent.h
@@ -205,9 +205,9 @@
- (IBAction)toggleLookAllFieldsMode:(id)sender;
- (IBAction)closeSheet:(id)sender;
-// Getter methods
+// Data accessors
- (NSArray *)currentResult;
-- (NSArray *)currentDataResult;
+- (NSArray *)currentDataResultWithNULLs:(BOOL)includeNULLs;
// Task interaction
- (void) startDocumentTaskForTab:(NSNotification *)aNotification;
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 5295bb3d..f9e66525 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -2215,82 +2215,103 @@
}
-// Accessors
+#pragma mark -
+#pragma mark Data accessors
/**
* Returns the current result (as shown in table content view) as array, the first object containing the field
* names as array, the following objects containing the rows as array.
*/
-- (NSArray *)currentDataResult
+- (NSArray *)currentDataResultWithNULLs:(BOOL)includeNULLs
{
+ NSInteger i;
NSArray *tableColumns;
NSMutableArray *currentResult = [NSMutableArray array];
NSMutableArray *tempRow = [NSMutableArray array];
- NSInteger i;
// Load table if not already done
- if ( ![tableDocumentInstance contentLoaded] ) {
+ if (![tableDocumentInstance contentLoaded]) {
[self loadTable:[tableDocumentInstance table]];
}
tableColumns = [tableContentView tableColumns];
// Set field names as first line
- for (NSTableColumn *aTableColumn in tableColumns) {
+ for (NSTableColumn *aTableColumn in tableColumns)
+ {
[tempRow addObject:[[aTableColumn headerCell] stringValue]];
}
+
[currentResult addObject:[NSArray arrayWithArray:tempRow]];
// Add rows
- for ( i = 0 ; i < [self numberOfRowsInTableView:tableContentView] ; i++) {
+ for (i = 0; i < [self numberOfRowsInTableView:tableContentView]; i++)
+ {
[tempRow removeAllObjects];
- for (NSTableColumn *aTableColumn in tableColumns) {
+
+ for (NSTableColumn *aTableColumn in tableColumns)
+ {
id o = SPDataStorageObjectAtRowAndColumn(tableValues, i, [[aTableColumn identifier] integerValue]);
- if ([o isNSNull])
- [tempRow addObject:@"NULL"];
- else if ([o isSPNotLoaded])
+
+ if ([o isNSNull]) {
+ [tempRow addObject:(includeNULLs) ? [NSNull null] : [prefs objectForKey:SPNullValue]];
+ }
+ else if ([o isSPNotLoaded]) {
[tempRow addObject:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")];
- else if([o isKindOfClass:[NSString class]])
+ }
+ else if([o isKindOfClass:[NSString class]]) {
[tempRow addObject:[o description]];
+ }
else if([o isKindOfClass:[MCPGeometryData class]]) {
SPGeometryDataView *v = [[SPGeometryDataView alloc] initWithCoordinates:[o coordinates]];
NSImage *image = [v thumbnailImage];
NSString *imageStr = @"";
+
if(image) {
NSString *maxSizeValue = @"WIDTH";
NSInteger imageWidth = [image size].width;
NSInteger imageHeight = [image size].height;
+
if(imageHeight > imageWidth) {
maxSizeValue = @"HEIGHT";
imageWidth = imageHeight;
}
+
if (imageWidth > 100) imageWidth = 100;
+
imageStr = [NSString stringWithFormat:
@"<BR><IMG %@='%ld' SRC=\"data:image/auto;base64,%@\">",
maxSizeValue,
(long)imageWidth,
[[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01f] base64EncodingWithLineLength:0]];
}
+
[v release];
[tempRow addObject:[NSString stringWithFormat:@"%@%@", [o wktString], imageStr]];
}
else {
NSImage *image = [[NSImage alloc] initWithData:o];
+
if (image) {
NSInteger imageWidth = [image size].width;
+
if (imageWidth > 100) imageWidth = 100;
[tempRow addObject:[NSString stringWithFormat:
@"<IMG WIDTH='%ld' SRC=\"data:image/auto;base64,%@\">",
(long)imageWidth,
[[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01f] base64EncodingWithLineLength:0]]];
- } else {
+ }
+ else {
[tempRow addObject:@"&lt;BLOB&gt;"];
}
+
if(image) [image release];
}
}
+
[currentResult addObject:[NSArray arrayWithArray:tempRow]];
}
+
return currentResult;
}
@@ -2330,6 +2351,8 @@
return currentResult;
}
+#pragma mark -
+
// Additional methods
/**
@@ -3849,7 +3872,7 @@
}
else
#endif
- if (aTableView == tableContentView) {
+ if (aTableView == tableContentView) {
NSUInteger columnIndex = [[aTableColumn identifier] integerValue];
id theValue = nil;
@@ -3893,7 +3916,6 @@
*/
- (void)tableView:(SPCopyTable *)aTableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)aTableColumn row:(NSInteger)rowIndex
{
-
#ifndef SP_REFACTOR
if(aTableView == filterTableView) {
if(filterTableIsSwapped && [[aTableColumn identifier] integerValue] == 0) {