Skip to content

Commit

Permalink
Tidy up some parameter naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuconnolly committed Oct 5, 2018
1 parent 623d40b commit bcb7fb6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Source/SPCreateDatabaseInfo.h
@@ -1,5 +1,5 @@
// //
// SPCreateDatabaseInfo.m // SPCreateDatabaseInfo.h
// sequel-pro // sequel-pro
// //
// Created by David Rekowski on April 29, 2010. // Created by David Rekowski on April 29, 2010.
Expand Down Expand Up @@ -35,8 +35,8 @@
NSString *defaultCollation; NSString *defaultCollation;
} }


@property (readwrite, retain) NSString *databaseName; @property (nonnull, readwrite, retain) NSString *databaseName;
@property (readwrite, retain) NSString *defaultEncoding; @property (nullable, readwrite, retain) NSString *defaultEncoding;
@property (readwrite, retain) NSString *defaultCollation; @property (nullable, readwrite, retain) NSString *defaultCollation;


@end @end
10 changes: 3 additions & 7 deletions Source/SPDatabaseAction.h
Expand Up @@ -42,17 +42,13 @@
/** /**
* @property connection References the SPMySQL.framework MySQL connection; it has to be set. * @property connection References the SPMySQL.framework MySQL connection; it has to be set.
*/ */
@property (readwrite, assign) SPMySQLConnection *connection; @property (nonnull, readwrite, assign) SPMySQLConnection *connection;


/**
* @property messageWindow The NSWindow instance to send message sheets to.
*/
@property (readwrite, assign) NSWindow *messageWindow;


/** /**
* @property tablesList * @property tablesList
*/ */
@property (readwrite, assign) SPTablesList *tablesList; @property (nonnull, readwrite, assign) SPTablesList *tablesList;


/** /**
* This method creates a new database. * This method creates a new database.
Expand All @@ -63,7 +59,7 @@
* *
* @see createDatabase:withEncoding:collation: * @see createDatabase:withEncoding:collation:
*/ */
- (BOOL)createDatabase:(SPCreateDatabaseInfo *)dbInfo; - (BOOL)createDatabase:(SPCreateDatabaseInfo *)databaseInfo;


/** /**
* This method creates a new database. * This method creates a new database.
Expand Down
9 changes: 4 additions & 5 deletions Source/SPDatabaseAction.m
Expand Up @@ -38,14 +38,13 @@
@implementation SPDatabaseAction @implementation SPDatabaseAction


@synthesize connection; @synthesize connection;
@synthesize messageWindow;
@synthesize tablesList; @synthesize tablesList;


- (BOOL)createDatabase:(SPCreateDatabaseInfo *)dbInfo - (BOOL)createDatabase:(SPCreateDatabaseInfo *)databaseInfo
{ {
return [self createDatabase:[dbInfo databaseName] return [self createDatabase:[databaseInfo databaseName]
withEncoding:[dbInfo defaultEncoding] withEncoding:[databaseInfo defaultEncoding]
collation:[dbInfo defaultCollation]]; collation:[databaseInfo defaultCollation]];
} }


- (BOOL)createDatabase:(NSString *)database withEncoding:(NSString *)encoding collation:(NSString *)collation - (BOOL)createDatabase:(NSString *)database withEncoding:(NSString *)encoding collation:(NSString *)collation
Expand Down
24 changes: 12 additions & 12 deletions Source/SPTableCopy.h
Expand Up @@ -39,46 +39,46 @@
* This method copies a table structure from one db to another. * This method copies a table structure from one db to another.
* *
* @param name name of the table in the source database * @param name name of the table in the source database
* @param sourceDB name of the source database * @param sourceDatabase name of the source database
* @param targetDB name of the target database * @param targetDatabase name of the target database
* *
* @return YES on success, NO on any kind of error (unspecified) * @return YES on success, NO on any kind of error (unspecified)
*/ */
- (BOOL)copyTable:(NSString *)name from:(NSString *)sourceDB to:(NSString *)targetDB; - (BOOL)copyTable:(NSString *)name from:(NSString *)sourceDatabase to:(NSString *)targetDatabase;


