diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-10-01 12:20:30 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-10-01 12:20:30 +0000 |
commit | 294af53678cda18e5f6e5f2007daa0893c1250d0 (patch) | |
tree | 1ba6643637001b2d4852094551e7deb2f22c929b | |
parent | d7efae3ff6e5cf9407af16dbba09a55be092ce45 (diff) | |
download | sequelpro-294af53678cda18e5f6e5f2007daa0893c1250d0.tar.gz sequelpro-294af53678cda18e5f6e5f2007daa0893c1250d0.tar.bz2 sequelpro-294af53678cda18e5f6e5f2007daa0893c1250d0.zip |
• added basic support for spatial data
- while querying and writing back make usage of AsText() and GeomFromText() to allow to edit each GEOMETRY field as text simple string
- works only in Content Tab so far
- the spatial data are not yet editable inside views
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m | 4 | ||||
-rw-r--r-- | Source/SPTableContent.m | 38 | ||||
-rw-r--r-- | Source/SPTableData.h | 1 | ||||
-rw-r--r-- | Source/SPTableData.m | 29 |
4 files changed, 64 insertions, 8 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m index 5c607912..5883bdc2 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m @@ -320,6 +320,10 @@ void _bytes2bin(Byte *n, NSUInteger nbytes, NSUInteger len, char *buf); cellData = [NSNull null]; break; + case FIELD_TYPE_GEOMETRY: + cellData = [NSData dataWithBytes:theData length:fieldLengths[i]]; + break; + default: NSLog(@"in fetchNextRowAsArray : Unknown type : %ld for column %ld, sending back a NSData object", (NSInteger)fieldDefinitions[i].type, (NSInteger)i); cellData = [NSData dataWithBytes:theData length:fieldLengths[i]]; 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 @"*"; + } } diff --git a/Source/SPTableData.h b/Source/SPTableData.h index ade1d30e..69a6ed2f 100644 --- a/Source/SPTableData.h +++ b/Source/SPTableData.h @@ -57,6 +57,7 @@ - (NSArray *) getConstraints; - (NSArray *) triggers; - (BOOL) columnIsBlobOrText:(NSString *)colName; +- (BOOL) columnIsGeometry:(NSString *)colName; - (NSString *) statusValueForKey:(NSString *)aKey; - (void)setStatusValue:(NSString *)value forKey:(NSString *)key; - (NSDictionary *) statusValues; diff --git a/Source/SPTableData.m b/Source/SPTableData.m index edff16b6..fc410044 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -258,6 +258,30 @@ return (BOOL) ([[[self columnWithName:colName] objectForKey:@"typegrouping"] isEqualToString:@"textdata" ] || [[[self columnWithName:colName] objectForKey:@"typegrouping"] isEqualToString:@"blobdata"]); } +/** + * Checks if this column is type geometry. + * Used to determine if we have to use AsText() in SELECT. + * + * @param colName The column name which should be checked. + */ + +- (BOOL) columnIsGeometry:(NSString *)colName +{ + + // Return if CREATE SYNTAX is being parsed + if(isWorking) return YES; // to be at the safe side + + if ([columns count] == 0) { + if ([tableListInstance tableType] == SPTableTypeView) { + [self updateInformationForCurrentView]; + } else { + [self updateInformationForCurrentTable]; + } + } + + return (BOOL) ([[[self columnWithName:colName] objectForKey:@"typegrouping"] isEqualToString:@"geometry"]); +} + /** * Retrieve the table status value for a supplied key, using or refreshing the cache as appropriate. @@ -1147,6 +1171,11 @@ } else if ([detailString isEqualToString:@"TINYTEXT"] || [detailString isEqualToString:@"TEXT"] || [detailString isEqualToString:@"MEDIUMTEXT"] || [detailString isEqualToString:@"LONGTEXT"]) { [fieldDetails setObject:@"textdata" forKey:@"typegrouping"]; + } else if ([detailString isEqualToString:@"POINT"] || [detailString isEqualToString:@"GEOMETRY"] + || [detailString isEqualToString:@"LINESTRING"] || [detailString isEqualToString:@"POLYGON"] + || [detailString isEqualToString:@"MULTIPOLYGON"] || [detailString isEqualToString:@"GEOMETRYCOLLECTION"] + || [detailString isEqualToString:@"MULTIPOINT"] || [detailString isEqualToString:@"MULTILINESTRING"]) { + [fieldDetails setObject:@"geometry" forKey:@"typegrouping"]; // Default to "blobdata". This means that future and currently unsupported types - including spatial extensions - // will be preserved unmangled. |