aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-03-31 00:34:03 +0000
committerrowanbeentje <rowan@beent.je>2010-03-31 00:34:03 +0000
commitb9f5c468900eca5748392d61a603b425492706f6 (patch)
treebee5f4c2ca46d39ec2e76972f089fba9e802be15
parentd060c9f395f938d1d1adeec0ce8a9444267bdebf (diff)
downloadsequelpro-b9f5c468900eca5748392d61a603b425492706f6.tar.gz
sequelpro-b9f5c468900eca5748392d61a603b425492706f6.tar.bz2
sequelpro-b9f5c468900eca5748392d61a603b425492706f6.zip
- Improve error checking for various actions, particularly permissions errors (NULL data returned) for views and stored procedures. This should fix http://log.sequelpro.com/view/27 , http://log.sequelpro.com/view/57 , and the last of http://log.sequelpro.com/view/53
-rw-r--r--Source/SPExtendedTableInfo.m11
-rw-r--r--Source/SPTableData.m35
-rw-r--r--Source/TableDocument.m22
-rw-r--r--Source/TableDump.m40
4 files changed, 92 insertions, 16 deletions
diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m
index 216057e0..9636ca4c 100644
--- a/Source/SPExtendedTableInfo.m
+++ b/Source/SPExtendedTableInfo.m
@@ -238,11 +238,12 @@
[tableCreateSyntaxTextView setString:@""];
NSString *createViewSyntax = [[tableDataInstance tableCreateSyntax] createViewSyntaxPrettifier];
-
- [tableCreateSyntaxTextView shouldChangeTextInRange:NSMakeRange(0, 0) replacementString:createViewSyntax];
- [tableCreateSyntaxTextView insertText:createViewSyntax];
- [tableCreateSyntaxTextView didChangeText];
- [tableCreateSyntaxTextView setEditable:NO];
+ if (createViewSyntax) {
+ [tableCreateSyntaxTextView shouldChangeTextInRange:NSMakeRange(0, 0) replacementString:createViewSyntax];
+ [tableCreateSyntaxTextView insertText:createViewSyntax];
+ [tableCreateSyntaxTextView didChangeText];
+ [tableCreateSyntaxTextView setEditable:NO];
+ }
} else {
[tableCreateSyntaxTextView setEditable:YES];
[tableCreateSyntaxTextView shouldChangeTextInRange:NSMakeRange(0, [[tableCreateSyntaxTextView string] length]) replacementString:@""];
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index b75f6dd5..7021ddc2 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -93,7 +93,10 @@
[self updateInformationForCurrentTable];
}
}
-
+
+ // On failure, return nil
+ if (!tableCreateSyntax) return nil;
+
return [NSString stringWithString:tableCreateSyntax];
}
@@ -354,8 +357,19 @@
// connection reconnect dialog to appear and the user chose to close the connection.
if (!syntaxResult) return nil;
- if (tableCreateSyntax != nil) [tableCreateSyntax release];
-
+ if (tableCreateSyntax != nil) [tableCreateSyntax release], tableCreateSyntax = nil;
+
+ // A NULL value indicates that the user does not have permission to view the syntax
+ if ([[syntaxResult objectAtIndex:1] isNSNull]) {
+ [[NSAlert alertWithMessageText:NSLocalizedString(@"Permission Denied", @"Permission Denied")
+ defaultButton:NSLocalizedString(@"OK", @"OK")
+ alternateButton:nil otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")]
+ beginSheetModalForWindow:[NSApp mainWindow]
+ modalDelegate:self didEndSelector:NULL contextInfo:NULL];
+ return nil;
+ }
+
tableCreateSyntax = [[NSString alloc] initWithString:[syntaxResult objectAtIndex:1]];
createTableParser = [[SPSQLParser alloc] initWithString:[syntaxResult objectAtIndex:1]];
@@ -708,7 +722,20 @@
// Retrieve the table syntax string
if (tableCreateSyntax) [tableCreateSyntax release], tableCreateSyntax = nil;
- tableCreateSyntax = [[NSString alloc] initWithString:[[theResult fetchRowAsArray] objectAtIndex:1]];
+ NSString *syntaxString = [[theResult fetchRowAsArray] objectAtIndex:1];
+
+ // A NULL value indicates that the user does not have permission to view the syntax
+ if ([syntaxString isNSNull]) {
+ [[NSAlert alertWithMessageText:NSLocalizedString(@"Permission Denied", @"Permission Denied")
+ defaultButton:NSLocalizedString(@"OK", @"OK")
+ alternateButton:nil otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")]
+ beginSheetModalForWindow:[NSApp mainWindow]
+ modalDelegate:self didEndSelector:NULL contextInfo:NULL];
+ return nil;
+ }
+
+ tableCreateSyntax = [[NSString alloc] initWithString:syntaxString];
// Retrieve the SHOW COLUMNS syntax for the table
theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [viewName backtickQuotedString]]];
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 936792b2..4ef781e3 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -1672,6 +1672,17 @@
NSString *tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs];
+ // A NULL value indicates that the user does not have permission to view the syntax
+ if ([tableSyntax isNSNull]) {
+ [[NSAlert alertWithMessageText:NSLocalizedString(@"Permission Denied", @"Permission Denied")
+ defaultButton:NSLocalizedString(@"OK", @"OK")
+ alternateButton:nil otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")]
+ beginSheetModalForWindow:tableWindow
+ modalDelegate:self didEndSelector:NULL contextInfo:NULL];
+ return;
+ }
+
[createTableSyntaxTextField setStringValue:[NSString stringWithFormat:@"Create syntax for %@ '%@'", typeString, [self table]]];
[createTableSyntaxTextView setEditable:YES];
@@ -1730,6 +1741,17 @@
NSString *tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs];
+ // A NULL value indicates that the user does not have permission to view the syntax
+ if ([tableSyntax isNSNull]) {
+ [[NSAlert alertWithMessageText:NSLocalizedString(@"Permission Denied", @"Permission Denied")
+ defaultButton:NSLocalizedString(@"OK", @"OK")
+ alternateButton:nil otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")]
+ beginSheetModalForWindow:tableWindow
+ modalDelegate:self didEndSelector:NULL contextInfo:NULL];
+ return;
+ }
+
// copy to the clipboard
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 11196204..a905d7be 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -1843,6 +1843,39 @@
continue;
}
+ // Retrieve the procedure CREATE syntax
+ MCPResult *createProcedureResult;
+ createProcedureResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW CREATE %@ %@ */;;",
+ procedureType,
+ [procedureName backtickQuotedString]]];
+ [createProcedureResult setReturnDataAsStrings:YES];
+
+ if ([mySQLConnection queryErrored]) {
+ [errors appendString:[NSString stringWithFormat:@"%@\n", [mySQLConnection getLastErrorMessage]]];
+ if ( [addErrorsSwitch state] == NSOnState ) {
+ [fileHandle writeData:[[NSString stringWithFormat:@"# Error: %@\n", [mySQLConnection getLastErrorMessage]]
+ dataUsingEncoding:NSUTF8StringEncoding]];
+ }
+ [proceduresList release];
+ continue;
+ }
+
+ NSDictionary *procedureInfo = [[NSDictionary alloc] initWithDictionary:[createProcedureResult fetchRowAsDictionary]];
+ NSString *createProcedure = [procedureInfo objectForKey:[NSString stringWithFormat:@"Create %@", [procedureType capitalizedString]]];
+
+ // A NULL result indicates a permission problem
+ if ([createProcedure isNSNull]) {
+ NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"Could not export the %@ '%@' because of a permisions error.\n", @"Procedure/function export permission error"), procedureType, procedureName];
+ [errors appendString:errorString];
+ if ( [addErrorsSwitch state] == NSOnState ) {
+ [fileHandle writeData:[[NSString stringWithFormat:@"# Error: %@\n", errorString]
+ dataUsingEncoding:NSUTF8StringEncoding]];
+ }
+ [proceduresList release];
+ [procedureInfo release];
+ continue;
+ }
+
// Add the "drop" command if specified in the export dialog
if ([addDropTableSwitch state] == NSOnState) {
[metaString appendString:[NSString stringWithFormat:@"/*!50003 DROP %@ IF EXISTS %@ */;;\n",
@@ -1863,17 +1896,10 @@
[[procedureDefiner objectAtIndex:1] backtickQuotedString]
];
- MCPResult *createProcedureResult;
- createProcedureResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW CREATE %@ %@ */;;",
- procedureType,
- [procedureName backtickQuotedString]]];
- [createProcedureResult setReturnDataAsStrings:YES];
- NSDictionary *procedureInfo = [[NSDictionary alloc] initWithDictionary:[createProcedureResult fetchRowAsDictionary]];
[metaString appendString:[NSString stringWithFormat:@"/*!50003 SET SESSION SQL_MODE=\"%@\"*/;;\n",
[procedureInfo objectForKey:@"sql_mode"]]];
- NSString *createProcedure = [procedureInfo objectForKey:[NSString stringWithFormat:@"Create %@", [procedureType capitalizedString]]];
NSRange procedureRange = [createProcedure rangeOfString:procedureType options:NSCaseInsensitiveSearch];
NSString *procedureBody = [createProcedure substringFromIndex:procedureRange.location];