aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPUserManager.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-02-23 02:13:56 +0000
committerrowanbeentje <rowan@beent.je>2012-02-23 02:13:56 +0000
commit05f1612cbb7e33cf9135a346fc2505cc0e87e853 (patch)
tree785824be4e44a61389271343d958851fa4ff7dd0 /Source/SPUserManager.m
parenta889340b9cb1eca0d3ff022e8e6e2c718480bf44 (diff)
downloadsequelpro-05f1612cbb7e33cf9135a346fc2505cc0e87e853.tar.gz
sequelpro-05f1612cbb7e33cf9135a346fc2505cc0e87e853.tar.bz2
sequelpro-05f1612cbb7e33cf9135a346fc2505cc0e87e853.zip
Warning: this branch commit is largely untested, and known to throw exceptions as database structure retrieval is currently missing!
Further work on SPMySQLFramework integration: - Improve SPMySQL framework build settings including correct ppc builds and a Distribution configuration for the build distributions to match - Add new convenience querying and result methods to the framework - Amend Sequel Pro source to use the new SPMySQL.framework methods everywhere, replacing MCPKit methods where they differ and improving some functions - Remove MCPKit from the source - Fix a number of warnings on Release-style builds
Diffstat (limited to 'Source/SPUserManager.m')
-rw-r--r--Source/SPUserManager.m56
1 files changed, 13 insertions, 43 deletions
diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m
index 83f0a12f..3b3add1e 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,11 @@ 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"];
+ [usersResultArray addObjectsFromArray:[result getAllRows]];
[self _initializeTree:usersResultArray];
@@ -173,8 +162,8 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
[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]];
@@ -193,7 +182,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn";
[result setReturnDataAsStrings:YES];
- while ((privRow = [result fetchRowAsArray]))
+ while ((privRow = [result getRowAsArray]))
{
privKey = [NSMutableString stringWithString:[privRow objectAtIndex:0]];
@@ -308,15 +297,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 +358,10 @@ 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];
- 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)
@@ -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;