From aeb18ba57dd1fe9332d937118123e283112d1fc3 Mon Sep 17 00:00:00 2001 From: dmoagx Date: Sun, 17 Mar 2013 03:33:15 +0000 Subject: * Add support for ALTER DATABASE statement (needs review) --- Interfaces/English.lproj/DBView.xib | 527 ++++++++++++++++++++++++++++++++-- Interfaces/English.lproj/MainMenu.xib | 83 +++++- Source/SPDatabaseDocument.h | 6 + Source/SPDatabaseDocument.m | 135 +++++++++ 4 files changed, 712 insertions(+), 39 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index fa42d4a8..12e07964 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -21,15 +21,16 @@ YES - - - - + - - + + + + + + YES @@ -5068,7 +5069,7 @@ 1034 {{25, 427}, {649, 5}} - {{0.5, 0}, {648, 5}} + {{2, 0}, {645, 5}} {0, 0} @@ -5091,7 +5092,7 @@ 1034 {{24, 316}, {649, 5}} - {{0.5, 0}, {648, 5}} + {{2, 0}, {645, 5}} {0, 0} @@ -6586,6 +6587,175 @@ {384, 155} {600, 155} + + 1 + 2 + {{157, 342}, {384, 119}} + 1954021376 + Alter Database + NSWindow + + {600, 119} + {384, 119} + + + 256 + + YES + + + 268 + {{17, 83}, {122, 14}} + + YES + + 68157504 + 71304192 + Database Encoding: + + + + + + + + + 268 + {{17, 58}, {122, 14}} + + YES + + 68157504 + 71304192 + Database Collation: + + + + + + + + + 289 + {{268, 13}, {101, 28}} + + 1 + YES + + 67108864 + 138018816 + Apply + + + 1 + -2038284288 + 1 + + + DQ + 200 + 25 + + + + + 289 + {{174, 13}, {96, 28}} + + YES + + 67108864 + 138018816 + Cancel + + + -2038284288 + 1 + + + Gw + 200 + 25 + + + + + 266 + {{143, 78}, {224, 22}} + + YES + + -2076049856 + 132096 + + + -2038284288 + 1 + + + + + + 400 + 75 + + YES + + OtherViews + + YES + + + -1 + 3 + YES + YES + 1 + + + + + 266 + {{143, 53}, {224, 22}} + + YES + + -2076049856 + 132096 + + + -2038284288 + 1 + + + + + + 400 + 75 + + YES + + OtherViews + + YES + + + -1 + 3 + YES + YES + 1 + + + + {384, 119} + + + {{0, 0}, {1920, 1178}} + {384, 141} + {600, 141} + 1 2 @@ -6872,7 +7042,7 @@ {600, 142} {384, 142} - + 256 YES @@ -6881,7 +7051,6 @@ 256 {{5, 105}, {128, 14}} - YES 68157504 @@ -6898,7 +7067,6 @@ 256 {{5, 80}, {128, 14}} - YES 68157504 @@ -6915,7 +7083,6 @@ 258 {{138, 104}, {226, 18}} - YES -1804599231 @@ -6933,7 +7100,6 @@ 257 {{291, 13}, {78, 28}} - 1 YES @@ -6957,7 +7123,6 @@ 258 {{135, 75}, {232, 22}} - YES -2076049856 @@ -6993,7 +7158,6 @@ 256 {{5, 54}, {128, 14}} - YES 68157504 @@ -7010,7 +7174,6 @@ 258 {{135, 50}, {232, 22}} - YES -2076049856 @@ -7046,7 +7209,6 @@ 257 {{209, 13}, {84, 28}} - YES 67108864 @@ -7065,8 +7227,6 @@ {384, 142} - - {{0, 0}, {2560, 1418}} {384, 164} @@ -16496,6 +16656,86 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 8275 + + + nextKeyView + + + + 8299 + + + + nextKeyView + + + + 8300 + + + + nextKeyView + + + + 8301 + + + + nextKeyView + + + + 8302 + + + + closePanelSheet: + + + + 8303 + + + + closePanelSheet: + + + + 8304 + + + + databaseAlterSheet + + + + 8305 + + + + databaseAlterEncodingButton + + + + 8306 + + + + databaseAlterCollationButton + + + + 8307 + + + + alterDatabaseEncodingButtonChanged: + + + + 8308 + @@ -23224,6 +23464,132 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + 8276 + + + YES + + + + Alter Database Sheet + + + 8277 + + + YES + + + + + + + + + + + 8278 + + + YES + + + + + + 8279 + + + YES + + + + + + 8280 + + + YES + + + + + + 8281 + + + YES + + + + + + 8282 + + + YES + + + + + + 8283 + + + YES + + + + + + 8284 + + + YES + + + + + + 8285 + + + + + 8286 + + + YES + + + + + + 8287 + + + + + 8288 + + + + + 8289 + + + + + 8290 + + + + + 8291 + + + @@ -24332,6 +24698,36 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 8270.IBPluginDependency 8271.IBEditorWindowLastContentRect 8271.IBPluginDependency + 8276.IBEditorWindowLastContentRect + 8276.IBPluginDependency + 8276.IBWindowTemplateEditedContentRect + 8276.NSWindowTemplate.visibleAtLaunch + 8276.windowTemplate.hasMaxSize + 8276.windowTemplate.hasMinSize + 8276.windowTemplate.maxSize + 8276.windowTemplate.minSize + 8277.IBPluginDependency + 8278.IBPluginDependency + 8278.IBViewBoundsToFrameTransform + 8279.IBPluginDependency + 8279.IBViewBoundsToFrameTransform + 8280.IBPluginDependency + 8280.IBViewBoundsToFrameTransform + 8281.IBPluginDependency + 8281.IBViewBoundsToFrameTransform + 8282.IBPluginDependency + 8282.IBViewBoundsToFrameTransform + 8283.IBPluginDependency + 8283.IBViewBoundsToFrameTransform + 8284.IBPluginDependency + 8285.IBEditorWindowLastContentRect + 8285.IBPluginDependency + 8286.IBPluginDependency + 8287.IBPluginDependency + 8288.IBPluginDependency + 8289.IBPluginDependency + 8290.IBPluginDependency + 8291.IBPluginDependency 858.IBPluginDependency 959.IBEditorWindowLastContentRect 959.IBPluginDependency @@ -24545,12 +24941,12 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - P4AAAL+AAABAoAAAwtoAAA + P4AAAL+AAABAoAAAwqYAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - P4AAAL+AAABDDwAAwuAAAA + P4AAAL+AAABDDwAAwqwAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -24856,9 +25252,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{329, 701}, {384, 133}} + {{521, 945}, {384, 133}} com.apple.InterfaceBuilder.CocoaPlugin - {{329, 701}, {384, 133}} + {{521, 945}, {384, 133}} {600, 133} @@ -24927,7 +25323,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - P4AAAL+AAABDTAAAwhwAAA + P4AAAL+AAABDTQAAwhwAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -25913,17 +26309,59 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - P4AAAL+AAABAoAAAwq4AAA + P4AAAL+AAABAoAAAwmgAAA + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDDwAAwnQAAA + + com.apple.InterfaceBuilder.CocoaPlugin + {{461, 758}, {224, 6}} + com.apple.InterfaceBuilder.CocoaPlugin + {{913, 959}, {384, 119}} + com.apple.InterfaceBuilder.CocoaPlugin + {{913, 959}, {384, 119}} + + + + {600, 119} + {384, 119} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDCQAAwsoAAA + + com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDCQAAwpgAAA + + com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDkIAAwhwAAA com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDJAAAwhwAAA + com.apple.InterfaceBuilder.CocoaPlugin - P4AAAL+AAABDFAAAwtYAAA + P4AAAL+AAABDiYAAwtAAAA + + com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDiYAAwp4AAA com.apple.InterfaceBuilder.CocoaPlugin {{461, 758}, {224, 6}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{329, 544}, {405, 267}} com.apple.InterfaceBuilder.CocoaPlugin {{329, 544}, {405, 267}} @@ -25950,7 +26388,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 8275 + 8308 @@ -27164,6 +27602,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 YES addConnectionToFavorites: addDatabase: + alterDatabase: + alterDatabaseEncodingButtonChanged: analyzeTable: backForwardInHistory: cancelTask: @@ -27257,6 +27697,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id + id @@ -27265,6 +27707,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 YES addConnectionToFavorites: addDatabase: + alterDatabase: + alterDatabaseEncodingButtonChanged: analyzeTable: backForwardInHistory: cancelTask: @@ -27320,6 +27764,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 addDatabase: id + + alterDatabase: + id + + + alterDatabaseEncodingButtonChanged: + id + analyzeTable: id @@ -27514,6 +27966,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 createTableSyntaxWindow customQueryInstance customQueryTextView + databaseAlterCollationButton + databaseAlterEncodingButton + databaseAlterSheet databaseCollationButton databaseCopyNameField databaseCopySheet @@ -27585,6 +28040,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSWindow id NSTextView + NSPopUpButton + NSPopUpButton + id id id id @@ -27659,6 +28117,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 createTableSyntaxWindow customQueryInstance customQueryTextView + databaseAlterCollationButton + databaseAlterEncodingButton + databaseAlterSheet databaseCollationButton databaseCopyNameField databaseCopySheet @@ -27766,6 +28227,18 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 customQueryTextView NSTextView + + databaseAlterCollationButton + NSPopUpButton + + + databaseAlterEncodingButton + NSPopUpButton + + + databaseAlterSheet + id + databaseCollationButton id diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index aa052a2f..848c0b09 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -12,7 +12,7 @@ YES - + YES @@ -1264,6 +1264,14 @@ + + + Alter Database… + + 2147483647 + + + YES @@ -3218,6 +3226,14 @@ 1231 + + + alterDatabase: + + + + 1233 + @@ -3586,6 +3602,7 @@ + @@ -4698,6 +4715,11 @@ + + 1232 + + + @@ -4789,6 +4811,7 @@ 1214.IBPluginDependency 1217.IBPluginDependency 1218.IBPluginDependency + 1232.IBPluginDependency 129.IBPluginDependency 129.ImportedFromIB2 130.IBEditorWindowLastContentRect @@ -5244,6 +5267,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{562, 439}, {64, 6}} com.apple.InterfaceBuilder.CocoaPlugin @@ -5321,7 +5345,7 @@ com.apple.InterfaceBuilder.CocoaPlugin {{449, 1007}, {197, 53}} - {{366, 686}, {583, 20}} + {{367, 1049}, {583, 20}} com.apple.InterfaceBuilder.CocoaPlugin {{506, 836}, {511, 20}} @@ -5355,7 +5379,7 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{333, 322}, {229, 253}} + {{378, 433}, {229, 253}} com.apple.InterfaceBuilder.CocoaPlugin {{518, 583}, {218, 253}} @@ -5363,7 +5387,7 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{608, 353}, {287, 333}} + {{609, 696}, {287, 353}} com.apple.InterfaceBuilder.CocoaPlugin {{312, 683}, {231, 153}} @@ -5641,7 +5665,7 @@ - 1231 + 1233 @@ -5654,6 +5678,7 @@ YES addDatabase: + alterDatabase: analyzeTable: checkTable: checksumTable: @@ -5712,6 +5737,7 @@ id id id + id @@ -5719,6 +5745,7 @@ YES addDatabase: + alterDatabase: analyzeTable: checkTable: checksumTable: @@ -5753,6 +5780,10 @@ addDatabase: id + + alterDatabase: + id + analyzeTable: id @@ -8075,6 +8106,7 @@ YES addConnectionToFavorites: addDatabase: + alterDatabase: analyzeTable: backForwardInHistory: cancelTask: @@ -8089,6 +8121,7 @@ copyCreateTableSyntax: copyCreateTableSyntaxFromSheet: copyDatabase: + databaseEncodingButtonChanged: export: exportSelectedTablesAs: flushPrivileges: @@ -8166,6 +8199,8 @@ id id id + id + id @@ -8174,6 +8209,7 @@ YES addConnectionToFavorites: addDatabase: + alterDatabase: analyzeTable: backForwardInHistory: cancelTask: @@ -8188,6 +8224,7 @@ copyCreateTableSyntax: copyCreateTableSyntaxFromSheet: copyDatabase: + databaseEncodingButtonChanged: export: exportSelectedTablesAs: flushPrivileges: @@ -8228,6 +8265,10 @@ addDatabase: id + + alterDatabase: + id + analyzeTable: id @@ -8284,6 +8325,10 @@ copyDatabase: id + + databaseEncodingButtonChanged: + id + export: id @@ -8418,6 +8463,7 @@ createTableSyntaxWindow customQueryInstance customQueryTextView + databaseCollationButton databaseCopyNameField databaseCopySheet databaseDataInstance @@ -8496,6 +8542,7 @@ id id id + id NSTableView id NSScrollView @@ -8561,6 +8608,7 @@ createTableSyntaxWindow customQueryInstance customQueryTextView + databaseCollationButton databaseCopyNameField databaseCopySheet databaseDataInstance @@ -8667,6 +8715,10 @@ customQueryTextView NSTextView + + databaseCollationButton + id + databaseCopyNameField id @@ -10609,11 +10661,13 @@ YES additionalDragHandleView collapseToggleButton + delegate YES NSView NSButton + id @@ -10622,6 +10676,7 @@ YES additionalDragHandleView collapseToggleButton + delegate YES @@ -10633,6 +10688,10 @@ collapseToggleButton NSButton + + delegate + id + @@ -12228,7 +12287,6 @@ outlineView privsSupportedByServer removeSchemaPrivButton - schemaController schemasTableView splitView tabView @@ -12250,7 +12308,6 @@ NSOutlineView NSMutableDictionary NSButton - NSArrayController NSTableView SPSplitView NSTabView @@ -12275,7 +12332,6 @@ outlineView privsSupportedByServer removeSchemaPrivButton - schemaController schemasTableView splitView tabView @@ -12336,10 +12392,6 @@ removeSchemaPrivButton NSButton - - schemaController - NSArrayController - schemasTableView NSTableView @@ -12367,6 +12419,13 @@ Source/SPUserManager.h + + SPUserManager + + IBProjectSource + Source/SPUserManagerDataSource.h + + SPUserManager diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index da3d3c56..5cee9759 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -111,6 +111,10 @@ IBOutlet id databaseSheet; IBOutlet id databaseCopySheet; IBOutlet id databaseRenameSheet; + + IBOutlet id databaseAlterSheet; + IBOutlet NSPopUpButton *databaseAlterEncodingButton; + IBOutlet NSPopUpButton *databaseAlterCollationButton; IBOutlet NSProgressIndicator* queryProgressBar; #ifndef SP_CODA @@ -327,6 +331,8 @@ #endif - (void)selectDatabase:(NSString *)aDatabase item:(NSString *)anItem; - (IBAction)addDatabase:(id)sender; +- (IBAction)alterDatabase:(id)sender; +- (IBAction)alterDatabaseEncodingButtonChanged:(id)sender; - (IBAction)databaseEncodingButtonChanged:(id)sender; - (IBAction)removeDatabase:(id)sender; - (IBAction)refreshTables:(id)sender; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index e4f75610..2a48b221 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -114,10 +114,12 @@ enum { static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; +static NSString *SPAlterDatabaseAction = @"SPAlterDatabase"; @interface SPDatabaseDocument () - (void)_evaluateCollationsForSelectedCharset; - (void)_addDatabase; +- (void)_alterDatabase; #ifndef SP_CODA /* method decls */ - (void)_copyDatabase; #endif @@ -804,6 +806,103 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; contextInfo:@"addDatabase"]; } + +/** + * Show UI for the ALTER DATABASE statement + * @warning Make sure this method is only called on mysql 4.1+ servers! + */ +- (IBAction)alterDatabase:(id)sender +{ + //once the database is created the charset and collation are written + //to the db.opt regardless if they were explicity given or not. + //So there is no longer a "Default" option. + + // Populate the database encoding popup button with a default menu item + [databaseAlterEncodingButton removeAllItems]; + NSString *currentCharset = [databaseDataInstance getDatabaseDefaultCharacterSet]; + + // Retrieve the server-supported encodings and add them to the menu + NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings]; + + if(![encodings count]) { + NSBeep(); + NSLog(@"%s: Trying to show ALTER UI but getting CHARACTER SET list failed!",__func__); + return; + } + + for (NSDictionary *encoding in encodings) + { + NSString *charsetId = [encoding objectForKey:@"CHARACTER_SET_NAME"]; + NSString *description = [encoding objectForKey:@"DESCRIPTION"]; + NSString *menuItemTitle = (![description length]) ? charsetId : [NSString stringWithFormat:@"%@ (%@)", description, charsetId]; + + NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:menuItemTitle action:NULL keyEquivalent:@""] autorelease]; + [menuItem setRepresentedObject:charsetId]; + + // If the UTF8 entry has been encountered, promote it to the top of the list (this time we don't want duplicates) + if ([charsetId isEqualToString:@"utf8"]) { + [[databaseAlterEncodingButton menu] insertItem:menuItem atIndex:0]; + [[databaseAlterEncodingButton menu] insertItem:[NSMenuItem separatorItem] atIndex:1]; + } + else { + [[databaseAlterEncodingButton menu] addItem:menuItem]; + } + + // select the current charset + if([charsetId isEqualToString:currentCharset]) + [databaseAlterEncodingButton selectItem:menuItem]; + + } + + //refresh collations for charset + [self alterDatabaseEncodingButtonChanged:nil]; + + [NSApp beginSheet:databaseAlterSheet + modalForWindow:parentWindow + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:SPAlterDatabaseAction]; +} + +/** + * Updates the list of collations for the currently selected encoding in the ALTER DATABASE sheet + * @warning Make sure this method is only called on mysql 4.1+ servers! + */ +- (IBAction)alterDatabaseEncodingButtonChanged:(id)sender +{ + NSString *currentCharset = [databaseDataInstance getDatabaseDefaultCharacterSet]; + NSString *currentCollation = [databaseDataInstance getDatabaseDefaultCollation]; + + //throw out all items + [databaseAlterCollationButton removeAllItems]; + + //get the selected charset id + NSString *charsetId = [[databaseAlterEncodingButton selectedItem] representedObject]; + //this should not fail so far down the line + if(![charsetId length]) { + NSLog(@"%s: Encoding menu item <%@> does not represent any charset!",__func__,[databaseAlterEncodingButton title]); + return; + } + + //now let's get the list of collations for the selected charset id + NSArray *applicableCollations = [databaseDataInstance getDatabaseCollationsForEncoding:charsetId]; + //and add the real items + for (NSDictionary *collation in applicableCollations) + { + NSString *collationName = [collation objectForKey:@"COLLATION_NAME"]; + + NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:collationName action:NULL keyEquivalent:@""] autorelease]; + [[databaseAlterCollationButton menu] addItem:menuItem]; + + //if the charset is the current charset and this is the current collation + //else if this collation is the default for the selected charset + // => select it + if(([charsetId isEqualToString:currentCharset] && [collationName isEqualToString:currentCollation]) || + (![charsetId isEqualToString:currentCharset] && [[collation objectForKey:@"IS_DEFAULT"] isEqualToString:@"Yes"])) + [databaseAlterCollationButton selectItem:menuItem]; + } +} + - (IBAction)databaseEncodingButtonChanged:(id)sender { [self _evaluateCollationsForSelectedCharset]; @@ -1021,6 +1120,11 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; } #endif } + else if([contextInfo isEqualToString:SPAlterDatabaseAction]) { + if(returnCode == NSOKButton) { + [self _alterDatabase]; + } + } #ifndef SP_CODA // Close error status sheet for OPTIMIZE, CHECK, REPAIR etc. else if ([contextInfo isEqualToString:@"statusError"]) { @@ -3492,6 +3596,11 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; return (enable && (tag == SPSQLExport)); } } + + //can only be enabled on mysql 4.1+ + if([menuItem action] == @selector(alterDatabase:)) { + return (([self database] != nil) && [serverSupport supportsPost41CharacterSetHandling]); + } if ([menuItem action] == @selector(import:) || [menuItem action] == @selector(removeDatabase:) || @@ -6001,6 +6110,32 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; [self selectDatabase:[databaseNameField stringValue] item:nil]; } +/** + * Run ALTER statement against current db. This is the callback to alterDatabase: + * @warning Make sure this method is only called on mysql 4.1+ servers! + */ +- (void)_alterDatabase +{ + //we'll always run the alter statement, even if old == new because after all that is what the user requested + + NSString *newCharset = [[databaseAlterEncodingButton selectedItem] representedObject]; + NSString *newCollation = [databaseAlterCollationButton titleOfSelectedItem]; + + NSString *alterStatement = [NSString stringWithFormat:@"ALTER DATABASE %@ DEFAULT CHARACTER SET %@ DEFAULT COLLATE %@", [[self database] backtickQuotedString],[newCharset backtickQuotedString],[newCollation backtickQuotedString]]; + + //run alter + [mySQLConnection queryString:alterStatement]; + + if ([mySQLConnection queryErrored]) { + // An error occurred + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't alter database.\nMySQL said: %@", @"Alter Database : Query Failed ($1 = mysql error message)"), [mySQLConnection lastErrorMessage]]); + return; + } + + //invalidate old cache values + [databaseDataInstance resetAllData]; +} + /** * Removes the current database. */ -- cgit v1.2.3