Skip to content

Commit 2710611

Browse files
committed
#2636: Fix display of indexes against geometry columns.
1 parent 3f24d5d commit 2710611

File tree

1 file changed

+17
-49
lines changed

1 file changed

+17
-49
lines changed

Source/SPTableStructure.m

+17-49
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@
5656
static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
5757

5858
@interface SPFieldTypeHelp ()
59+
5960
@property(copy,readwrite) NSString *typeName;
6061
@property(copy,readwrite) NSString *typeDefinition;
6162
@property(copy,readwrite) NSString *typeRange;
6263
@property(copy,readwrite) NSString *typeDescription;
64+
6365
@end
6466

6567
@implementation SPFieldTypeHelp
@@ -505,17 +507,17 @@ - (IBAction)removeField:(id)sender
505507
}
506508

507509
/**
508-
*
510+
* Resets the auto increment value of a table.
509511
*/
510512
- (IBAction)resetAutoIncrement:(id)sender
511513
{
512-
#ifndef SP_CODA
513514
if ([sender tag] == 1) {
514515

515516
[resetAutoIncrementLine setHidden:YES];
516517

517-
if ([tableDocumentInstance currentlySelectedView] == SPTableViewStructure)
518+
if ([tableDocumentInstance currentlySelectedView] == SPTableViewStructure){
518519
[resetAutoIncrementLine setHidden:NO];
520+
}
519521

520522
// Begin the sheet
521523
[NSApp beginSheet:resetAutoIncrementSheet
@@ -529,31 +531,30 @@ - (IBAction)resetAutoIncrement:(id)sender
529531
else if ([sender tag] == 2) {
530532
[self setAutoIncrementTo:@1];
531533
}
532-
#endif
533534
}
534535

535536
/**
536537
* Process the autoincrement sheet closing, resetting if the user confirmed the action.
537538
*/
538539
- (void)resetAutoincrementSheetDidEnd:(NSWindow *)theSheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
539540
{
540-
#ifndef SP_CODA
541541
// Order out current sheet to suppress overlapping of sheets
542542
[theSheet orderOut:nil];
543543

544544
if (returnCode == NSAlertDefaultReturn) {
545545
[self takeAutoIncrementFrom:resetAutoIncrementValue];
546546
}
547-
#endif
548547
}
549548

550549
- (void)takeAutoIncrementFrom:(NSTextField *)field
551550
{
552551
id obj = [field objectValue];
552+
553553
//nil is handled by -setAutoIncrementTo:
554-
if(obj && ![obj isKindOfClass:[NSNumber class]]) {
554+
if (obj && ![obj isKindOfClass:[NSNumber class]]) {
555555
[NSException raise:NSInternalInconsistencyException format:@"[$field objectValue] should return NSNumber *, but was %@",[obj class]];
556556
}
557+
557558
[self setAutoIncrementTo:(NSNumber *)obj];
558559
}
559560

@@ -728,7 +729,6 @@ - (NSArray *)convertIndexResultToArray:(SPMySQLResult *)theResult
728729
return tempResult;
729730
}
730731

731-
732732
/**
733733
* A method to be called whenever the selection changes or the table would be reloaded
734734
* or altered; checks whether the current row is being edited, and if so attempts to save
@@ -1062,40 +1062,6 @@ - (NSString *)_buildPartialColumnDefinitionString:(NSDictionary *)theRow
10621062
return queryString;
10631063
}
10641064

1065-
#ifdef SP_CODA /* glue */
1066-
1067-
- (void)setDatabaseDocument:(SPDatabaseDocument*)doc
1068-
{
1069-
tableDocumentInstance = doc;
1070-
}
1071-
1072-
- (void)setTableListInstance:(SPTablesList*)list
1073-
{
1074-
tablesListInstance = list;
1075-
}
1076-
1077-
- (void)setTableDataInstance:(SPTableData*)data
1078-
{
1079-
tableDataInstance = data;
1080-
}
1081-
1082-
- (void)setDatabaseDataInstance:(SPDatabaseData*)data
1083-
{
1084-
databaseDataInstance = data;
1085-
}
1086-
1087-
- (void)setTableSourceView:(SPTableView*)tv
1088-
{
1089-
tableSourceView = tv;
1090-
}
1091-
1092-
- (void)setEncodingPopupCell:(NSPopUpButtonCell*)cell
1093-
{
1094-
encodingPopupCell = cell;
1095-
}
1096-
1097-
#endif
1098-
10991065
/**
11001066
* A method to show an error sheet after a short delay, so that it can
11011067
* be called from within an endSheet selector. This should be called on
@@ -1555,23 +1521,25 @@ - (void)loadTable:(NSString *)aTable
15551521
}
15561522

15571523
// Process the indexes into a local array of dictionaries
1558-
NSArray *theTableIndexes = [self convertIndexResultToArray:indexResult];
1524+
NSArray *tableIndexes = [self convertIndexResultToArray:indexResult];
15591525

15601526
// Set the Key column
1561-
for (NSDictionary* theIndex in theTableIndexes)
1527+
for (NSDictionary *index in tableIndexes)
15621528
{
15631529
for (id field in theTableFields)
15641530
{
1565-
if ([[field objectForKey:@"name"] isEqualToString:[theIndex objectForKey:@"Column_name"]]) {
1566-
if ([[theIndex objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"]) {
1531+
if ([[field objectForKey:@"name"] isEqualToString:[index objectForKey:@"Column_name"]]) {
1532+
if ([[index objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"]) {
15671533
[field setObject:@"PRI" forKey:@"Key"];
15681534
}
15691535
else {
1570-
if ([[field objectForKey:@"typegrouping"] isEqualToString:@"geometry"]) {
1536+
if ([[field objectForKey:@"typegrouping"] isEqualToString:@"geometry"] &&
1537+
[[index objectForKey:@"Index_type"] isEqualToString:@"SPATIAL"]
1538+
![field objectForKey:@"Key"]) {
15711539
[field setObject:@"SPA" forKey:@"Key"];
15721540
}
15731541
else {
1574-
[field setObject:(([[theIndex objectForKey:@"Non_unique"] isEqualToString:@"1"]) ? @"MUL" : @"UNI") forKey:@"Key"];
1542+
[field setObject:[[index objectForKey:@"Non_unique"] isEqualToString:@"1"] ? @"MUL" : @"UNI" forKey:@"Key"];
15751543
}
15761544
}
15771545

@@ -1716,7 +1684,7 @@ - (void)loadTable:(NSString *)aTable
17161684
NSDictionary *tableDetails = [NSDictionary dictionaryWithObjectsAndKeys:
17171685
aTable, @"name",
17181686
theTableFields, @"tableFields",
1719-
theTableIndexes, @"tableIndexes",
1687+
tableIndexes, @"tableIndexes",
17201688
theTableEnumLists, @"enumLists",
17211689
nil];
17221690

0 commit comments

Comments
 (0)