diff options
author | stuconnolly <stuart02@gmail.com> | 2010-06-13 14:22:16 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-06-13 14:22:16 +0000 |
commit | ebd964e9a6d4b5975a806a4354f4df5ab28146d0 (patch) | |
tree | 7d7ec1977ee7059f041bf74b7e699550707e49e4 /Source/SPSQLExporter.m | |
parent | f286f3f05162e663fb6bc6abaf2a08b1e02d1d86 (diff) | |
download | sequelpro-ebd964e9a6d4b5975a806a4354f4df5ab28146d0.tar.gz sequelpro-ebd964e9a6d4b5975a806a4354f4df5ab28146d0.tar.bz2 sequelpro-ebd964e9a6d4b5975a806a4354f4df5ab28146d0.zip |
Exporter ehancements:
- Make sure the export button is disabled when the global structure, content and drop options are enabled, but the desellect all button is checked.
- Replace the export dialog toolbar with a tabview, reducing the dialogs overall size.
- Add the option to SQL dumps to specify when a new INSERT statement should be created, either after a certain amount of data or after a specific number of rows (defaults to every 250KiB). Known issue: incorrect VALUES clause generation of last row when creating a new INSERT after a specific number of rows.
Diffstat (limited to 'Source/SPSQLExporter.m')
-rw-r--r-- | Source/SPSQLExporter.m | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m index 1c1ebadc..dd43a600 100644 --- a/Source/SPSQLExporter.m +++ b/Source/SPSQLExporter.m @@ -54,6 +54,8 @@ @synthesize sqlOutputIncludeErrors; @synthesize sqlOutputCompressFile; @synthesize sqlCurrentTableExportIndex; +@synthesize sqlInsertAfterNValue; +@synthesize sqlInsertDivider; /** * Initialise an instance of SPSQLExporter using the supplied delegate. @@ -65,6 +67,9 @@ [self setDelegate:exportDelegate]; [self setSqlExportCurrentTable:nil]; + + [self setSqlInsertDivider:SPSQLInsertEveryNDataBytes]; + [self setSqlInsertAfterNValue:250000]; } return self; @@ -92,7 +97,7 @@ SPTableType tableType = SPTableTypeTable; id createTableSyntax = nil; - NSUInteger i, j, t, s, rowCount, queryLength, lastProgressValue; + NSUInteger i, j, k, t, s, rowCount, queryLength, lastProgressValue; BOOL sqlOutputIncludeStructure; BOOL sqlOutputIncludeContent; @@ -311,11 +316,10 @@ [[self exportOutputFileHandle] writeData:[metaString dataUsingEncoding:[self exportOutputEncoding]]]; // Construct the start of the insertion command - [[self exportOutputFileHandle] writeData:[[NSString stringWithFormat:@"INSERT INTO %@ (%@)\nVALUES\n\t(", - [tableName backtickQuotedString], [fieldNames componentsJoinedAndBacktickQuoted]] dataUsingEncoding:NSUTF8StringEncoding]]; + [[self exportOutputFileHandle] writeData:[[NSString stringWithFormat:@"INSERT INTO %@ (%@)\nVALUES\n\t(", [tableName backtickQuotedString], [fieldNames componentsJoinedAndBacktickQuoted]] dataUsingEncoding:NSUTF8StringEncoding]]; // Iterate through the rows to construct a VALUES group for each - j = 0; + j, k = 0; sqlExportPool = [[NSAutoreleasePool alloc] init]; @@ -335,10 +339,13 @@ } j++; + k++; + [sqlString setString:@""]; // Update the progress NSUInteger progress = (j * ([self exportMaxProgress] / rowCount)); + if (progress > lastProgressValue) { [self setExportProgressValue:progress]; lastProgressValue = progress; @@ -393,7 +400,7 @@ if ([cellValue length] == 0) { [sqlString appendString:@"''"]; } - else { + else { // If this is a numeric column type, add the number directly. if ([NSArrayObjectAtIndex(tableColumnNumericStatus, t) boolValue]) { [sqlString appendString:cellValue]; @@ -415,12 +422,14 @@ // Close this VALUES group and set up the next one if appropriate if (j != rowCount) { - - // Add a new INSERT starter command every ~250k of data - if (queryLength > 250000) { - [sqlString appendString:[NSString stringWithFormat:@");\n\nINSERT INTO %@ (%@)\nVALUES\n\t(", - [tableName backtickQuotedString], [fieldNames componentsJoinedAndBacktickQuoted]]]; - queryLength = 0; + + // If required start a new INSERT statment + if ((([self sqlInsertDivider] == SPSQLInsertEveryNDataBytes) && (queryLength >= ([self sqlInsertAfterNValue] * 1024))) || + (([self sqlInsertDivider] == SPSQLInsertEveryNRows) && (k == [self sqlInsertAfterNValue]))) + { + [sqlString appendString:[NSString stringWithFormat:@");\n\nINSERT INTO %@ (%@)\nVALUES\n\t(", [tableName backtickQuotedString], [fieldNames componentsJoinedAndBacktickQuoted]]]; + + queryLength, k = 0; // Use the opportunity to drain and reset the autorelease pool [sqlExportPool release]; @@ -433,7 +442,7 @@ else { [sqlString appendString:@")"]; } - + // Write this row to the file [[self exportOutputFileHandle] writeData:[sqlString dataUsingEncoding:NSUTF8StringEncoding]]; } |