aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPCopyTable.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-03-19 22:46:50 +0000
committerrowanbeentje <rowan@beent.je>2012-03-19 22:46:50 +0000
commitf37571808b516360a9f1f6f6291f6469e30b7c06 (patch)
treef40b012390d9dd88e7167f2cf1a759fff664c490 /Source/SPCopyTable.m
parentb222f608ac679b877b984b3645c7a0bb455f582a (diff)
downloadsequelpro-f37571808b516360a9f1f6f6291f6469e30b7c06.tar.gz
sequelpro-f37571808b516360a9f1f6f6291f6469e30b7c06.tar.bz2
sequelpro-f37571808b516360a9f1f6f6291f6469e30b7c06.zip
- Fix incorrect Copy as SQL INSERT processing leaving out commas; this addresses Issue #1300
- Improve Copy as SQL INSERT logic to correctly calculate maximum line lengths
Diffstat (limited to 'Source/SPCopyTable.m')
-rw-r--r--Source/SPCopyTable.m29
1 files changed, 13 insertions, 16 deletions
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m
index b5137935..79fc89e6 100644
--- a/Source/SPCopyTable.m
+++ b/Source/SPCopyTable.m
@@ -410,7 +410,6 @@ static const NSInteger kBlobAsImageFile = 4;
NSUInteger rowCounter = 0;
NSUInteger penultimateRowIndex = [selectedRows count];
NSUInteger c;
- NSUInteger valueLength = 0;
NSMutableString *result = [NSMutableString stringWithCapacity:2000];
@@ -462,7 +461,8 @@ static const NSInteger kBlobAsImageFile = 4;
[value appendString:@"\t("];
cellData = nil;
rowCounter++;
-
+ NSMutableArray *rowValues = [[NSMutableArray alloc] initWithCapacity:numColumns];
+
for (c = 0; c < numColumns; c++)
{
cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
@@ -489,7 +489,7 @@ static const NSInteger kBlobAsImageFile = 4;
// Check for NULL value
if ([cellData isNSNull]) {
- [value appendString:@"NULL, "];
+ [rowValues addObject:@"NULL"];
continue;
}
@@ -500,28 +500,29 @@ static const NSInteger kBlobAsImageFile = 4;
// Convert numeric types to unquoted strings
case 0:
- [value appendFormat:@"%@, ", [cellData description]];
+ [rowValues addObject:[cellData description]];
break;
// Quote string, text and blob types appropriately
case 1:
case 2:
if ([cellData isKindOfClass:nsDataClass]) {
- [value appendString:[mySQLConnection escapeAndQuoteData:cellData]];
+ [rowValues addObject:[mySQLConnection escapeAndQuoteData:cellData]];
} else {
- [value appendString:[mySQLConnection escapeAndQuoteString:[cellData description]]];
+ [rowValues addObject:[mySQLConnection escapeAndQuoteString:[cellData description]]];
}
break;
// GEOMETRY
case 3:
- [value appendString:[mySQLConnection escapeAndQuoteData:[cellData data]]];
+ [rowValues addObject:[mySQLConnection escapeAndQuoteData:[cellData data]]];
break;
// Unhandled cases - abort
default:
NSBeep();
free(columnMappings);
free(columnTypes);
+ [rowValues release];
return nil;
}
@@ -531,29 +532,25 @@ static const NSInteger kBlobAsImageFile = 4;
NSBeep();
free(columnMappings);
free(columnTypes);
-
+ [rowValues release];
return nil;
}
}
- // Remove the trailing ', ' from the query
- if ([value length] > 2) {
- [value deleteCharactersInRange:NSMakeRange([value length] - 2, 2)];
- }
-
- valueLength += [value length];
+ // Add to the string in comma-separated form, and increment the string length
+ [value appendString:[rowValues componentsJoinedByString:@", "]];
+ [rowValues release];
// Close this VALUES group and set up the next one if appropriate
if (rowCounter != penultimateRowIndex) {
// Add a new INSERT starter command every ~250k of data.
- if (valueLength > 250000) {
+ if ([value length] > 250000) {
[result appendFormat:@"%@);\n\nINSERT INTO %@ (%@)\nVALUES\n",
value,
[(selectedTable == nil) ? @"<table>" : selectedTable backtickQuotedString],
[tbHeader componentsJoinedAndBacktickQuoted]];
[value setString:@""];
- valueLength = 0;
}
else {
[value appendString:@"),\n"];