Skip to content

Commit 310fb07

Browse files
committed
Resolve #1938: In the query console display the database the query was executed in.
1 parent e3c342d commit 310fb07

File tree

12 files changed

+448
-103
lines changed

12 files changed

+448
-103
lines changed

Interfaces/English.lproj/Console.xib

Lines changed: 334 additions & 57 deletions
Large diffs are not rendered by default.

Resources/Plists/PreferenceDefaults.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<true/>
1919
<key>ConsoleShowConnections</key>
2020
<true/>
21+
<key>ConsoleShowDatabases</key>
22+
<true/>
2123
<key>ConsoleShowHelps</key>
2224
<true/>
2325
<key>ConsoleShowSelectsAndShows</key>

Source/SPConnectionDelegate.m

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ - (void)willQueryString:(NSString *)query connection:(id)connection
4848
{
4949
#ifndef SP_CODA
5050
if ([prefs boolForKey:SPConsoleEnableLogging]) {
51-
if ((_queryMode == SPInterfaceQueryMode && [prefs boolForKey:SPConsoleEnableInterfaceLogging])
52-
|| (_queryMode == SPCustomQueryQueryMode && [prefs boolForKey:SPConsoleEnableCustomQueryLogging])
53-
|| (_queryMode == SPImportExportQueryMode && [prefs boolForKey:SPConsoleEnableImportExportLogging]))
51+
if ((_queryMode == SPInterfaceQueryMode && [prefs boolForKey:SPConsoleEnableInterfaceLogging]) ||
52+
(_queryMode == SPCustomQueryQueryMode && [prefs boolForKey:SPConsoleEnableCustomQueryLogging]) ||
53+
(_queryMode == SPImportExportQueryMode && [prefs boolForKey:SPConsoleEnableImportExportLogging]))
5454
{
55-
[[SPQueryController sharedQueryController] showMessageInConsole:query connection:[self name]];
55+
[[SPQueryController sharedQueryController] showMessageInConsole:query connection:[self name] database:[self database]];
5656
}
5757
}
5858
#endif
@@ -65,7 +65,7 @@ - (void)queryGaveError:(NSString *)error connection:(id)connection
6565
{
6666
#ifndef SP_CODA
6767
if ([prefs boolForKey:SPConsoleEnableLogging] && [prefs boolForKey:SPConsoleEnableErrorLogging]) {
68-
[[SPQueryController sharedQueryController] showErrorInConsole:error connection:[self name]];
68+
[[SPQueryController sharedQueryController] showErrorInConsole:error connection:[self name] database:[self database]];
6969
}
7070
#endif
7171
}
@@ -75,7 +75,6 @@ - (void)queryGaveError:(NSString *)error connection:(id)connection
7575
*/
7676
- (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection
7777
{
78-
7978
// If no keychain item is available, return an empty password
8079
if (![connectionController connectionKeychainItemName]) return nil;
8180

@@ -96,23 +95,26 @@ - (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection
9695
*/
9796
- (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection
9897
{
99-
10098
// If no keychain item is available, return an empty password
10199
if (![connectionController connectionKeychainItemName]) return @"";
102100

103101
// Otherwise, pull the password from the keychain using the details from this connection
104102
SPKeychain *keychain = [[SPKeychain alloc] init];
103+
105104
NSString *connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]] retain];
106105
NSString *connectionSSHKeychainItemAccount = [[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]] retain];
107-
NSString *sshpw = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
108-
if (!sshpw || ![sshpw length])
109-
sshpw = @"";
106+
NSString *sshPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
107+
108+
if (!sshPassword || ![sshPassword length]) {
109+
sshPassword = @"";
110+
}
111+
112+
if (connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
113+
if (connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
110114

111-
if(connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
112-
if(connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
113115
[keychain release];
114116

115-
return sshpw;
117+
return sshPassword;
116118
}
117119

118120
/**
@@ -121,7 +123,17 @@ - (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection
121123
*/
122124
- (void)noConnectionAvailable:(id)connection
123125
{
124-
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"));
126+
SPBeginAlertSheet(
127+
NSLocalizedString(@"No connection available", @"no connection available message"),
128+
NSLocalizedString(@"OK", @"OK button"),
129+
nil,
130+
nil,
131+
[self parentWindow],
132+
self,
133+
nil,
134+
nil,
135+
NSLocalizedString(@"An error has occured and there doesn't seem to be a connection available.", @"no connection available informatie message")
136+
);
125137
}
126138

127139
/**

Source/SPConsoleMessage.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,24 @@
3434
NSDate *messageDate;
3535

3636
NSString *message;
37+
NSString *messageDatabase;
3738
NSString *messageConnection;
3839
}
3940

4041
@property (readwrite, assign) BOOL isError;
4142
@property (readwrite, retain) NSDate *messageDate;
4243
@property (readwrite, retain) NSString *message;
44+
@property (readwrite, retain) NSString *messageDatabase;
4345
@property (readwrite, retain) NSString *messageConnection;
4446

45-
+ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)consoleMessage date:(NSDate *)date connection:(NSString *)connection;
47+
+ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)consoleMessage
48+
date:(NSDate *)date
49+
connection:(NSString *)connection
50+
database:(NSString *)database;
4651

47-
- (id)initWithMessage:(NSString *)message date:(NSDate *)date connection:(NSString *)connection;
52+
- (id)initWithMessage:(NSString *)message
53+
date:(NSDate *)date
54+
connection:(NSString *)connection
55+
database:(NSString *)database;
4856

4957
@end

Source/SPConsoleMessage.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,26 @@ @implementation SPConsoleMessage
3535
@synthesize isError;
3636
@synthesize messageDate;
3737
@synthesize message;
38+
@synthesize messageDatabase;
3839
@synthesize messageConnection;
3940

4041
/**
4142
* Returns a new console message instance using the suppled message, date and connection.
4243
*/
43-
+ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)message date:(NSDate *)date connection:(NSString *)connection
44+
+ (SPConsoleMessage *)consoleMessageWithMessage:(NSString *)message date:(NSDate *)date connection:(NSString *)connection database:(NSString *)database
4445
{
45-
return [[[SPConsoleMessage alloc] initWithMessage:message date:date connection:connection] autorelease];
46+
return [[[SPConsoleMessage alloc] initWithMessage:message date:date connection:connection database:database] autorelease];
4647
}
4748

4849
/**
4950
* Initializes a new console message instance using the suppled message, date and connection.
5051
*/
51-
- (id)initWithMessage:(NSString *)consoleMessage date:(NSDate *)date connection:(NSString *)connection
52+
- (id)initWithMessage:(NSString *)consoleMessage date:(NSDate *)date connection:(NSString *)connection database:(NSString *)database
5253
{
5354
if ((self = [super init])) {
5455
[self setMessageDate:date];
5556
[self setMessage:consoleMessage];
57+
[self setMessageDatabase:database];
5658
[self setMessageConnection:connection];
5759
}
5860

@@ -65,6 +67,7 @@ - (void)dealloc
6567
{
6668
[message release], message = nil;
6769
[messageDate release], messageDate = nil;
70+
[messageDatabase release], messageDatabase = nil;
6871
[messageConnection release], messageConnection = nil;
6972

7073
[super dealloc];

Source/SPConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ extern NSString *SPLastUsedVersion;
355355
// GUI Prefs
356356
extern NSString *SPConsoleShowTimestamps;
357357
extern NSString *SPConsoleShowConnections;
358+
extern NSString *SPConsoleShowDatabases;
358359
extern NSString *SPConsoleShowSelectsAndShows;
359360
extern NSString *SPConsoleShowHelps;
360361
extern NSString *SPEditInSheetEnabled;

Source/SPConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
NSString *SPConsoleShowSelectsAndShows = @"ConsoleShowSelectsAndShows";
164164
NSString *SPConsoleShowTimestamps = @"ConsoleShowTimestamps";
165165
NSString *SPConsoleShowConnections = @"ConsoleShowConnections";
166+
NSString *SPConsoleShowDatabases = @"ConsoleShowDatabases";
166167
NSString *SPEditInSheetEnabled = @"EditInSheetEnabled";
167168
NSString *SPTableInformationPanelCollapsed = @"TableInformationPanelCollapsed";
168169
NSString *SPTableColumnWidths = @"tableColumnWidths";

Source/SPQueryConsoleDataSource.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColum
5454
{
5555
#ifndef SP_CODA
5656
NSString *returnValue = nil;
57+
58+
NSString *identifier = [tableColumn identifier];
59+
60+
if (!identifier) return returnValue;
5761

58-
id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:[tableColumn identifier]];
62+
id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:identifier];
5963

6064
if ([[tableColumn identifier] isEqualToString:SPTableViewDateColumnID]) {
6165

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

6973
returnValue = object;
7074
}
71-
75+
76+
if (!returnValue) return returnValue;
77+
7278
NSMutableDictionary *stringAtributes = nil;
7379

7480
if (consoleFont) {

Source/SPQueryController.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
extern NSString *SPQueryConsoleWindowAutoSaveName;
3333
extern NSString *SPTableViewDateColumnID;
3434
extern NSString *SPTableViewConnectionColumnID;
35+
extern NSString *SPTableViewDatabaseColumnID;
3536
#endif
3637

3738
@interface SPQueryController : NSWindowController
@@ -42,22 +43,26 @@ extern NSString *SPTableViewConnectionColumnID;
4243
IBOutlet NSSearchField *consoleSearchField;
4344
IBOutlet NSTextField *loggingDisabledTextField;
4445
IBOutlet NSProgressIndicator *progressIndicator;
45-
IBOutlet NSButton *includeTimeStampsButton, *includeConnectionButton, *saveConsoleButton, *clearConsoleButton;
46-
47-
NSFont *consoleFont;
48-
NSMutableArray *messagesFullSet, *messagesFilteredSet, *messagesVisibleSet;
46+
IBOutlet NSButton *includeTimeStampsButton;
47+
IBOutlet NSButton *includeConnectionButton;
48+
IBOutlet NSButton *includeDatabaseButton;
49+
IBOutlet NSButton *saveConsoleButton;
50+
IBOutlet NSButton *clearConsoleButton;
51+
4952
BOOL showSelectStatementsAreDisabled;
5053
BOOL showHelpStatementsAreDisabled;
5154
BOOL filterIsActive;
5255
BOOL allowConsoleUpdate;
53-
56+
57+
NSFont *consoleFont;
5458
NSMutableString *activeFilterString;
55-
59+
NSMutableArray *messagesFullSet, *messagesFilteredSet, *messagesVisibleSet;
60+
5661
// DocumentsController
57-
NSUInteger untitledDocumentCounter;
5862
NSMutableDictionary *favoritesContainer;
5963
NSMutableDictionary *historyContainer;
6064
NSMutableDictionary *contentFilterContainer;
65+
NSUInteger untitledDocumentCounter;
6166
NSUInteger numberOfMaxAllowedHistory;
6267
#endif
6368

@@ -84,6 +89,7 @@ extern NSString *SPTableViewConnectionColumnID;
8489
- (IBAction)saveConsoleAs:(id)sender;
8590
- (IBAction)toggleShowTimeStamps:(id)sender;
8691
- (IBAction)toggleShowConnections:(id)sender;
92+
- (IBAction)toggleShowDatabases:(id)sender;
8793
- (IBAction)toggleShowSelectShowStatements:(id)sender;
8894
- (IBAction)toggleShowHelpStatements:(id)sender;
8995

@@ -92,8 +98,8 @@ extern NSString *SPTableViewConnectionColumnID;
9298
- (BOOL)allowConsoleUpdate;
9399
- (void)setAllowConsoleUpdate:(BOOL)allowUpdate;
94100

95-
- (void)showMessageInConsole:(NSString *)message connection:(NSString *)connection;
96-
- (void)showErrorInConsole:(NSString *)error connection:(NSString *)connection;
101+
- (void)showMessageInConsole:(NSString *)message connection:(NSString *)connection database:(NSString *)database;
102+
- (void)showErrorInConsole:(NSString *)error connection:(NSString *)connection database:(NSString *)database;
97103

98104
- (NSUInteger)consoleMessageCount;
99105

0 commit comments

Comments
 (0)