aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit
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 /Frameworks/MCPKit/MCPFoundationKit
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 'Frameworks/MCPKit/MCPFoundationKit')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h3
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m41
2 files changed, 32 insertions, 12 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
index 10d46df2..60c9dcb6 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
@@ -288,7 +288,8 @@ void performThreadedKeepAlive(void *ptr);
- (MCPResult *)listDBsLike:(NSString *)dbsName;
- (MCPResult *)listTables;
- (MCPResult *)listTablesLike:(NSString *)tablesName;
-- (MCPResult *)listTablesFromDB:(NSString *)dbName like:(NSString *)tablesName;
+- (NSArray *)listTablesFromDB:(NSString *)dbName;
+- (NSArray *)listTablesFromDB:(NSString *)dbName like:(NSString *)tablesName;
- (MCPResult *)listFieldsFromTable:(NSString *)tableName;
- (MCPResult *)listFieldsFromTable:(NSString *)tableName like:(NSString *)fieldsName;
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index 27ae11ae..a8eb923a 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -33,6 +33,7 @@
#import "MCPStreamingResult.h"
#import "MCPConnectionProxy.h"
#import "MCPStringAdditions.h"
+#import "SPStringAdditions.h"
#import "RegexKitLite.h"
#include <unistd.h>
@@ -1847,26 +1848,41 @@ void performThreadedKeepAlive(void *ptr)
return theResult;
}
+- (NSArray *)listTablesFromDB:(NSString *)dbName {
+ return [self listTablesFromDB:dbName like:nil];
+}
+
/**
* List tables in DB specified by dbName and corresponding to pattern.
* This method indeed issues a !{SHOW TABLES FROM dbName LIKE ...} query to the server.
* This is done this way to make sure the selected DB is not changed by this method.
*/
-- (MCPResult *)listTablesFromDB:(NSString *)dbName like:(NSString *)tablesName
-{
+- (NSArray *)listTablesFromDB:(NSString *)dbName like:(NSString *)tablesName {
MCPResult *theResult;
-
if ((tablesName == nil) || ([tablesName isEqualToString:@""])) {
- NSString *theQuery = [NSString stringWithFormat:@"SHOW TABLES FROM %@", dbName];
+ NSString *theQuery = [NSString stringWithFormat:@"SHOW TABLES FROM %@",
+ [dbName backtickQuotedString]];
theResult = [self queryString:theQuery];
- }
- else {
- NSString *theQuery = [NSString stringWithFormat:@"SHOW TABLES FROM %@ LIKE '%@'", dbName, tablesName];
+ } else {
+ NSString *theQuery = [NSString stringWithFormat:@"SHOW TABLES FROM %@ LIKE '%@'",
+ [dbName backtickQuotedString],
+ [tablesName backtickQuotedString]];
theResult = [self queryString:theQuery];
}
[theResult setReturnDataAsStrings:YES];
-
- return theResult;
+ NSString *theTableName;
+ NSMutableArray *theDBTables = [NSMutableArray array];
+
+ // NSLog(@"num of fields: %@; num of rows: %@", [theResult numOfFields], [theResult numOfRows]);
+ if ([theResult numOfRows] > 0) {
+ int i;
+ for ( i = 0 ; i < [theResult numOfRows] ; i++ ) {
+ theTableName = [[theResult fetchRowAsArray] objectAtIndex:0];
+ [theDBTables addObject:theTableName];
+ }
+ }
+
+ return theDBTables;
}
/**
@@ -1887,11 +1903,14 @@ void performThreadedKeepAlive(void *ptr)
MCPResult *theResult;
if ((fieldsName == nil) || ([fieldsName isEqualToString:@""])) {
- NSString *theQuery = [NSString stringWithFormat:@"SHOW COLUMNS FROM %@", tableName];
+ NSString *theQuery = [NSString stringWithFormat:@"SHOW COLUMNS FROM %@",
+ [tableName backtickQuotedString]];
theResult = [self queryString:theQuery];
}
else {
- NSString *theQuery = [NSString stringWithFormat:@"SHOW COLUMNS FROM %@ LIKE '%@'", tableName, fieldsName];
+ NSString *theQuery = [NSString stringWithFormat:@"SHOW COLUMNS FROM %@ LIKE '%@'",
+ [tableName backtickQuotedString],
+ [fieldsName backtickQuotedString]];
theResult = [self queryString:theQuery];
}
[theResult setReturnDataAsStrings:YES];