Commits

Tuukka Norri committed 736c038

Altered the metadata queries to return only existing columns (fixes #63)

Comments (0)

Files changed (2)

Framework/Sources/PGTSFieldInfo.m

 {
     if (nil == name && index != 0)
     {
-        PGTSResultSet* res = [connection executeQuery: @"SELECT attname, atttypid, attnotnull FROM pg_attribute WHERE attrelid = $1 AND attnum = $2"
-                                           parameters: PGTSOidAsObject ([table oid]), [NSNumber numberWithUnsignedInt: index]];
+		NSString* query = @"SELECT attname, atttypid, attnotnull FROM pg_attribute WHERE attisdropped = false AND attrelid = $1 AND attnum = $2";
+        PGTSResultSet* res = [connection executeQuery: query parameters: PGTSOidAsObject ([table oid]), [NSNumber numberWithUnsignedInt: index]];
         if ([res advanceRow])
         {
             [self setName: [res valueForFieldNamed: @"attname"]];
 {
     if (index == 0 && nil != name)
     {
-        PGTSResultSet* res = [connection executeQuery: @"SELECT attnumber, atttypid, attnotnull FROM pg_attribute WHERE attrelid = $1 AND attname = $2"
-                                           parameters: PGTSOidAsObject ([table oid]), name];
+		NSString* query = @"SELECT attnumber, atttypid, attnotnull FROM pg_attribute WHERE attisdropped = false AND attrelid = $1 AND attname = $2";
+        PGTSResultSet* res = [connection executeQuery: query parameters: PGTSOidAsObject ([table oid]), name];
         [self setIndex: [[res valueForFieldNamed: @"attnumber"] unsignedIntValue]];
         typeOid = [[res valueForFieldNamed: @"atttypid"] PGTSOidValue];
 		isNotNull = [[res valueForFieldNamed: @"attnotnull"] boolValue];

Framework/Sources/PGTSTableInfo.m

 {
     if (NSNotFound == fieldCount)
     {
-        NSString* query = @"SELECT max (attnum) AS count FROM pg_attribute WHERE attrelid = $1";
-        PGTSResultSet* res = [connection executeQuery: query
-                                           parameters: PGTSOidAsObject (oid)];
+        NSString* query = @"SELECT max (attnum) AS count FROM pg_attribute WHERE attisdropped = false AND attrelid = $1";
+        PGTSResultSet* res = [connection executeQuery: query parameters: PGTSOidAsObject (oid)];
         [res advanceRow];
         [self setFieldCount: [[res valueForKey: @"count"] unsignedIntValue]];
     }