Commits

Tuukka Norri committed 015ecef

Fixed a bug which caused PGTSTableDescription to return the wrong index as the primary key under certain conditions
- The indices were sorted by the index oid instead of the relation oid and primarity.
- Added an additional check for this.

Comments (0)

Files changed (2)

Sources/PGTSMetadataContainer.m

 	@" WHERE i.indisunique = true AND "
 	@"  n.nspname NOT IN ('information_schema', 'baseten') AND "
 	@"  n.nspname NOT LIKE 'pg_%' "
-	@" ORDER BY i.indexrelid ASC, i.indisprimary DESC";
+	@" ORDER BY i.indrelid ASC, i.indisprimary DESC";
 	PGTSResultSet* res = [connection executeQuery: query];
 	ExpectV ([res querySucceeded]);
 

Sources/PGTSTableDescription.mm

 
 #import "PGTSTableDescription.h"
 #import "PGTSColumnDescription.h"
+#import "PGTSIndexDescription.h"
 #import "PGTSCollections.h"
 #import "PGTSScannedMemoryAllocator.h"
 #import "BXLogger.h"
 	Expect (mUniqueIndexes);
 	id retval = nil;
 	IdList::const_iterator it = mUniqueIndexes->begin ();
-	if (mUniqueIndexes->end () != it)
+	if (mUniqueIndexes->end () != it && [*it isPrimaryKey])
 		retval = *it;
 	return retval;
 }
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.