Tuukka Norri avatar Tuukka Norri committed 9143fda

All array types are now returned as NSArrays
- References #177.
- Added a length field in PGTSTypeDescription. Made it significantly larger than the corresponding field in Postgres.
- Removed element count field from PGTSTypeDescription because it wasn't used.
- Wrote some generic code to handle array types. Now all array types should be guaranteed to be mapped to NSArray.
- Changed -[NSAutoreleasePool release] to -drain.
- Removed manually listed array types from datatypeassociations.plist.

Comments (0)

Files changed (6)

Resources/datatypeassociations.plist

     <string>PGTSACLItem</string>
     <key>uuid</key>
     <string>NSString</string>
-    
-    <!-- Array types -->
-    <key>_abstime</key>
-    <string>NSArray</string>
-    <key>_aclitem</key>    
-    <string>NSArray</string>
-    <key>_bit</key>
-    <string>NSArray</string>
-    <key>_bool</key>
-    <string>NSArray</string>
-    <key>_box</key>
-    <string>NSArray</string>
-    <key>_bpchar</key>
-    <string>NSArray</string>
-    <key>_bytea</key>
-    <string>NSArray</string>
-    <key>_char</key>
-    <string>NSArray</string>
-    <key>_cid</key>
-    <string>NSArray</string>
-    <key>_cidr</key>
-    <string>NSArray</string>
-    <key>_circle</key>
-    <string>NSArray</string>
-    <key>_date</key>
-    <string>NSArray</string>
-    <key>_float4</key>
-    <string>NSArray</string>
-    <key>_float8</key>
-    <string>NSArray</string>
-    <key>_inet</key>
-    <string>NSArray</string>
-    <key>_int2</key>
-    <string>NSArray</string>
-    <key>_int2vector</key>
-    <string>NSArray</string>
-    <key>_int4</key>
-    <string>NSArray</string>
-    <key>_int8</key>
-    <string>NSArray</string>
-    <key>_interval</key>
-    <string>NSArray</string>
-    <key>_line</key>
-    <string>NSArray</string>
-    <key>_lseg</key>
-    <string>NSArray</string>
-    <key>_macaddr</key>
-    <string>NSArray</string>
-    <key>_money</key>
-    <string>NSArray</string>
-    <key>_name</key>
-    <string>NSArray</string>
-    <key>_numeric</key>
-    <string>NSArray</string>
-    <key>_oid</key>
-    <string>NSArray</string>
-    <key>_oidvector</key>
-    <string>NSArray</string>
-    <key>_path</key>
-    <string>NSArray</string>
-    <key>_point</key>
-    <string>NSArray</string>
-    <key>_polygon</key>
-    <string>NSArray</string>
-    <key>_refcursor</key>
-    <string>NSArray</string>
-    <key>_regclass</key>
-    <string>NSArray</string>
-    <key>_regoper</key>
-    <string>NSArray</string>
-    <key>_regoperator</key>
-    <string>NSArray</string>
-    <key>_regproc</key>
-    <string>NSArray</string>
-    <key>_regprocedure</key>
-    <string>NSArray</string>
-    <key>_regtype</key>
-    <string>NSArray</string>
-    <key>_reltime</key>
-    <string>NSArray</string>
-    <key>_text</key>
-    <string>NSArray</string>
-    <key>_tid</key>
-    <string>NSArray</string>
-    <key>_time</key>
-    <string>NSArray</string>
-    <key>_timestamp</key>
-    <string>NSArray</string>
-    <key>_timestamptz</key>
-    <string>NSArray</string>
-    <key>_timetz</key>
-    <string>NSArray</string>
-    <key>_tinterval</key>
-    <string>NSArray</string>
-    <key>_varbit</key>
-    <string>NSArray</string>
-    <key>_varchar</key>
-    <string>NSArray</string>
-    <key>_xid</key>
-    <string>NSArray</string>
 </dict>
 </plist>

