Permalink
Browse files

- #1235: Prevent renaming a database which contains any non-table obj…

…ects 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
  • Loading branch information...
stuconnolly committed Mar 23, 2017
1 parent bab93f8 commit d37a2f490a271b6170a5c2978f505fb403d1ad64
@@ -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
@@ -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
View
@@ -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;
View
@@ -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:(SPCreateDatabaseInfo *)dbInfo
- (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]];
}
View
@@ -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;
View
@@ -30,6 +30,7 @@
#import "SPDatabaseCopy.h"
#import "SPTableCopy.h"
#import "SPCreateDatabaseInfo.h"
#import <SPMySQL/SPMySQL.h>
@@ -38,10 +39,11 @@ @implementation SPDatabaseCopy
- (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;
@@ -269,7 +269,9 @@
NSArray *statusValues;
// Alert return codes
NSInteger saveDocPrefSheetStatus;
NSInteger confirmCopyDatabaseReturnCode;
// Properties
SPWindowController *parentWindowController;
@@ -90,14 +90,18 @@
#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,17 +596,17 @@ - (void)setConnection:(SPMySQLConnection *)theConnection
*
* @return The document's connection
*/
- (SPMySQLConnection *) getConnection
- (SPMySQLConnection *)getConnection
{
return mySQLConnection;
}
/**
* 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,24 +872,55 @@ Next we need to ask the user to select another connection (from the favourites l
- (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];
[NSApp beginSheet:databaseCopySheet
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 @@ - (IBAction)removeDatabase:(id)sender
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 @@ - (NSArray *)allSystemDatabaseNames
/**
* 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 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt
}
}
#ifndef SP_CODA
else if ([contextInfo isEqualToString:@"copyDatabase"]) {
else if ([contextInfo isEqualToString:SPCopyDatabaseAction]) {
if (returnCode == NSOKButton) {
[self _copyDatabase];
}
@@ -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;
Oops, something went wrong.

0 comments on commit d37a2f4

Please sign in to comment.