aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTablesList.m
diff options
context:
space:
mode:
authorMax <dmoagx@users.noreply.github.com>2018-05-03 22:26:12 +0200
committerMax <dmoagx@users.noreply.github.com>2018-05-03 22:26:27 +0200
commitb49edf67744ba6e54b7c0bdab7dc197cf8faac96 (patch)
tree25333e30eabfc6c40c9251322d2342ff6c21a530 /Source/SPTablesList.m
parent7f35608f0ab5f9192245a5bc8dd74da793788389 (diff)
downloadsequelpro-b49edf67744ba6e54b7c0bdab7dc197cf8faac96.tar.gz
sequelpro-b49edf67744ba6e54b7c0bdab7dc197cf8faac96.tar.bz2
sequelpro-b49edf67744ba6e54b7c0bdab7dc197cf8faac96.zip
Replace all non-cyclic NSAutoreleasepools with @autoreleasepool
Diffstat (limited to 'Source/SPTablesList.m')
-rw-r--r--Source/SPTablesList.m170
1 files changed, 87 insertions, 83 deletions
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index eceb57f2..ab620645 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -2350,117 +2350,121 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
return;
}
- NSAutoreleasePool *tableAdditionPool = [[NSAutoreleasePool alloc] init];
-
- [tableDocumentInstance startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Creating %@...", @"Creating table task string"), [tableNameField stringValue]]];
+ @autoreleasepool {
+ [tableDocumentInstance startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Creating %@...", @"Creating table task string"), [tableNameField stringValue]]];
- NSString *charSetStatement = @"";
- NSString *collationStatement = @"";
- NSString *engineStatement = @"";
+ NSString *charSetStatement = @"";
+ NSString *collationStatement = @"";
+ NSString *engineStatement = @"";
- NSString *tableType = [tableTypeButton title];
- NSString *tableName = [tableNameField stringValue];
+ NSString *tableType = [tableTypeButton title];
+ NSString *tableName = [tableNameField stringValue];
- // Ensure the use of UTF8 when creating new tables
- BOOL changeEncoding = ![[mySQLConnection encoding] isEqualToString:@"utf8"];
-
- if (changeEncoding) {
- [mySQLConnection storeEncodingForRestoration];
- [mySQLConnection setEncoding:@"utf8"];
- }
+ // Ensure the use of UTF8 when creating new tables
+ BOOL changeEncoding = ![[mySQLConnection encoding] isEqualToString:@"utf8"];
- // If there is an encoding selected other than the default we must specify it in CREATE TABLE statement
- NSString *encodingName = [addTableCharsetHelper selectedCharset];
- if (encodingName)
- charSetStatement = [NSString stringWithFormat:@"DEFAULT CHARACTER SET %@", [encodingName backtickQuotedString]];
-
- // If there is a collation selected other than the default we must specify it in the CREATE TABLE statement
- NSString *collationName = [addTableCharsetHelper selectedCollation];
- if (collationName)
- collationStatement = [NSString stringWithFormat:@"DEFAULT COLLATE %@",[collationName backtickQuotedString]];
+ if (changeEncoding) {
+ [mySQLConnection storeEncodingForRestoration];
+ [mySQLConnection setEncoding:@"utf8"];
+ }
- // If there is a type selected other than the default we must specify it in CREATE TABLE statement
- if ([tableTypeButton indexOfSelectedItem] > 0) {
- engineStatement = [NSString stringWithFormat:@"%@ = %@", [[tableDocumentInstance serverSupport] engineTypeQueryName], [[tableDocumentInstance serverSupport] supportsQuotingEngineTypeInCreateSyntax] ? [tableType backtickQuotedString] : tableType];
- }
+ // If there is an encoding selected other than the default we must specify it in CREATE TABLE statement
+ NSString *encodingName = [addTableCharsetHelper selectedCharset];
+ if (encodingName) charSetStatement = [NSString stringWithFormat:@"DEFAULT CHARACTER SET %@", [encodingName backtickQuotedString]];
- NSString *createStatement = [NSString stringWithFormat:@"CREATE TABLE %@ (id INT(11) UNSIGNED NOT NULL%@) %@ %@ %@", [tableName backtickQuotedString], [tableType isEqualToString:@"CSV"] ? @"" : @" PRIMARY KEY AUTO_INCREMENT", charSetStatement, collationStatement, engineStatement];
+ // If there is a collation selected other than the default we must specify it in the CREATE TABLE statement
+ NSString *collationName = [addTableCharsetHelper selectedCollation];
+ if (collationName) collationStatement = [NSString stringWithFormat:@"DEFAULT COLLATE %@",[collationName backtickQuotedString]];
- // Create the table
- [mySQLConnection queryString:createStatement];
+ // If there is a type selected other than the default we must specify it in CREATE TABLE statement
+ if ([tableTypeButton indexOfSelectedItem] > 0) {
+ engineStatement = [NSString stringWithFormat:@"%@ = %@", [[tableDocumentInstance serverSupport] engineTypeQueryName], [[tableDocumentInstance serverSupport] supportsQuotingEngineTypeInCreateSyntax] ? [tableType backtickQuotedString] : tableType];
+ }
- if (![mySQLConnection queryErrored]) {
+ NSString *createStatement = [NSString stringWithFormat:@"CREATE TABLE %@ (id INT(11) UNSIGNED NOT NULL%@) %@ %@ %@", [tableName backtickQuotedString], [tableType isEqualToString:@"CSV"] ? @"" : @" PRIMARY KEY AUTO_INCREMENT", charSetStatement, collationStatement, engineStatement];
- // Table creation was successful - insert the new item into the tables list and select it.
- NSInteger addItemAtIndex = NSNotFound;
+ // Create the table
+ [mySQLConnection queryString:createStatement];
- for (NSUInteger i = 0; i < [tables count]; i++)
- {
- NSInteger eachTableType = [[tableTypes objectAtIndex:i] integerValue];
+ if (![mySQLConnection queryErrored]) {
- if (eachTableType == SPTableTypeNone) continue;
- if (eachTableType == SPTableTypeProc || eachTableType == SPTableTypeFunc) {
- addItemAtIndex = (i - 1);
- break;
+ // Table creation was successful - insert the new item into the tables list and select it.
+ NSInteger addItemAtIndex = NSNotFound;
+
+ for (NSUInteger i = 0; i < [tables count]; i++)
+ {
+ NSInteger eachTableType = [[tableTypes objectAtIndex:i] integerValue];
+
+ if (eachTableType == SPTableTypeNone) continue;
+ if (eachTableType == SPTableTypeProc || eachTableType == SPTableTypeFunc) {
+ addItemAtIndex = (i - 1);
+ break;
+ }
+
+ if ([tableName localizedCompare:[tables objectAtIndex:i]] == NSOrderedAscending) {
+ addItemAtIndex = i;
+ break;
+ }
}
- if ([tableName localizedCompare:[tables objectAtIndex:i]] == NSOrderedAscending) {
- addItemAtIndex = i;
- break;
+ if (addItemAtIndex == NSNotFound) {
+ [tables addObject:tableName];
+ [tableTypes addObject:[NSNumber numberWithInteger:SPTableTypeTable]];
+ }
+ else {
+ [tables insertObject:tableName atIndex:addItemAtIndex];
+ [tableTypes insertObject:[NSNumber numberWithInteger:SPTableTypeTable] atIndex:addItemAtIndex];
}
- }
- if (addItemAtIndex == NSNotFound) {
- [tables addObject:tableName];
- [tableTypes addObject:[NSNumber numberWithInteger:SPTableTypeTable]];
- }
- else {
- [tables insertObject:tableName atIndex:addItemAtIndex];
- [tableTypes insertObject:[NSNumber numberWithInteger:SPTableTypeTable] atIndex:addItemAtIndex];
- }
+ // Set the selected table name and type, and then update the filter list and the
+ // selection.
+ if (selectedTableName) [selectedTableName release];
- // Set the selected table name and type, and then update the filter list and the
- // selection.
- if (selectedTableName) [selectedTableName release];
-
- selectedTableName = [[NSString alloc] initWithString:tableName];
- selectedTableType = SPTableTypeTable;
+ selectedTableName = [[NSString alloc] initWithString:tableName];
+ selectedTableType = SPTableTypeTable;
- [[self onMainThread] updateFilter:self];
- [[tablesListView onMainThread] scrollRowToVisible:[tablesListView selectedRow]];
+ [[self onMainThread] updateFilter:self];
+ [[tablesListView onMainThread] scrollRowToVisible:[tablesListView selectedRow]];
- // Select the newly created table and switch to the table structure view for easier setup
- [tableDocumentInstance loadTable:selectedTableName ofType:selectedTableType];
+ // Select the newly created table and switch to the table structure view for easier setup
+ [tableDocumentInstance loadTable:selectedTableName ofType:selectedTableType];
#ifndef SP_CODA
- [tableDocumentInstance viewStructure:self];
+ [tableDocumentInstance viewStructure:self];
#endif
#ifdef SP_CODA
- [sidebarViewController setTableNames:[self allTableNames] selectedTableName:selectedTableName];
+ [sidebarViewController setTableNames:[self allTableNames] selectedTableName:selectedTableName];
#endif
- // Query the structure of all databases in the background (mainly for completion)
- [[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}];
- }
- else {
- // Error while creating new table
- alertSheetOpened = YES;
+ // Query the structure of all databases in the background (mainly for completion)
+ [[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}];
+ }
+ else {
+ // Error while creating new table
+ alertSheetOpened = YES;
+
+ SPBeginAlertSheet(
+ NSLocalizedString(@"Error adding new table", @"error adding new table message"),
+ NSLocalizedString(@"OK", @"OK button"),
+ nil,
+ nil,
+ [tableDocumentInstance parentWindow],
+ self,
+ @selector(sheetDidEnd:returnCode:contextInfo:),
+ SPAddRow,
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to add the new table '%@'.\n\nMySQL said: %@", @"error adding new table informative message"), tableName, [mySQLConnection lastErrorMessage]]
+ );
- SPBeginAlertSheet(NSLocalizedString(@"Error adding new table", @"error adding new table message"),
- NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self,
- @selector(sheetDidEnd:returnCode:contextInfo:), SPAddRow,
- [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to add the new table '%@'.\n\nMySQL said: %@", @"error adding new table informative message"), tableName, [mySQLConnection lastErrorMessage]]);
+ if (changeEncoding) [mySQLConnection restoreStoredEncoding];
- if (changeEncoding) [mySQLConnection restoreStoredEncoding];
-
- [[tablesListView onMainThread] reloadData];
- }
+ [[tablesListView onMainThread] reloadData];
+ }
- // Clear table name
- [[tableNameField onMainThread] setStringValue:@""];
+ // Clear table name
+ [[tableNameField onMainThread] setStringValue:@""];
- [tableDocumentInstance endTask];
- [tableAdditionPool release];
+ [tableDocumentInstance endTask];
+ }
}
#ifndef SP_CODA