aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-22 10:12:59 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-22 10:12:59 +0000
commitf4e32dd6a24793454e0af44a4429cdd9ca737724 (patch)
tree5c8964aa14c0885e10b6d45a0efa3503a5b28590 /Source
parent1c037fd0f3014833dd3c47d5c1b30d0e525536db (diff)
downloadsequelpro-f4e32dd6a24793454e0af44a4429cdd9ca737724.tar.gz
sequelpro-f4e32dd6a24793454e0af44a4429cdd9ca737724.tar.bz2
sequelpro-f4e32dd6a24793454e0af44a4429cdd9ca737724.zip
• fixed bug while CSV import
- calculate correctly whether global variables are used or not to avoid a crash if the number of columns in the csv file differs
Diffstat (limited to 'Source')
-rw-r--r--Source/SPFieldMapperController.h3
-rw-r--r--Source/SPFieldMapperController.m18
-rw-r--r--Source/TableDump.h2
-rw-r--r--Source/TableDump.m15
4 files changed, 31 insertions, 7 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h
index 26491bf0..d291399f 100644
--- a/Source/SPFieldMapperController.h
+++ b/Source/SPFieldMapperController.h
@@ -98,6 +98,7 @@
BOOL importFieldNamesHeader;
BOOL showAdvancedView;
BOOL targetTableHasPrimaryKey;
+
NSString *primaryKeyField;
NSNumber *lastDisabledCSVFieldcolumn;
@@ -127,8 +128,10 @@
- (NSArray*)fieldMappingArray;
- (NSArray*)fieldMappingTableColumnNames;
- (NSArray*)fieldMappingGlobalValueArray;
+- (NSArray*)fieldMappingTableDefaultValues;
- (BOOL)importFieldNamesHeader;
- (BOOL)insertRemainingRowsAfterUpdate;
+- (BOOL)globalValuesInUsage;
- (NSString*)onupdateString;
- (NSString*)importHeaderString;
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index 9483161b..c8f2c90b 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -212,11 +212,27 @@
return fieldMappingGlobalValues;
}
+- (BOOL)globalValuesInUsage
+{
+ NSInteger i = 0;
+ for(id item in fieldMappingArray) {
+ if([item intValue] >= numberOfImportColumns && [fieldMappingOperatorArray objectAtIndex:i] != doNotImport)
+ return YES;
+ i++;
+ }
+ return NO;
+}
+
- (NSArray*)fieldMappingTableColumnNames
{
return fieldMappingTableColumnNames;
}
+- (NSArray*)fieldMappingTableDefaultValues
+{
+ return fieldMappingTableDefaultValues;
+}
+
- (BOOL)importFieldNamesHeader
{
return ([importFieldNamesHeaderSwitch state] == NSOnState)?YES:NO;
@@ -335,7 +351,7 @@
if ([column objectForKey:@"default"])
[fieldMappingTableDefaultValues addObject:[column objectForKey:@"default"]];
else
- [fieldMappingTableDefaultValues addObject:@"NULL"];
+ [fieldMappingTableDefaultValues addObject:[NSNull null]];
}
[fieldMappingTableTypes addObject:[NSString stringWithString:type]];
diff --git a/Source/TableDump.h b/Source/TableDump.h
index 8f785f72..dc5af40f 100644
--- a/Source/TableDump.h
+++ b/Source/TableDump.h
@@ -106,6 +106,7 @@ typedef enum _SPExportModes {
NSArray *fieldMappingTableColumnNames;
NSArray *fieldMappingArray;
NSArray *fieldMappingGlobalValueArray;
+ NSArray *fieldMappingTableDefaultValues;
NSArray *fieldMapperOperator;
NSString *selectedTableTarget;
NSString *selectedImportMethod;
@@ -113,6 +114,7 @@ typedef enum _SPExportModes {
NSString *csvImportHeaderString;
NSString *csvImportTailString;
NSInteger fieldMapperSheetStatus;
+ NSInteger numberOfImportDataColumns;
BOOL fieldMappingArrayHasGlobalVariables;
BOOL csvImportMethodHasTail;
BOOL insertRemainingRowsAfterUpdate;
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 6657a4ee..12ab01de 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -1124,6 +1124,7 @@
if(fieldMappingArray) [fieldMappingArray release]; fieldMappingArray = nil;
if(fieldMappingGlobalValueArray) [fieldMappingGlobalValueArray release]; fieldMappingGlobalValueArray = nil;
if(fieldMappingTableColumnNames) [fieldMappingTableColumnNames release]; fieldMappingTableColumnNames = nil;
+ if(fieldMappingTableDefaultValues) [fieldMappingTableDefaultValues release]; fieldMappingTableDefaultValues = nil;
if(fieldMapperOperator) [fieldMapperOperator release]; fieldMapperOperator = nil;
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
@@ -1238,6 +1239,7 @@
// Set the import array
if (fieldMappingImportArray) [fieldMappingImportArray release];
fieldMappingImportArray = [[NSArray alloc] initWithArray:importData];
+ numberOfImportDataColumns = [[importData objectAtIndex:0] count];
fieldMapperSheetStatus = 1;
fieldMappingArrayHasGlobalVariables = NO;
@@ -1268,8 +1270,10 @@
selectedImportMethod = [NSString stringWithString:[fieldMapperController selectedImportMethod]];
fieldMappingTableColumnNames = [[NSArray arrayWithArray:[fieldMapperController fieldMappingTableColumnNames]] retain];
fieldMappingGlobalValueArray = [[NSArray arrayWithArray:[fieldMapperController fieldMappingGlobalValueArray]] retain];
+ fieldMappingTableDefaultValues = [[NSArray arrayWithArray:[fieldMapperController fieldMappingTableDefaultValues]] retain];
csvImportHeaderString = [[NSString stringWithString:[fieldMapperController importHeaderString]] retain];
csvImportTailString = [[NSString stringWithString:[fieldMapperController onupdateString]] retain];
+ fieldMappingArrayHasGlobalVariables = [fieldMapperController globalValuesInUsage];
csvImportMethodHasTail = ([csvImportTailString length] == 0) ? NO : YES;
insertRemainingRowsAfterUpdate = [fieldMapperController insertRemainingRowsAfterUpdate];
importMethodIsUpdate = ([selectedImportMethod isEqualToString:@"UPDATE"]) ? YES : NO;
@@ -1286,9 +1290,6 @@
return FALSE;
}
- if([fieldMappingImportArray count] && [fieldMappingGlobalValueArray count] > [NSArrayObjectAtIndex(fieldMappingImportArray,0) count])
- fieldMappingArrayHasGlobalVariables = YES;
-
[importFieldNamesSwitch setState:[fieldMapperController importFieldNamesHeader]];
[prefs setBool:[importFieldNamesSwitch state] forKey:SPCSVImportFirstLineIsHeader];
@@ -1336,7 +1337,7 @@
[setString appendString:@"="];
// Append the data
// - check for global values
- if(fieldMappingArrayHasGlobalVariables && mapColumn >= [csvRowArray count])
+ if(fieldMappingArrayHasGlobalVariables && mapColumn >= numberOfImportDataColumns)
cellData = NSArrayObjectAtIndex(fieldMappingGlobalValueArray, mapColumn);
else
cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
@@ -1356,7 +1357,7 @@
[whereString appendString:[NSArrayObjectAtIndex(fieldMappingTableColumnNames, i) backtickQuotedString]];
// Append the data
// - check for global values
- if(fieldMappingArrayHasGlobalVariables && mapColumn >= [csvRowArray count])
+ if(fieldMappingArrayHasGlobalVariables && mapColumn >= numberOfImportDataColumns)
cellData = NSArrayObjectAtIndex(fieldMappingGlobalValueArray, mapColumn);
else
cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
@@ -1397,7 +1398,7 @@
// Append the data
// - check for global values
- if(fieldMappingArrayHasGlobalVariables && mapColumn >= [csvRowArray count])
+ if(fieldMappingArrayHasGlobalVariables && mapColumn >= numberOfImportDataColumns)
cellData = NSArrayObjectAtIndex(fieldMappingGlobalValueArray, mapColumn);
else
cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
@@ -2942,6 +2943,7 @@
fieldMappingArray = nil;
fieldMappingGlobalValueArray = nil;
fieldMappingTableColumnNames = nil;
+ fieldMappingTableDefaultValues = nil;
fieldMappingImportArray = nil;
csvImportTailString = nil;
csvImportHeaderString = nil;
@@ -2950,6 +2952,7 @@
fieldMappingArrayHasGlobalVariables = NO;
importMethodIsUpdate = NO;
insertRemainingRowsAfterUpdate = NO;
+ numberOfImportDataColumns = 0;
prefs = nil;
lastFilename = nil;