aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2013-09-05 23:36:59 +0000
committerrowanbeentje <rowan@beent.je>2013-09-05 23:36:59 +0000
commitf800cc92469c2615fe5fb6cc351a24b1cfd6e944 (patch)
treedc1bfbc4df30735c00dd184198933b1480b33ecc
parent6023b60b4a6bbb338d3363c43ccebe8eeee9c97a (diff)
downloadsequelpro-f800cc92469c2615fe5fb6cc351a24b1cfd6e944.tar.gz
sequelpro-f800cc92469c2615fe5fb6cc351a24b1cfd6e944.tar.bz2
sequelpro-f800cc92469c2615fe5fb6cc351a24b1cfd6e944.zip
- Fix an issue that could cause invalid SQL exports if table contents changed between two queries, addressing Issue #1726
- Remove a check against export cancellation when exporting every cell of a table, leaving the check on every row
-rw-r--r--Source/SPSQLExporter.m82
1 files changed, 35 insertions, 47 deletions
diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m
index e578ebdf..faf76e67 100644
--- a/Source/SPSQLExporter.m
+++ b/Source/SPSQLExporter.m
@@ -105,7 +105,7 @@
SPTableType tableType = SPTableTypeTable;
id createTableSyntax = nil;
- NSUInteger j, k, t, s, rowCount, queryLength, lastProgressValue;
+ NSUInteger j, k, t, s, rowCount, queryLength, lastProgressValue, cleanAutoReleasePool = NO;
BOOL sqlOutputIncludeStructure;
BOOL sqlOutputIncludeContent;
@@ -366,7 +366,7 @@
[[self exportOutputFile] writeData:[metaString dataUsingEncoding:[self exportOutputEncoding]]];
// Construct the start of the insertion command
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"INSERT INTO %@ (%@)\nVALUES\n\t(", [tableName backtickQuotedString], [rawColumnNames componentsJoinedAndBacktickQuoted]] dataUsingEncoding:NSUTF8StringEncoding]];
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"INSERT INTO %@ (%@)\nVALUES", [tableName backtickQuotedString], [rawColumnNames componentsJoinedAndBacktickQuoted]] dataUsingEncoding:NSUTF8StringEncoding]];
// Iterate through the rows to construct a VALUES group for each
j = 0, k = 0;
@@ -396,8 +396,6 @@
j++;
k++;
- [sqlString setString:@""];
-
// Update the progress
NSUInteger progress = (NSUInteger)(j * ([self exportMaxProgress] / rowCount));
@@ -409,23 +407,32 @@
[delegate performSelectorOnMainThread:@selector(sqlExportProcessProgressUpdated:) withObject:self waitUntilDone:NO];
}
- for (t = 0; t < colCount; t++)
+
+ // Set up the new row as appropriate. If a new INSERT statement should be created,
+ // set one up; otherwise, set up a new row
+ if ((([self sqlInsertDivider] == SPSQLInsertEveryNDataBytes) && (queryLength >= ([self sqlInsertAfterNValue] * 1024))) ||
+ (([self sqlInsertDivider] == SPSQLInsertEveryNRows) && (k == [self sqlInsertAfterNValue])))
{
- // Check for cancellation flag
- if ([self isCancelled]) {
- [connection cancelCurrentQuery];
- [streamingResult cancelResultLoad];
- [streamingResult release];
- [sqlExportPool release];
- [errors release];
- [sqlString release];
- [pool release];
- free(useRawDataForColumnAtIndex);
- free(useRawHexDataForColumnAtIndex);
-
- return;
- }
+ [sqlString setString:@";\n\nINSERT INTO "];
+ [sqlString appendString:[tableName backtickQuotedString]];
+ [sqlString appendString:@" ("];
+ [sqlString appendString:[rawColumnNames componentsJoinedAndBacktickQuoted]];
+ [sqlString appendString:@")\nVALUES\n\t("];
+ queryLength = 0, k = 0;
+
+ // Use the opportunity to drain and reset the autorelease pool at the end of this row
+ cleanAutoReleasePool = YES;
+ }
+ else if (j == 1) {
+ [sqlString setString:@"\n\t("];
+ }
+ else {
+ [sqlString setString:@",\n\t("];
+ }
+
+ for (t = 0; t < colCount; t++)
+ {
id object = NSArrayObjectAtIndex(row, t);
// Add NULL values directly to the output row; use a pointer comparison to the singleton
@@ -486,38 +493,19 @@
// Add the field separator if this isn't the last cell in the row
if (t != ([row count] - 1)) [sqlString appendString:@","];
}
-
+
+ [sqlString appendString:@")"];
queryLength += [sqlString length];
-
- // Close this VALUES group and set up the next one if appropriate
- if (j != rowCount) {
-
- // If required start a new INSERT statment
- if ((([self sqlInsertDivider] == SPSQLInsertEveryNDataBytes) && (queryLength >= ([self sqlInsertAfterNValue] * 1024))) ||
- (([self sqlInsertDivider] == SPSQLInsertEveryNRows) && (k == [self sqlInsertAfterNValue])))
- {
- [sqlString appendString:@");\n\nINSERT INTO "];
- [sqlString appendString:[tableName backtickQuotedString]];
- [sqlString appendString:@" ("];
- [sqlString appendString:[rawColumnNames componentsJoinedAndBacktickQuoted]];
- [sqlString appendString:@")\nVALUES\n\t("];
-
- queryLength = 0, k = 0;
-
- // Use the opportunity to drain and reset the autorelease pool
- [sqlExportPool release];
- sqlExportPool = [[NSAutoreleasePool alloc] init];
- }
- else {
- [sqlString appendString:@"),\n\t("];
- }
- }
- else {
- [sqlString appendString:@")"];
- }
// Write this row to the file
[[self exportOutputFile] writeData:[sqlString dataUsingEncoding:NSUTF8StringEncoding]];
+
+ // Clean autorelease pool if so decided earlier
+ if (cleanAutoReleasePool) {
+ [sqlExportPool release];
+ sqlExportPool = [[NSAutoreleasePool alloc] init];
+ cleanAutoReleasePool = NO;
+ }
}
// Complete the command