diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-03-06 14:42:51 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-03-06 14:42:51 +0000 |
commit | ecbc556ad0ed6e6c66c76145085a524bf8d6035d (patch) | |
tree | 54f4c7513026113ab0baef757e0983325eb66f2e /Source | |
parent | 54da3a6b973deb893ce9c8d094ce37ef4c66f9d6 (diff) | |
download | sequelpro-ecbc556ad0ed6e6c66c76145085a524bf8d6035d.tar.gz sequelpro-ecbc556ad0ed6e6c66c76145085a524bf8d6035d.tar.bz2 sequelpro-ecbc556ad0ed6e6c66c76145085a524bf8d6035d.zip |
• CSV Import Field Mapper
- added to INSERT advanced option "Skip existing rows"
This option allows to insert only those source file rows which primary keys do not exist. It executes INSERT INTO … ON DUPLICATE KEY UPDATE `pri_key_name` = `pri_key_name`. This statement suppresses all warnings/errors regarding to duplicates pri keys etc. BUT it gives an error if an INSERT… statement of a remaining row was erroneous.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPFieldMapperController.h | 3 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 44 |
2 files changed, 40 insertions, 7 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index 7db0f5c9..26491bf0 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -62,6 +62,7 @@ IBOutlet id lowPriorityReplaceCheckBox; IBOutlet id lowPriorityUpdateCheckBox; IBOutlet id highPriorityCheckBox; + IBOutlet id skipexistingRowsCheckBox; IBOutlet CMTextView *onupdateTextView; IBOutlet id advancedButton; @@ -96,6 +97,8 @@ BOOL fieldMappingImportArrayIsPreview; BOOL importFieldNamesHeader; BOOL showAdvancedView; + BOOL targetTableHasPrimaryKey; + NSString *primaryKeyField; NSNumber *lastDisabledCSVFieldcolumn; MCPConnection *mySQLConnection; diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index 7224c38a..a33d6300 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -112,11 +112,14 @@ [lowPriorityReplaceCheckBox setState:NO]; [lowPriorityUpdateCheckBox setState:NO]; [highPriorityCheckBox setState:NO]; - - [advancedButton setState:NSOffState]; + [skipexistingRowsCheckBox setState:NO]; + [skipexistingRowsCheckBox setEnabled:NO]; + [advancedButton setState:NO]; [advancedBox setHidden:YES]; showAdvancedView = NO; + targetTableHasPrimaryKey = NO; + primaryKeyField = nil; heightOffset = 0; [advancedReplaceView setHidden:YES]; [advancedUpdateView setHidden:YES]; @@ -283,6 +286,7 @@ SPTableData *selectedTableData = [[SPTableData alloc] init]; [selectedTableData setConnection:mySQLConnection]; NSDictionary *tableDetails = [selectedTableData informationForTable:[tableTargetPopup titleOfSelectedItem]]; + targetTableHasPrimaryKey = NO; BOOL isReplacePossible = NO; // NSLog(@"d %@", tableDetails); if (tableDetails) { @@ -303,7 +307,8 @@ } else { [fieldMappingTableDefaultValues addObject:@"0"]; } - isReplacePossible = YES; + targetTableHasPrimaryKey = YES; + primaryKeyField = [tableDetails objectForKey:@"primarykeyfield"]; } else { if([column objectForKey:@"unique"]) { [type appendFormat:@",%@",@"UNIQUE"]; @@ -324,7 +329,8 @@ [selectedTableData release]; [[importMethodPopup menu] setAutoenablesItems:NO]; - [[importMethodPopup itemWithTitle:@"REPLACE"] setEnabled:isReplacePossible]; + [[importMethodPopup itemWithTitle:@"REPLACE"] setEnabled:(targetTableHasPrimaryKey|isReplacePossible)]; + [skipexistingRowsCheckBox setEnabled:targetTableHasPrimaryKey]; // Update the table view fieldMappingCurrentRow = 0; @@ -604,16 +610,40 @@ [lowPriorityReplaceCheckBox setState:NO]; return; } + if(sender == skipexistingRowsCheckBox) { + if([skipexistingRowsCheckBox state] == NSOnState) { + [delayedCheckBox setState:NO]; + [delayedCheckBox setEnabled:NO]; + [onupdateCheckBox setState:YES]; + [onupdateCheckBox setEnabled:NO]; + [onupdateTextView setEditable:YES]; + [onupdateTextView setSelectedRange:NSMakeRange(0,[[onupdateTextView string] length])]; + [onupdateTextView insertText:[NSString stringWithFormat:@"%@ = %@", [primaryKeyField backtickQuotedString], [primaryKeyField backtickQuotedString]]]; + [onupdateTextView setBackgroundColor:[NSColor lightGrayColor]]; + [onupdateTextView setEditable:NO]; + } else { + [delayedCheckBox setEnabled:YES]; + [onupdateCheckBox setState:NO]; + [onupdateCheckBox setEnabled:YES]; + BOOL oldEditableState = [onupdateTextView isEditable]; + [onupdateTextView setEditable:YES]; + [onupdateTextView setSelectedRange:NSMakeRange(0,[[onupdateTextView string] length])]; + [onupdateTextView insertText:@""]; + [onupdateTextView setEditable:oldEditableState]; + } + } if(sender == lowPriorityCheckBox && [lowPriorityCheckBox state] == NSOnState) { [highPriorityCheckBox setState:NO]; [delayedCheckBox setState:NO]; - [onupdateCheckBox setEnabled:YES]; + if([skipexistingRowsCheckBox state] == NSOffState) + [onupdateCheckBox setEnabled:YES]; } if(sender == highPriorityCheckBox && [highPriorityCheckBox state] == NSOnState) { [lowPriorityCheckBox setState:NO]; [delayedCheckBox setState:NO]; - [onupdateCheckBox setEnabled:YES]; + if([skipexistingRowsCheckBox state] == NSOffState) + [onupdateCheckBox setEnabled:YES]; } if(sender == delayedCheckBox) { if([delayedCheckBox state] == NSOnState) { @@ -631,7 +661,7 @@ [onupdateTextView setEditable:YES]; [[self window] makeFirstResponder:onupdateTextView]; } - if([onupdateCheckBox state] == NSOffState) { + if([onupdateCheckBox state] == NSOffState && [skipexistingRowsCheckBox state] == NSOffState) { [onupdateTextView setBackgroundColor:[NSColor lightGrayColor]]; [onupdateTextView setEditable:NO]; } |