aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableData.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/SPTableData.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/SPTableData.m')
-rw-r--r--Source/SPTableData.m62
1 files changed, 28 insertions, 34 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 297718b9..5f043548 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -30,6 +30,8 @@
#import "SPAlertSheets.h"
#import "RegexKitLite.h"
#import "SPServerSupport.h"
+#import "SPMySQL.h"
+#include <pthread.h>
@interface SPTableData (PrivateAPI)
@@ -70,7 +72,7 @@
*
* @param theConnection The used connection for the SPDatabaseDocument
*/
-- (void) setConnection:(MCPConnection *)theConnection
+- (void) setConnection:(SPMySQLConnection *)theConnection
{
mySQLConnection = theConnection;
[mySQLConnection retain];
@@ -476,7 +478,7 @@
[constraints removeAllObjects];
// Retrieve the CREATE TABLE syntax for the table
- MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE %@", [tableName backtickQuotedString]]];
+ SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE %@", [tableName backtickQuotedString]]];
[theResult setReturnDataAsStrings:YES];
// Check for any errors, but only display them if a connection still exists
@@ -485,10 +487,10 @@
SPBeginAlertSheet(NSLocalizedString(@"Error retrieving table information", @"error retrieving table information message"), NSLocalizedString(@"OK", @"OK button"),
nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving the information for table '%@'. Please try again.\n\nMySQL said: %@", @"error retrieving table information informative message"),
- tableName, [mySQLConnection getLastErrorMessage]]);
+ tableName, [mySQLConnection lastErrorMessage]]);
// If the current table doesn't exist anymore reload table list
- if([mySQLConnection getLastErrorID] == 1146) {
+ if([mySQLConnection lastErrorID] == 1146) {
// Release the table loading lock to allow reselection/reloading to requery the database.
pthread_mutex_unlock(&dataProcessingLock);
@@ -503,8 +505,8 @@
}
// Retrieve the table syntax string
- NSArray *syntaxResult = [theResult fetchRowAsArray];
- NSArray *resultFieldNames = [theResult fetchFieldNames];
+ NSArray *syntaxResult = [theResult getRowAsArray];
+ NSArray *resultFieldNames = [theResult fieldNames];
// Only continue if syntaxResult is not nil. This accommodates causes where the above query caused the
// connection reconnect dialog to appear and the user chose to close the connection.
@@ -798,7 +800,6 @@
NSMutableArray *tableColumns;
NSDictionary *resultRow;
NSMutableDictionary *tableColumn, *viewData;
- NSUInteger i;
BOOL changeEncoding = ![[mySQLConnection encoding] isEqualToString:@"utf8"];
// Catch unselected views and return nil
@@ -811,7 +812,7 @@
}
// Retrieve the CREATE TABLE syntax for the table
- MCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@",
+ SPMySQLResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@",
[viewName backtickQuotedString]
]];
[theResult setReturnDataAsStrings:YES];
@@ -822,7 +823,7 @@
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"),
nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),
- [mySQLConnection getLastErrorMessage]]);
+ [mySQLConnection lastErrorMessage]]);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
return nil;
@@ -830,7 +831,7 @@
// Retrieve the table syntax string
if (tableCreateSyntax) [tableCreateSyntax release], tableCreateSyntax = nil;
- NSString *syntaxString = [[theResult fetchRowAsArray] objectAtIndex:1];
+ NSString *syntaxString = [[theResult getRowAsArray] objectAtIndex:1];
// A NULL value indicates that the user does not have permission to view the syntax
if ([syntaxString isNSNull]) {
@@ -856,20 +857,18 @@
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"),
nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),
- [mySQLConnection getLastErrorMessage]]);
+ [mySQLConnection lastErrorMessage]]);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
return nil;
}
// Loop through the fields and capture details
- if ([theResult numOfRows]) [theResult dataSeek:0];
tableColumns = [[NSMutableArray alloc] init];
tableColumn = [[NSMutableDictionary alloc] init];
fieldParser = [[SPSQLParser alloc] init];
- for ( i = 0; i < [theResult numOfRows] ; i++ ) {
+ for (resultRow in theResult) {
[tableColumn removeAllObjects];
- resultRow = [theResult fetchRowAsDictionary];
// Add the column index and name
[tableColumn setObject:[NSString stringWithFormat:@"%llu", (unsigned long long)[tableColumns count]] forKey:@"datacolumnindex"];
@@ -938,7 +937,7 @@
[escapedTableName replaceOccurrencesOfString:@"\\" withString:@"\\\\" options:0 range:NSMakeRange(0, [escapedTableName length])];
[escapedTableName replaceOccurrencesOfString:@"'" withString:@"\\\'" options:0 range:NSMakeRange(0, [escapedTableName length])];
- MCPResult *tableStatusResult = nil;
+ SPMySQLResult *tableStatusResult = nil;
if ([tableListInstance tableType] == SPTableTypeProc) {
NSMutableString *escapedDatabaseName = [NSMutableString stringWithString:[tableDocumentInstance database]];
@@ -967,7 +966,7 @@
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"),
nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"),
- [mySQLConnection getLastErrorMessage]]);
+ [mySQLConnection lastErrorMessage]]);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
pthread_mutex_unlock(&dataProcessingLock);
@@ -975,7 +974,7 @@
}
// Retrieve the status as a dictionary and set as the cache
- [status setDictionary:[tableStatusResult fetchRowAsDictionary]];
+ [status setDictionary:[tableStatusResult getRowAsDictionary]];
if ([tableListInstance tableType] == SPTableTypeTable) {
@@ -1001,10 +1000,10 @@
// [status objectForKey:@"Rows"] is NULL then try to get the number of rows via SELECT COUNT(1) FROM `foo`
// this happens e.g. for db "information_schema"
- if([[status objectForKey:@"Rows"] isKindOfClass:[NSNull class]]) {
+ if([[status objectForKey:@"Rows"] isNSNull]) {
tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@", [escapedTableName backtickQuotedString] ]];
if (![mySQLConnection queryErrored])
- [status setObject:[[tableStatusResult fetchRowAsArray] objectAtIndex:0] forKey:@"Rows"];
+ [status setObject:[[tableStatusResult getRowAsArray] objectAtIndex:0] forKey:@"Rows"];
[status setObject:@"y" forKey:@"RowsCountAccurate"];
}
@@ -1042,7 +1041,7 @@
[mySQLConnection setEncoding:@"utf8"];
}
- MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */",
+ SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */",
[[tableListInstance tableName] tickQuotedString]]];
[theResult setReturnDataAsStrings:YES];
@@ -1052,7 +1051,7 @@
SPBeginAlertSheet(NSLocalizedString(@"Error retrieving trigger information", @"error retrieving trigger information message"), NSLocalizedString(@"OK", @"OK button"),
nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving the trigger information for table '%@'. Please try again.\n\nMySQL said: %@", @"error retrieving table information informative message"),
- [tableListInstance tableName], [mySQLConnection getLastErrorMessage]]);
+ [tableListInstance tableName], [mySQLConnection lastErrorMessage]]);
if (triggers) [triggers release], triggers = nil;
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
@@ -1061,11 +1060,8 @@
return NO;
}
- if (triggers) [triggers release];
- triggers = [[NSMutableArray alloc] init];
- for (NSUInteger i=0; i<[theResult numOfRows]; i++) {
- [triggers addObject:[theResult fetchRowAsDictionary]];
- }
+ [triggers removeAllObjects];
+ [triggers addObjectsFromArray:[theResult getAllRows]];
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
@@ -1298,9 +1294,7 @@
NSString *selectedTable = [tableListInstance tableName];
if(![selectedTable length]) return nil;
- MCPResult *r;
- NSArray *resultRow;
- NSUInteger i;
+ SPMySQLResult *r;
NSMutableArray *keyColumns = [NSMutableArray array];
// select all columns that are primary keys
@@ -1308,22 +1302,22 @@
r = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@ /*!50003 WHERE `key` = 'PRI'*/", [selectedTable backtickQuotedString]]];
[r setReturnDataAsStrings:YES];
- if([r numOfRows] < 1) {
+ if ([r numberOfRows] < 1) {
if (changeEncoding && [mySQLConnection isConnected]) [mySQLConnection restoreStoredEncoding];
return nil;
}
if ([mySQLConnection queryErrored]) {
if ([mySQLConnection isConnected]) {
- NSRunAlertPanel(@"Error", [NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving the PRIMARY KEY data:\n\n%@",@"message when the query that fetches the primary keys fails"), [mySQLConnection getLastErrorMessage]], @"OK", nil, nil);
+ NSRunAlertPanel(@"Error", [NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving the PRIMARY KEY data:\n\n%@",@"message when the query that fetches the primary keys fails"), [mySQLConnection lastErrorMessage]], @"OK", nil, nil);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
return nil;
}
- for( i = 0; i < [r numOfRows]; i++ ) {
- resultRow = [r fetchRowAsArray];
+ for (NSArray *resultRow in r) {
+
// check if the row is indeed a key (for MySQL servers before 5.0.3)
if ([[NSArrayObjectAtIndex(resultRow ,3) description] isEqualToString:@"PRI"]) {
[keyColumns addObject:[NSArrayObjectAtIndex(resultRow ,0) description]];
@@ -1382,4 +1376,4 @@
#endif
-@end \ No newline at end of file
+@end