aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSQLExporter.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-04-12 23:48:20 +0000
committerrowanbeentje <rowan@beent.je>2012-04-12 23:48:20 +0000
commit5ce91070b5ff229de819d5e4b68fcae72297f634 (patch)
tree25763d533323cdee786d8dc629ec1310f7b30892 /Source/SPSQLExporter.m
parent25b0b6857cd501277790c64d90850e1ddf56e5af (diff)
downloadsequelpro-5ce91070b5ff229de819d5e4b68fcae72297f634.tar.gz
sequelpro-5ce91070b5ff229de819d5e4b68fcae72297f634.tar.bz2
sequelpro-5ce91070b5ff229de819d5e4b68fcae72297f634.zip
- Manually handle some SPFileHandle memory management to significantly improve memory usage during large exports, particularly improving memory which appeared to never be reclaimed
- Fix some minor memory leaks throughout the application
Diffstat (limited to 'Source/SPSQLExporter.m')
-rw-r--r--Source/SPSQLExporter.m46
1 files changed, 27 insertions, 19 deletions
diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m
index 286abc22..907360ea 100644
--- a/Source/SPSQLExporter.m
+++ b/Source/SPSQLExporter.m
@@ -108,7 +108,6 @@
NSMutableArray *funcs = [NSMutableArray array];
NSMutableString *metaString = [NSMutableString string];
- NSMutableString *cellValue = [NSMutableString string];
NSMutableString *errors = [[NSMutableString alloc] init];
NSMutableString *sqlString = [[NSMutableString alloc] init];
@@ -287,6 +286,8 @@
{
// Check for cancellation flag
if ([self isCancelled]) {
+ [errors release];
+ [sqlString release];
[pool release];
return;
}
@@ -345,51 +346,58 @@
[streamingResult cancelResultLoad];
[streamingResult release];
[sqlExportPool release];
+ [errors release];
+ [sqlString release];
[pool release];
-
+
return;
}
-
+
j++;
k++;
-
+
[sqlString setString:@""];
-
- // Update the progress
+
+ // Update the progress
NSUInteger progress = (NSUInteger)(j * ([self exportMaxProgress] / rowCount));
-
+
if (progress > lastProgressValue) {
[self setExportProgressValue:progress];
lastProgressValue = progress;
-
+
// Inform the delegate that the export's progress has been updated
[delegate performSelectorOnMainThread:@selector(sqlExportProcessProgressUpdated:) withObject:self waitUntilDone:NO];
}
-
- for (t = 0; t < colCount; t++)
+
+ for (t = 0; t < colCount; t++)
{
// Check for cancellation flag
if ([self isCancelled]) {
+ [connection cancelCurrentQuery];
+ [streamingResult cancelResultLoad];
+ [streamingResult release];
[sqlExportPool release];
+ [errors release];
+ [sqlString release];
[pool release];
-
+
return;
}
-
+
id object = NSArrayObjectAtIndex(row, t);
-
+
// Add NULL values directly to the output row; use a pointer comparison to the singleton
// instance for speed.
if (object == [NSNull null]) {
[sqlString appendString:@"NULL"];
- }
+ }
// If the field is off type BIT, the values need a binary prefix of b'x'.
else if ([[NSArrayObjectAtIndex([tableDetails objectForKey:@"columns"], t) objectForKey:@"type"] isEqualToString:@"BIT"]) {
[sqlString appendFormat:@"b'%@'", [object description]];
}
// Add data types directly as hex data
else if ([object isKindOfClass:[NSData class]]) {
-
+
if ([self sqlOutputEncodeBLOBasHex]) {
[sqlString appendString:[connection escapeAndQuoteData:object]];
}
@@ -415,19 +423,18 @@
[sqlString appendString:[connection escapeAndQuoteData:[object data]]];
}
else {
- [cellValue setString:[object description]];
// Add empty strings as a pair of quotes
- if ([cellValue length] == 0) {
+ if ([object length] == 0) {
[sqlString appendString:@"''"];
}
else {
if ([NSArrayObjectAtIndex(tableColumnNumericStatus, t) boolValue]) {
- [sqlString appendString:cellValue];
+ [sqlString appendString:object];
}
// Otherwise add a quoted string with special characters escaped
else {
- [sqlString appendString:[connection escapeAndQuoteString:cellValue]];
+ [sqlString appendString:[connection escapeAndQuoteString:object]];
}
}
}
@@ -874,6 +881,7 @@
[sqlDatabaseName release], sqlDatabaseName = nil;
[sqlExportCurrentTable release], sqlExportCurrentTable = nil;
[sqlDatabaseVersion release], sqlDatabaseVersion = nil;
+ [sqlExportErrors release], sqlExportErrors = nil;
[super dealloc];
}