aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTablesList.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-10-07 18:56:33 +0000
committerstuconnolly <stuart02@gmail.com>2010-10-07 18:56:33 +0000
commit44a5f9e552b3d5e1f9ef1c6d11f34e893d67e85b (patch)
treec833ba970d8cae5f756a31bc274e365c0a44b3bf /Source/SPTablesList.m
parent95d2e4acc393e91aa70ed4c71daa1f776454a936 (diff)
downloadsequelpro-44a5f9e552b3d5e1f9ef1c6d11f34e893d67e85b.tar.gz
sequelpro-44a5f9e552b3d5e1f9ef1c6d11f34e893d67e85b.tar.bz2
sequelpro-44a5f9e552b3d5e1f9ef1c6d11f34e893d67e85b.zip
Various improvements to server capability/version checking, including:
- Add a new ServerSupport class, for which an instance is created upon each new connection and is then subsequently accessible via SPDatabaseDocument. - Replace the majority of manual version checking with calls to properties in the above new class. - Improve the user manager's compatibility with MySQL 3 and 4 servers. Fixes issue #811 Other changes include: - Disable the encoding popup button when adding a new table or database to servers running pre MySQL 4.1 as it only contains one option, 'Default'. - Fix various potential memory leaks discovered during static analysis. - General tidy up and comments.
Diffstat (limited to 'Source/SPTablesList.m')
-rw-r--r--Source/SPTablesList.m42
1 files changed, 24 insertions, 18 deletions
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 9f409e57..1a694fc2 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -42,6 +42,7 @@
#import "SPNavigatorController.h"
#import "SPMainThreadTrampoline.h"
#import "SPHistoryController.h"
+#import "SPServerSupport.h"
@interface SPTablesList (PrivateAPI)
@@ -125,12 +126,12 @@
// Reorder the tables in alphabetical order
[tables sortArrayUsingSelector:@selector(localizedCompare:) withPairedMutableArrays:tableTypes, nil];
- /* grab the procedures and functions
+ /* Grab the procedures and functions
*
- * using information_schema gives us more info (for information window perhaps?) but breaks
+ * Using information_schema gives us more info (for information window perhaps?) but breaks
* backward compatibility with pre 4 I believe. I left the other methods below, in case.
*/
- if ([mySQLConnection serverMajorVersion] >= 5) {
+ if ([[tableDocumentInstance serverSupport] supportsInformationSchema]) {
NSString *pQuery = [NSString stringWithFormat:@"SELECT * FROM information_schema.routines WHERE routine_schema = '%@' ORDER BY routine_name",[tableDocumentInstance database]];
theResult = [mySQLConnection queryString:pQuery];
@@ -226,9 +227,11 @@
// Add the table headers even if no tables were found
if (tableListContainsViews) {
[tables insertObject:NSLocalizedString(@"TABLES & VIEWS",@"header for table & views list") atIndex:0];
- } else {
+ }
+ else {
[tables insertObject:NSLocalizedString(@"TABLES",@"header for table list") atIndex:0];
}
+
[tableTypes insertObject:[NSNumber numberWithInteger:SPTableTypeNone] atIndex:0];
[[tablesListView onMainThread] reloadData];
@@ -237,7 +240,7 @@
// but not if the update was called from SPTableData since it calls that method
// if a selected table doesn't exist - this happens if a table was deleted/renamed by an other user
// or if the table name contains characters which are not supported by the current set encoding
- if( ![sender isKindOfClass:[SPTableData class]] && previousSelectedTable != nil && [tables indexOfObject:previousSelectedTable] < [tables count]) {
+ if ( ![sender isKindOfClass:[SPTableData class]] && previousSelectedTable != nil && [tables indexOfObject:previousSelectedTable] < [tables count]) {
NSInteger itemToReselect = [tables indexOfObject:previousSelectedTable];
tableListIsSelectable = YES;
[[tablesListView onMainThread] selectRowIndexes:[NSIndexSet indexSetWithIndex:itemToReselect] byExtendingSelection:NO];
@@ -245,7 +248,8 @@
if (selectedTableName) [selectedTableName release];
selectedTableName = [[NSString alloc] initWithString:[tables objectAtIndex:itemToReselect]];
selectedTableType = [[tableTypes objectAtIndex:itemToReselect] integerValue];
- } else {
+ }
+ else {
if (selectedTableName) [selectedTableName release];
selectedTableName = nil;
selectedTableType = SPTableTypeNone;
@@ -253,6 +257,7 @@
// Determine whether or not to show the list filter based on the number of tables, and clear it
[[self onMainThread] clearFilter];
+
if ([tables count] > 20) [self showFilter];
else [self hideFilter];
@@ -264,14 +269,12 @@
if (previousSelectedTable) [previousSelectedTable release];
// Query the structure of all databases in the background
- if(sender == self)
+ if (sender == self)
// Invoked by SP
[NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:nil];
else
// User press refresh button ergo force update
[NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", [NSNumber numberWithBool:YES], @"cancelQuerying", nil]];
-
-
}
/**
@@ -279,9 +282,7 @@
*/
- (IBAction)addTable:(id)sender
{
- if ((![tableSourceInstance saveRowOnDeselect]) || (![tableContentInstance saveRowOnDeselect]) || (![tableDocumentInstance database])) {
- return;
- }
+ if ((![tableSourceInstance saveRowOnDeselect]) || (![tableContentInstance saveRowOnDeselect]) || (![tableDocumentInstance database])) return;
[[tableDocumentInstance parentWindow] endEditingFor:nil];
@@ -305,13 +306,16 @@
// Retrieve the server-supported encodings and add them to the menu
NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings];
+
NSString *utf8MenuItemTitle = nil;
- if ([encodings count] > 0
- && ([mySQLConnection serverMajorVersion] > 4
- || ([mySQLConnection serverMajorVersion] == 4 && [mySQLConnection serverMinorVersion] >= 1)))
- {
+
+ [tableEncodingButton setEnabled:YES];
+
+ if (([encodings count] > 0) && [[tableDocumentInstance serverSupport] supportsPost41CharacterSetHandling]) {
[[tableEncodingButton menu] addItem:[NSMenuItem separatorItem]];
- for (NSDictionary *encoding in encodings) {
+
+ for (NSDictionary *encoding in encodings)
+ {
NSString *menuItemTitle = (![encoding objectForKey:@"DESCRIPTION"]) ? [encoding objectForKey:@"CHARACTER_SET_NAME"] : [NSString stringWithFormat:@"%@ (%@)", [encoding objectForKey:@"DESCRIPTION"], [encoding objectForKey:@"CHARACTER_SET_NAME"]];
[tableEncodingButton addItemWithTitle:menuItemTitle];
@@ -327,6 +331,9 @@
[tableEncodingButton insertItemWithTitle:utf8MenuItemTitle atIndex:2];
}
}
+ else {
+ [tableEncodingButton setEnabled:NO];
+ }
[NSApp beginSheet:tableSheet
modalForWindow:[tableDocumentInstance parentWindow]
@@ -1580,7 +1587,6 @@
*/
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
{
-
// Disallow selection while the document is working on a task
if ([tableDocumentInstance isWorking]) return NO;