From ecbc556ad0ed6e6c66c76145085a524bf8d6035d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 6 Mar 2010 14:42:51 +0000 Subject: =?UTF-8?q?=E2=80=A2=20CSV=20Import=20Field=20Mapper=20-=20added?= =?UTF-8?q?=20to=20INSERT=20advanced=20option=20"Skip=20existing=20rows"?= =?UTF-8?q?=20This=20option=20allows=20to=20insert=20only=20those=20source?= =?UTF-8?q?=20file=20rows=20which=20primary=20keys=20do=20not=20exist.=20I?= =?UTF-8?q?t=20executes=20INSERT=20INTO=20=E2=80=A6=20ON=20DUPLICATE=20KEY?= =?UTF-8?q?=20UPDATE=20`pri=5Fkey=5Fname`=20=3D=20`pri=5Fkey=5Fname`.=20Th?= =?UTF-8?q?is=20statement=20suppresses=20all=20warnings/errors=20regarding?= =?UTF-8?q?=20to=20duplicates=20pri=20keys=20etc.=20BUT=20it=20gives=20an?= =?UTF-8?q?=20error=20if=20an=20INSERT=E2=80=A6=20statement=20of=20a=20rem?= =?UTF-8?q?aining=20row=20was=20erroneous.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DataMigrationDialog.xib | 84 ++++++++++++++++++++++-- Source/SPFieldMapperController.h | 3 + Source/SPFieldMapperController.m | 44 +++++++++++-- 3 files changed, 117 insertions(+), 14 deletions(-) diff --git a/Interfaces/English.lproj/DataMigrationDialog.xib b/Interfaces/English.lproj/DataMigrationDialog.xib index 53f1370f..489491c5 100644 --- a/Interfaces/English.lproj/DataMigrationDialog.xib +++ b/Interfaces/English.lproj/DataMigrationDialog.xib @@ -12,7 +12,7 @@ YES - + YES @@ -937,7 +937,7 @@ -2038284033 - 134217857 + 436207745 200 @@ -1025,6 +1025,28 @@ 293 YES + + + 268 + {{227, 62}, {134, 18}} + + YES + + -2080244224 + 131072 + Skip existing rows + + + 1211912703 + 2 + + + + + 200 + 25 + + 274 @@ -2257,6 +2279,22 @@ 395 + + + skipexistingRowsCheckBox + + + + 398 + + + + advancedCheckboxValidation: + + + + 399 + @@ -2943,6 +2981,7 @@ + Advanced View for INSERT @@ -3156,6 +3195,20 @@ + + 396 + + + YES + + + + + + 397 + + + @@ -3294,6 +3347,9 @@ 39.IBPluginDependency 392.IBPluginDependency 393.IBPluginDependency + 396.IBAttributePlaceholdersKey + 396.IBPluginDependency + 397.IBPluginDependency 40.IBPluginDependency 41.IBPluginDependency 42.IBPluginDependency @@ -3326,9 +3382,9 @@ YES com.apple.InterfaceBuilder.CocoaPlugin - {{99, 328}, {522, 348}} + {{361, 389}, {522, 348}} com.apple.InterfaceBuilder.CocoaPlugin - {{99, 328}, {522, 348}} + {{361, 389}, {522, 348}} {{387, 725}, {432, 282}} @@ -3378,7 +3434,7 @@ ToolTip - Go back to file chooser (⌥←) + Go back to file chooser (⇧⌥⌘←) com.apple.InterfaceBuilder.CocoaPlugin @@ -3537,6 +3593,16 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Do not import existing rows identified by the PRIMARY KEY + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3583,7 +3649,7 @@ - 395 + 399 @@ -3666,6 +3732,7 @@ advancedUpdateView alignByPopup alignByPopupLabel + customQueryInstance delayedCheckBox delayedReplaceCheckBox fieldMapperTableScrollView @@ -3693,6 +3760,7 @@ replaceAfterSavingCheckBox rowDownButton rowUpButton + skipexistingRowsCheckBox tableTargetPopup theDelegate @@ -3711,6 +3779,7 @@ id id id + id NSTableView id NSPathControl @@ -3729,12 +3798,13 @@ id NSMenuItem id - id + CMTextView id NSButton id id id + id NSPopUpButton id 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]; } -- cgit v1.2.3