diff options
author | Stuart Connolly <stuart02@gmail.com> | 2017-03-23 18:26:02 +0000 |
---|---|---|
committer | Stuart Connolly <stuart02@gmail.com> | 2017-03-23 18:26:02 +0000 |
commit | d37a2f490a271b6170a5c2978f505fb403d1ad64 (patch) | |
tree | 4b817ac830d64aeeab9cb4c2d80afea671b7a426 /Source | |
parent | bab93f8ce74a6644c9a3d8a50fa26230f127c550 (diff) | |
download | sequelpro-d37a2f490a271b6170a5c2978f505fb403d1ad64.tar.gz sequelpro-d37a2f490a271b6170a5c2978f505fb403d1ad64.tar.bz2 sequelpro-d37a2f490a271b6170a5c2978f505fb403d1ad64.zip |
- #1235: Prevent renaming a database which contains any non-table objects as it's currently not supported.
- #1235: Inform the user when duplicating a database than any non-table objects won't be copied.
- Add missing high resolution images to project.
- Fix a potential memory leak inside SPCreateDatabaseInfo
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPCreateDatabaseInfo.h | 42 | ||||
-rw-r--r-- | Source/SPCreateDatabaseInfo.m | 49 | ||||
-rw-r--r-- | Source/SPDatabaseAction.h | 17 | ||||
-rw-r--r-- | Source/SPDatabaseAction.m | 24 | ||||
-rw-r--r-- | Source/SPDatabaseCopy.h | 1 | ||||
-rw-r--r-- | Source/SPDatabaseCopy.m | 10 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.h | 2 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 72 | ||||
-rw-r--r-- | Source/SPDatabaseRename.h | 1 | ||||
-rw-r--r-- | Source/SPDatabaseRename.m | 16 | ||||
-rw-r--r-- | Source/SPTableCopy.h | 3 | ||||
-rw-r--r-- | Source/SPTableCopy.m | 9 | ||||
-rw-r--r-- | Source/SPTablesList.h | 91 | ||||
-rw-r--r-- | Source/SPTablesList.m | 172 |
14 files changed, 307 insertions, 202 deletions
diff --git a/Source/SPCreateDatabaseInfo.h b/Source/SPCreateDatabaseInfo.h new file mode 100644 index 00000000..8ddc6268 --- /dev/null +++ b/Source/SPCreateDatabaseInfo.h @@ -0,0 +1,42 @@ +// +// SPCreateDatabaseInfo.m +// sequel-pro +// +// Created by David Rekowski on April 29, 2010. +// Copyright (c) 2010 David Rekowski. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// More info at <https://github.com/sequelpro/sequelpro> + +@interface SPCreateDatabaseInfo : NSObject +{ + NSString *databaseName; + NSString *defaultEncoding; + NSString *defaultCollation; +} + +@property (readwrite, retain) NSString *databaseName; +@property (readwrite, retain) NSString *defaultEncoding; +@property (readwrite, retain) NSString *defaultCollation; + +@end diff --git a/Source/SPCreateDatabaseInfo.m b/Source/SPCreateDatabaseInfo.m new file mode 100644 index 00000000..0dc4c123 --- /dev/null +++ b/Source/SPCreateDatabaseInfo.m @@ -0,0 +1,49 @@ +// +// SPCreateDatabaseInfo.m +// sequel-pro +// +// Created by David Rekowski on April 29, 2010. +// Copyright (c) 2010 David Rekowski. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// More info at <https://github.com/sequelpro/sequelpro> + +#import "SPCreateDatabaseInfo.h" + +@implementation SPCreateDatabaseInfo + +@synthesize databaseName; +@synthesize defaultEncoding; +@synthesize defaultCollation; + +- (void)dealloc +{ + if (databaseName) SPClear(databaseName); + if (defaultEncoding) SPClear(defaultEncoding); + if (defaultCollation) SPClear(defaultCollation); + + [super dealloc]; +} + +@end + diff --git a/Source/SPDatabaseAction.h b/Source/SPDatabaseAction.h index 7ca8d402..98143ad8 100644 --- a/Source/SPDatabaseAction.h +++ b/Source/SPDatabaseAction.h @@ -30,19 +30,7 @@ @class SPTablesList; @class SPMySQLConnection; - -@interface SPCreateDatabaseInfo : NSObject -{ - NSString *databaseName; - NSString *defaultEncoding; - NSString *defaultCollation; -} - -@property (readwrite,retain) NSString *databaseName; -@property (readwrite,retain) NSString *defaultEncoding; -@property (readwrite,retain) NSString *defaultCollation; - -@end +@class SPCreateDatabaseInfo; @interface SPDatabaseAction : NSObject { @@ -70,7 +58,9 @@ * This method creates a new database. * * @param dbInfo database name/charset/collation (charset, collation may be nil) + * * @return success + * * @see createDatabase:withEncoding:collation: */ - (BOOL)createDatabase:(SPCreateDatabaseInfo *)dbInfo; @@ -81,6 +71,7 @@ * @param database name of the new database to be created * @param encoding charset of the new database (can be nil to skip) * @param collation sorting collation of the new database (can be nil) + * * @return YES on success, otherwise NO */ - (BOOL)createDatabase:(NSString *)database withEncoding:(NSString *)encoding collation:(NSString *)collation; diff --git a/Source/SPDatabaseAction.m b/Source/SPDatabaseAction.m index 413e2378..ad96fed1 100644 --- a/Source/SPDatabaseAction.m +++ b/Source/SPDatabaseAction.m @@ -29,25 +29,10 @@ // More info at <https://github.com/sequelpro/sequelpro> #import "SPDatabaseAction.h" +#import "SPCreateDatabaseInfo.h" #import <SPMySQL/SPMySQL.h> -@implementation SPCreateDatabaseInfo - -@synthesize databaseName; -@synthesize defaultEncoding; -@synthesize defaultCollation; - -- (void)dealloc -{ - [self setDatabaseName:nil]; - [self setDefaultEncoding:nil]; - [self setDefaultCollation:nil]; - [super dealloc]; -} - -@end - #pragma mark - @implementation SPDatabaseAction @@ -65,17 +50,18 @@ - (BOOL)createDatabase:(NSString *)database withEncoding:(NSString *)encoding collation:(NSString *)collation { - if(![database length]) { + if (![database length]) { SPLog(@"'database' should not be nil or empty!"); return NO; } NSMutableString *query = [NSMutableString stringWithFormat:@"CREATE DATABASE %@", [database backtickQuotedString]]; - if([encoding length]) { // [nil length] == 0 + if ([encoding length]) { // [nil length] == 0 [query appendFormat:@" DEFAULT CHARACTER SET = %@",[encoding backtickQuotedString]]; } - if([collation length]) { + + if ([collation length]) { [query appendFormat:@" DEFAULT COLLATE = %@",[collation backtickQuotedString]]; } diff --git a/Source/SPDatabaseCopy.h b/Source/SPDatabaseCopy.h index 3adf7fa0..57f29653 100644 --- a/Source/SPDatabaseCopy.h +++ b/Source/SPDatabaseCopy.h @@ -40,6 +40,7 @@ * * @param sourceDatabase information tuple about source database * @param targetDatabaseName the name of the target database + * * @result success */ - (BOOL)copyDatabaseFrom:(SPCreateDatabaseInfo *)sourceDatabase to:(NSString *)targetDatabaseName withContent:(BOOL)copyWithContent; diff --git a/Source/SPDatabaseCopy.m b/Source/SPDatabaseCopy.m index 94a5e896..976bd809 100644 --- a/Source/SPDatabaseCopy.m +++ b/Source/SPDatabaseCopy.m @@ -30,6 +30,7 @@ #import "SPDatabaseCopy.h" #import "SPTableCopy.h" +#import "SPCreateDatabaseInfo.h" #import <SPMySQL/SPMySQL.h> @@ -38,10 +39,11 @@ - (BOOL)copyDatabaseFrom:(SPCreateDatabaseInfo *)sourceDatabase to:(NSString *)targetDatabaseName withContent:(BOOL)copyWithContent { NSArray *tables = nil; - - // Check whether the source database exists and the target database doesn't. - BOOL sourceExists = [[connection databases] containsObject:[sourceDatabase databaseName]]; - BOOL targetExists = [[connection databases] containsObject:targetDatabaseName]; + NSArray *databases = [connection databases]; + + // Check whether the source database exists and the target database doesn't + BOOL sourceExists = [databases containsObject:[sourceDatabase databaseName]]; + BOOL targetExists = [databases containsObject:targetDatabaseName]; if (!sourceExists || targetExists) return NO; diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index 6596ca8c..fc00f647 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -269,7 +269,9 @@ NSArray *statusValues; + // Alert return codes NSInteger saveDocPrefSheetStatus; + NSInteger confirmCopyDatabaseReturnCode; // Properties SPWindowController *parentWindowController; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 3548c284..128ec297 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -90,14 +90,18 @@ enum { #import "SPCharsetCollationHelper.h" #import "SPGotoDatabaseController.h" #import "SPFunctions.h" +#import "SPCreateDatabaseInfo.h" #import <SPMySQL/SPMySQL.h> #include <libkern/OSAtomic.h> // Constants +static NSString *SPCopyDatabaseAction = @"SPCopyDatabase"; +static NSString *SPConfirmCopyDatabaseAction = @"SPConfirmCopyDatabase"; static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; static NSString *SPAlterDatabaseAction = @"SPAlterDatabase"; + static int64_t SPDatabaseDocumentInstanceCounter = 0; @interface SPDatabaseDocument () @@ -592,7 +596,7 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; * * @return The document's connection */ -- (SPMySQLConnection *) getConnection +- (SPMySQLConnection *)getConnection { return mySQLConnection; } @@ -600,9 +604,9 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; /** * Sets this connection's Keychain ID. */ -- (void)setKeychainID:(NSString *)theID +- (void)setKeychainID:(NSString *)theId { - keyChainID = [[NSString stringWithString:theID] retain]; + keyChainID = [[NSString stringWithString:theId] retain]; } #pragma mark - @@ -868,7 +872,25 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; - (IBAction)copyDatabase:(id)sender { if (![tablesListInstance selectionShouldChangeInTableView:nil]) return; - + + // Inform the user that we don't support copying objects other than tables and ask them if they'd like to proceed + if ([tablesListInstance hasNonTableObjects]) { + [SPAlertSheets beginWaitingAlertSheetWithTitle:@"" + defaultButton:NSLocalizedString(@"Continue", "continue button") + alternateButton:NSLocalizedString(@"Cancel", @"cancel button") + otherButton:nil + alertStyle:NSAlertStyleWarning + docWindow:parentWindow + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:SPConfirmCopyDatabaseAction + msg:NSLocalizedString(@"Only Partially Supported", @"partial copy database support message") + infoText:[NSString stringWithFormat:NSLocalizedString(@"Duplicating the database '%@' is only partially supported as it contains objects other tables (i.e. views, procedures, functions, etc.), which will not be copied.\n\nWould you like to continue?", @"partial copy database support informative message"), selectedDatabase] + returnCode:&confirmCopyDatabaseReturnCode]; + + if (confirmCopyDatabaseReturnCode == NSAlertAlternateReturn) return; + } + [databaseCopyNameField setStringValue:selectedDatabase]; [copyDatabaseMessageField setStringValue:selectedDatabase]; @@ -876,16 +898,29 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; modalForWindow:parentWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) - contextInfo:@"copyDatabase"]; + contextInfo:SPCopyDatabaseAction]; } #endif /** - * opens the rename database sheet and renames the databsae + * Opens the rename database sheet and renames the databsae. */ - (IBAction)renameDatabase:(id)sender { if (![tablesListInstance selectionShouldChangeInTableView:nil]) return; + + // We currently don't support moving any objects other than tables (i.e. views, functions, procs, etc.) from one database to another + // so inform the user and don't allow them to proceed. Copy/duplicate is more appropriate in this case, but with the same limitation. + if ([tablesListInstance hasNonTableObjects]) { + SPOnewayAlertSheet( + NSLocalizedString(@"Database Rename Unsupported", @"databsse rename unsupported message"), + parentWindow, + [NSString stringWithFormat:NSLocalizedString( + @"Ranaming the database '%@' is currently unsupported as it contains objects other than tables (i.e. views, procedures, functions, etc.).\n\nIf you would like to rename a database please use the 'Duplicate Database', move any non-table objects manually then drop the old database.", + @"databsse rename unsupported informative message"), selectedDatabase] + ); + return; + } [databaseRenameNameField setStringValue:selectedDatabase]; [renameDatabaseMessageField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Rename database '%@' to:", @"rename database message"), selectedDatabase]]; @@ -912,8 +947,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Delete database '%@'?", @"delete database message"), [self database]] defaultButton:NSLocalizedString(@"Delete", @"delete button") alternateButton:NSLocalizedString(@"Cancel", @"cancel button") - otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"Are you sure you want to delete the database '%@'? This operation cannot be undone.", @"delete database informative message"), [self database]]; + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"Are you sure you want to delete the database '%@'? This operation cannot be undone.", @"delete database informative message"), [self database]]; NSArray *buttons = [alert buttons]; @@ -1022,26 +1057,29 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; /** * Alert sheet method. Invoked when an alert sheet is dismissed. - * - * if contextInfo == removeDatabase -> Remove the selected database - * if contextInfo == addDatabase -> Add a new database - * if contextInfo == copyDatabase -> Duplicate the selected database - * if contextInfo == renameDatabase -> Rename the selected database */ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo { #ifndef SP_CODA - if([contextInfo isEqualToString:@"saveDocPrefSheetStatus"]) { + + // Those that are just setting a return code and don't need to order out the sheet. See SPAlertSheets+beginWaitingAlertSheetWithTitle: + if ([contextInfo isEqualToString:@"saveDocPrefSheetStatus"]) { saveDocPrefSheetStatus = returnCode; return; } + else if ([contextInfo isEqualToString:SPConfirmCopyDatabaseAction]) { + confirmCopyDatabaseReturnCode = returnCode; + return; + } #endif // Order out current sheet to suppress overlapping of sheets - if ([sheet respondsToSelector:@selector(orderOut:)]) + if ([sheet respondsToSelector:@selector(orderOut:)]) { [sheet orderOut:nil]; - else if ([sheet respondsToSelector:@selector(window)]) + } + else if ([sheet respondsToSelector:@selector(window)]) { [[sheet window] orderOut:nil]; + } // Remove the current database if ([contextInfo isEqualToString:@"removeDatabase"]) { @@ -1081,7 +1119,7 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; } } #ifndef SP_CODA - else if ([contextInfo isEqualToString:@"copyDatabase"]) { + else if ([contextInfo isEqualToString:SPCopyDatabaseAction]) { if (returnCode == NSOKButton) { [self _copyDatabase]; } diff --git a/Source/SPDatabaseRename.h b/Source/SPDatabaseRename.h index becf460e..678fd962 100644 --- a/Source/SPDatabaseRename.h +++ b/Source/SPDatabaseRename.h @@ -40,6 +40,7 @@ * * @param sourceDatabase information tuple about the source database * @param targetDatabase the name of the target database + * * @result success */ - (BOOL)renameDatabaseFrom:(SPCreateDatabaseInfo *)sourceDatabase to:(NSString *)targetDatabase; diff --git a/Source/SPDatabaseRename.m b/Source/SPDatabaseRename.m index a6b393be..0c980384 100644 --- a/Source/SPDatabaseRename.m +++ b/Source/SPDatabaseRename.m @@ -32,6 +32,7 @@ #import "SPTableCopy.h" #import "SPViewCopy.h" #import "SPTablesList.h" +#import "SPCreateDatabaseInfo.h" #import <SPMySQL/SPMySQL.h> @@ -46,6 +47,9 @@ @implementation SPDatabaseRename +/** + * Note that this doesn't currently support moving any non-table objects (i.e. views, proc, functions, events, etc). + */ - (BOOL)renameDatabaseFrom:(SPCreateDatabaseInfo *)sourceDatabase to:(NSString *)targetDatabase { // Check, whether the source database exists and the target database doesn't @@ -55,23 +59,13 @@ if (!sourceExists || targetExists) return NO; NSArray *tables = [tablesList allTableNames]; -// NSArray *views = [tablesList allViewNames]; // TODO: handle views when renaming database - + BOOL success = [self createDatabase:targetDatabase withEncoding:[sourceDatabase defaultEncoding] collation:[sourceDatabase defaultCollation]]; [self _moveTables:tables fromDatabase:[sourceDatabase databaseName] toDatabase:targetDatabase]; -#warning Section disabled because it might destroy data (views, functions, events, ...) -/* - tables = [connection tablesFromDatabase:[sourceDatabase databaseName]]; - - if ([tables count] == 0) { - [self _dropDatabase:[sourceDatabase databaseName]]; - } -*/ - return success; } diff --git a/Source/SPTableCopy.h b/Source/SPTableCopy.h index c0d87929..eba968c6 100644 --- a/Source/SPTableCopy.h +++ b/Source/SPTableCopy.h @@ -41,6 +41,7 @@ * @param name name of the table in the source database * @param sourceDB name of the source database * @param targetDB name of the target database + * * @return YES on success, NO on any kind of error (unspecified) */ - (BOOL)copyTable:(NSString *)name from:(NSString *)sourceDB to:(NSString *)targetDB; @@ -61,6 +62,7 @@ * @param sourceDB name of the source database * @param targetDB name of the target database * @param copyWithContent whether to copy the content too, otherwise only structure + * * @return YES on success, NO on any kind of error (unspecified) */ - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to: (NSString *)targetDB withContent:(BOOL)copyWithContent; @@ -72,6 +74,7 @@ * @param sourceDB name of the source database * @param targetDB name of the target database * @param copyWithContent whether to copy the content too, otherwise only structure + * * @return YES on success, NO on any kind of error (unspecified) * * This method is able to copy InnoDB tables with foreign key constraints. diff --git a/Source/SPTableCopy.m b/Source/SPTableCopy.m index 07f03846..bc13bc5c 100644 --- a/Source/SPTableCopy.m +++ b/Source/SPTableCopy.m @@ -117,7 +117,7 @@ success = NO; } - // re-enable id creation + // Re-enable id creation [connection queryString:@"/*!40101 SET SQL_MODE=@OLD_SQL_MODE */"]; if ([connection queryErrored]) { @@ -147,11 +147,12 @@ { NSString *showCreateTableStatment = [NSString stringWithFormat:@"SHOW CREATE TABLE %@.%@", [sourceDatabase backtickQuotedString], [tableName backtickQuotedString]]; - SPMySQLResult *theResult = [connection queryString:showCreateTableStatment]; + SPMySQLResult *result = [connection queryString:showCreateTableStatment]; - if([theResult numberOfRows] > 0) return [[theResult getRowAsArray] objectAtIndex:1]; + if ([result numberOfRows] > 0) return [[result getRowAsArray] objectAtIndex:1]; - NSLog(@"query <%@> failed to return the expected result.\n Error state: %@ (%lu)",showCreateTableStatment,[connection lastErrorMessage],[connection lastErrorID]); + SPLog(@"query <%@> failed to return the expected result.\n Error state: %@ (%lu)", showCreateTableStatment, [connection lastErrorMessage], [connection lastErrorID]); + return nil; } diff --git a/Source/SPTablesList.h b/Source/SPTablesList.h index 433879ea..e299654c 100644 --- a/Source/SPTablesList.h +++ b/Source/SPTablesList.h @@ -38,52 +38,43 @@ @class SPTableContent; @class SPSplitView; @class SPCharsetCollationHelper; - -#ifdef SP_CODA -@class SQLSidebarViewController; -#endif +@class SPCustomQuery; +@class SPTableImport; +@class SPTableData; +@class SPTableInfo; +@class SPTableTriggers; +@class SPExtendedTableInfo; @interface SPTablesList : NSObject <NSTextFieldDelegate, NSTableViewDelegate> { - IBOutlet SPDatabaseDocument* tableDocumentInstance; - IBOutlet SPTableStructure* tableSourceInstance; - IBOutlet SPTableContent* tableContentInstance; -#ifndef SP_CODA /* ivars */ - IBOutlet id customQueryInstance; - IBOutlet id tableDumpInstance; - IBOutlet id tableDataInstance; - IBOutlet id extendedTableInfoInstance; -#endif - IBOutlet SPDatabaseData* databaseDataInstance; -#ifndef SP_CODA /* ivars */ - IBOutlet id tableInfoInstance; - IBOutlet id tableTriggersInstance; + IBOutlet SPDatabaseDocument *tableDocumentInstance; + IBOutlet SPTableStructure *tableSourceInstance; + IBOutlet SPTableContent *tableContentInstance; + IBOutlet SPDatabaseData *databaseDataInstance; IBOutlet SPHistoryController *spHistoryControllerInstance; + IBOutlet SPCustomQuery *customQueryInstance; + IBOutlet SPTableImport *tableDumpInstance; + IBOutlet SPTableData *tableDataInstance; + IBOutlet SPExtendedTableInfo *extendedTableInfoInstance; + IBOutlet SPTableInfo *tableInfoInstance; + IBOutlet SPTableTriggers *tableTriggersInstance; IBOutlet id copyTableSheet; -#endif IBOutlet SPTableView *tablesListView; -#ifndef SP_CODA /* ivars */ IBOutlet id copyTableButton; IBOutlet id copyTableNameField; IBOutlet id copyTableMessageField; IBOutlet NSButton *copyTableContentSwitch; -#endif IBOutlet id tableSheet; IBOutlet id tableNameField; IBOutlet id tableEncodingButton; IBOutlet id tableCollationButton; IBOutlet id tableTypeButton; IBOutlet id toolbarAddButton; -#ifdef SP_CODA - id toolbarDeleteButton; -#endif -#ifndef SP_CODA + IBOutlet id toolbarActionsButton; -#endif IBOutlet id toolbarReloadButton; IBOutlet id addTableButton; -#ifndef SP_CODA IBOutlet id truncateTableButton; IBOutlet SPSplitView *tableListSplitView; IBOutlet SPSplitView *tableListFilterSplitView; @@ -101,11 +92,9 @@ IBOutlet NSMenuItem *copyCreateSyntaxMenuItem; IBOutlet NSMenuItem *separatorTableMenuItem2; IBOutlet NSMenuItem *separatorTableMenuItem3; -#endif SPMySQLConnection *mySQLConnection; - -#ifndef SP_CODA /* ivars */ + // Table list context menu items IBOutlet NSMenuItem *removeTableContextMenuItem; IBOutlet NSMenuItem *duplicateTableContextMenuItem; @@ -118,7 +107,6 @@ IBOutlet NSMenuItem *copyCreateSyntaxContextMenuItem; IBOutlet NSMenuItem *separatorTableContextMenuItem2; IBOutlet NSMenuItem *separatorTableContextMenuItem3; -#endif NSMutableArray *tables; NSMutableArray *filteredTables; @@ -131,13 +119,7 @@ BOOL tableListContainsViews; BOOL alertSheetOpened; -#ifndef SP_CODA /* ivars */ NSFont *smallSystemFont; -#endif - -#ifdef SP_CODA - SQLSidebarViewController* sidebarViewController; -#endif SPCharsetCollationHelper *addTableCharsetHelper; } @@ -147,25 +129,20 @@ - (IBAction)addTable:(nullable id)sender; - (IBAction)closeSheet:(nullable id)sender; - (IBAction)removeTable:(nullable id)sender; - -#ifndef SP_CODA /* method decls */ - (IBAction)copyTable:(nullable id)sender; - (IBAction)renameTable:(nullable id)sender; - (IBAction)truncateTable:(nullable id)sender; - (IBAction)openTableInNewTab:(nullable id)sender; - (IBAction)openTableInNewWindow:(nullable id)sender; - (IBAction)togglePaneCollapse:(nullable id)sender; -#endif +- (IBAction)updateFilter:(nullable id)sender; // Additional methods - (void)setConnection:(nonnull SPMySQLConnection *)theConnection; - (void)setSelectionState:(nullable NSDictionary *)selectionDetails; - -#ifndef SP_CODA /* method decls */ - (void)selectTableAtIndex:(nullable NSNumber *)row; - (void)makeTableListFilterHaveFocus; - (void)makeTableListHaveFocus; -#endif // Getters - (nonnull NSArray *)selectedTableNames; @@ -184,18 +161,20 @@ - (nonnull NSArray *)allDatabaseNames; - (nonnull NSArray *)allSystemDatabaseNames; - (nullable NSString *)selectedDatabase; +- (BOOL)hasViews; +- (BOOL)hasFunctions; +- (BOOL)hasProcedures; +- (BOOL)hasEvents; +- (BOOL)hasNonTableObjects; // Setters - (BOOL)selectItemWithName:(nullable NSString *)theName; -#ifndef SP_CODA /* method decls */ - (BOOL)selectItemsWithNames:(nonnull NSArray *)theNames; // Table list filter interaction - (void)showFilter; - (void)hideFilter; - (void)clearFilter; -#endif -- (IBAction) updateFilter:(nullable id)sender; // Task interaction - (void)startDocumentTaskForTab:(nullable NSNotification *)aNotification; @@ -203,28 +182,6 @@ - (void)setTableListSelectability:(BOOL)isSelectable; - (BOOL)isTableNameValid:(nullable NSString *)tableName forType:(SPTableType)tableType; - (BOOL)isTableNameValid:(nullable NSString *)tableName forType:(SPTableType)tableType ignoringSelectedTable:(BOOL)ignoreSelectedTable; - -#ifdef SP_CODA /* method decls */ -@property (assign) SPTableStructure* tableSourceInstance; -@property (assign) SPTableContent* tableContentInstance; -@property (assign) id toolbarAddButton; -@property (assign) id toolbarDeleteButton; -@property (assign) id toolbarReloadButton; -@property (assign) id tableSheet; -@property (assign) id tableNameField; -@property (assign) id tableEncodingButton; -@property (assign) id tableTypeButton; -@property (assign) id databaseDataInstance; -@property (assign) id addTableButton; -@property (assign) SPTableView* tablesListView; -@property (assign) SQLSidebarViewController* sidebarViewController; - -- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView; -- (void)setDatabaseDocument:(SPDatabaseDocument*)val; -- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; - -#endif - - (BOOL)selectionShouldChangeInTableView:(nullable NSTableView *)aTableView; @end diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m index b82a44e3..c9c60908 100644 --- a/Source/SPTablesList.m +++ b/Source/SPTablesList.m @@ -34,39 +34,24 @@ #import "SPTableStructure.h" #import "SPDatabaseStructure.h" #import "SPDatabaseViewController.h" - -#ifndef SP_CODA /* headers */ #import "SPTableContent.h" -#endif #import "SPTableData.h" -#ifndef SP_CODA /* headers */ #import "SPTableInfo.h" #import "SPDataImport.h" #import "SPTableView.h" #import "ImageAndTextCell.h" #import "RegexKitLite.h" -#endif #import "SPDatabaseData.h" #import "SPAlertSheets.h" -#ifndef SP_CODA /* headers */ #import "SPNavigatorController.h" #import "SPHistoryController.h" -#endif #import "SPServerSupport.h" -#ifndef SP_CODA /* headers */ #import "SPWindowController.h" #import "SPAppController.h" #import "SPSplitView.h" -#endif #import "SPThreadAdditions.h" #import "SPFunctions.h" - -#ifdef SP_CODA -#import "SQLSidebarViewController.h" -#endif - #import "SPCharsetCollationHelper.h" - #import "SPWindowManagement.h" #import <SPMySQL/SPMySQL.h> @@ -75,50 +60,31 @@ static NSString *SPAddRow = @"SPAddRow"; static NSString *SPAddNewTable = @"SPAddNewTable"; static NSString *SPRemoveTable = @"SPRemoveTable"; -#ifndef SP_CODA static NSString *SPTruncateTable = @"SPTruncateTable"; static NSString *SPDuplicateTable = @"SPDuplicateTable"; -#endif @interface SPTablesList () -#ifndef SP_CODA - (void)_removeTable:(NSNumber *)force; - (void)_truncateTable; -#endif - (void)_addTable; -#ifndef SP_CODA - (void)_copyTable; -#endif - (void)_renameTableOfType:(SPTableType)tableType from:(NSString *)oldTableName to:(NSString *)newTableName; - (void)_duplicateConnectionToFrontTab; - (NSMutableArray *)_allSchemaObjectsOfType:(SPTableType)type; +- (BOOL)_databaseHasObjectOfType:(SPTableType)type; + @end @implementation SPTablesList -#ifdef SP_CODA -@synthesize sidebarViewController; -@synthesize databaseDataInstance; -@synthesize toolbarAddButton; -@synthesize toolbarDeleteButton; -@synthesize toolbarReloadButton; -@synthesize tableSourceInstance; -@synthesize tableContentInstance; -@synthesize tableSheet; -@synthesize tableNameField; -@synthesize tableEncodingButton; -@synthesize tableTypeButton; -@synthesize addTableButton; -@synthesize tablesListView; -#endif - #pragma mark - #pragma mark Initialisation - (id)init { if ((self = [super init])) { + tables = [[NSMutableArray alloc] init]; filteredTables = tables; tableTypes = [[NSMutableArray alloc] init]; @@ -128,11 +94,11 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; tableListContainsViews = NO; selectedTableType = SPTableTypeNone; selectedTableName = nil; -#ifndef SP_CODA + [tables addObject:NSLocalizedString(@"TABLES", @"header for table list")]; smallSystemFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; -#endif + addTableCharsetHelper = nil; //initialized in awakeFromNib } @@ -141,8 +107,6 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; - (void)awakeFromNib { -#ifndef SP_CODA - // Configure the table information pane [tableListSplitView setCollapsibleSubviewIndex:1]; @@ -157,22 +121,20 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; // Disable tab edit behaviour in the tables list [tablesListView setTabEditingDisabled:YES]; -#endif // Add observers for document task activity [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTaskForTab:) name:SPDocumentTaskStartNotification object:tableDocumentInstance]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endDocumentTaskForTab:) name:SPDocumentTaskEndNotification object:tableDocumentInstance]; -#ifndef SP_CODA [tablesListView registerForDraggedTypes:@[SPNavigatorTableDataPasteboardDragType]]; -#endif - + //create the charset helper addTableCharsetHelper = [[SPCharsetCollationHelper alloc] initWithCharsetButton:tableEncodingButton CollationButton:tableCollationButton]; } @@ -1273,57 +1235,66 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; } /** - * Database tables accessors for a given table type + * Database tables accessors for a given table type. */ - (NSArray *)allTableAndViewNames { NSMutableArray *returnArray = [NSMutableArray array]; - NSUInteger i; - NSUInteger cnt = [[self tables] count]; - for(i=0; i<cnt; i++) { - SPTableType tt = (SPTableType)[NSArrayObjectAtIndex([self tableTypes],i) integerValue]; - if(tt == SPTableTypeTable || tt == SPTableTypeView) + + for (NSUInteger i = 0; i < [[self tables] count]; i++) + { + SPTableType tt = (SPTableType)[NSArrayObjectAtIndex([self tableTypes], i) integerValue]; + + if (tt == SPTableTypeTable || tt == SPTableTypeView) { [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; + } } + return returnArray; } +/** + * Returns an array of all table names. + */ - (NSArray *)allTableNames { return [self _allSchemaObjectsOfType:SPTableTypeTable]; } +/** + * Returns an array of view names. + */ - (NSArray *)allViewNames { NSMutableArray *returnArray = [self _allSchemaObjectsOfType:SPTableTypeView]; + [returnArray sortUsingSelector:@selector(compare:)]; + return returnArray; } +/** + * Returns an array of all procedure names. + */ - (NSArray *)allProcedureNames { return [self _allSchemaObjectsOfType:SPTableTypeProc]; } + +/** + * Returns an array of all function names. + */ - (NSArray *)allFunctionNames { return [self _allSchemaObjectsOfType:SPTableTypeFunc]; } +/** + * Returns an array of event names. + */ - (NSArray *)allEventNames { - return [self _allSchemaObjectsOfType:SPTableTypeEvent]; -} - -- (NSMutableArray *)_allSchemaObjectsOfType:(SPTableType)type -{ - NSMutableArray *returnArray = [NSMutableArray array]; - NSInteger i; - NSInteger cnt = [[self tables] count]; - for(i=0; i<cnt; i++) { - if([NSArrayObjectAtIndex([self tableTypes],i) integerValue] == type) - [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; - } - return returnArray; + return [self _allSchemaObjectsOfType:SPTableTypeEvent]; } /** @@ -1355,6 +1326,46 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; return tableTypes; } +/** + * Returns whether or not the current database contains any views. + */ +- (BOOL)hasViews +{ + return [self _databaseHasObjectOfType:SPTableTypeView]; +} + +/** + * Returns whether or not the current database contains any functions. + */ +- (BOOL)hasFunctions +{ + return [self _databaseHasObjectOfType:SPTableTypeFunc]; +} + +/** + * Returns whether or not the current database has any procedures. + */ +- (BOOL)hasProcedures +{ + return [self _databaseHasObjectOfType:SPTableTypeProc]; +} + +/** + * Returns whether or not the current database has any events. + */ +- (BOOL)hasEvents +{ + return [self _databaseHasObjectOfType:SPTableTypeEvent]; +} + +/** + * Returns whether or not the current database has any non-table objects. + */ +- (BOOL)hasNonTableObjects +{ + return [self hasViews] || [self hasProcedures] || [self hasFunctions] || [self hasEvents]; +} + #pragma mark - #pragma mark Setter methods @@ -2740,6 +2751,35 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; [NSException raise:@"Object of unknown type" format:NSLocalizedString(@"An error occured while renaming. '%@' is of an unknown type.", @"rename error - don't know what type the renamed thing is"), oldTableName]; } +- (NSMutableArray *)_allSchemaObjectsOfType:(SPTableType)type +{ + NSMutableArray *returnArray = [NSMutableArray array]; + + for (NSUInteger i = 0; i < [[self tables] count]; i++) + { + if ([NSArrayObjectAtIndex([self tableTypes], i) integerValue] == type) { + [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; + } + } + + return returnArray; +} + +- (BOOL)_databaseHasObjectOfType:(SPTableType)type +{ + BOOL hasObjectOfType = NO; + + for (NSUInteger i = 0; i < [[self tables] count]; i++) + { + if ([NSArrayObjectAtIndex([self tableTypes], i) integerValue] == type) { + hasObjectOfType = YES; + break; + } + } + + return hasObjectOfType; +} + #pragma mark - - (void)dealloc @@ -2748,12 +2788,10 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; SPClear(tables); SPClear(tableTypes); -#ifndef SP_CODA + if (isTableListFiltered && filteredTables) SPClear(filteredTables); if (isTableListFiltered && filteredTableTypes) SPClear(filteredTableTypes); -#endif if (selectedTableName) SPClear(selectedTableName); - if (addTableCharsetHelper) SPClear(addTableCharsetHelper); [super dealloc]; |