aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPExportFileUtilities.m6
-rw-r--r--Source/SPXMLExporter.m41
-rw-r--r--Source/SPXMLExporterDelegate.m6
3 files changed, 26 insertions, 27 deletions
diff --git a/Source/SPExportFileUtilities.m b/Source/SPExportFileUtilities.m
index 2688b369..fd4be8b0 100644
--- a/Source/SPExportFileUtilities.m
+++ b/Source/SPExportFileUtilities.m
@@ -86,9 +86,13 @@
[header appendFormat:@"- %@: %@\n", NSLocalizedString(@"Database", @"export header database label"), [tableDocumentInstance database]];
[header appendFormat:@"- %@ Time: %@\n", NSLocalizedString(@"Generation Time", @"export header generation time label"), [NSDate date]];
[header appendString:@"-\n-->\n\n"];
+ [header appendFormat:@"<%@ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n", (exportSource == SPTableExport) ? @"mysqldump" : @"resultset"];
if (exportSource == SPTableExport) {
- [header appendFormat:@"<%@>\n\n", [[tableDocumentInstance database] HTMLEscapeString]];
+ [header appendFormat:@"<database name=\"%@\">\n\n", [tableDocumentInstance database]];
+ }
+ else {
+ [header appendString:@"\n"];
}
[file writeData:[header dataUsingEncoding:NSUTF8StringEncoding]];
diff --git a/Source/SPXMLExporter.m b/Source/SPXMLExporter.m
index c3fee7c2..1ff32018 100644
--- a/Source/SPXMLExporter.m
+++ b/Source/SPXMLExporter.m
@@ -63,10 +63,10 @@
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *xmlRow = nil;
+ NSArray *fieldNames = nil;
NSString *dataConversionString = nil;
MCPStreamingResult *streamingResult = nil;
- NSMutableArray *xmlTags = [NSMutableArray array];
NSMutableString *xmlString = [NSMutableString string];
NSMutableString *xmlItem = [NSMutableString string];
@@ -94,27 +94,18 @@
if ((![self xmlDataArray]) && [self xmlTableName]) {
totalRows = [[[[connection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@", [[self xmlTableName] backtickQuotedString]]] fetchRowAsArray] objectAtIndex:0] integerValue];
streamingResult = [connection streamingQueryString:[NSString stringWithFormat:@"SELECT * FROM %@", [[self xmlTableName] backtickQuotedString]] useLowMemoryBlockingStreaming:[self exportUsingLowMemoryBlockingStreaming]];
+
+ [xmlString appendFormat:@"\t<table_data name=\"%@\">\n\n", [self xmlTableName]];
}
else {
totalRows = [[self xmlDataArray] count];
}
// Set up an array of encoded field names as opening and closing tags
- xmlRow = ([self xmlDataArray]) ? [[self xmlDataArray] objectAtIndex:0] : [streamingResult fetchFieldNames];
-
- for (i = 0; i < [xmlRow count]; i++)
- {
- [xmlTags addObject:[NSMutableArray array]];
-
- [[xmlTags objectAtIndex:i] addObject:[NSString stringWithFormat:@"\t\t<%@>", [[[xmlRow objectAtIndex:i] description] HTMLEscapeString]]];
- [[xmlTags objectAtIndex:i] addObject:[NSString stringWithFormat:@"</%@>\n", [[[xmlRow objectAtIndex:i] description] HTMLEscapeString]]];
- }
+ fieldNames = ([self xmlDataArray]) ? [[self xmlDataArray] objectAtIndex:0] : [streamingResult fetchFieldNames];
[[self exportOutputFile] writeData:[xmlString dataUsingEncoding:[self exportOutputEncoding]]];
- // Write an opening tag in the form of the table name
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"\t<%@>\n", ([self xmlTableName]) ? [[self xmlTableName] HTMLEscapeString] : @"custom"] dataUsingEncoding:[self exportOutputEncoding]]];
-
// Set up the starting row, which is 0 for streaming result sets and
// 1 for supplied arrays which include the column headers as the first row.
currentRowIndex = 0;
@@ -176,6 +167,7 @@
return;
}
+ BOOL dataIsNULL = NO;
id data = NSArrayObjectAtIndex(xmlRow, i);
// Retrieve the contents of this tag
@@ -190,7 +182,7 @@
[dataConversionString release];
}
else if ([data isKindOfClass:[NSNull class]]) {
- [xmlItem setString:[self xmlNULLString]];
+ dataIsNULL = YES;
}
else if ([data isKindOfClass:[MCPGeometryData class]]) {
[xmlItem setString:[data wktString]];
@@ -198,15 +190,19 @@
else {
[xmlItem setString:[data description]];
}
+
+ [xmlString appendFormat:@"\t\t<field name=\"%@\"", [[NSArrayObjectAtIndex(fieldNames, i) description] HTMLEscapeString]];
- // Add the opening and closing tag and the contents to the XML string
- [xmlString appendString:NSArrayObjectAtIndex(NSArrayObjectAtIndex(xmlTags, i), 0)];
- [xmlString appendString:[xmlItem HTMLEscapeString]];
- [xmlString appendString:NSArrayObjectAtIndex(NSArrayObjectAtIndex(xmlTags, i), 1)];
+ if (dataIsNULL) {
+ [xmlString appendString:@" xsi:nil=\"true\" \\>\n"];
+ }
+ else {
+ [xmlString appendFormat:@">%@</field>\n", [xmlItem HTMLEscapeString]];
+ }
}
- [xmlString appendString:@"\t</row>\n"];
-
+ [xmlString appendString:@"\t</row>\n\n"];
+
// Record the total length for use with pool flushing
currentPoolDataLength += [xmlString length];
@@ -239,8 +235,9 @@
if ([self xmlDataArray] && totalRows == currentRowIndex) break;
}
- // Write the closing tag for the table
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"\t</%@>\n\n", ([self xmlTableName]) ? [[self xmlTableName] HTMLEscapeString] : @"custom"] dataUsingEncoding:[self exportOutputEncoding]]];
+ if ((![self xmlDataArray]) && [self xmlTableName]) {
+ [[self exportOutputFile] writeData:[@"\t</table_data>\n\n" dataUsingEncoding:[self exportOutputEncoding]]];
+ }
// Write data to disk
[[[self exportOutputFile] exportFileHandle] synchronizeFile];
diff --git a/Source/SPXMLExporterDelegate.m b/Source/SPXMLExporterDelegate.m
index 12274a4b..cae852ac 100644
--- a/Source/SPXMLExporterDelegate.m
+++ b/Source/SPXMLExporterDelegate.m
@@ -69,7 +69,7 @@
// If we're exporting to multiple files then close the file handle of the exporter
// that just finished, ensuring its data is written to disk.
if (exportToMultipleFiles) {
- [[exporter exportOutputFile] writeData:[[NSString stringWithFormat:@"</%@>\n", [[tableDocumentInstance database] HTMLEscapeString]] dataUsingEncoding:[connection stringEncoding]]];
+ [[exporter exportOutputFile] writeData:[(exportSource == SPTableExport) ? @"</database>\n</mysqldump>\n" : @"</resultset>\n" dataUsingEncoding:[connection stringEncoding]]];
[[exporter exportOutputFile] close];
}
@@ -82,9 +82,7 @@
}
// Otherwise if the exporter list is empty, close the progress sheet
else {
- if (exportSource == SPTableExport) {
- [[exporter exportOutputFile] writeData:[[NSString stringWithFormat:@"</%@>\n", [[tableDocumentInstance database] HTMLEscapeString]] dataUsingEncoding:[connection stringEncoding]]];
- }
+ [[exporter exportOutputFile] writeData:[(exportSource == SPTableExport) ? @"</database>\n</mysqldump>\n" : @"</resultset>\n" dataUsingEncoding:[connection stringEncoding]]];
// Close the last exporter's file handle
[[exporter exportOutputFile] close];