From 4efbaf34545f7a11baf3b426b8a9b1c25f4f93c7 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 9 May 2011 00:35:29 +0000 Subject: - When importing CSVs, or editing custom query results, set numeric fields to NULL instead of 0 if an empty string is entered. This matches TableContent behaviour and addresses Issue #1034. --- Source/SPCustomQuery.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'Source/SPCustomQuery.m') diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index bed5506e..26810323 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -1980,11 +1980,13 @@ if (aTableView == customQueryView) { NSDictionary *columnDefinition; + NSString *columnTypeGroup; // Retrieve the column defintion for(id c in cqColumnDefinition) { if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[aTableColumn identifier]]) { columnDefinition = [NSDictionary dictionaryWithDictionary:c]; + columnTypeGroup = [columnDefinition objectForKey:@"typegrouping"]; break; } } @@ -2018,13 +2020,16 @@ } else { if ( [[anObject description] isEqualToString:@"CURRENT_TIMESTAMP"] ) { newObject = @"CURRENT_TIMESTAMP"; - } else if([anObject isEqualToString:[prefs stringForKey:SPNullValue]]) { + } else if ([anObject isEqualToString:[prefs stringForKey:SPNullValue]] + || (([columnTypeGroup isEqualToString:@"float"] || [columnTypeGroup isEqualToString:@"integer"]) + && [[anObject description] isEqualToString:@""])) + { newObject = @"NULL"; - } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"geometry"]) { + } else if ([columnTypeGroup isEqualToString:@"geometry"]) { newObject = [(NSString*)anObject getGeomFromTextString]; - } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { + } else if ([columnTypeGroup isEqualToString:@"bit"]) { newObject = [NSString stringWithFormat:@"b'%@'", ((![[anObject description] length] || [[anObject description] isEqualToString:@"0"]) ? @"0" : [anObject description])]; - } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"date"] + } else if ([columnTypeGroup isEqualToString:@"date"] && [[anObject description] isEqualToString:@"NOW()"]) { newObject = @"NOW()"; } else { -- cgit v1.2.3