Skip to content

Commit

Permalink
Resolve #1938: In the query console display the database the query wa…
Browse files Browse the repository at this point in the history
…s executed in.
  • Loading branch information
stuconnolly committed Aug 28, 2014
1 parent e3c342d commit 310fb07
Show file tree
Hide file tree
Showing 12 changed files with 448 additions and 103 deletions.
391 changes: 334 additions & 57 deletions Interfaces/English.lproj/Console.xib

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Resources/Plists/PreferenceDefaults.plist
Expand Up @@ -18,6 +18,8 @@
<true/>
<key>ConsoleShowConnections</key>
<true/>
<key>ConsoleShowDatabases</key>
<true/>
<key>ConsoleShowHelps</key>
<true/>
<key>ConsoleShowSelectsAndShows</key>
Expand Down
40 changes: 26 additions & 14 deletions Source/SPConnectionDelegate.m
Expand Up @@ -48,11 +48,11 @@ - (void)willQueryString:(NSString *)query connection:(id)connection
{
#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
Expand All @@ -65,7 +65,7 @@ - (void)queryGaveError:(NSString *)error connection:(id)connection
{
#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
}
Expand All @@ -75,7 +75,6 @@ - (void)queryGaveError:(NSString *)error connection:(id)connection
*/
- (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection
{

// If no keychain item is available, return an empty password
if (![connectionController connectionKeychainItemName]) return nil;

Expand All @@ -96,23 +95,26 @@ - (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection
*/
- (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;
}

/**
Expand All @@ -121,7 +123,17 @@ - (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection
*/
- (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")
);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions Source/SPConsoleMessage.h
Expand Up @@ -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
9 changes: 6 additions & 3 deletions Source/SPConsoleMessage.m
Expand Up @@ -35,24 +35,26 @@ @implementation SPConsoleMessage
@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];
}

Expand All @@ -65,6 +67,7 @@ - (void)dealloc
{
[message release], message = nil;
[messageDate release], messageDate = nil;
[messageDatabase release], messageDatabase = nil;
[messageConnection release], messageConnection = nil;

[super dealloc];
Expand Down
1 change: 1 addition & 0 deletions Source/SPConstants.h
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/SPConstants.m
Expand Up @@ -163,6 +163,7 @@
NSString *SPConsoleShowSelectsAndShows = @"ConsoleShowSelectsAndShows";
NSString *SPConsoleShowTimestamps = @"ConsoleShowTimestamps";
NSString *SPConsoleShowConnections = @"ConsoleShowConnections";
NSString *SPConsoleShowDatabases = @"ConsoleShowDatabases";
NSString *SPEditInSheetEnabled = @"EditInSheetEnabled";
NSString *SPTableInformationPanelCollapsed = @"TableInformationPanelCollapsed";
NSString *SPTableColumnWidths = @"tableColumnWidths";
Expand Down
10 changes: 8 additions & 2 deletions Source/SPQueryConsoleDataSource.m
Expand Up @@ -54,8 +54,12 @@ - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColum
{
#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]) {

Expand All @@ -68,7 +72,9 @@ - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColum

returnValue = object;
}


if (!returnValue) return returnValue;

NSMutableDictionary *stringAtributes = nil;

if (consoleFont) {
Expand Down
24 changes: 15 additions & 9 deletions Source/SPQueryController.h
Expand Up @@ -32,6 +32,7 @@
extern NSString *SPQueryConsoleWindowAutoSaveName;
extern NSString *SPTableViewDateColumnID;
extern NSString *SPTableViewConnectionColumnID;
extern NSString *SPTableViewDatabaseColumnID;
#endif

@interface SPQueryController : NSWindowController
Expand All @@ -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

Expand All @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit 310fb07

Please sign in to comment.