From 294af53678cda18e5f6e5f2007daa0893c1250d0 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 1 Oct 2010 12:20:30 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20basic=20support=20for=20spatial=20d?= =?UTF-8?q?ata=20-=20while=20querying=20and=20writing=20back=20make=20usag?= =?UTF-8?q?e=20of=20AsText()=20and=20GeomFromText()=20to=20allow=20to=20ed?= =?UTF-8?q?it=20each=20GEOMETRY=20field=20as=20text=20simple=20string=20-?= =?UTF-8?q?=20works=20only=20in=20Content=20Tab=20so=20far=20-=20the=20spa?= =?UTF-8?q?tial=20data=20are=20not=20yet=20editable=20inside=20views?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTableContent.m | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'Source/SPTableContent.m') diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 71173f96..b620cf0b 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -2387,6 +2387,8 @@ { [rowValue setString:@"CURRENT_TIMESTAMP"]; + } else if ( [[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"typegrouping"] isEqualToString:@"geometry"] ) { + [rowValue setString:[NSString stringWithFormat:@"GeomFromText('%@')", rowObject]]; // 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:@""]) ) { @@ -2672,8 +2674,12 @@ [value setString:[NSString stringWithFormat:@"b'%@'", [mySQLConnection prepareString:tempValue]]]; } // BLOB/TEXT data - else if ([tempValue isKindOfClass:[NSData class]]) - [value setString:[NSString stringWithFormat:@"X'%@'", [mySQLConnection prepareBinaryData:tempValue]]]; + else if ([tempValue isKindOfClass:[NSData class]]) { + if([tableDataInstance columnIsGeometry:NSArrayObjectAtIndex(keys, i)]) + [value setString:[NSString stringWithFormat:@"GeomFromText('%@')", [[[NSString alloc] initWithData:tempValue encoding:NSASCIIStringEncoding] autorelease]]]; + else + [value setString:[NSString stringWithFormat:@"X'%@'", [mySQLConnection prepareBinaryData:tempValue]]]; + } else [value setString:[NSString stringWithFormat:@"'%@'", [mySQLConnection prepareString:tempValue]]]; @@ -2712,15 +2718,18 @@ { NSInteger i; NSMutableArray *fields = [NSMutableArray array]; + NSArray *columnNames = [tableDataInstance columnNames]; + BOOL hasGeometryFields = NO; if (([prefs boolForKey:SPLoadBlobsAsNeeded]) && ([dataColumns count] > 0)) { - NSArray *columnNames = [tableDataInstance columnNames]; - for (i = 0 ; i < [columnNames count]; i++) { if (![tableDataInstance columnIsBlobOrText:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"]] ) { - [fields addObject:[NSArrayObjectAtIndex(columnNames, i) backtickQuotedString]]; + if([tableDataInstance columnIsGeometry:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"]]) + [fields addObject:[NSString stringWithFormat:@"AsText(%@)", [NSArrayObjectAtIndex(columnNames, i) backtickQuotedString]]]; + else + [fields addObject:[NSArrayObjectAtIndex(columnNames, i) backtickQuotedString]]; } else { // For blob/text fields, select a null placeholder so the column count is still correct @@ -2729,9 +2738,22 @@ } return [fields componentsJoinedByString:@","]; - } - else { - return @"*"; + } else { + + for (i = 0 ; i < [columnNames count]; i++) + { + if([tableDataInstance columnIsGeometry:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"]]) { + [fields addObject:[NSString stringWithFormat:@"AsText(%@)", [NSArrayObjectAtIndex(columnNames, i) backtickQuotedString]]]; + hasGeometryFields = YES; + } + else + [fields addObject:[NSArrayObjectAtIndex(columnNames, i) backtickQuotedString]]; + } + if(hasGeometryFields) + return [fields componentsJoinedByString:@","]; + else + return @"*"; + } } -- cgit v1.2.3