diff options
author | mtvee <emptyvee@gmail.com> | 2009-05-18 06:51:08 +0000 |
---|---|---|
committer | mtvee <emptyvee@gmail.com> | 2009-05-18 06:51:08 +0000 |
commit | 570bd13276ebca100befb65b273e7ba51e578b1a (patch) | |
tree | e695930a6895da3801b32dfb70f7becafe556586 | |
parent | 61da30eb923d774336ad10d252d4d0790999f33f (diff) | |
download | sequelpro-570bd13276ebca100befb65b273e7ba51e578b1a.tar.gz sequelpro-570bd13276ebca100befb65b273e7ba51e578b1a.tar.bz2 sequelpro-570bd13276ebca100befb65b273e7ba51e578b1a.zip |
- hide 'rename' context menu if selection is not a table
- added methods to CMMCPConnection to determine server major,minor,release version
-rw-r--r-- | Source/CMMCPConnection.h | 9 | ||||
-rw-r--r-- | Source/CMMCPConnection.m | 75 | ||||
-rw-r--r-- | Source/TablesList.m | 10 | ||||
-rw-r--r-- | Unit Tests/mcpKitTest.h | 18 | ||||
-rw-r--r-- | Unit Tests/mcpKitTest.m | 26 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 6 |
6 files changed, 139 insertions, 5 deletions
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index 8473c962..1ca4a953 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -50,6 +50,8 @@ BOOL useKeepAlive; float keepAliveInterval; + NSString *serverVersionString; + NSTimer *keepAliveTimer; NSDate *lastKeepAliveSuccess; } @@ -79,4 +81,11 @@ - (void) threadedKeepAlive; - (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding; +/* return server major version number or -1 on fail */ +- (int)serverMajorVersion; +/* return server minor version number or -1 on fail */ +- (int)serverMinorVersion; +/* return server release version number or -1 on fail */ +- (int)serverReleaseVersion; + @end diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 99b72e42..bfd30062 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -29,9 +29,26 @@ static jmp_buf pingTimeoutJumpLocation; static void forcePingTimeout(int signalNumber); -@implementation CMMCPConnection +@interface CMMCPConnection(hidden) +- (void)getServerVersionString; +@end + +@implementation CMMCPConnection(hidden) +- (void)getServerVersionString +{ + if( mConnected ) { + CMMCPResult *theResult; + theResult = [self queryString:@"SHOW VARIABLES WHERE Variable_name = 'version'"]; + if ([theResult numOfRows]) + [theResult dataSeek:0]; + serverVersionString = [NSString stringWithString:[[theResult fetchRowAsDictionary] objectForKey:@"Value"]]; + } +} +@end +@implementation CMMCPConnection + /* * Override the normal init methods, extending them to also init additional details. */ @@ -39,6 +56,7 @@ static void forcePingTimeout(int signalNumber); { [self initSPExtensions]; self = [super init]; + serverVersionString = nil; return self; } - (id) initToHost:(NSString *) host withLogin:(NSString *) login password:(NSString *) pass usingPort:(int) port @@ -123,9 +141,64 @@ static void forcePingTimeout(int signalNumber); if (connectionSocket) [connectionSocket release]; connectionSocket = nil; + if( serverVersionString != nil ) { + serverVersionString = nil; + } + [self stopKeepAliveTimer]; } +/* + * return the server major version or -1 on fail + */ +- (int)serverMajorVersion +{ + + if( mConnected ) { + if( serverVersionString == nil ) { + [self getServerVersionString]; + } + if( serverVersionString != nil ) { + return [[[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:0] intValue]; + } + } + return -1; +} + +/* + * return the server minor version or -1 on fail + */ +- (int)serverMinorVersion +{ + + if( mConnected ) { + if( serverVersionString == nil ) { + [self getServerVersionString]; + } + if( serverVersionString != nil ) { + return [[[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:1] intValue]; + } + } + return -1; +} + +/* + * return the server release version or -1 on fail + */ +- (int)serverReleaseVersion +{ + if( mConnected ) { + if( serverVersionString == nil ) { + [self getServerVersionString]; + } + if( serverVersionString != nil ) { + NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:2]; + return [[[s componentsSeparatedByString:@"-"] objectAtIndex:0] intValue]; + } + } + return -1; +} + /* * Reconnect to the currently "active" - but possibly disconnected - connection, using the diff --git a/Source/TablesList.m b/Source/TablesList.m index aae6136b..8d4769ac 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -49,11 +49,13 @@ NSString *selectedTable = nil; NSInteger selectedRowIndex; + NSLog( @"%d %d %d", [mySQLConnection serverMajorVersion], [mySQLConnection serverMinorVersion], [mySQLConnection serverReleaseVersion] ); + selectedRowIndex = [tablesListView selectedRow]; if(selectedRowIndex > 0 && [tables count]){ selectedTable = [NSString stringWithString:[tables objectAtIndex:selectedRowIndex]]; } - + [tablesListView deselectAll:self]; [tables removeAllObjects]; [tableTypes removeAllObjects]; @@ -961,7 +963,8 @@ [[tableSubMenu itemAtIndex:8] setHidden:NO]; [[tableSubMenu itemAtIndex:8] setTitle:NSLocalizedString(@"Flush View", @"flush view menu item")]; [[tableSubMenu itemAtIndex:9] setHidden:YES]; // checksum - + + [renameTableMenuItem setHidden:YES]; [removeTableMenuItem setTitle:NSLocalizedString(@"Remove view", @"remove view menu title")]; [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate view", @"duplicate view menu title")]; } @@ -979,6 +982,7 @@ [[tableSubMenu itemAtIndex:8] setTitle:NSLocalizedString(@"Flush Table", @"flush table menu item")]; [[tableSubMenu itemAtIndex:9] setHidden:NO]; + [renameTableMenuItem setHidden:NO]; [removeTableMenuItem setTitle:NSLocalizedString(@"Remove table", @"remove table menu title")]; [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate table", @"duplicate table menu title")]; } @@ -994,6 +998,7 @@ [[tableSubMenu itemAtIndex:8] setHidden:YES]; [[tableSubMenu itemAtIndex:9] setHidden:YES]; + [renameTableMenuItem setHidden:YES]; [removeTableMenuItem setTitle:NSLocalizedString(@"Remove procedure", @"remove proc menu title")]; [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate procedure", @"duplicate proc menu title")]; } @@ -1009,6 +1014,7 @@ [[tableSubMenu itemAtIndex:8] setHidden:YES]; [[tableSubMenu itemAtIndex:9] setHidden:YES]; + [renameTableMenuItem setHidden:YES]; [removeTableMenuItem setTitle:NSLocalizedString(@"Remove function", @"remove func menu title")]; [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate function", @"duplicate func menu title")]; } diff --git a/Unit Tests/mcpKitTest.h b/Unit Tests/mcpKitTest.h index e692cd3c..f2cdea92 100644 --- a/Unit Tests/mcpKitTest.h +++ b/Unit Tests/mcpKitTest.h @@ -3,7 +3,23 @@ // sequel-pro // // Created by J Knight on 17/05/09. -// Copyright 2009 TalonEdge Ltd.. All rights reserved. +// Copyright 2009 J Knight. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> // #import <SenTestingKit/SenTestingKit.h> diff --git a/Unit Tests/mcpKitTest.m b/Unit Tests/mcpKitTest.m index 486e7c4a..b8425dde 100644 --- a/Unit Tests/mcpKitTest.m +++ b/Unit Tests/mcpKitTest.m @@ -3,7 +3,23 @@ // sequel-pro // // Created by J Knight on 17/05/09. -// Copyright 2009 TalonEdge Ltd.. All rights reserved. +// Copyright 2009 J Knight. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> // #import "mcpKitTest.h" @@ -44,6 +60,14 @@ } } +- (void)testServerVersion +{ + if( mySQLConnection == nil ) + return; + + STAssertTrue( [mySQLConnection serverMajorVersion] != 0, @"server version"); +} + - (void)testTableList { diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 588e2edc..cf9efe34 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -68,6 +68,7 @@ 380F4EF50FC0B68F00B0BFD7 /* stringCategoryAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 380F4EF40FC0B68F00B0BFD7 /* stringCategoryAdditionsTest.m */; }; 380F4F250FC0C3D300B0BFD7 /* mcpKitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 380F4F240FC0C3D300B0BFD7 /* mcpKitTest.m */; }; 380F4F270FC0C51C00B0BFD7 /* MCPKit_bundled.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DECC3330EC2A170008D359E /* MCPKit_bundled.framework */; }; + 380F4FE30FC109E400B0BFD7 /* SPScriptEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 380F4FE20FC109E400B0BFD7 /* SPScriptEngine.m */; }; 384582BE0FB95C9100DDACB6 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 384582BC0FB95C9100DDACB6 /* Localizable.strings */; }; 384582C40FB95FF800DDACB6 /* func-small.png in Resources */ = {isa = PBXBuildFile; fileRef = 384582C30FB95FF800DDACB6 /* func-small.png */; }; 384582C70FB9603600DDACB6 /* proc-small.png in Resources */ = {isa = PBXBuildFile; fileRef = 384582C60FB9603600DDACB6 /* proc-small.png */; }; @@ -283,6 +284,8 @@ 380F4EF40FC0B68F00B0BFD7 /* stringCategoryAdditionsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = stringCategoryAdditionsTest.m; sourceTree = "<group>"; }; 380F4F230FC0C3D300B0BFD7 /* mcpKitTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mcpKitTest.h; sourceTree = "<group>"; }; 380F4F240FC0C3D300B0BFD7 /* mcpKitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = mcpKitTest.m; sourceTree = "<group>"; }; + 380F4FE10FC109E400B0BFD7 /* SPScriptEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPScriptEngine.h; sourceTree = "<group>"; }; + 380F4FE20FC109E400B0BFD7 /* SPScriptEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPScriptEngine.m; sourceTree = "<group>"; }; 384582BD0FB95C9100DDACB6 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = Interfaces/English.lproj/Localizable.strings; sourceTree = SOURCE_ROOT; }; 384582C30FB95FF800DDACB6 /* func-small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "func-small.png"; sourceTree = "<group>"; }; 384582C60FB9603600DDACB6 /* proc-small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "proc-small.png"; sourceTree = "<group>"; }; @@ -556,6 +559,8 @@ 17E641710EF01F5C001BC333 /* GUI */, 17E641720EF01F6B001BC333 /* SSHTunnel */, B57747D60F7A8990003B34F9 /* Category Additions */, + 380F4FE10FC109E400B0BFD7 /* SPScriptEngine.h */, + 380F4FE20FC109E400B0BFD7 /* SPScriptEngine.m */, ); name = Other; sourceTree = "<group>"; @@ -1003,6 +1008,7 @@ 5841423F0F97E11000A34B47 /* NoodleLineNumberView.m in Sources */, BCD0AD490FBBFC340066EA5C /* SPSQLTokenizer.l in Sources */, 387BBBA80FBCB6CB00B31746 /* TableRelations.m in Sources */, + 380F4FE30FC109E400B0BFD7 /* SPScriptEngine.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |