Permalink
Browse files

Add support for adding relations on MySQL < 5 (#530)

  • Loading branch information...
dmoagx committed Nov 6, 2015
1 parent b21b4ff commit 72951bfbb85dd91095823fc6a170d3ce41718246
Showing with 19 additions and 5 deletions.
  1. +19 −5 Source/SPTableRelations.m
@@ -270,11 +270,25 @@ - (IBAction)addRelation:(id)sender
}
// Get all InnoDB tables in the current database
// TODO: MySQL 4 compatibility
SPMySQLResult *result = [connection queryString:[NSString stringWithFormat:@"SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND engine = 'InnoDB' AND table_schema = %@", [[tableDocumentInstance database] tickQuotedString]]];
[result setDefaultRowReturnType:SPMySQLResultRowAsArray];
for (NSArray *eachRow in result) {
[refTablePopUpButton addItemWithTitle:[eachRow objectAtIndex:0]];
if ([[tableDocumentInstance serverSupport] supportsInformationSchema]) {
//MySQL 5.0+
SPMySQLResult *result = [connection queryString:[NSString stringWithFormat:@"SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND engine = 'InnoDB' AND table_schema = %@", [[tableDocumentInstance database] tickQuotedString]]];
[result setDefaultRowReturnType:SPMySQLResultRowAsArray];
for (NSArray *eachRow in result) {
[refTablePopUpButton addItemWithTitle:[eachRow objectAtIndex:0]];
}
}
else {
//this will work back to 3.23.0, innodb was added in 3.23.49
SPMySQLResult *result = [connection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS FROM %@", [[tableDocumentInstance database] backtickQuotedString]]];
[result setDefaultRowReturnType:SPMySQLResultRowAsArray];
[result setReturnDataAsStrings:YES]; // some mysql versions would return NSData for string fields otherwise
for (NSArray *eachRow in result) {
// col[1] was named "Type" < 4.1, "Engine" afterwards
if(![[[eachRow objectAtIndex:1] uppercaseString] isEqualToString:@"INNODB"]) continue;
// col[0] is the table name
[refTablePopUpButton addItemWithTitle:[eachRow objectAtIndex:0]];
}
}
// Reset other fields

0 comments on commit 72951bf

Please sign in to comment.