aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseDocument.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPDatabaseDocument.m')
-rw-r--r--Source/SPDatabaseDocument.m443
1 files changed, 225 insertions, 218 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 654f06cd..0b4abdb9 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -330,7 +330,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[tableTabView setTabViewType:NSNoTabsNoBorder];
// Hide the activity list
- [self setActivityPaneHidden:[NSNumber numberWithInteger:1]];
+ [self setActivityPaneHidden:@1];
// Load additional nibs, keeping track of the top-level objects to allow correct release
NSArray *connectionDialogTopLevelObjects = nil;
@@ -473,7 +473,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// Update the selected database if appropriate
if ([connectionController database] && ![[connectionController database] isEqualToString:@""]) {
- if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
+ if (selectedDatabase) SPClear(selectedDatabase);
selectedDatabase = [[NSString alloc] initWithString:[connectionController database]];
#ifndef SP_CODA /* [spHistoryControllerInstance updateHistoryEntries] */
[spHistoryControllerInstance updateHistoryEntries];
@@ -552,10 +552,10 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
notificationName:@"Connected"];
// Init Custom Query editor with the stored queries in a spf file if given.
- [spfDocData setObject:[NSNumber numberWithBool:NO] forKey:@"save_editor_content"];
+ [spfDocData setObject:@NO forKey:@"save_editor_content"];
if (spfSession != nil && [spfSession objectForKey:@"queries"]) {
- [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"save_editor_content"];
+ [spfDocData setObject:@YES forKey:@"save_editor_content"];
if ([[spfSession objectForKey:@"queries"] isKindOfClass:[NSData class]]) {
NSString *q = [[NSString alloc] initWithData:[[spfSession objectForKey:@"queries"] decompress] encoding:NSUTF8StringEncoding];
[self initQueryEditorWithString:q];
@@ -569,8 +569,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
if (queryEditorInitString && [queryEditorInitString length]) {
[self viewQuery:self];
[customQueryInstance doPerformLoadQueryService:queryEditorInitString];
- [queryEditorInitString release];
- queryEditorInitString = nil;
+ SPClear(queryEditorInitString);
}
if (spfSession != nil) {
@@ -665,8 +664,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[[chooseDatabaseButton menu] addItem:[NSMenuItem separatorItem]];
#endif
- if (allDatabases) [allDatabases release];
- if (allSystemDatabases) [allSystemDatabases release];
+ if (allDatabases) SPClear(allDatabases);
+ if (allSystemDatabases) SPClear(allSystemDatabases);
NSArray *theDatabaseList = [mySQLConnection databases];
@@ -1012,8 +1011,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[self _addDatabase];
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:databaseStructureRetrieval selector:@selector(queryDbStructureWithUserInfo:) object:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]];
- }
+ [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:databaseStructureRetrieval selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
+ }
else {
// Reset chooseDatabaseButton
if ([[self database] length]) {
@@ -1056,7 +1055,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
#ifndef SP_CODA
// Close error status sheet for OPTIMIZE, CHECK, REPAIR etc.
else if ([contextInfo isEqualToString:@"statusError"]) {
- if (statusValues) [statusValues release], statusValues = nil;
+ if (statusValues) SPClear(statusValues);
}
#endif
}
@@ -1096,7 +1095,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
if(![dbName isNSNull]) {
if(![dbName isEqualToString:selectedDatabase]) {
- if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
+ if (selectedDatabase) SPClear(selectedDatabase);
selectedDatabase = [[NSString alloc] initWithString:dbName];
[chooseDatabaseButton selectItemWithTitle:selectedDatabase];
#ifndef SP_CODA /* [self updateWindowTitle:self] */
@@ -1104,7 +1103,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
#endif
}
} else {
- if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
+ if (selectedDatabase) SPClear(selectedDatabase);
[chooseDatabaseButton selectItemAtIndex:0];
#ifndef SP_CODA /* [self updateWindowTitle:self] */
[self updateWindowTitle:self];
@@ -1313,8 +1312,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// If the window has been fully faded in, clean up the timer.
if (alphaValue == 1.0) {
- [taskDrawTimer invalidate], [taskDrawTimer release], taskDrawTimer = nil;
- [taskFadeInStartDate release], taskFadeInStartDate = nil;
+ [taskDrawTimer invalidate], SPClear(taskDrawTimer);
+ SPClear(taskFadeInStartDate);
}
#endif
}
@@ -1424,8 +1423,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
#ifndef SP_CODA
// Cancel the draw timer if it exists
if (taskDrawTimer) {
- [taskDrawTimer invalidate], [taskDrawTimer release], taskDrawTimer = nil;
- [taskFadeInStartDate release], taskFadeInStartDate = nil;
+ [taskDrawTimer invalidate], SPClear(taskDrawTimer);
+ SPClear(taskFadeInStartDate);
}
// Hide the task interface and reset to indeterminate
@@ -1631,30 +1630,31 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
*/
- (NSNumber *)encodingTagFromMySQLEncoding:(NSString *)mysqlEncoding
{
- NSDictionary *translationMap = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:SPEncodingUCS2], @"ucs2",
- [NSNumber numberWithInt:SPEncodingUTF8], @"utf8",
- [NSNumber numberWithInt:SPEncodingUTF8viaLatin1], @"utf8-",
- [NSNumber numberWithInt:SPEncodingASCII], @"ascii",
- [NSNumber numberWithInt:SPEncodingLatin1], @"latin1",
- [NSNumber numberWithInt:SPEncodingMacRoman], @"macroman",
- [NSNumber numberWithInt:SPEncodingCP1250Latin2], @"cp1250",
- [NSNumber numberWithInt:SPEncodingISOLatin2], @"latin2",
- [NSNumber numberWithInt:SPEncodingCP1256Arabic], @"cp1256",
- [NSNumber numberWithInt:SPEncodingGreek], @"greek",
- [NSNumber numberWithInt:SPEncodingHebrew], @"hebrew",
- [NSNumber numberWithInt:SPEncodingLatin5Turkish], @"latin5",
- [NSNumber numberWithInt:SPEncodingCP1257WinBaltic], @"cp1257",
- [NSNumber numberWithInt:SPEncodingCP1251WinCyrillic], @"cp1251",
- [NSNumber numberWithInt:SPEncodingBig5Chinese], @"big5",
- [NSNumber numberWithInt:SPEncodingShiftJISJapanese], @"sjis",
- [NSNumber numberWithInt:SPEncodingEUCJPJapanese], @"ujis",
- [NSNumber numberWithInt:SPEncodingEUCKRKorean], @"euckr",
- nil];
+ NSDictionary *translationMap = @{
+ @"ucs2" : @(SPEncodingUCS2),
+ @"utf8" : @(SPEncodingUTF8),
+ @"utf8-" : @(SPEncodingUTF8viaLatin1),
+ @"ascii" : @(SPEncodingASCII),
+ @"latin1" : @(SPEncodingLatin1),
+ @"macroman" : @(SPEncodingMacRoman),
+ @"cp1250" : @(SPEncodingCP1250Latin2),
+ @"latin2" : @(SPEncodingISOLatin2),
+ @"cp1256" : @(SPEncodingCP1256Arabic),
+ @"greek" : @(SPEncodingGreek),
+ @"hebrew" : @(SPEncodingHebrew),
+ @"latin5" : @(SPEncodingLatin5Turkish),
+ @"cp1257" : @(SPEncodingCP1257WinBaltic),
+ @"cp1251" : @(SPEncodingCP1251WinCyrillic),
+ @"big5" : @(SPEncodingBig5Chinese),
+ @"sjis" : @(SPEncodingShiftJISJapanese),
+ @"ujis" : @(SPEncodingEUCJPJapanese),
+ @"euckr" : @(SPEncodingEUCKRKorean),
+ @"utf8mb4" : @(SPEncodingUTF8MB4)
+ };
NSNumber *encodingTag = [translationMap valueForKey:mysqlEncoding];
if (!encodingTag)
- return [NSNumber numberWithInt:SPEncodingAutodetect];
+ return @(SPEncodingAutodetect);
return encodingTag;
}
@@ -1665,24 +1665,25 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
- (NSString *)mysqlEncodingFromEncodingTag:(NSNumber *)encodingTag
{
NSDictionary *translationMap = [NSDictionary dictionaryWithObjectsAndKeys:
- @"ucs2", [NSString stringWithFormat:@"%i", SPEncodingUCS2],
- @"utf8", [NSString stringWithFormat:@"%i", SPEncodingUTF8],
- @"utf8-", [NSString stringWithFormat:@"%i", SPEncodingUTF8viaLatin1],
- @"ascii", [NSString stringWithFormat:@"%i", SPEncodingASCII],
- @"latin1", [NSString stringWithFormat:@"%i", SPEncodingLatin1],
+ @"ucs2", [NSString stringWithFormat:@"%i", SPEncodingUCS2],
+ @"utf8", [NSString stringWithFormat:@"%i", SPEncodingUTF8],
+ @"utf8-", [NSString stringWithFormat:@"%i", SPEncodingUTF8viaLatin1],
+ @"ascii", [NSString stringWithFormat:@"%i", SPEncodingASCII],
+ @"latin1", [NSString stringWithFormat:@"%i", SPEncodingLatin1],
@"macroman", [NSString stringWithFormat:@"%i", SPEncodingMacRoman],
- @"cp1250", [NSString stringWithFormat:@"%i", SPEncodingCP1250Latin2],
- @"latin2", [NSString stringWithFormat:@"%i", SPEncodingISOLatin2],
- @"cp1256", [NSString stringWithFormat:@"%i", SPEncodingCP1256Arabic],
- @"greek", [NSString stringWithFormat:@"%i", SPEncodingGreek],
- @"hebrew", [NSString stringWithFormat:@"%i", SPEncodingHebrew],
- @"latin5", [NSString stringWithFormat:@"%i", SPEncodingLatin5Turkish],
- @"cp1257", [NSString stringWithFormat:@"%i", SPEncodingCP1257WinBaltic],
- @"cp1251", [NSString stringWithFormat:@"%i", SPEncodingCP1251WinCyrillic],
- @"big5", [NSString stringWithFormat:@"%i", SPEncodingBig5Chinese],
- @"sjis", [NSString stringWithFormat:@"%i", SPEncodingShiftJISJapanese],
- @"ujis", [NSString stringWithFormat:@"%i", SPEncodingEUCJPJapanese],
- @"euckr", [NSString stringWithFormat:@"%i", SPEncodingEUCKRKorean],
+ @"cp1250", [NSString stringWithFormat:@"%i", SPEncodingCP1250Latin2],
+ @"latin2", [NSString stringWithFormat:@"%i", SPEncodingISOLatin2],
+ @"cp1256", [NSString stringWithFormat:@"%i", SPEncodingCP1256Arabic],
+ @"greek", [NSString stringWithFormat:@"%i", SPEncodingGreek],
+ @"hebrew", [NSString stringWithFormat:@"%i", SPEncodingHebrew],
+ @"latin5", [NSString stringWithFormat:@"%i", SPEncodingLatin5Turkish],
+ @"cp1257", [NSString stringWithFormat:@"%i", SPEncodingCP1257WinBaltic],
+ @"cp1251", [NSString stringWithFormat:@"%i", SPEncodingCP1251WinCyrillic],
+ @"big5", [NSString stringWithFormat:@"%i", SPEncodingBig5Chinese],
+ @"sjis", [NSString stringWithFormat:@"%i", SPEncodingShiftJISJapanese],
+ @"ujis", [NSString stringWithFormat:@"%i", SPEncodingEUCJPJapanese],
+ @"euckr", [NSString stringWithFormat:@"%i", SPEncodingEUCKRKorean],
+ @"utf8mb4", [NSString stringWithFormat:@"%i", SPEncodingUTF8MB4],
nil];
NSString *mysqlEncoding = [translationMap valueForKey:[NSString stringWithFormat:@"%i", [encodingTag intValue]]];
@@ -1710,7 +1711,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
NSString *mysqlEncoding = [databaseDataInstance getDatabaseDefaultCharacterSet];
- [selectedDatabaseEncoding release], selectedDatabaseEncoding = nil;
+ SPClear(selectedDatabaseEncoding);
// Fallback or older version? -> set encoding to mysql default encoding latin1
if ( !mysqlEncoding ) {
@@ -1841,7 +1842,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// show syntax(es) in sheet
if (sender == self) {
NSPasteboard *pb = [NSPasteboard generalPasteboard];
- [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
+ [pb declareTypes:@[NSStringPboardType] owner:self];
[pb setString:createSyntax forType:NSStringPboardType];
// Table syntax copied Growl notification
@@ -1951,7 +1952,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
contextInfo:NULL];
} else {
message = NSLocalizedString(@"MySQL said:",@"mysql said message");
- if (statusValues) [statusValues release], statusValues = nil;
+ if (statusValues) SPClear(statusValues);
statusValues = [resultStatuses retain];
NSAlert *alert = [[NSAlert new] autorelease];
[alert setInformativeText:message];
@@ -2028,7 +2029,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
contextInfo:NULL];
} else {
message = NSLocalizedString(@"MySQL said:",@"mysql said message");
- if (statusValues) [statusValues release], statusValues = nil;
+ if (statusValues) SPClear(statusValues);
statusValues = [resultStatuses retain];
NSAlert *alert = [[NSAlert new] autorelease];
[alert setInformativeText:message];
@@ -2105,7 +2106,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
contextInfo:NULL];
} else {
message = NSLocalizedString(@"MySQL said:",@"mysql said message");
- if (statusValues) [statusValues release], statusValues = nil;
+ if (statusValues) SPClear(statusValues);
statusValues = [resultStatuses retain];
NSAlert *alert = [[NSAlert new] autorelease];
[alert setInformativeText:message];
@@ -2181,7 +2182,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
contextInfo:NULL];
} else {
message = NSLocalizedString(@"MySQL said:",@"mysql said message");
- if (statusValues) [statusValues release], statusValues = nil;
+ if (statusValues) SPClear(statusValues);
statusValues = [resultStatuses retain];
NSAlert *alert = [[NSAlert new] autorelease];
[alert setInformativeText:message];
@@ -2257,7 +2258,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
contextInfo:NULL];
} else {
message = NSLocalizedString(@"MySQL said:",@"mysql said message");
- if (statusValues) [statusValues release], statusValues = nil;
+ if (statusValues) SPClear(statusValues);
statusValues = [resultStatuses retain];
NSAlert *alert = [[NSAlert new] autorelease];
[alert setInformativeText:message];
@@ -2313,7 +2314,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
didEndSelector:NULL
contextInfo:NULL];
} else {
- if (statusValues) [statusValues release], statusValues = nil;
+ if (statusValues) SPClear(statusValues);
statusValues = [resultStatuses retain];
NSAlert *alert = [[NSAlert new] autorelease];
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Checksums of %@",@"Checksums of %@ message"), what]];
@@ -2330,7 +2331,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
{
NSSavePanel *panel = [NSSavePanel savePanel];
- [panel setAllowedFileTypes:[NSArray arrayWithObject:SPFileExtensionSQL]];
+ [panel setAllowedFileTypes:@[SPFileExtensionSQL]];
[panel setExtensionHidden:NO];
[panel setAllowsOtherFileTypes:YES];
@@ -2361,7 +2362,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// Copy to the clipboard
NSPasteboard *pb = [NSPasteboard generalPasteboard];
- [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
+ [pb declareTypes:@[NSStringPboardType] owner:self];
[pb setString:createSyntax forType:NSStringPboardType];
// Table syntax copied Growl notification
@@ -2485,7 +2486,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[userManagerInstance beginSheetModalForWindow:parentWindow
completionHandler:^(){
- [userManagerInstance release], userManagerInstance = nil;
+ SPClear(userManagerInstance);
}];
}
@@ -2526,8 +2527,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
- (IBAction)openCurrentConnectionInNewWindow:(id)sender
{
- [[NSApp delegate] newWindow:self];
- SPDatabaseDocument *newTableDocument = [[NSApp delegate] frontDocument];
+ [SPAppDelegate newWindow:self];
+ SPDatabaseDocument *newTableDocument = [SPAppDelegate frontDocument];
[newTableDocument setStateFromConnectionFile:[[self fileURL] path]];
}
@@ -2768,6 +2769,17 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
return tablesListInstance;
}
+- (SPCreateDatabaseInfo *)createDatabaseInfo
+{
+ SPCreateDatabaseInfo *dbInfo = [[SPCreateDatabaseInfo alloc] init];
+
+ [dbInfo setDatabaseName:[self database]];
+ [dbInfo setDefaultEncoding:[databaseDataInstance getDatabaseDefaultCharacterSet]];
+ [dbInfo setDefaultCollation:[databaseDataInstance getDatabaseDefaultCollation]];
+
+ return [dbInfo autorelease];
+}
+
#pragma mark -
#pragma mark Notification center methods
@@ -2829,10 +2841,10 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[panel setCanSelectHiddenExtension:YES];
// Save Query...
- if (sender != nil && ([sender tag] == 1006 || [sender tag] == 1008)) {
+ if (sender != nil && ([sender tag] == SPMainMenuFileSaveQuery || [sender tag] == SPMainMenuFileSaveQueryAs)) {
// If Save was invoked, check whether the file was previously opened, and if so save without the panel
- if ([sender tag] == 1006 && [[[self sqlFileURL] path] length]) {
+ if ([sender tag] == SPMainMenuFileSaveQuery && [[[self sqlFileURL] path] length]) {
NSError *error = nil;
NSString *content = [NSString stringWithString:[[[customQueryInstance valueForKeyPath:@"textView"] textStorage] string]];
[content writeToURL:sqlFileURL atomically:YES encoding:sqlFileEncoding error:&error];
@@ -2843,7 +2855,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:SPLastSQLFileEncoding]
includeDefaultEntry:NO encodingPopUp:&encodingPopUp]];
- [panel setAllowedFileTypes:[NSArray arrayWithObjects:SPFileExtensionSQL, nil]];
+ [panel setAllowedFileTypes:@[SPFileExtensionSQL]];
if (![prefs stringForKey:@"lastSqlFileName"]) {
[prefs setObject:@"" forKey:@"lastSqlFileName"];
@@ -2863,11 +2875,11 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// Save As… or Save
}
- else if (sender == nil || [sender tag] == 1005 || [sender tag] == 1004) {
+ else if (sender == nil || [sender tag] == SPMainMenuFileSaveConnection || [sender tag] == SPMainMenuFileSaveConnectionAs) {
// If Save was invoked check for fileURL and Untitled docs and save the spf file without save panel
// otherwise ask for file name
- if (sender != nil && [sender tag] == 1004 && [[[self fileURL] path] length] && ![self isUntitled]) {
+ if (sender != nil && [sender tag] == SPMainMenuFileSaveConnection && [[[self fileURL] path] length] && ![self isUntitled]) {
[self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:NO contextInfo:nil];
return;
}
@@ -2880,7 +2892,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
// Save current session (open connection windows as SPF file)
- [panel setAllowedFileTypes:[NSArray arrayWithObjects:SPFileExtensionDefault, nil]];
+ [panel setAllowedFileTypes:@[SPFileExtensionDefault]];
//Restore accessory view settings if possible
if ([spfDocData objectForKey:@"save_password"]) {
@@ -2918,10 +2930,10 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
contextInfo = sender == nil ? @"saveSPFfileAndClose" : @"saveSPFfile";
}
// Save Session or Save Session As...
- else if (sender == nil || [sender tag] == 1020 || [sender tag] == 1021)
+ else if (sender == nil || [sender tag] == SPMainMenuFileSaveSession || [sender tag] == SPMainMenuFileSaveSessionAs)
{
// Save As Session
- if ([sender tag] == 1020 && [[NSApp delegate] sessionURL]) {
+ if ([sender tag] == SPMainMenuFileSaveSession && [SPAppDelegate sessionURL]) {
[self saveConnectionPanelDidEnd:panel returnCode:1 contextInfo:@"saveAsSession"];
return;
}
@@ -2933,9 +2945,9 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
return;
}
- [panel setAllowedFileTypes:[NSArray arrayWithObjects:SPBundleFileExtension, nil]];
+ [panel setAllowedFileTypes:@[SPBundleFileExtension]];
- NSDictionary *spfSessionData = [[NSApp delegate] spfSessionDocData];
+ NSDictionary *spfSessionData = [SPAppDelegate spfSessionDocData];
// Restore accessory view settings if possible
if ([spfSessionData objectForKey:@"save_password"]) {
@@ -2967,8 +2979,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[panel setAccessoryView:saveConnectionAccessory];
// Set file name
- if ([[NSApp delegate] sessionURL])
- filename = [[[[NSApp delegate] sessionURL] absoluteString] lastPathComponent];
+ if ([SPAppDelegate sessionURL])
+ filename = [[[SPAppDelegate sessionURL] absoluteString] lastPathComponent];
else
filename = [NSString stringWithFormat:NSLocalizedString(@"Session",@"Initial filename for 'Save session' file")];
@@ -3042,7 +3054,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[self saveDocumentWithFilePath:fileName inBackground:NO onlyPreferences:NO contextInfo:nil];
// Manually loaded nibs don't have their top-level objects released automatically - do that here.
- [saveConnectionAccessory release];
+ SPClear(saveConnectionAccessory);
if(contextInfo == @"saveSPFfileAndClose")
[self closeAndDisconnect];
@@ -3055,8 +3067,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// info.plist will contain the opened structure (windows and tabs for each window). Each connection
// is linked to a saved spf file either in 'Contents' for unTitled ones or already saved spf files.
- if(contextInfo == @"saveAsSession" && [[NSApp delegate] sessionURL])
- fileName = [[[NSApp delegate] sessionURL] path];
+ if(contextInfo == @"saveAsSession" && [SPAppDelegate sessionURL])
+ fileName = [[SPAppDelegate sessionURL] path];
if(!fileName || ![fileName length]) return;
@@ -3072,7 +3084,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
}
- [fileManager createDirectoryAtPath:fileName withIntermediateDirectories:TRUE attributes:nil error:&error];
+ [fileManager createDirectoryAtPath:fileName withIntermediateDirectories:YES attributes:nil error:&error];
if(error != nil) {
NSAlert *errorAlert = [NSAlert alertWithError:error];
@@ -3080,7 +3092,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
return;
}
- [fileManager createDirectoryAtPath:[NSString stringWithFormat:@"%@/Contents", fileName] withIntermediateDirectories:TRUE attributes:nil error:&error];
+ [fileManager createDirectoryAtPath:[NSString stringWithFormat:@"%@/Contents", fileName] withIntermediateDirectories:YES attributes:nil error:&error];
if(error != nil) {
NSAlert *errorAlert = [NSAlert alertWithError:error];
@@ -3094,7 +3106,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// retrieve save panel data for passing them to each doc
NSMutableDictionary *spfDocData_temp = [NSMutableDictionary dictionary];
if(contextInfo == @"saveAsSession") {
- [spfDocData_temp addEntriesFromDictionary:[[NSApp delegate] spfSessionDocData]];
+ [spfDocData_temp addEntriesFromDictionary:[SPAppDelegate spfSessionDocData]];
} else {
[spfDocData_temp setObject:[NSNumber numberWithBool:([saveConnectionEncrypt state]==NSOnState) ? YES : NO ] forKey:@"encrypted"];
if([[spfDocData_temp objectForKey:@"encrypted"] boolValue])
@@ -3105,7 +3117,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[spfDocData_temp setObject:[NSNumber numberWithBool:([saveConnectionIncludeQuery state]==NSOnState) ? YES : NO ] forKey:@"save_editor_content"];
// Save the session's accessory view settings
- [[NSApp delegate] setSpfSessionDocData:spfDocData_temp];
+ [SPAppDelegate setSpfSessionDocData:spfDocData_temp];
}
@@ -3114,11 +3126,11 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[info setObject:[NSNumber numberWithBool:[[spfDocData_temp objectForKey:@"save_password"] boolValue]] forKey:@"save_password"];
[info setObject:[NSNumber numberWithBool:[[spfDocData_temp objectForKey:@"include_session"] boolValue]] forKey:@"include_session"];
[info setObject:[NSNumber numberWithBool:[[spfDocData_temp objectForKey:@"save_editor_content"] boolValue]] forKey:@"save_editor_content"];
- [info setObject:[NSNumber numberWithInteger:1] forKey:@"version"];
+ [info setObject:@1 forKey:@"version"];
[info setObject:@"connection bundle" forKey:@"format"];
// Loop through all windows
- for(NSWindow *window in [[NSApp delegate] orderedDatabaseConnectionWindows]) {
+ for(NSWindow *window in [SPAppDelegate orderedDatabaseConnectionWindows]) {
// First window is always the currently key window
@@ -3142,12 +3154,12 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// save it as temporary spf file inside the bundle with save panel options spfDocData_temp
[doc saveDocumentWithFilePath:filePath inBackground:NO onlyPreferences:NO contextInfo:[NSDictionary dictionaryWithDictionary:spfDocData_temp]];
[doc setIsSavedInBundle:YES];
- [tabData setObject:[NSNumber numberWithBool:NO] forKey:@"isAbsolutePath"];
+ [tabData setObject:@NO forKey:@"isAbsolutePath"];
[tabData setObject:newName forKey:@"path"];
} else {
// save it to the original location and take the file's spfDocData
[doc saveDocumentWithFilePath:[[doc fileURL] path] inBackground:YES onlyPreferences:NO contextInfo:nil];
- [tabData setObject:[NSNumber numberWithBool:YES] forKey:@"isAbsolutePath"];
+ [tabData setObject:@YES forKey:@"isAbsolutePath"];
[tabData setObject:[[doc fileURL] path] forKey:@"path"];
}
[tabs addObject:tabData];
@@ -3192,7 +3204,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
return;
}
- [[NSApp delegate] setSessionURL:fileName];
+ [SPAppDelegate setSessionURL:fileName];
// Register spfs bundle in Recent Files
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:fileName]];
@@ -3219,7 +3231,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[spfDocData_temp setObject:[NSNumber numberWithBool:([saveConnectionAutoConnect state]==NSOnState) ? YES : NO ] forKey:@"auto_connect"];
[spfDocData_temp setObject:[NSNumber numberWithBool:([saveConnectionSavePassword state]==NSOnState) ? YES : NO ] forKey:@"save_password"];
[spfDocData_temp setObject:[NSNumber numberWithBool:([saveConnectionIncludeData state]==NSOnState) ? YES : NO ] forKey:@"include_session"];
- [spfDocData_temp setObject:[NSNumber numberWithBool:NO] forKey:@"save_editor_content"];
+ [spfDocData_temp setObject:@NO forKey:@"save_editor_content"];
if([[[[customQueryInstance valueForKeyPath:@"textView"] textStorage] string] length])
[spfDocData_temp setObject:[NSNumber numberWithBool:([saveConnectionIncludeQuery state]==NSOnState) ? YES : NO ] forKey:@"save_editor_content"];
@@ -3323,7 +3335,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
NSMutableDictionary *spfData = [NSMutableDictionary dictionary];
// Add basic details
- [spfStructure setObject:[NSNumber numberWithInteger:1] forKey:@"version"];
+ [spfStructure setObject:@1 forKey:@"version"];
[spfStructure setObject:@"connection" forKey:@"format"];
[spfStructure setObject:@"mysql" forKey:@"rdbms_type"];
if([self mySQLVersion])
@@ -3334,30 +3346,30 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// Set up the document details to store
NSMutableDictionary *stateDetailsToSave = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:YES], @"connection",
- [NSNumber numberWithBool:YES], @"history",
+ @YES, @"connection",
+ @YES, @"history",
nil];
// Include session data like selected table, view etc. ?
if ([[spfDocData_temp objectForKey:@"include_session"] boolValue])
- [stateDetailsToSave setObject:[NSNumber numberWithBool:YES] forKey:@"session"];
+ [stateDetailsToSave setObject:@YES forKey:@"session"];
// Include the query editor contents if asked to
if ([[spfDocData_temp objectForKey:@"save_editor_content"] boolValue]) {
- [stateDetailsToSave setObject:[NSNumber numberWithBool:YES] forKey:@"query"];
- [stateDetailsToSave setObject:[NSNumber numberWithBool:YES] forKey:@"enablecompression"];
+ [stateDetailsToSave setObject:@YES forKey:@"query"];
+ [stateDetailsToSave setObject:@YES forKey:@"enablecompression"];
}
// Add passwords if asked to
if ([[spfDocData_temp objectForKey:@"save_password"] boolValue])
- [stateDetailsToSave setObject:[NSNumber numberWithBool:YES] forKey:@"password"];
+ [stateDetailsToSave setObject:@YES forKey:@"password"];
// Retrieve details and add to the appropriate dictionaries
NSMutableDictionary *stateDetails = [NSMutableDictionary dictionaryWithDictionary:[self stateIncludingDetails:stateDetailsToSave]];
[spfStructure setObject:[stateDetails objectForKey:SPQueryFavorites] forKey:SPQueryFavorites];
[spfStructure setObject:[stateDetails objectForKey:SPQueryHistory] forKey:SPQueryHistory];
[spfStructure setObject:[stateDetails objectForKey:SPContentFilters] forKey:SPContentFilters];
- [stateDetails removeObjectsForKeys:[NSArray arrayWithObjects:SPQueryFavorites, SPQueryHistory, SPContentFilters, nil]];
+ [stateDetails removeObjectsForKeys:@[SPQueryFavorites, SPQueryHistory, SPContentFilters]];
[spfData addEntriesFromDictionary:stateDetails];
// Determine whether to use encryption when adding the data
@@ -3443,23 +3455,23 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[[parentWindow windowController] addNewConnection:self];
// Get the current state
- NSDictionary *allStateDetails = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:YES], @"connection",
- [NSNumber numberWithBool:YES], @"history",
- [NSNumber numberWithBool:YES], @"session",
- [NSNumber numberWithBool:YES], @"query",
- [NSNumber numberWithBool:YES], @"password",
- nil];
+ NSDictionary *allStateDetails = @{
+ @"connection" : @YES,
+ @"history" : @YES,
+ @"session" : @YES,
+ @"query" : @YES,
+ @"password" : @YES
+ };
NSMutableDictionary *currentState = [NSMutableDictionary dictionaryWithDictionary:[self stateIncludingDetails:allStateDetails]];
// Ensure it's set to autoconnect, and clear the table
- [currentState setObject:[NSNumber numberWithBool:YES] forKey:@"auto_connect"];
+ [currentState setObject:@YES forKey:@"auto_connect"];
NSMutableDictionary *sessionDict = [NSMutableDictionary dictionaryWithDictionary:[currentState objectForKey:@"session"]];
[sessionDict removeObjectForKey:@"table"];
[currentState setObject:sessionDict forKey:@"session"];
// Set the connection on the new tab
- [[[NSApp delegate] frontDocument] setState:currentState];
+ [[SPAppDelegate frontDocument] setState:currentState];
}
/**
@@ -3589,7 +3601,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
if (action == @selector(importFromClipboard:)){
- return [self database] && [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:NSStringPboardType, nil]];
+ return [self database] && [[NSPasteboard generalPasteboard] availableTypeFromArray:@[NSStringPboardType]];
}
// Change "Save Query/Queries" menu item title dynamically
@@ -4046,7 +4058,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
*/
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
- return [NSArray arrayWithObjects:
+ return @[
SPMainToolbarDatabaseSelection,
SPMainToolbarHistoryNavigation,
SPMainToolbarShowConsole,
@@ -4061,8 +4073,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
- NSToolbarSeparatorItemIdentifier,
- nil];
+ NSToolbarSeparatorItemIdentifier
+ ];
}
/**
@@ -4070,7 +4082,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
*/
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
- return [NSArray arrayWithObjects:
+ return @[
SPMainToolbarDatabaseSelection,
SPMainToolbarTableStructure,
SPMainToolbarTableContent,
@@ -4081,8 +4093,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
NSToolbarFlexibleSpaceItemIdentifier,
SPMainToolbarHistoryNavigation,
SPMainToolbarUserManager,
- SPMainToolbarShowConsole,
- nil];
+ SPMainToolbarShowConsole
+ ];
}
/**
@@ -4090,14 +4102,14 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
*/
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{
- return [NSArray arrayWithObjects:
+ return @[
SPMainToolbarTableStructure,
SPMainToolbarTableContent,
SPMainToolbarCustomQuery,
SPMainToolbarTableInfo,
SPMainToolbarTableRelations,
- SPMainToolbarTableTriggers,
- nil];
+ SPMainToolbarTableTriggers
+ ];
}
@@ -4355,7 +4367,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
*/
- (void)setFileURL:(NSURL *)theURL
{
- if (spfFileURL) [spfFileURL release], spfFileURL = nil;
+ if (spfFileURL) SPClear(spfFileURL);
spfFileURL = [theURL retain];
if ([parentWindowController selectedTableDocument] == self) {
if (spfFileURL && [spfFileURL isFileURL])
@@ -4440,9 +4452,9 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
{
BOOL returnConnection = [[detailsToReturn objectForKey:@"connection"] boolValue];
BOOL includePasswords = [[detailsToReturn objectForKey:@"password"] boolValue];
- BOOL returnSession = [[detailsToReturn objectForKey:@"session"] boolValue];
- BOOL returnHistory = [[detailsToReturn objectForKey:@"history"] boolValue];
- BOOL returnQuery = [[detailsToReturn objectForKey:@"query"] boolValue];
+ BOOL returnSession = [[detailsToReturn objectForKey:@"session"] boolValue];
+ BOOL returnHistory = [[detailsToReturn objectForKey:@"history"] boolValue];
+ BOOL returnQuery = [[detailsToReturn objectForKey:@"query"] boolValue];
if (!returnConnection && !returnSession && !returnHistory && !returnQuery) return nil;
NSMutableDictionary *stateDetails = [NSMutableDictionary dictionary];
@@ -4481,7 +4493,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[connection setObject:[self name] forKey:@"name"];
[connection setObject:[self host] forKey:@"host"];
[connection setObject:[self user] forKey:@"user"];
- if([connectionController colorIndex])
+ if([connectionController colorIndex] >= 0)
[connection setObject:[NSNumber numberWithInteger:[connectionController colorIndex]] forKey:SPFavoriteColorIndexKey];
if([connectionController port] && [[connectionController port] length])
[connection setObject:[NSNumber numberWithInteger:[[connectionController port] integerValue]] forKey:@"port"];
@@ -4565,8 +4577,9 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[sessionState setObject:[NSNumber numberWithBool:[tableContentInstance sortColumnIsAscending]] forKey:@"contentSortColIsAsc"];
[sessionState setObject:[NSNumber numberWithInteger:[tableContentInstance pageNumber]] forKey:@"contentPageNumber"];
[sessionState setObject:NSStringFromRect([tableContentInstance viewport]) forKey:@"contentViewport"];
- if ([tableContentInstance filterSettings])
- [sessionState setObject:[tableContentInstance filterSettings] forKey:@"contentFilter"];
+ NSDictionary *filterSettings = [tableContentInstance filterSettings];
+ if (filterSettings)
+ [sessionState setObject:filterSettings forKey:@"contentFilter"];
NSDictionary *contentSelectedRows = [tableContentInstance selectionDetailsAllowingIndexSelection:YES];
if (contentSelectedRows) {
@@ -4807,11 +4820,11 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// Ask for a password if SPF file passwords were encrypted, via a sheet
if ([spf objectForKey:@"encrypted"] && [[spf valueForKey:@"encrypted"] boolValue]) {
- if([self isSaveInBundle] && [[[NSApp delegate] spfSessionDocData] objectForKey:@"e_string"]) {
- encryptpw = [[[NSApp delegate] spfSessionDocData] objectForKey:@"e_string"];
+ if([self isSaveInBundle] && [[SPAppDelegate spfSessionDocData] objectForKey:@"e_string"]) {
+ encryptpw = [[SPAppDelegate spfSessionDocData] objectForKey:@"e_string"];
} else {
[inputTextWindowHeader setStringValue:NSLocalizedString(@"Connection file is encrypted", @"Connection file is encrypted")];
- [inputTextWindowMessage setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Please enter the password for ‘%@’:", @"Please enter the password"), ([self isSaveInBundle]) ? [[[[NSApp delegate] sessionURL] absoluteString] lastPathComponent] : [path lastPathComponent]]];
+ [inputTextWindowMessage setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Please enter the password for ‘%@’:", @"Please enter the password"), ([self isSaveInBundle]) ? [[[SPAppDelegate sessionURL] absoluteString] lastPathComponent] : [path lastPathComponent]]];
[inputTextWindowSecureTextField setStringValue:@""];
[inputTextWindowSecureTextField selectText:nil];
@@ -4843,9 +4856,9 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
encryptpw = [inputTextWindowSecureTextField stringValue];
if ([self isSaveInBundle]) {
NSMutableDictionary *spfSessionData = [NSMutableDictionary dictionary];
- [spfSessionData addEntriesFromDictionary:[[NSApp delegate] spfSessionDocData]];
+ [spfSessionData addEntriesFromDictionary:[SPAppDelegate spfSessionDocData]];
[spfSessionData setObject:encryptpw forKey:@"e_string"];
- [[NSApp delegate] setSpfSessionDocData:spfSessionData];
+ [SPAppDelegate setSpfSessionDocData:spfSessionData];
}
} else {
[self closeAndDisconnect];
@@ -4917,16 +4930,16 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[data setObject:[spf objectForKey:SPContentFilters] forKey:SPContentFilters];
// Ensure the encryption status is stored in the spfDocData store for future saves
- [spfDocData setObject:[NSNumber numberWithBool:NO] forKey:@"encrypted"];
+ [spfDocData setObject:@NO forKey:@"encrypted"];
if (encryptpw != nil) {
- [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"encrypted"];
+ [spfDocData setObject:@YES forKey:@"encrypted"];
[spfDocData setObject:encryptpw forKey:@"e_string"];
}
encryptpw = nil;
// If session data is available, ensure it is marked for save
if ([data objectForKey:@"session"]) {
- [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"include_session"];
+ [spfDocData setObject:@YES forKey:@"include_session"];
}
if (![self isSaveInBundle]) {
@@ -4935,11 +4948,11 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[spfDocData setObject:[NSNumber numberWithBool:([[data objectForKey:@"connection"] objectForKey:@"password"]) ? YES : NO] forKey:@"save_password"];
- [spfDocData setObject:[NSNumber numberWithBool:NO] forKey:@"auto_connect"];
+ [spfDocData setObject:@NO forKey:@"auto_connect"];
if([spf objectForKey:@"auto_connect"] && [[spf valueForKey:@"auto_connect"] boolValue]) {
- [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"auto_connect"];
- [data setObject:[NSNumber numberWithBool:YES] forKey:@"auto_connect"];
+ [spfDocData setObject:@YES forKey:@"auto_connect"];
+ [data setObject:@YES forKey:@"auto_connect"];
}
// Set the state dictionary, triggering an autoconnect if appropriate
@@ -5014,8 +5027,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[self updateWindowTitle:self];
// dealloc spfSession data
- [spfSession release];
- spfSession = nil;
+ SPClear(spfSession);
// End the task
[self endTask];
@@ -5264,7 +5276,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:&inError];
[fm removeItemAtPath:queryFileName error:nil];
if(inError == nil && query && [query length]) {
- [customQueryInstance performQueries:[NSArray arrayWithObject:query] withCallback:NULL];
+ [customQueryInstance performQueries:@[query] withCallback:NULL];
}
}
return;
@@ -5312,9 +5324,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
NSInteger itemType = SPTableTypeNone;
- NSString *itemTypeStr = @"TABLE";
NSUInteger i;
- NSInteger queryCol = 1;
// Loop through the unfiltered tables/views to find the desired item
for (i = 0; i < [availableItems count]; i++) {
@@ -5327,19 +5337,26 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// If no match found, continue
if (itemType == SPTableTypeNone) continue;
+ NSString *itemTypeStr;
+ NSInteger queryCol;
+
switch(itemType) {
case SPTableTypeTable:
case SPTableTypeView:
- itemTypeStr = @"TABLE";
- break;
+ itemTypeStr = @"TABLE";
+ queryCol = 1;
+ break;
case SPTableTypeProc:
- itemTypeStr = @"PROCEDURE";
- queryCol = 2;
- break;
+ itemTypeStr = @"PROCEDURE";
+ queryCol = 2;
+ break;
case SPTableTypeFunc:
- itemTypeStr = @"FUNCTION";
- queryCol = 2;
- break;
+ itemTypeStr = @"FUNCTION";
+ queryCol = 2;
+ break;
+ default:
+ NSLog(@"%s: Unhandled SPTableType=%ld for item=%@ (skipping)", __func__, itemType, item);
+ continue;
}
// Ensure that queries are made in UTF8
@@ -5379,7 +5396,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
return;
}
if(doSyntaxHighlighting) {
- [result appendFormat:@"%@<br>", [[NSApp delegate] doSQLSyntaxHighlightForString:[syntaxString createViewSyntaxPrettifier] cssLike:doSyntaxHighlightingViaCSS]];
+ [result appendFormat:@"%@<br>", [SPAppDelegate doSQLSyntaxHighlightForString:[syntaxString createViewSyntaxPrettifier] cssLike:doSyntaxHighlightingViaCSS]];
} else {
[result appendFormat:@"%@\n", [syntaxString createViewSyntaxPrettifier]];
}
@@ -5591,13 +5608,13 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[runningActivitiesArray addObject:commandDict];
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self];
- if([runningActivitiesArray count] || [[[NSApp delegate] runningActivities] count])
- [self performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0];
+ if([runningActivitiesArray count] || [[SPAppDelegate runningActivities] count])
+ [self performSelector:@selector(setActivityPaneHidden:) withObject:@0 afterDelay:1.0];
else {
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(setActivityPaneHidden:)
- object:[NSNumber numberWithInteger:0]];
- [self setActivityPaneHidden:[NSNumber numberWithInteger:1]];
+ object:@0];
+ [self setActivityPaneHidden:@1];
}
}
@@ -5612,13 +5629,13 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
}
- if([runningActivitiesArray count] || [[[NSApp delegate] runningActivities] count])
- [self performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0];
+ if([runningActivitiesArray count] || [[SPAppDelegate runningActivities] count])
+ [self performSelector:@selector(setActivityPaneHidden:) withObject:@0 afterDelay:1.0];
else {
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(setActivityPaneHidden:)
- object:[NSNumber numberWithInteger:0]];
- [self setActivityPaneHidden:[NSNumber numberWithInteger:1]];
+ object:@0];
+ [self setActivityPaneHidden:@1];
}
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self];
@@ -5643,7 +5660,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
- (NSDictionary*)shellVariables
{
- if(!_isConnected) return [NSDictionary dictionary];
+ if(!_isConnected) return @{};
NSMutableDictionary *env = [NSMutableDictionary dictionary];
@@ -5865,9 +5882,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
{
NSPasteboard *pb = [NSPasteboard generalPasteboard];
- [pb declareTypes:[NSArray arrayWithObjects: NSTabularTextPboardType,
- NSStringPboardType, nil]
- owner:nil];
+ [pb declareTypes:@[NSTabularTextPboardType, NSStringPboardType] owner:nil];
[pb setString:tmp forType:NSStringPboardType];
[pb setString:tmp forType:NSTabularTextPboardType];
@@ -5900,7 +5915,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
BOOL copyWithContent = [copyDatabaseDataButton state] == NSOnState;
- if ([dbActionCopy copyDatabaseFrom:[self database] to:[databaseCopyNameField stringValue] withContent:copyWithContent]) {
+ if ([dbActionCopy copyDatabaseFrom:[self createDatabaseInfo] to:[databaseCopyNameField stringValue] withContent:copyWithContent]) {
[self selectDatabase:[databaseCopyNameField stringValue] item:nil];
}
else {
@@ -5931,7 +5946,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[dbActionRename setConnection:[self getConnection]];
[dbActionRename setMessageWindow:parentWindow];
- if ([dbActionRename renameDatabaseFrom:[self database] to:newDatabaseName]) {
+ if ([dbActionRename renameDatabaseFrom:[self createDatabaseInfo] to:newDatabaseName]) {
[self setDatabases:self];
[self selectDatabase:newDatabaseName item:nil];
}
@@ -5971,25 +5986,16 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// As we're amending identifiers, ensure UTF8
if (![[mySQLConnection encoding] isEqualToString:@"utf8"]) [mySQLConnection setEncoding:@"utf8"];
- NSString *createStatement = [NSString stringWithFormat:@"CREATE DATABASE %@", [[databaseNameField stringValue] backtickQuotedString]];
+ SPDatabaseAction *dbAction = [[SPDatabaseAction alloc] init];
+ [dbAction setConnection:mySQLConnection];
+ BOOL res = [dbAction createDatabase:[databaseNameField stringValue]
+ withEncoding:[addDatabaseCharsetHelper selectedCharset]
+ collation:[addDatabaseCharsetHelper selectedCollation]];
+ [dbAction release];
- // If there is an encoding selected other than the default we must specify it in CREATE DATABASE statement
- NSString *encodingName = [addDatabaseCharsetHelper selectedCharset];
- if (encodingName)
- createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [encodingName backtickQuotedString]];
-
- // If there is a collation selected other than the default we must specify it in the CREATE DATABASE statement
- NSString *collationName = [addDatabaseCharsetHelper selectedCollation];
- if (collationName)
- createStatement = [NSString stringWithFormat:@"%@ DEFAULT COLLATE %@", createStatement, [collationName backtickQuotedString]];
-
- // Create the database
- [mySQLConnection queryString:createStatement];
-
- if ([mySQLConnection queryErrored]) {
+ if (!res) {
// An error occurred
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't create database.\nMySQL said: %@", @"message of panel when creation of db failed"), [mySQLConnection lastErrorMessage]]);
-
return;
}
@@ -6064,7 +6070,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// that's why we can run this on main thread
[databaseStructureRetrieval queryDbStructureWithUserInfo:nil];
- if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
+ if (selectedDatabase) SPClear(selectedDatabase);
[self setDatabases:self];
@@ -6134,7 +6140,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
#ifndef SP_CODA /* chooseDatabaseButton selectItemWithTitle: */
[[chooseDatabaseButton onMainThread] selectItemWithTitle:targetDatabaseName];
#endif
- if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
+ if (selectedDatabase) SPClear(selectedDatabase);
selectedDatabase = [[NSString alloc] initWithString:targetDatabaseName];
[databaseDataInstance resetAllData];
@@ -6198,7 +6204,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
#ifndef SP_CODA
- (void)_processDatabaseChangedBundleTriggerActions
{
- NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionDatabaseChanged];
+ NSArray *triggeredCommands = [SPAppDelegate bundleCommandsForTrigger:SPBundleTriggerActionDatabaseChanged];
for (NSString* cmdPath in triggeredCommands)
{
@@ -6229,7 +6235,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
if(!stopTrigger) {
if([[data objectAtIndex:1] isEqualToString:SPBundleScopeGeneral]) {
- [[[NSApp delegate] onMainThread] executeBundleItemForApp:aMenuItem];
+ [[SPAppDelegate onMainThread] executeBundleItemForApp:aMenuItem];
}
else if([[data objectAtIndex:1] isEqualToString:SPBundleScopeDataTable]) {
if ([[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SPCopyTable"]) {
@@ -6261,6 +6267,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[prefs removeObserver:tableSourceInstance forKeyPath:SPUseMonospacedFonts];
[prefs removeObserver:[SPQueryController sharedQueryController] forKeyPath:SPUseMonospacedFonts];
[prefs removeObserver:tableContentInstance forKeyPath:SPGlobalResultTableFont];
+ [prefs removeObserver:tableContentInstance forKeyPath:SPDisplayBinaryDataAsHex];
[prefs removeObserver:[SPQueryController sharedQueryController] forKeyPath:SPConsoleEnableLogging];
[prefs removeObserver:self forKeyPath:SPConsoleEnableLogging];
@@ -6280,59 +6287,59 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
#ifndef SP_CODA /* release nib objects */
for (id retainedObject in nibObjectsToRelease) [retainedObject release];
- [nibObjectsToRelease release];
+ SPClear(nibObjectsToRelease);
#endif
// Tell listeners that this database document is being closed - fixes retain cycles and allows cleanup
[[NSNotificationCenter defaultCenter] postNotificationName:SPDocumentWillCloseNotification object:self];
- [databaseStructureRetrieval release];
+ SPClear(databaseStructureRetrieval);
- [allDatabases release];
- [allSystemDatabases release];
- [gotoDatabaseController release];
+ SPClear(allDatabases);
+ SPClear(allSystemDatabases);
+ SPClear(gotoDatabaseController);
#ifndef SP_CODA /* dealloc ivars */
- [undoManager release];
- [printWebView release];
+ SPClear(undoManager);
+ SPClear(printWebView);
#endif
- [selectedDatabaseEncoding release];
+ SPClear(selectedDatabaseEncoding);
#ifndef SP_CODA
[taskProgressWindow close];
#endif
- if (selectedTableName) [selectedTableName release];
- if (connectionController) [connectionController release];
+ if (selectedTableName) SPClear(selectedTableName);
+ if (connectionController) SPClear(connectionController);
#ifndef SP_CODA /* dealloc ivars */
- if (processListController) [processListController release];
- if (serverVariablesController) [serverVariablesController release];
+ if (processListController) SPClear(processListController);
+ if (serverVariablesController) SPClear(serverVariablesController);
#endif
- if (mySQLConnection) [mySQLConnection release], mySQLConnection = nil;
- if (selectedDatabase) [selectedDatabase release];
- if (mySQLVersion) [mySQLVersion release];
+ if (mySQLConnection) SPClear(mySQLConnection);
+ if (selectedDatabase) SPClear(selectedDatabase);
+ if (mySQLVersion) SPClear(mySQLVersion);
#ifndef SP_CODA
- if (taskDrawTimer) [taskDrawTimer invalidate], [taskDrawTimer release];
- if (taskFadeInStartDate) [taskFadeInStartDate release];
+ if (taskDrawTimer) [taskDrawTimer invalidate], SPClear(taskDrawTimer);
+ if (taskFadeInStartDate) SPClear(taskFadeInStartDate);
#endif
- if (queryEditorInitString) [queryEditorInitString release];
+ if (queryEditorInitString) SPClear(queryEditorInitString);
#ifndef SP_CODA
- if (sqlFileURL) [sqlFileURL release];
- if (spfFileURL) [spfFileURL release];
- if (spfPreferences) [spfPreferences release];
- if (spfSession) [spfSession release];
- if (spfDocData) [spfDocData release];
+ if (sqlFileURL) SPClear(sqlFileURL);
+ if (spfFileURL) SPClear(spfFileURL);
+ if (spfPreferences) SPClear(spfPreferences);
+ if (spfSession) SPClear(spfSession);
+ if (spfDocData) SPClear(spfDocData);
#endif
- if (keyChainID) [keyChainID release];
+ if (keyChainID) SPClear(keyChainID);
#ifndef SP_CODA
- if (mainToolbar) [mainToolbar release];
+ if (mainToolbar) SPClear(mainToolbar);
#endif
- if (titleAccessoryView) [titleAccessoryView release];
+ if (titleAccessoryView) SPClear(titleAccessoryView);
#ifndef SP_CODA
- if (taskProgressWindow) [taskProgressWindow release];
+ if (taskProgressWindow) SPClear(taskProgressWindow);
#endif
- if (serverSupport) [serverSupport release];
+ if (serverSupport) SPClear(serverSupport);
#ifndef SP_CODA /* dealloc ivars */
- if (processID) [processID release];
- if (runningActivitiesArray) [runningActivitiesArray release];
+ if (processID) SPClear(processID);
+ if (runningActivitiesArray) SPClear(runningActivitiesArray);
#endif
#ifdef SP_CODA
@@ -6340,8 +6347,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
if (customQueryInstance) [customQueryInstance release];
#endif
- if (alterDatabaseCharsetHelper) [alterDatabaseCharsetHelper release];
- if (addDatabaseCharsetHelper) [addDatabaseCharsetHelper release];
+ if (alterDatabaseCharsetHelper) SPClear(alterDatabaseCharsetHelper);
+ if (addDatabaseCharsetHelper) SPClear(addDatabaseCharsetHelper);
[super dealloc];
}