From f36685ae1bee7b9274de27414ab8b64dbc57770f Mon Sep 17 00:00:00 2001 From: drx777 Date: Wed, 28 Apr 2010 17:11:41 +0000 Subject: 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 --- Source/SPDatabaseInfo.m | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Source/SPDatabaseInfo.m (limited to 'Source/SPDatabaseInfo.m') 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 -- cgit v1.2.3