diff options
Diffstat (limited to 'Source/SPDatabaseInfo.m')
-rw-r--r-- | Source/SPDatabaseInfo.m | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Source/SPDatabaseInfo.m b/Source/SPDatabaseInfo.m index 551a1c77..3c70aec9 100644 --- a/Source/SPDatabaseInfo.m +++ b/Source/SPDatabaseInfo.m @@ -27,42 +27,44 @@ @implementation SPDatabaseInfo --(BOOL)databaseExists:(NSString *)databaseName { +-(BOOL)databaseExists:(NSString *)databaseName +{ NSArray *names = [self listDBs]; + return [names containsObject:databaseName]; } -- (NSArray *)listDBs { +- (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, messageWindow, self, 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; - } + if ([connection queryErrored]) return NO; NSMutableArray *names = [NSMutableArray array]; NSMutableString *name; + if ([theResult numOfRows] > 1) { - int i; - for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { + + NSUInteger i; + + for (i = 0 ; i < [theResult numOfRows]; i++) + { name = [[theResult fetchRowAsArray] objectAtIndex:0]; + [names addObject:name]; } } |