aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-18 12:54:38 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-18 12:54:38 +0000
commit1bde8b65c0213bcf0514c69f1b8b70a00971b573 (patch)
treeb4a56556179011242f9309f8df1b21355bf4c11b /Source
parent299e8821edf9a1705a556c482a2a0ea4d6f9a0a8 (diff)
downloadsequelpro-1bde8b65c0213bcf0514c69f1b8b70a00971b573.tar.gz
sequelpro-1bde8b65c0213bcf0514c69f1b8b70a00971b573.tar.bz2
sequelpro-1bde8b65c0213bcf0514c69f1b8b70a00971b573.zip
• CSV Import Field Mapper
- allow to define a list of global variables (incl. a true NULL value) - such a global variable will be inserted into the mapped table target field for all rows imported
Diffstat (limited to 'Source')
-rw-r--r--Source/SPFieldMapperController.h3
-rw-r--r--Source/SPFieldMapperController.m43
-rw-r--r--Source/TableDump.h2
-rw-r--r--Source/TableDump.m16
4 files changed, 61 insertions, 3 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h
index 5f55abe4..7632e179 100644
--- a/Source/SPFieldMapperController.h
+++ b/Source/SPFieldMapperController.h
@@ -43,6 +43,7 @@
IBOutlet id globalValuesSheet;
IBOutlet NSButton *addGlobalValueButton;
IBOutlet NSButton *removeGlobalValueButton;
+ IBOutlet NSButton *insertNULLValueButton;
id theDelegate;
id fieldMappingImportArray;
@@ -89,6 +90,7 @@
- (NSString*)selectedImportMethod;
- (NSArray*)fieldMappingArray;
- (NSArray*)fieldMappingTableColumnNames;
+- (NSArray*)fieldMappingGlobalValueArray;
- (BOOL)importFieldNamesHeader;
// IBAction methods
@@ -103,6 +105,7 @@
- (IBAction)addGlobalValue:(id)sender;
- (IBAction)removeGlobalValue:(id)sender;
+- (IBAction)insertNULLValue:(id)sender;
- (IBAction)closeGlobalValuesSheet:(id)sender;
// Others
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index 4313dc59..7ecdb8f0 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -105,6 +105,7 @@
[fieldMapperTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
[removeGlobalValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] > 0)];
+ [insertNULLValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] == 1)];
[self updateFieldNameAlignment];
}
@@ -175,6 +176,11 @@
return fieldMappingArray;
}
+- (NSArray*)fieldMappingGlobalValueArray
+{
+ return fieldMappingGlobalValues;
+}
+
- (NSArray*)fieldMappingTableColumnNames
{
return fieldMappingTableColumnNames;
@@ -377,6 +383,18 @@
[[globalValuesSheet window] makeFirstResponder:globalValuesTableView];
[removeGlobalValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] > 0)];
+ [insertNULLValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] == 1)];
+}
+
+- (IBAction)insertNULLValue:(id)sender;
+{
+ if([globalValuesTableView numberOfSelectedRows] != 1) return;
+
+ [globalValuesTableView abortEditing];
+ [fieldMappingGlobalValues replaceObjectAtIndex:[globalValuesTableView selectedRow]+numberOfImportColumns withObject:[NSNull null]];
+
+ [globalValuesTableView reloadData];
+
}
- (IBAction)closeGlobalValuesSheet:(id)sender
@@ -396,6 +414,7 @@
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
[[globalValuesSheet window] orderOut:self];
+ [self updateFieldMappingButtonCell];
}
- (void)matchHeaderNames
@@ -466,15 +485,27 @@
- (void)updateFieldMappingButtonCell
{
NSInteger i;
-
+ if([fieldMappingImportArray count] == 0) return;
[fieldMappingButtonOptions setArray:[fieldMappingImportArray objectAtIndex:fieldMappingCurrentRow]];
for (i = 0; i < [fieldMappingButtonOptions count]; i++) {
if ([[fieldMappingButtonOptions objectAtIndex:i] isNSNull]) {
- [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, [prefs objectForKey:SPNullValue]]];
+ [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. <%@>", i+1, [prefs objectForKey:SPNullValue]]];
} else {
[fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingButtonOptions, i)]];
}
}
+
+ // Add global values if any
+ if([fieldMappingGlobalValues count]>numberOfImportColumns)
+ for(i; i < [fieldMappingGlobalValues count]; i++) {
+ if ([NSArrayObjectAtIndex(fieldMappingGlobalValues, i) isNSNull])
+ [fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%i. <%@>", i+1, [prefs objectForKey:SPNullValue]]];
+ else
+ [fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingGlobalValues, i)]];
+ }
+
+ [fieldMapperTableView reloadData];
+
}
/*
@@ -565,13 +596,20 @@
if(aTableView == fieldMapperTableView) {
if([[aTableColumn identifier] isEqualToString:@"import_value"] && [importFieldNamesHeaderSwitch state] == NSOnState) {
+
if ([fieldMappingOperatorArray objectAtIndex:rowIndex] == doNotImport) return @"";
+
+ if([NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]>=[NSArrayObjectAtIndex(fieldMappingImportArray, 0) count])
+ return [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Global value", @"global value"),
+ NSArrayObjectAtIndex(fieldMappingGlobalValues, [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue])];
+
if(fieldMappingCurrentRow)
return [NSString stringWithFormat:@"%@: %@",
[NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, 0), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description],
[NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, fieldMappingCurrentRow), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description]];
else
return [NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, 0), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description];
+
}
else if([[aTableColumn identifier] isEqualToString:@"import_value"] && [importFieldNamesHeaderSwitch state] == NSOffState)
return [NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, fieldMappingCurrentRow), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description];
@@ -680,6 +718,7 @@
if (object == globalValuesTableView) {
[removeGlobalValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] > 0)];
+ [insertNULLValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] == 1)];
}
}
diff --git a/Source/TableDump.h b/Source/TableDump.h
index 8054bf06..9475649b 100644
--- a/Source/TableDump.h
+++ b/Source/TableDump.h
@@ -105,11 +105,13 @@ typedef enum _SPExportModes {
BOOL fieldMappingImportArrayIsPreview;
NSArray *fieldMappingTableColumnNames;
NSArray *fieldMappingArray;
+ NSArray *fieldMappingGlobalValueArray;
NSArray *fieldMapperOperator;
NSString *selectedTableTarget;
NSString *selectedImportMethod;
NSString *lastFilename;
NSInteger fieldMapperSheetStatus;
+ BOOL fieldMappingArrayHasGlobalVariables;
NSUInteger exportMode;
NSUserDefaults *prefs;
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 2a39aca5..b1cbbda8 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -782,6 +782,7 @@
BOOL insertBaseStringHasEntries;
NSStringEncoding csvEncoding = [MCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]];
fieldMappingArray = nil;
+ fieldMappingGlobalValueArray = nil;
// Start the notification timer to allow notifications to be shown even if frontmost for long queries
[[SPGrowlController sharedGrowlController] setVisibilityForNotificationName:@"Import Finished"];
@@ -1039,6 +1040,7 @@
[parsedRows release];
[parsePositions release];
if(fieldMappingArray) [fieldMappingArray release]; fieldMappingArray = nil;
+ if(fieldMappingGlobalValueArray) [fieldMappingGlobalValueArray release]; fieldMappingGlobalValueArray = nil;
if(fieldMapperOperator) [fieldMapperOperator release]; fieldMapperOperator = nil;
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
@@ -1154,6 +1156,7 @@
fieldMappingImportArray = [[NSArray alloc] initWithArray:importData];
fieldMapperSheetStatus = 1;
+ fieldMappingArrayHasGlobalVariables = NO;
// Init the field mapper controller
fieldMapperController = [[SPFieldMapperController alloc] initWithDelegate:self];
@@ -1180,6 +1183,11 @@
selectedTableTarget = [NSString stringWithString:[fieldMapperController selectedTableTarget]];
selectedImportMethod = [NSString stringWithString:[fieldMapperController selectedImportMethod]];
fieldMappingTableColumnNames = [NSArray arrayWithArray:[fieldMapperController fieldMappingTableColumnNames]];
+ fieldMappingGlobalValueArray = [[NSArray arrayWithArray:[fieldMapperController fieldMappingGlobalValueArray]] retain];
+
+ if([fieldMappingGlobalValueArray count] > [fieldMappingArray count])
+ fieldMappingArrayHasGlobalVariables = YES;
+
[importFieldNamesSwitch setState:[fieldMapperController importFieldNamesHeader]];
[prefs setBool:[importFieldNamesSwitch state] forKey:SPCSVImportFirstLineIsHeader];
@@ -1219,7 +1227,11 @@
if ([valueString length] > 1) [valueString appendString:@","];
// Append the data
- cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
+ // - check for global values
+ if(fieldMappingArrayHasGlobalVariables && mapColumn >= [csvRowArray count])
+ cellData = NSArrayObjectAtIndex(fieldMappingGlobalValueArray, mapColumn);
+ else
+ cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
if (cellData == [NSNull null]) {
[valueString appendString:@"NULL"];
@@ -2783,8 +2795,10 @@
tables = [[NSMutableArray alloc] init];
fieldMappingArray = nil;
+ fieldMappingGlobalValueArray = nil;
fieldMappingImportArray = nil;
fieldMappingImportArrayIsPreview = NO;
+ fieldMappingArrayHasGlobalVariables = NO;
prefs = nil;
lastFilename = nil;