From db2d9565c996e206d82a441cfd8e60627f0eab6d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 22 Mar 2010 14:56:05 +0000 Subject: =?UTF-8?q?=E2=80=A2=20CSV=20Import=20-=20if=20a=20parsed=20row=20?= =?UTF-8?q?in=20the=20csv=20file=20doesn't=20have=20the=20same=20number=20?= =?UTF-8?q?of=20columns=20as=20the=20first=20row=20fill=20the=20missing=20?= =?UTF-8?q?columns=20with=20SPNotLoaded=20to=20allow=20while=20importing?= =?UTF-8?q?=20that=20these=20missing=20data=20can=20be=20replaced=20by=20t?= =?UTF-8?q?he=20table=20column's=20DEFAULT=20value=20-=20fixed=20tiny=20is?= =?UTF-8?q?sue=20for=20field=20mapper=20sheet=20to=20display=20the=20corre?= =?UTF-8?q?ct=20tooltip=20for=20default=20values=20=E2=80=A2=20SPTableData?= =?UTF-8?q?=20-=20ATTENTION:=20changed=20the=20object=20for=20returned=20k?= =?UTF-8?q?ey=20'default':=20if=20its=20value=20is=20NULL=20now=20it=20ret?= =?UTF-8?q?urns=20a=20[NSNull=20null]=20object=20-=20changed=20instances?= =?UTF-8?q?=20to=20handle=20this=20=20[NSNull=20null]=20object=20(must=20b?= =?UTF-8?q?e=20checked)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableDump.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Source/TableDump.m') 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"]]]; -- cgit v1.2.3