Sources/BXLogger.m

 		free (executable);
 	if (library)
 		free (library);
-	[pool release];
+	[pool drain];
 }

Sources/PGTSMetadataContainer.m

 {
 	ExpectV (connection);
 	NSString* query = 
-	@"SELECT t.oid, typname, typnamespace, typelem, typdelim, typtype "
+	@"SELECT t.oid, typname, typnamespace, typelem, typdelim, typtype, typlen "
 	@" FROM pg_type t ";
 	PGTSResultSet* res = [connection executeQuery: query];
 	ExpectV ([res querySucceeded]);
 		[res setClass: [NSNumber class] forKey: @"typelem"];
 		[res setClass: [NSString class] forKey: @"typdelim"];
 		[res setClass: [NSString class] forKey: @"typtype"];
+		[res setClass: [NSNumber class] forKey: @"typlen"];
 		
 		while ([res advanceRow])
 		{
 			unichar kind = [[res valueForKey: @"typtype"] characterAtIndex: 0];
 			ExpectV (kind <= UCHAR_MAX);
 			[type setKind: kind];
+			NSInteger length = [[res valueForKey: @"typlen"] integerValue];
+			[type setLength: length];
 			
 			[type setSchema: [mDatabase schemaWithOid: [[res valueForKey: @"typnamespace"] PGTSOidValue]]];
 			

Sources/PGTSResultSet.mm

 		
 		if (! aClass)
 		{
-			//Come up with some reasonable defaults. Maybe a delegate could be asked, too?
-			switch ([type kind]) 
+			//Check for arrays. Other types that satisfy the condition (like int2vector and oidvector) 
+			//should have an entry in deserializationDictionary, if they are used.
+			if (-1 == [type length] && InvalidOid != [type elementOid])
 			{
-				case 'e':
-					aClass = [NSString class];
-					break;
-					
-				case 'c':
-					//FIXME: handle composite types.
-				case 'd':
-					//FIXME: handle domains.
-				case 'p':
-					//FIXME: handle pseudo-types.
-				case 'b':
-				default:
-					aClass = [NSData class];					
-					break;
-			}			
+				aClass = [NSArray class];
+			}
+			else
+			{
+				//Handle other types by kind.
+				switch ([type kind]) 
+				{
+					case 'e':
+						aClass = [NSString class];
+						break;
+						
+					case 'c':
+						//FIXME: handle composite types.
+					case 'd':
+						//FIXME: handle domains.
+					case 'p':
+						//FIXME: handle pseudo-types. (On the other hand, this shouldn't get reached.)
+					case 'b':
+					default:
+						aClass = [NSData class];					
+						break;
+				}				
+			}
 		}
 		
 		[self setClass: aClass forFieldAtIndex: i];

Sources/PGTSTypeDescription.h

 @interface PGTSTypeDescription : PGTSSchemaObjectDescription 
 {
     Oid mElementOid;
-    unsigned int mElementCount;
+	NSInteger mLength;
     char mDelimiter;
 	char mKind;
 }
 - (Oid) elementOid;
+- (NSInteger) length;
 - (char) delimiter;
 - (char) kind;
 
 //Thread un-safe methods.
 - (void) setElementOid: (Oid) anOid;
+- (void) setLength: (NSInteger) length;
 - (void) setDelimiter: (char) delimiter;
 - (void) setKind: (char) kind;
 @end

Sources/PGTSTypeDescription.m

     if ((self = [super init]))
     {
         mElementOid = InvalidOid;
-        mElementCount = 0;
         mDelimiter = '\0';
     }
     return self;
 	return mElementOid;
 }
 
+- (NSInteger) length
+{
+	return mLength;
+}
+
 - (char) delimiter
 {
     return mDelimiter;
 	mElementOid = elementOid;
 }
 
+- (void) setLength: (NSInteger) length
+{
+	mLength = length;
+}
+
 - (void) setDelimiter: (char) delimiter
 {
 	mDelimiter = delimiter;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.