aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableRelations.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-04-16 00:24:53 +0200
committerMax <post@wickenrode.com>2015-04-16 00:24:53 +0200
commit028f1ff9ac1e22db9abec6ea3838079a08aa471e (patch)
tree547215225796afb958a27e29f99eed0bb6e393ed /Source/SPTableRelations.m
parent8f27fbe9ca78b8258809d1266820095361b46a13 (diff)
downloadsequelpro-028f1ff9ac1e22db9abec6ea3838079a08aa471e.tar.gz
sequelpro-028f1ff9ac1e22db9abec6ea3838079a08aa471e.tar.bz2
sequelpro-028f1ff9ac1e22db9abec6ea3838079a08aa471e.zip
Restore detailed error messages for FK errors in MySQL 5.5+
Diffstat (limited to 'Source/SPTableRelations.m')
-rw-r--r--Source/SPTableRelations.m24
1 files changed, 14 insertions, 10 deletions
diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m
index 5734a96d..43156eae 100644
--- a/Source/SPTableRelations.m
+++ b/Source/SPTableRelations.m
@@ -35,6 +35,7 @@
#import "SPTableView.h"
#import "SPAlertSheets.h"
#import "RegexKitLite.h"
+#import "SPServerSupport.h"
#import <SPMySQL/SPMySQL.h>
@@ -192,16 +193,19 @@ static NSString *SPRelationOnDeleteKey = @"on_delete";
// most common are 121 (name probably in use) and 150 (types don't exactly match).
// Retrieve the InnoDB status and extract the most recent error for more helpful text.
if ([connection lastErrorID] == 1005) {
- NSString *statusText = [connection getFirstFieldFromQuery:@"SHOW INNODB STATUS"];
- NSString *detailErrorString = [statusText stringByMatching:@"latest foreign key error\\s+-----*\\s+[0-9: ]*(.*?)\\s+-----" options:(RKLCaseless | RKLDotAll) inRange:NSMakeRange(0, [statusText length]) capture:1L error:NULL];
- if (detailErrorString) {
- errorText = [NSString stringWithFormat:NSLocalizedString(@"%@\n\nDetail: %@", @"Add relation error detail intro"), errorText, [detailErrorString stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
- }
-
- // Detect name duplication if appropriate
- if ([errorText isMatchedByRegex:@"errno: 121"] && [errorText isMatchedByRegex:@"already exists"]) {
- [takenConstraintNames addObject:[[constraintName stringValue] lowercaseString]];
- [self controlTextDidChange:[NSNotification notificationWithName:@"dummy" object:constraintName]];
+ SPInnoDBStatusQueryFormat status = [[tableDocumentInstance serverSupport] innoDBStatusQuery];
+ if(status.queryString) {
+ NSString *statusText = [[[connection queryString:status.queryString] getRowAsArray] objectAtIndex:status.columnIndex];
+ NSString *detailErrorString = [statusText stringByMatching:@"latest foreign key error\\s+-----*\\s+[0-9: ]*(.*?)\\s+-----" options:(RKLCaseless | RKLDotAll) inRange:NSMakeRange(0, [statusText length]) capture:1L error:NULL];
+ if (detailErrorString) {
+ errorText = [NSString stringWithFormat:NSLocalizedString(@"%@\n\nDetail: %@", @"Add relation error detail intro"), errorText, [detailErrorString stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
+ }
+
+ // Detect name duplication if appropriate
+ if ([errorText isMatchedByRegex:@"errno: 121"] && [errorText isMatchedByRegex:@"already exists"]) {
+ [takenConstraintNames addObject:[[constraintName stringValue] lowercaseString]];
+ [self controlTextDidChange:[NSNotification notificationWithName:@"dummy" object:constraintName]];
+ }
}
}