/** /**
* This method moves a table from one db to another. * This method moves a table from one db to another.
* *
* @param name name of the table in the source database * @param name name of the table in the source database
* @param sourceDB name of the source database * @param sourceDatabase name of the source database
* @param targetDB name of the target database * @param targetDatabase name of the target database
*/ */
- (BOOL)moveTable:(NSString *)name from:(NSString *)sourceDB to:(NSString *)targetDB; - (BOOL)moveTable:(NSString *)name from:(NSString *)sourceDatabase to:(NSString *)targetDatabase;


/** /**
* This method copies a table including its data from one db to another. * This method copies a table including its data from one db to another.
* *
* @param name name of the table in the source database * @param name name of the table in the source database
* @param sourceDB name of the source database * @param sourceDatabase name of the source database
* @param targetDB name of the target database * @param targetDatabase name of the target database
* @param copyWithContent whether to copy the content too, otherwise only structure * @param copyWithContent whether to copy the content too, otherwise only structure
* *
* @return YES on success, NO on any kind of error (unspecified) * @return YES on success, NO on any kind of error (unspecified)
*/ */
- (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to: (NSString *)targetDB withContent:(BOOL)copyWithContent; - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDatabase to:(NSString *)targetDatabase withContent:(BOOL)copyWithContent;


/** /**
* This method copies a bunch of tables including their data from one db to another. * This method copies a bunch of tables including their data from one db to another.
* *
* @param tableArray array of NSStrings with the table names in the sourceDB * @param tableArray array of NSStrings with the table names in the sourceDB
* @param sourceDB name of the source database * @param sourceDatabase name of the source database
* @param targetDB name of the target database * @param targetDatabase name of the target database
* @param copyWithContent whether to copy the content too, otherwise only structure * @param copyWithContent whether to copy the content too, otherwise only structure
* *
* @return YES on success, NO on any kind of error (unspecified) * @return YES on success, NO on any kind of error (unspecified)
* *
* This method is able to copy InnoDB tables with foreign key constraints. * This method is able to copy InnoDB tables with foreign key constraints.
*/ */
- (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDB to:(NSString *)targetDB withContent:(BOOL)copyWithContent; - (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDatabase to:(NSString *)targetDatabase withContent:(BOOL)copyWithContent;


@end @end
28 changes: 14 additions & 14 deletions Source/SPTableCopy.m
Expand Up @@ -34,23 +34,23 @@


@interface SPTableCopy () @interface SPTableCopy ()


- (NSString *)_createTableStatementFor:(NSString *)tableName inDatabase:(NSString *)sourceDatabase; - (NSString *)_createTableStatementFor:(NSString *)tableName inDatabase:(NSString *)sourceDatabase;


@end @end




@implementation SPTableCopy @implementation SPTableCopy


- (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDatabase to:(NSString *)targetDatabase
{ {
NSString *createTableResult = [self _createTableStatementFor:tableName inDatabase:sourceDB]; NSString *createTableResult = [self _createTableStatementFor:tableName inDatabase:sourceDatabase];


if ([createTableResult hasPrefix:@"CREATE TABLE"]) { if ([createTableResult hasPrefix:@"CREATE TABLE"]) {
NSMutableString *createTableStatement = [[NSMutableString alloc] initWithString:createTableResult]; NSMutableString *createTableStatement = [[NSMutableString alloc] initWithString:createTableResult];


// Add the target DB name and the separator dot after "CREATE TABLE ". // Add the target DB name and the separator dot after "CREATE TABLE ".
[createTableStatement insertString:@"." atIndex:13]; [createTableStatement insertString:@"." atIndex:13];
[createTableStatement insertString:[targetDB backtickQuotedString] atIndex:13]; [createTableStatement insertString:[targetDatabase backtickQuotedString] atIndex:13];


[connection queryString:createTableStatement]; [connection queryString:createTableStatement];


Expand All @@ -62,18 +62,18 @@ - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *
return NO; return NO;
} }


- (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB withContent:(BOOL)copyWithContent - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDatabase to:(NSString *)targetDatabase withContent:(BOOL)copyWithContent
{ {
// Copy the table structure // Copy the table structure
BOOL structureCopySuccess = [self copyTable:tableName from:sourceDB to:targetDB]; BOOL structureCopySuccess = [self copyTable:tableName from:sourceDatabase to:targetDatabase];


// Optionally copy the table data using an insert select // Optionally copy the table data using an insert select
if (structureCopySuccess && copyWithContent) { if (structureCopySuccess && copyWithContent) {


NSString *copyDataStatement = [NSString stringWithFormat:@"INSERT INTO %@.%@ SELECT * FROM %@.%@", NSString *copyDataStatement = [NSString stringWithFormat:@"INSERT INTO %@.%@ SELECT * FROM %@.%@",
[targetDB backtickQuotedString], [targetDatabase backtickQuotedString],
[tableName backtickQuotedString], [tableName backtickQuotedString],
[sourceDB backtickQuotedString], [sourceDatabase backtickQuotedString],
[tableName backtickQuotedString] [tableName backtickQuotedString]
]; ];


Expand All @@ -85,7 +85,7 @@ - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *
return structureCopySuccess; return structureCopySuccess;
} }


- (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDB to:(NSString *)targetDB withContent:(BOOL)copyWithContent - (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDatabase to:(NSString *)targetDatabase withContent:(BOOL)copyWithContent
{ {
BOOL success = YES; BOOL success = YES;


Expand All @@ -105,7 +105,7 @@ - (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDB to:(NSString


for (NSString *tableName in tablesArray) for (NSString *tableName in tablesArray)
{ {
if (![self copyTable:tableName from:sourceDB to:targetDB withContent:copyWithContent]) { if (![self copyTable:tableName from:sourceDatabase to:targetDatabase withContent:copyWithContent]) {
success = NO; success = NO;
} }
} }
Expand All @@ -127,12 +127,12 @@ - (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDB to:(NSString
return success; return success;
} }


- (BOOL)moveTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB - (BOOL)moveTable:(NSString *)tableName from:(NSString *)sourceDatabase to:(NSString *)targetDatabase
{ {
NSString *moveStatement = [NSString stringWithFormat:@"RENAME TABLE %@.%@ TO %@.%@", NSString *moveStatement = [NSString stringWithFormat:@"RENAME TABLE %@.%@ TO %@.%@",
[sourceDB backtickQuotedString], [sourceDatabase backtickQuotedString],
[tableName backtickQuotedString], [tableName backtickQuotedString],
[targetDB backtickQuotedString], [targetDatabase backtickQuotedString],
[tableName backtickQuotedString]]; [tableName backtickQuotedString]];


[connection queryString:moveStatement]; [connection queryString:moveStatement];
Expand All @@ -143,7 +143,7 @@ - (BOOL)moveTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *
#pragma mark - #pragma mark -
#pragma mark Private API #pragma mark Private API


- (NSString *)_createTableStatementFor:(NSString *)tableName inDatabase:(NSString *)sourceDatabase - (NSString *)_createTableStatementFor:(NSString *)tableName inDatabase:(NSString *)sourceDatabase
{ {
NSString *showCreateTableStatment = [NSString stringWithFormat:@"SHOW CREATE TABLE %@.%@", [sourceDatabase backtickQuotedString], [tableName backtickQuotedString]]; NSString *showCreateTableStatment = [NSString stringWithFormat:@"SHOW CREATE TABLE %@.%@", [sourceDatabase backtickQuotedString], [tableName backtickQuotedString]];


Expand Down

0 comments on commit bcb7fb6

Please sign in to comment.