aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-22 14:56:05 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-22 14:56:05 +0000
commitdb2d9565c996e206d82a441cfd8e60627f0eab6d (patch)
treecddd29b39dfaac95062a9412f4a70786f1205171
parentf4e32dd6a24793454e0af44a4429cdd9ca737724 (diff)
downloadsequelpro-db2d9565c996e206d82a441cfd8e60627f0eab6d.tar.gz
sequelpro-db2d9565c996e206d82a441cfd8e60627f0eab6d.tar.bz2
sequelpro-db2d9565c996e206d82a441cfd8e60627f0eab6d.zip
• CSV Import
- if a parsed row in the csv file doesn't have the same number of columns as the first row fill the missing columns with SPNotLoaded to allow while importing that these missing data can be replaced by the table column's DEFAULT value - fixed tiny issue for field mapper sheet to display the correct tooltip for default values • SPTableData - ATTENTION: changed the object for returned key 'default': if its value is NULL now it returns a [NSNull null] object - changed instances to handle this [NSNull null] object (must be checked)
-rw-r--r--Source/SPCSVParser.m6
-rw-r--r--Source/SPFieldMapperController.m21
-rw-r--r--Source/SPTableData.m14
-rw-r--r--Source/TableContent.m2
-rw-r--r--Source/TableDump.m17
5 files changed, 39 insertions, 21 deletions
diff --git a/Source/SPCSVParser.m b/Source/SPCSVParser.m
index d9a77a62..e4755a7e 100644
--- a/Source/SPCSVParser.m
+++ b/Source/SPCSVParser.m
@@ -24,6 +24,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPCSVParser.h"
+#import "SPNotLoaded.h"
/**
* Please see the header files for a general description of the purpose of this class.
@@ -294,11 +295,12 @@
}
// Capture the length of the first row when processing, and ensure that all
- // subsequent rows contain that many cells
+ // subsequent rows contain that many cells (fill them with [SPNotLoaded notLoaded]
+ // to allow to replace these by the table column's DEFAULT value)
if (fieldCount == NSNotFound) {
fieldCount = [csvRowArray count];
} else if ([csvRowArray count] < fieldCount) {
- for (j = [csvRowArray count]; j < fieldCount; j++) [csvRowArray addObject:[NSNull null]];
+ for (j = [csvRowArray count]; j < fieldCount; j++) [csvRowArray addObject:[SPNotLoaded notLoaded]];
}
// Return the row
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index c8f2c90b..a269f75e 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -30,6 +30,7 @@
#import "SPArrayAdditions.h"
#import "SPStringAdditions.h"
#import "SPConstants.h"
+#import "SPNotLoaded.h"
@implementation SPFieldMapperController
@@ -345,13 +346,14 @@
[type appendFormat:@",%@",@"UNIQUE"];
isReplacePossible = YES;
}
- if([[[column objectForKey:@"onupdatetimestamp"] description] isEqualToString:@"1"])
- [fieldMappingTableDefaultValues addObject:@"time_stamp"];
+ // if([[[column objectForKey:@"onupdatetimestamp"] description] isEqualToString:@"1"]) {
+ // [fieldMappingTableDefaultValues addObject:@"CURRENT_TIMESTAMP"];
+ // } else {
+ if ([column objectForKey:@"default"])
+ [fieldMappingTableDefaultValues addObject:[column objectForKey:@"default"]];
else
- if ([column objectForKey:@"default"])
- [fieldMappingTableDefaultValues addObject:[column objectForKey:@"default"]];
- else
- [fieldMappingTableDefaultValues addObject:[NSNull null]];
+ [fieldMappingTableDefaultValues addObject:[NSNull null]];
+ // }
}
[fieldMappingTableTypes addObject:[NSString stringWithString:type]];
@@ -838,6 +840,8 @@
for (i = 0; i < [fieldMappingButtonOptions count]; i++) {
if ([[fieldMappingButtonOptions objectAtIndex:i] isNSNull])
[fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. <%@>", i+1, [prefs objectForKey:SPNullValue]]];
+ else if ([[fieldMappingButtonOptions objectAtIndex:i] isSPNotLoaded])
+ [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. <%@>", i+1, @"DEFAULT"]];
else
[fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingButtonOptions, i)]];
}
@@ -950,9 +954,10 @@
{
if(aTableView == fieldMapperTableView) {
- if([[aTableColumn identifier] isEqualToString:@"import_value"] && [importFieldNamesHeaderSwitch state] == NSOnState) {
- if ([fieldMappingOperatorArray objectAtIndex:rowIndex] == doNotImport) return [NSString stringWithFormat:@"DEFAULT: %@", [fieldMappingTableDefaultValues objectAtIndex:rowIndex]];
+ if ([fieldMappingOperatorArray objectAtIndex:rowIndex] == doNotImport) return [NSString stringWithFormat:@"DEFAULT: %@", [fieldMappingTableDefaultValues objectAtIndex:rowIndex]];
+
+ if([[aTableColumn identifier] isEqualToString:@"import_value"] && [importFieldNamesHeaderSwitch state] == NSOnState) {
if([NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]>=[NSArrayObjectAtIndex(fieldMappingImportArray, 0) count])
return [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Global value", @"global value"), NSArrayObjectAtIndex(fieldMappingGlobalValues, [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue])];
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 34ab2358..698270fe 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -749,13 +749,8 @@
}
// Select the column default if available
- if ([resultRow objectForKey:@"Default"]) {
- if ([[resultRow objectForKey:@"Default"] isNSNull]) {
- [tableColumn setValue:[NSString stringWithString:[[NSUserDefaults standardUserDefaults] objectForKey:SPNullValue]] forKey:@"default"];
- } else {
- [tableColumn setValue:[NSString stringWithString:[resultRow objectForKey:@"Default"]] forKey:@"default"];
- }
- }
+ if ([resultRow objectForKey:@"Default"])
+ [tableColumn setObject:[NSString stringWithString:[resultRow objectForKey:@"Default"]] forKey:@"default"];
// Add the column to the list
[tableColumns addObject:[NSDictionary dictionaryWithDictionary:tableColumn]];
@@ -1017,7 +1012,10 @@
// Field defaults
} else if ([detailString isEqualToString:@"DEFAULT"] && (definitionPartsIndex + 1 < partsArrayLength)) {
detailParser = [[SPSQLParser alloc] initWithString:[definitionParts objectAtIndex:definitionPartsIndex+1]];
- [fieldDetails setValue:[detailParser unquotedString] forKey:@"default"];
+ if([[detailParser unquotedString] isEqualToString:@"NULL"])
+ [fieldDetails setObject:[NSNull null] forKey:@"default"];
+ else
+ [fieldDetails setValue:[detailParser unquotedString] forKey:@"default"];
[detailParser release];
definitionPartsIndex++;
diff --git a/Source/TableContent.m b/Source/TableContent.m
index abc6a8e7..42f65d7f 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -1283,7 +1283,7 @@
for ( i = 0 ; i < [dataColumns count] ; i++ ) {
column = NSArrayObjectAtIndex(dataColumns, i);
- if ([column objectForKey:@"default"] == nil || [[column objectForKey:@"default"] isEqualToString:@"NULL"]) {
+ if ([column objectForKey:@"default"] == nil || [column objectForKey:@"default"] == [NSNull null]) {
[newRow addObject:[NSNull null]];
} else {
[newRow addObject:[column objectForKey:@"default"]];
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 12ab01de..a035c750 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -40,6 +40,7 @@
#import "SPAlertSheets.h"
#import "SPFieldMapperController.h"
#import "SPMainThreadTrampoline.h"
+#import "SPNotLoaded.h"
@implementation TableDump
@@ -1342,6 +1343,10 @@
else
cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
+ // If import column isn't specified import the table column default value
+ if ([cellData isSPNotLoaded])
+ cellData = NSArrayObjectAtIndex(fieldMappingTableDefaultValues, i);
+
if (cellData == [NSNull null]) {
[setString appendString:@"NULL"];
} else {
@@ -1362,6 +1367,10 @@
else
cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
+ // If import column isn't specified import the table column default value
+ if ([cellData isSPNotLoaded])
+ cellData = NSArrayObjectAtIndex(fieldMappingTableDefaultValues, i);
+
if (cellData == [NSNull null]) {
[whereString appendString:@" IS NULL"];
} else {
@@ -1403,6 +1412,10 @@
else
cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn);
+ // If import column isn't specified import the table column default value
+ if ([cellData isSPNotLoaded])
+ cellData = NSArrayObjectAtIndex(fieldMappingTableDefaultValues, i);
+
if (cellData == [NSNull null]) {
[valueString appendString:@"NULL"];
} else {
@@ -2783,12 +2796,12 @@
if ([column objectForKey:@"default"]) {
// Some MySQL server versions show a default of NULL for NOT NULL columns - don't export those.
- if ([[column objectForKey:@"default"] isEqualToString:@"NULL"]) {
+ if ([column objectForKey:@"default"] == [NSNull null]) {
if ([[column objectForKey:@"null"] integerValue])
[fieldString appendString:@" DEFAULT NULL"];
} else if ([[column objectForKey:@"type"] isEqualToString:@"TIMESTAMP"]
- && [[[column objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) {
+ && [column objectForKey:@"default"] != [NSNull null] && [[[column objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) {
[fieldString appendString:@" DEFAULT CURRENT_TIMESTAMP"];
} else {
[fieldString appendFormat:@" DEFAULT '%@'", [mySQLConnection prepareString:[column objectForKey:@"default"]]];