aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPUserManager.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-03-17 15:32:00 +0000
committerrowanbeentje <rowan@beent.je>2012-03-17 15:32:00 +0000
commitac8ebfe4bba6d7da6edad87c75b174156d919621 (patch)
tree08a3c2843d3c520090f40e6341b26043a7ccf014 /Source/SPUserManager.m
parent8886d935e933c6239aa9b35e900d96f7d07527c7 (diff)
parenteab6df4de773259f90dd5a1d25e44ca4d2765bbf (diff)
downloadsequelpro-ac8ebfe4bba6d7da6edad87c75b174156d919621.tar.gz
sequelpro-ac8ebfe4bba6d7da6edad87c75b174156d919621.tar.bz2
sequelpro-ac8ebfe4bba6d7da6edad87c75b174156d919621.zip
Merge in the SPMySQL Framework. This new framework should provide much of the functionality required from MCPKit and is based around its interface for relatively easy integration.
Externally visible changes as a result of this merge: - Speed improvements, particularly when loading large data sets - Stability improvements, particularly related to connection state after the connection is dropped (eg Issue #1256) - Improved support for new MySQL data types, which should address Issue #1052. - Database structure retrieval and query cancellation now use a single persistent helper connection instead of lots of connections on-demand. This should help Issue #1097. - More internal commands now use queries instead of MySQL functions; for example USE queries are now used to trigger database selection, improving transcripts. This addresses Issue #1247. - Improved internal encoding work; while this needs support within the UI, it lays the foundation for issues like Issue #1280. Code improvements: - Much improved class layouts including extensive category usage - Improved documentation across framework methods - Support for fast enumeration across result objects - Rewrite fixes use of a number of deprecate functions - Much less code duplication across result set types - Improved encapsultation within the framework, limiting the number of methods exposed, and also not exposing all the MySQL headers From the Readme file: The SPMySQL Framework is intended to provide a stable MySQL connection framework, with the ability to run text-based queries and rapidly retrieve result sets with conversion from MySQL data types to Cocoa objects. SPMySQL.framework has an interface loosely based around that provided by MCPKit by Serge Cohen and Bertrand Mansion (http://mysql-cocoa.sourceforge.net/), and in particular the heavily modified Sequel Pro version (http://www.sequelpro.com/). It is a full rewrite of the original framework, although it includes code from patches implementing the following Sequel Pro functionality, largely contributed by Hans-Jörg Bibiko, Stuart Connolly, Jakob Egger, and Rowan Beentje: - Connection locking (Jakob et al) - Ping & keepalive (Rowan et al) - Query cancellation (Rowan et al) - Delegate setup (Stuart et al) - SSL support (Rowan et al) - Connection checking (Rowan et al) - Version state (Stuart et al) - Maximum packet size control (Hans et al) - Result multithreading and streaming (Rowan et al) - Improved encoding support & switching (Rowan et al) - Database structure; moved to inside the app (Hans et al) - Query reattempts and error-handling approach (Rowan et al) - Geometry result class (Hans et al) - Connection proxy (Stuart et al)
Diffstat (limited to 'Source/SPUserManager.m')
-rw-r--r--Source/SPUserManager.m66
1 files changed, 18 insertions, 48 deletions
diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m
index 83f0a12f..0e5f14cf 100644
--- a/Source/SPUserManager.m
+++ b/Source/SPUserManager.m
@@ -29,6 +29,7 @@
#import "SPConnectionController.h"
#import "SPServerSupport.h"
#import "SPAlertSheets.h"
+#import "SPMySQL.h"
#import <BWToolkitFramework/BWAnchoredButtonBar.h>
static const NSString *SPTableViewNameColumnID = @"NameColumn";
@@ -140,23 +141,12 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
NSMutableString *privKey;
NSArray *privRow;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- NSMutableArray *resultAsArray = [NSMutableArray array];
NSMutableArray *usersResultArray = [NSMutableArray array];
// Select users from the mysql.user table
- MCPResult *result = [self.mySqlConnection queryString:@"SELECT * FROM mysql.user ORDER BY user"];
-
- NSUInteger rows = (NSUInteger)[result numOfRows];
-
- if (rows > 0) [result dataSeek:0];
-
- for (NSUInteger i = 0; i < rows; i++)
- {
- [resultAsArray addObject:[result fetchRowAsDictionary]];
- }
-
- [usersResultArray addObjectsFromArray:resultAsArray];
+ SPMySQLResult *result = [self.mySqlConnection queryString:@"SELECT * FROM mysql.user ORDER BY user"];
+ [result setReturnDataAsStrings:YES];
+ [usersResultArray addObjectsFromArray:[result getAllRows]];
[self _initializeTree:usersResultArray];
@@ -169,12 +159,11 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
if ([serverSupport supportsShowPrivileges]) {
result = [self.mySqlConnection queryString:@"SHOW PRIVILEGES"];
-
[result setReturnDataAsStrings:YES];
}
- if (result && [result numOfRows]) {
- while ((privRow = [result fetchRowAsArray]))
+ if (result && [result numberOfRows]) {
+ while ((privRow = [result getRowAsArray]))
{
privKey = [NSMutableString stringWithString:[[privRow objectAtIndex:0] lowercaseString]];
@@ -189,11 +178,10 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
}
// If that fails, base privilege support on the mysql.users columns
else {
- result = [self.mySqlConnection queryString:@"SHOW COLUMNS FROM mysql.user"];
-
+ result = [self.mySqlConnection queryString:@"SHOW COLUMNS FROM mysql.user"];
[result setReturnDataAsStrings:YES];
- while ((privRow = [result fetchRowAsArray]))
+ while ((privRow = [result getRowAsArray]))
{
privKey = [NSMutableString stringWithString:[privRow objectAtIndex:0]];
@@ -308,15 +296,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
{
// Initialize Databases
[schemas removeAllObjects];
-
- MCPResult *results = [self.mySqlConnection listDBs];
-
- if ([results numOfRows]) [results dataSeek:0];
-
- for (NSUInteger i = 0; i < [results numOfRows]; i++)
- {
- [schemas addObject:[results fetchRowAsDictionary]];
- }
+ [schemas addObjectsFromArray:[self.mySqlConnection databases]];
[schemaController rearrangeObjects];
@@ -377,16 +357,11 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
NSString *queryString = [NSString stringWithFormat:@"SELECT * from mysql.db d WHERE d.user = %@ and d.host = %@",
[[[child parent] valueForKey:@"user"] tickQuotedString], [[child valueForKey:@"host"] tickQuotedString]];
- MCPResult *queryResults = [self.mySqlConnection queryString:queryString];
+ SPMySQLResult *queryResults = [self.mySqlConnection queryString:queryString];
+ [queryResults setReturnDataAsStrings:YES];
- if ([queryResults numOfRows] > 0) {
- // Go to the beginning
- [queryResults dataSeek:0];
- }
-
- for (NSUInteger i = 0; i < [queryResults numOfRows]; i++)
+ for (NSDictionary *rowDict in queryResults)
{
- NSDictionary *rowDict = [queryResults fetchRowAsDictionary];
NSManagedObject *dbPriv = [NSEntityDescription insertNewObjectForEntityForName:@"Privileges"
inManagedObjectContext:[self managedObjectContext]];
for (NSString *key in rowDict)
@@ -881,7 +856,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
// The passed in objects should be an array of NSDictionaries with a key
// of "name".
NSManagedObject *selectedHost = [[treeController selectedObjects] objectAtIndex:0];
- NSString *selectedDb = [[[schemaController selectedObjects] objectAtIndex:0] valueForKey:@"Database"];
+ NSString *selectedDb = [[schemaController selectedObjects] objectAtIndex:0];
NSArray *selectedPrivs = [self _fetchPrivsWithUser:[selectedHost valueForKeyPath:@"parent.user"]
schema:[selectedDb stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"]
host:[selectedHost valueForKey:@"host"]];
@@ -1212,12 +1187,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
[[schemaPriv valueForKeyPath:@"user.host"] tickQuotedString],
[dbName tickQuotedString]];
- MCPResult *result = [self.mySqlConnection queryString:statement];
-
- NSUInteger rows = (NSUInteger)[result numOfRows];
- BOOL userExists = YES;
-
- if (rows == 0) userExists = NO;
+ NSArray *matchingUsers = [self.mySqlConnection getAllRowsFromQuery:statement];
for (NSString *key in self.privsSupportedByServer)
{
@@ -1228,7 +1198,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
[grantPrivileges addObject:[privilege replaceUnderscoreWithSpace]];
}
else {
- if (userExists || [grantPrivileges count] > 0) {
+ if ([matchingUsers count] || [grantPrivileges count] > 0) {
[revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]];
}
}
@@ -1433,11 +1403,11 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
{
if ([self.mySqlConnection queryErrored]) {
if (isSaving) {
- [errorsString appendFormat:@"%@\n", [self.mySqlConnection getLastErrorMessage]];
+ [errorsString appendFormat:@"%@\n", [self.mySqlConnection lastErrorMessage]];
} else {
SPBeginAlertSheet(NSLocalizedString(@"An error occurred", @"mysql error occurred message"),
NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occurred whilst trying to perform the operation.\n\nMySQL said: %@", @"mysql error occurred informative message"), [self.mySqlConnection getLastErrorMessage]]);
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred whilst trying to perform the operation.\n\nMySQL said: %@", @"mysql error occurred informative message"), [self.mySqlConnection lastErrorMessage]]);
}
return NO;
@@ -1565,7 +1535,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
// Check to see if the user host node was selected
if ([user valueForKey:@"host"]) {
- NSString *selectedSchema = [[[schemaController selectedObjects] objectAtIndex:0] valueForKey:@"Database"];
+ NSString *selectedSchema = [[schemaController selectedObjects] objectAtIndex:0];
NSArray *results = [self _fetchPrivsWithUser:[[user parent] valueForKey:@"user"]
schema:[selectedSchema stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"]
host:[user valueForKey:@"host"]];