aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseInfo.m
diff options
context:
space:
mode:
authordrx777 <david.rekowski@gmx.de>2010-04-28 17:11:41 +0000
committerdrx777 <david.rekowski@gmx.de>2010-04-28 17:11:41 +0000
commitf36685ae1bee7b9274de27414ab8b64dbc57770f (patch)
tree269b242812332fab9bfdbe37955fbfbe72a87def /Source/SPDatabaseInfo.m
parent29b42d1c3b751781fb70684f5bb779001d19b1f3 (diff)
downloadsequelpro-f36685ae1bee7b9274de27414ab8b64dbc57770f.tar.gz
sequelpro-f36685ae1bee7b9274de27414ab8b64dbc57770f.tar.bz2
sequelpro-f36685ae1bee7b9274de27414ab8b64dbc57770f.zip
This changeset implements renaming and duplicating databases on a server. Details as follows:
* altered MCPConnection listTablesFromDB:like: to return NSArray * altered MCPConnection listFieldsFromTable:like: to use backtick quoted strings for table and fieldnames * added MCPConnection listTablesFromDB for a complete table list * added SPStringAdditions.h to various files to prevent warnings * added sheets for duplicate/rename DB in DBView.xib * added duplicate/rename menu items to MainMenu.xib * added outlets in TableDocument: databaseNewSheet databaseRenameSheet databaseCopyNameField databaseRenameNameField copyOnlyStructureButton copyDatabaseButton renameDatabaseButton * added methods in TableDocument: getConnection, copyDatabase, renameDatabase, _copyDatabase, _renameDatabase * added OCMock Framework for object mocking in tests * added group Others/DatabaseActions
Diffstat (limited to 'Source/SPDatabaseInfo.m')
-rw-r--r--Source/SPDatabaseInfo.m66
1 files changed, 66 insertions, 0 deletions
diff --git a/Source/SPDatabaseInfo.m b/Source/SPDatabaseInfo.m
new file mode 100644
index 00000000..b2c2469d
--- /dev/null
+++ b/Source/SPDatabaseInfo.m
@@ -0,0 +1,66 @@
+//
+// SPDatabaseInfo.m
+// sequel-pro
+//
+// Created by David Rekowski on 19.04.10.
+// Copyright 2010 Papaya Software GmbH. All rights reserved.
+//
+
+#import "SPAlertSheets.h"
+#import "SPDatabaseInfo.h"
+#import "SPStringAdditions.h"
+#import "Sequel-Pro.pch"
+
+@implementation SPDatabaseInfo
+
+@synthesize connection;
+@synthesize parent;
+
+- (NSObject *)getTableWindow {
+ return [NSApp mainWindow];
+}
+
+-(BOOL)databaseExists:(NSString *)databaseName {
+ NSArray *names = [self listDBs];
+ return [names containsObject:databaseName];
+}
+
+- (NSArray *)listDBs {
+ return [self listDBsLike:nil];
+}
+
+- (NSArray *)listDBsLike:(NSString *)dbsName
+{
+ NSString *listDBStatement = nil;
+ if ((dbsName == nil) || ([dbsName isEqualToString:@""])) {
+ listDBStatement = [NSString stringWithFormat:@"SHOW DATABASES"];
+ }
+ else {
+ listDBStatement = [NSString stringWithFormat:@"SHOW DATABASES LIKE %@", [dbsName backtickQuotedString]];
+ }
+ DLog(@"running query : %@", listDBStatement);
+ MCPResult *theResult = [connection queryString:listDBStatement];
+
+ if ([connection queryErrored]) {
+ SPBeginAlertSheet(NSLocalizedString(@"Failed to retrieve databases list", @"database list error message"),
+ NSLocalizedString(@"OK", @"OK button"), nil, nil, [self getTableWindow], self, nil, nil, nil,
+ [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to retrieve a list of databases.\n\nMySQL said: %@",
+ @"database list error informative message"),
+ [connection getLastErrorMessage]]);
+ return NO;
+ }
+
+ NSMutableArray *names = [NSMutableArray array];
+ NSMutableString *name;
+ if ([theResult numOfRows] > 1) {
+ int i;
+ for ( i = 0 ; i < [theResult numOfRows] ; i++ ) {
+ name = [[theResult fetchRowAsArray] objectAtIndex:0];
+ [names addObject:name];
+ }
+ }
+
+ return names;
+}
+
+@end