diff options
author | rowanbeentje <rowan@beent.je> | 2008-12-08 01:05:08 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2008-12-08 01:05:08 +0000 |
commit | 2d18384fb11c4a3ae1e2752f58d573d99d7154a4 (patch) | |
tree | 5d12225347242e0d986f1995862dc3f240539ccc /TableDump.m | |
parent | f98a2f1a45997bedd70d6d57661e7f177f7db03c (diff) | |
download | sequelpro-2d18384fb11c4a3ae1e2752f58d573d99d7154a4.tar.gz sequelpro-2d18384fb11c4a3ae1e2752f58d573d99d7154a4.tar.bz2 sequelpro-2d18384fb11c4a3ae1e2752f58d573d99d7154a4.zip |
- No longer export trailing commas for CSV lines
- Don't output the CSV "headers" for exports of single tables
- Use the correct line ending as specified in the export dialog when exporting CSV headers and spacing for multi-table exports
Diffstat (limited to 'TableDump.m')
-rw-r--r-- | TableDump.m | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/TableDump.m b/TableDump.m index a40458d0..859bc233 100644 --- a/TableDump.m +++ b/TableDump.m @@ -1024,7 +1024,7 @@ // For NULL objects supplied from a queryResult, no data is added to the cell if ([[csvRow objectAtIndex:j] isKindOfClass:[NSNull class]]) { - [csvString appendString:fieldSeparatorString]; + if (j < [csvRow count] - 1) [csvString appendString:fieldSeparatorString]; continue; } @@ -1091,7 +1091,7 @@ [csvString appendString:enclosingString]; } } - [csvString appendString:fieldSeparatorString]; + if (j < [csvRow count] - 1) [csvString appendString:fieldSeparatorString]; } // Append the line ending to the string for this row @@ -1408,6 +1408,7 @@ NSMutableString *infoString = [NSMutableString string]; NSMutableString *errors = [NSMutableString string]; NSStringEncoding connectionEncoding = [mySQLConnection encoding]; + NSMutableString *csvLineEnd; // Reset the interface [errorsView setString:@""]; @@ -1423,10 +1424,22 @@ didEndSelector:nil contextInfo:nil]; - // Add the dump header to the dump file, dependant on export type. + // Add a dump header to the dump file, dependant on export type. if ( [type isEqualToString:@"csv"] ) { - [infoString setString:[NSString stringWithFormat:@"Host: %@ Database: %@ Generation Time: %@\n\n", - [tableDocumentInstance host], [tableDocumentInstance database], [NSDate date]]]; + csvLineEnd = [NSMutableString stringWithString:[exportMultipleLinesTerminatedField stringValue]]; + [csvLineEnd replaceOccurrencesOfString:@"\\t" withString:@"\t" + options:NSLiteralSearch + range:NSMakeRange(0, [csvLineEnd length])]; + [csvLineEnd replaceOccurrencesOfString:@"\\n" withString:@"\n" + options:NSLiteralSearch + range:NSMakeRange(0, [csvLineEnd length])]; + [csvLineEnd replaceOccurrencesOfString:@"\\r" withString:@"\r" + options:NSLiteralSearch + range:NSMakeRange(0, [csvLineEnd length])]; + if ([selectedTables count] > 1) { + [infoString setString:[NSString stringWithFormat:@"Host: %@ Database: %@ Generation Time: %@%@%@", + [tableDocumentInstance host], [tableDocumentInstance database], [NSDate date], csvLineEnd, csvLineEnd]]; + } } else if ( [type isEqualToString:@"xml"] ) { [infoString setString:@"<?xml version=\"1.0\"?>\n\n"]; [infoString appendString:@"<!--\n-\n"]; @@ -1455,9 +1468,9 @@ [singleProgressBar setUsesThreadedAnimation:YES]; [singleProgressBar startAnimation:self]; - // For CSV exports, output the name of the table - if ( [type isEqualToString:@"csv"] ) { - [fileHandle writeData:[[NSString stringWithFormat:@"Table %@\n\n", tableName] dataUsingEncoding:connectionEncoding]]; + // For CSV exports of more than one table, output the name of the table + if ( [type isEqualToString:@"csv"] && [selectedTables count] > 1) { + [fileHandle writeData:[[NSString stringWithFormat:@"Table %@%@%@", tableName, csvLineEnd, csvLineEnd] dataUsingEncoding:connectionEncoding]]; } // Retrieve all the content within this table @@ -1487,16 +1500,20 @@ escapedBy:[exportMultipleFieldsEscapedField stringValue] lineEnds:[exportMultipleLinesTerminatedField stringValue] silently:YES]; + + // Add a spacer to the file + [fileHandle writeData:[[NSString stringWithFormat:@"%@%@%@", csvLineEnd, csvLineEnd, csvLineEnd] dataUsingEncoding:connectionEncoding]]; } else if ( [type isEqualToString:@"xml"] ) { [self writeXmlForArray:nil orQueryResult:queryResult toFileHandle:fileHandle tableName:tableName withHeader:NO silently:YES]; + + // Add a spacer to the file + [fileHandle writeData:[[NSString stringWithString:@"\n\n\n"] dataUsingEncoding:connectionEncoding]]; } - // Add a spacer to the file - [fileHandle writeData:[[NSString stringWithString:@"\n\n\n"] dataUsingEncoding:connectionEncoding]]; } // For XML output, close the database tag |