aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorStuart Connolly <stuart02@gmail.com>2014-08-28 19:08:14 +0100
committerStuart Connolly <stuart02@gmail.com>2014-08-28 19:08:14 +0100
commit310fb079c75d551bf2a129b69c897905ca83e061 (patch)
treeae163e957f6e43c49fef9014a96f8cab7b99cbfa /Source
parente3c342d623b24a55215fadb3b7c72f80df303e83 (diff)
downloadsequelpro-310fb079c75d551bf2a129b69c897905ca83e061.tar.gz
sequelpro-310fb079c75d551bf2a129b69c897905ca83e061.tar.bz2
sequelpro-310fb079c75d551bf2a129b69c897905ca83e061.zip
Resolve #1938: In the query console display the database the query was executed in.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConnectionDelegate.m40
-rw-r--r--Source/SPConsoleMessage.h12
-rw-r--r--Source/SPConsoleMessage.m9
-rw-r--r--Source/SPConstants.h1
-rw-r--r--Source/SPConstants.m1
-rw-r--r--Source/SPQueryConsoleDataSource.m10
-rw-r--r--Source/SPQueryController.h24
-rw-r--r--Source/SPQueryController.m52
-rw-r--r--Source/SPQueryControllerInitializer.m1
-rw-r--r--Source/SPTableContent.m8
10 files changed, 112 insertions, 46 deletions
diff --git a/Source/SPConnectionDelegate.m b/Source/SPConnectionDelegate.m
index b7bbc47e..caf7926c 100644
--- a/Source/SPConnectionDelegate.m
+++ b/Source/SPConnectionDelegate.m
@@ -48,11 +48,11 @@
{
#ifndef SP_CODA
if ([prefs boolForKey:SPConsoleEnableLogging]) {
- if ((_queryMode == SPInterfaceQueryMode && [prefs boolForKey:SPConsoleEnableInterfaceLogging])
- || (_queryMode == SPCustomQueryQueryMode && [prefs boolForKey:SPConsoleEnableCustomQueryLogging])
- || (_queryMode == SPImportExportQueryMode && [prefs boolForKey:SPConsoleEnableImportExportLogging]))
+ if ((_queryMode == SPInterfaceQueryMode && [prefs boolForKey:SPConsoleEnableInterfaceLogging]) ||
+ (_queryMode == SPCustomQueryQueryMode && [prefs boolForKey:SPConsoleEnableCustomQueryLogging]) ||
+ (_queryMode == SPImportExportQueryMode && [prefs boolForKey:SPConsoleEnableImportExportLogging]))
{
- [[SPQueryController sharedQueryController] showMessageInConsole:query connection:[self name]];
+ [[SPQueryController sharedQueryController] showMessageInConsole:query connection:[self name] database:[self database]];
}
}
#endif
@@ -65,7 +65,7 @@
{
#ifndef SP_CODA
if ([prefs boolForKey:SPConsoleEnableLogging] && [prefs boolForKey:SPConsoleEnableErrorLogging]) {
- [[SPQueryController sharedQueryController] showErrorInConsole:error connection:[self name]];
+ [[SPQueryController sharedQueryController] showErrorInConsole:error connection:[self name] database:[self database]];
}
#endif
}
@@ -75,7 +75,6 @@
*/
- (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection
{
-
// If no keychain item is available, return an empty password
if (![connectionController connectionKeychainItemName]) return nil;
@@ -96,23 +95,26 @@
*/
- (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection
{
-
// If no keychain item is available, return an empty password
if (![connectionController connectionKeychainItemName]) return @"";
// Otherwise, pull the password from the keychain using the details from this connection
SPKeychain *keychain = [[SPKeychain alloc] init];
+
NSString *connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]] retain];
NSString *connectionSSHKeychainItemAccount = [[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]] retain];
- NSString *sshpw = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
- if (!sshpw || ![sshpw length])
- sshpw = @"";
+ NSString *sshPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
+
+ if (!sshPassword || ![sshPassword length]) {
+ sshPassword = @"";
+ }
+
+ if (connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
+ if (connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
- if(connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
- if(connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
[keychain release];
- return sshpw;
+ return sshPassword;
}
/**
@@ -121,7 +123,17 @@
*/
- (void)noConnectionAvailable:(id)connection
{
- SPBeginAlertSheet(NSLocalizedString(@"No connection available", @"no connection available message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, NSLocalizedString(@"An error has occured and there doesn't seem to be a connection available.", @"no connection available informatie message"));
+ SPBeginAlertSheet(
+ NSLocalizedString(@"No connection available", @"no connection available message"),
+ NSLocalizedString(@"OK", @"OK button"),
+ nil,
+ nil,
+ [self parentWindow],
+ self,
+ nil,
+ nil,
+ NSLocalizedString(@"An error has occured and there doesn't seem to be a connection available.", @"no connection available informatie message")
+ );
}
/**
diff --git a/Source/SPConsoleMessage.h b/Source/SPConsoleMessage.h
index 7fe1b711..e79845ae 100644
--- a/Source/SPConsoleMessage.h
+++ b/Source/SPConsoleMessage.h
@@ -34,16 +34,24 @@
NSDate *messageDate;
NSString *message;
+ NSString *messageDatabase;
NSString *messageConnection;
}
@property (readwrite, assign) BOOL isError;
@property (readwrite, retain) NSDate *messageDate;
@property (readwrite, retain) NSString *message;
+@property (readwrite, retain) NSString *messageDatabase;
@property (readwrite, retain) NSString *messageConnection;
-+ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)consoleMessage date:(NSDate *)date connection:(NSString *)connection;
++ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)consoleMessage
+ date:(NSDate *)date
+ connection:(NSString *)connection
+ database:(NSString *)database;
-- (id)initWithMessage:(NSString *)message date:(NSDate *)date connection:(NSString *)connection;
+- (id)initWithMessage:(NSString *)message
+ date:(NSDate *)date
+ connection:(NSString *)connection
+ database:(NSString *)database;
@end
diff --git a/Source/SPConsoleMessage.m b/Source/SPConsoleMessage.m
index 0a5c2bcf..6ada323a 100644
--- a/Source/SPConsoleMessage.m
+++ b/Source/SPConsoleMessage.m
@@ -35,24 +35,26 @@
@synthesize isError;
@synthesize messageDate;
@synthesize message;
+@synthesize messageDatabase;
@synthesize messageConnection;
/**
* Returns a new console message instance using the suppled message, date and connection.
*/
-+ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)message date:(NSDate *)date connection:(NSString *)connection
++ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)message date:(NSDate *)date connection:(NSString *)connection database:(NSString *)database
{
- return [[[SPConsoleMessage alloc] initWithMessage:message date:date connection:connection] autorelease];
+ return [[[SPConsoleMessage alloc] initWithMessage:message date:date connection:connection database:database] autorelease];
}
/**
* Initializes a new console message instance using the suppled message, date and connection.
*/
-- (id)initWithMessage:(NSString *)consoleMessage date:(NSDate *)date connection:(NSString *)connection
+- (id)initWithMessage:(NSString *)consoleMessage date:(NSDate *)date connection:(NSString *)connection database:(NSString *)database
{
if ((self = [super init])) {
[self setMessageDate:date];
[self setMessage:consoleMessage];
+ [self setMessageDatabase:database];
[self setMessageConnection:connection];
}
@@ -65,6 +67,7 @@
{
[message release], message = nil;
[messageDate release], messageDate = nil;
+ [messageDatabase release], messageDatabase = nil;
[messageConnection release], messageConnection = nil;
[super dealloc];
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 1778a1d5..76f51f49 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -355,6 +355,7 @@ extern NSString *SPLastUsedVersion;
// GUI Prefs
extern NSString *SPConsoleShowTimestamps;
extern NSString *SPConsoleShowConnections;
+extern NSString *SPConsoleShowDatabases;
extern NSString *SPConsoleShowSelectsAndShows;
extern NSString *SPConsoleShowHelps;
extern NSString *SPEditInSheetEnabled;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index a1bcce8d..6b986506 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -163,6 +163,7 @@ NSString *SPConsoleShowHelps = @"ConsoleShowHelps";
NSString *SPConsoleShowSelectsAndShows = @"ConsoleShowSelectsAndShows";
NSString *SPConsoleShowTimestamps = @"ConsoleShowTimestamps";
NSString *SPConsoleShowConnections = @"ConsoleShowConnections";
+NSString *SPConsoleShowDatabases = @"ConsoleShowDatabases";
NSString *SPEditInSheetEnabled = @"EditInSheetEnabled";
NSString *SPTableInformationPanelCollapsed = @"TableInformationPanelCollapsed";
NSString *SPTableColumnWidths = @"tableColumnWidths";
diff --git a/Source/SPQueryConsoleDataSource.m b/Source/SPQueryConsoleDataSource.m
index 343f2dcd..eaac2151 100644
--- a/Source/SPQueryConsoleDataSource.m
+++ b/Source/SPQueryConsoleDataSource.m
@@ -54,8 +54,12 @@ static NSUInteger SPMessageTruncateCharacterLength = 256;
{
#ifndef SP_CODA
NSString *returnValue = nil;
+
+ NSString *identifier = [tableColumn identifier];
+
+ if (!identifier) return returnValue;
- id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:[tableColumn identifier]];
+ id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:identifier];
if ([[tableColumn identifier] isEqualToString:SPTableViewDateColumnID]) {
@@ -68,7 +72,9 @@ static NSUInteger SPMessageTruncateCharacterLength = 256;
returnValue = object;
}
-
+
+ if (!returnValue) return returnValue;
+
NSMutableDictionary *stringAtributes = nil;
if (consoleFont) {
diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h
index ce48dced..8d128fe3 100644
--- a/Source/SPQueryController.h
+++ b/Source/SPQueryController.h
@@ -32,6 +32,7 @@
extern NSString *SPQueryConsoleWindowAutoSaveName;
extern NSString *SPTableViewDateColumnID;
extern NSString *SPTableViewConnectionColumnID;
+extern NSString *SPTableViewDatabaseColumnID;
#endif
@interface SPQueryController : NSWindowController
@@ -42,22 +43,26 @@ extern NSString *SPTableViewConnectionColumnID;
IBOutlet NSSearchField *consoleSearchField;
IBOutlet NSTextField *loggingDisabledTextField;
IBOutlet NSProgressIndicator *progressIndicator;
- IBOutlet NSButton *includeTimeStampsButton, *includeConnectionButton, *saveConsoleButton, *clearConsoleButton;
-
- NSFont *consoleFont;
- NSMutableArray *messagesFullSet, *messagesFilteredSet, *messagesVisibleSet;
+ IBOutlet NSButton *includeTimeStampsButton;
+ IBOutlet NSButton *includeConnectionButton;
+ IBOutlet NSButton *includeDatabaseButton;
+ IBOutlet NSButton *saveConsoleButton;
+ IBOutlet NSButton *clearConsoleButton;
+
BOOL showSelectStatementsAreDisabled;
BOOL showHelpStatementsAreDisabled;
BOOL filterIsActive;
BOOL allowConsoleUpdate;
-
+
+ NSFont *consoleFont;
NSMutableString *activeFilterString;
-
+ NSMutableArray *messagesFullSet, *messagesFilteredSet, *messagesVisibleSet;
+
// DocumentsController
- NSUInteger untitledDocumentCounter;
NSMutableDictionary *favoritesContainer;
NSMutableDictionary *historyContainer;
NSMutableDictionary *contentFilterContainer;
+ NSUInteger untitledDocumentCounter;
NSUInteger numberOfMaxAllowedHistory;
#endif
@@ -84,6 +89,7 @@ extern NSString *SPTableViewConnectionColumnID;
- (IBAction)saveConsoleAs:(id)sender;
- (IBAction)toggleShowTimeStamps:(id)sender;
- (IBAction)toggleShowConnections:(id)sender;
+- (IBAction)toggleShowDatabases:(id)sender;
- (IBAction)toggleShowSelectShowStatements:(id)sender;
- (IBAction)toggleShowHelpStatements:(id)sender;
@@ -92,8 +98,8 @@ extern NSString *SPTableViewConnectionColumnID;
- (BOOL)allowConsoleUpdate;
- (void)setAllowConsoleUpdate:(BOOL)allowUpdate;
-- (void)showMessageInConsole:(NSString *)message connection:(NSString *)connection;
-- (void)showErrorInConsole:(NSString *)error connection:(NSString *)connection;
+- (void)showMessageInConsole:(NSString *)message connection:(NSString *)connection database:(NSString *)database;
+- (void)showErrorInConsole:(NSString *)error connection:(NSString *)connection database:(NSString *)database;
- (NSUInteger)consoleMessageCount;
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index f31ce808..01cb50e1 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -39,6 +39,7 @@
NSString *SPQueryConsoleWindowAutoSaveName = @"QueryConsole";
NSString *SPTableViewDateColumnID = @"messageDate";
NSString *SPTableViewConnectionColumnID = @"messageConnection";
+NSString *SPTableViewDatabaseColumnID = @"messageDatabase";
#endif
@interface SPQueryController ()
@@ -46,8 +47,8 @@ NSString *SPTableViewConnectionColumnID = @"messageConnection";
- (void)_updateFilterState;
- (void)_allowFilterClearOrSave:(NSNumber *)enabled;
- (BOOL)_messageMatchesCurrentFilters:(NSString *)message;
-- (NSString *)_getConsoleStringWithTimeStamps:(BOOL)timeStamps connections:(BOOL)connections;
-- (void)_addMessageToConsole:(NSString *)message connection:(NSString *)connection isError:(BOOL)error;
+- (NSString *)_getConsoleStringWithTimeStamps:(BOOL)timeStamps connections:(BOOL)connections databases:(BOOL)databases;
+- (void)_addMessageToConsole:(NSString *)message connection:(NSString *)connection isError:(BOOL)error database:(NSString *)database;
@end
@@ -161,6 +162,7 @@ static SPQueryController *sharedQueryController = nil;
BOOL includeTimestamps = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] isHidden];
BOOL includeConnections = ![[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] isHidden];
+ BOOL includeDatabases = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] isHidden];
[string setString:@""];
@@ -181,7 +183,12 @@ static SPQueryController *sharedQueryController = nil;
[string appendString:@" "];
}
- if (includeTimestamps || includeConnections) [string appendString:@"*/ "];
+ if (includeDatabases) {
+ [string appendString:[message messageDatabase]];
+ [string appendString:@" "];
+ }
+
+ if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"*/ "];
[string appendFormat:@"%@\n", [message message]];
}
@@ -228,10 +235,12 @@ static SPQueryController *sharedQueryController = nil;
[panel setAccessoryView:saveLogView];
[panel setNameFieldStringValue:NSLocalizedString(@"ConsoleLog", @"Console : Save as : Initial filename")];
+
[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger returnCode) {
if (returnCode == NSOKButton) {
[[self _getConsoleStringWithTimeStamps:[includeTimeStampsButton state]
- connections:[includeConnectionButton state]] writeToFile:[[panel URL] path] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
+ connections:[includeConnectionButton state]
+ databases:[includeDatabaseButton state]] writeToFile:[[panel URL] path] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}
}];
#endif
@@ -243,17 +252,27 @@ static SPQueryController *sharedQueryController = nil;
- (IBAction)toggleShowTimeStamps:(id)sender
{
#ifndef SP_CODA
- [[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:([sender state])];
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:[sender state]];
#endif
}
/**
- * Toggles the display of message connections column in the table view.
+ * Toggles the display of the message connections column in the table view.
*/
- (IBAction)toggleShowConnections:(id)sender
{
#ifndef SP_CODA
- [[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:([sender state])];
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:[sender state]];
+#endif
+}
+
+/**
+ * Toggles the display of the message databases column in the table view.
+ */
+- (IBAction)toggleShowDatabases:(id)sender
+{
+#ifndef SP_CODA
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] setHidden:[sender state]];
#endif
}
@@ -286,20 +305,20 @@ static SPQueryController *sharedQueryController = nil;
/**
* Shows the supplied message from the supplied connection in the console.
*/
-- (void)showMessageInConsole:(NSString *)message connection:(NSString *)connection
+- (void)showMessageInConsole:(NSString *)message connection:(NSString *)connection database:(NSString *)database
{
#ifndef SP_CODA
- [self _addMessageToConsole:message connection:connection isError:NO];
+ [self _addMessageToConsole:message connection:connection isError:NO database:database];
#endif
}
/**
* Shows the supplied error from the supplied connection in the console.
*/
-- (void)showErrorInConsole:(NSString *)error connection:(NSString *)connection
+- (void)showErrorInConsole:(NSString *)error connection:(NSString *)connection database:(NSString *)database
{
#ifndef SP_CODA
- [self _addMessageToConsole:error connection:connection isError:YES];
+ [self _addMessageToConsole:error connection:connection isError:YES database:database];
#endif
}
@@ -538,7 +557,7 @@ static SPQueryController *sharedQueryController = nil;
* Creates and returns a string made entirely of all of the console's messages and includes the message
* time stamp and connection if specified.
*/
-- (NSString *)_getConsoleStringWithTimeStamps:(BOOL)timeStamps connections:(BOOL)connections
+- (NSString *)_getConsoleStringWithTimeStamps:(BOOL)timeStamps connections:(BOOL)connections databases:(BOOL)databases
{
NSMutableString *consoleString = [NSMutableString string];
@@ -563,6 +582,11 @@ static SPQueryController *sharedQueryController = nil;
[consoleString appendString:@" "];
}
+ if (databases && [message messageDatabase]) {
+ [consoleString appendString:[message messageDatabase]];
+ [consoleString appendString:@" "];
+ }
+
// Close the comment
if (timeStamps || connections) [consoleString appendString:@"*/ "];
@@ -578,7 +602,7 @@ static SPQueryController *sharedQueryController = nil;
/**
* Adds the supplied message to the query console.
*/
-- (void)_addMessageToConsole:(NSString *)message connection:(NSString *)connection isError:(BOOL)error
+- (void)_addMessageToConsole:(NSString *)message connection:(NSString *)connection isError:(BOOL)error database:(NSString *)database
{
#ifndef SP_CODA
NSString *messageTemp = [[message stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
@@ -586,7 +610,7 @@ static SPQueryController *sharedQueryController = nil;
// Only append a semi-colon (;) if the supplied message is not an error
if (!error) messageTemp = [messageTemp stringByAppendingString:@";"];
- SPConsoleMessage *consoleMessage = [SPConsoleMessage consoleMessageWithMessage:messageTemp date:[NSDate date] connection:connection];
+ SPConsoleMessage *consoleMessage = [SPConsoleMessage consoleMessageWithMessage:messageTemp date:[NSDate date] connection:connection database:database];
[consoleMessage setIsError:error];
diff --git a/Source/SPQueryControllerInitializer.m b/Source/SPQueryControllerInitializer.m
index 93854863..8890a607 100644
--- a/Source/SPQueryControllerInitializer.m
+++ b/Source/SPQueryControllerInitializer.m
@@ -57,6 +57,7 @@ static NSString *SPCompletionTokensSnippetsKey = @"function_argument_snippets";
// Show/hide table columns
[[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:![prefs boolForKey:SPConsoleShowTimestamps]];
[[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:![prefs boolForKey:SPConsoleShowConnections]];
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] setHidden:![prefs boolForKey:SPConsoleShowDatabases]];
showSelectStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowSelectsAndShows];
showHelpStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowHelps];
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 8e537178..dcf22d49 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -2956,13 +2956,17 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
[tableValues removeRowAtIndex:currentlyEditingRow];
[self updateCountText];
isEditingNewRow = NO;
- } else {
+ }
+ else {
[tableValues replaceRowAtIndex:currentlyEditingRow withRowContents:oldRow];
}
+
isEditingRow = NO;
currentlyEditingRow = -1;
[tableContentView reloadData];
- [[SPQueryController sharedQueryController] showErrorInConsole:NSLocalizedString(@"/* WARNING: No rows have been affected */\n", @"warning shown in the console when no rows have been affected after writing to the db") connection:[tableDocumentInstance name]];
+
+ [[SPQueryController sharedQueryController] showErrorInConsole:NSLocalizedString(@"/* WARNING: No rows have been affected */\n", @"warning shown in the console when no rows have been affected after writing to the db") connection:[tableDocumentInstance name] database:[tableDocumentInstance database]];
+
return YES;
// On success...