diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPCustomQuery.m | 2 | ||||
-rw-r--r-- | Source/SPDataImport.m | 2 | ||||
-rw-r--r-- | Source/SPStringAdditions.h | 2 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 27 | ||||
-rw-r--r-- | Source/SPTableContent.m | 5 |
5 files changed, 34 insertions, 4 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 097b5cd6..3938a72f 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -1907,7 +1907,7 @@ } else if([anObject isEqualToString:[prefs stringForKey:SPNullValue]]) { newObject = @"NULL"; } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"geometry"]) { - newObject = [NSString stringWithFormat:@"GeomFromText('%@')", anObject]; + newObject = [(NSString*)anObject getGeomFromTextFromString]; } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { newObject = [NSString stringWithFormat:@"b'%@'", ((![[anObject description] length] || [[anObject description] isEqualToString:@"0"]) ? @"0" : [anObject description])]; } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"date"] diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m index d467e0a1..98cbb697 100644 --- a/Source/SPDataImport.m +++ b/Source/SPDataImport.m @@ -1358,7 +1358,7 @@ } else { // Apply GeomFromText() for each geometry field if([geometryFields count] && [geometryFieldsMapIndex containsIndex:i]) { - [valueString appendFormat:@"GeomFromText('%@')", [mySQLConnection prepareString:cellData]]; + [valueString appendString:[mySQLConnection prepareString:[(NSString*)cellData getGeomFromTextFromString]]]; } else { [valueString appendFormat:@"'%@'", [mySQLConnection prepareString:cellData]]; } diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index 1826f888..260f44d9 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -67,6 +67,8 @@ static inline id NSMutableAttributedStringAttributeAtIndex (NSMutableAttributedS - (NSArray *)lineRangesForRange:(NSRange)aRange; - (NSString *)createViewSyntaxPrettifier; +- (NSString*)getGeomFromTextFromString; + - (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)charSet options:(NSUInteger)mask; - (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)charSet; diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 2eafb4e9..a8695dbb 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -375,6 +375,33 @@ } /** + * Create the GeomFromText() string according to a possible SRID value + */ +- (NSString*)getGeomFromTextFromString +{ + + NSString *geomStr = [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + if(![self rangeOfString:@")"].length || [self length] < 5) return @""; + + // No SRID + if([geomStr hasSuffix:@")"]) + return [NSString stringWithFormat:@"GeomFromText('%@')", geomStr]; + // Has SRID + else { + NSUInteger idx = [geomStr length]-1; + while(idx>1) { + if([geomStr characterAtIndex:idx] == ')') + break; + idx--; + } + return [NSString stringWithFormat:@"GeomFromText('%@'%@)", + [geomStr substringToIndex:idx+1], [geomStr substringFromIndex:idx+1]]; + } + +} + +/** * Returns the minimum of a, b and c. */ - (NSInteger)smallestOf:(NSInteger)a andOf:(NSInteger)b andOf:(NSInteger)c diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index ab0a15c3..027f86a3 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -2340,6 +2340,7 @@ contextInfo:nil]; } + /** * Tries to write a new row to the database. * Returns YES if row is written to database, otherwise NO; also returns YES if no row @@ -2392,7 +2393,7 @@ [rowValue setString:@"CURRENT_TIMESTAMP"]; } else if ( [[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"typegrouping"] isEqualToString:@"geometry"] ) { - [rowValue setString:[NSString stringWithFormat:@"GeomFromText('%@')", ([rowObject isKindOfClass:[MCPGeometryData class]]) ? [rowObject wktString] : rowObject]]; + [rowValue setString:([rowObject isKindOfClass:[MCPGeometryData class]]) ? [[rowObject wktString] getGeomFromTextFromString] : [(NSString*)rowObject getGeomFromTextFromString]]; // Convert the object to a string (here we can add special treatment for date-, number- and data-fields) } else if ( [rowObject isNSNull] || ([rowObject isMemberOfClass:[NSString class]] && [[rowObject description] isEqualToString:@""]) ) { @@ -3565,7 +3566,7 @@ } else if([anObject isEqualToString:[prefs stringForKey:SPNullValue]]) { newObject = @"NULL"; } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"geometry"]) { - newObject = [NSString stringWithFormat:@"GeomFromText('%@')", anObject]; + newObject = [(NSString*)anObject getGeomFromTextFromString]; } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { newObject = [NSString stringWithFormat:@"b'%@'", ((![[anObject description] length] || [[anObject description] isEqualToString:@"0"]) ? @"0" : [anObject description])]; } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"date"] |