aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSQLExporter.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/SPSQLExporter.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/SPSQLExporter.m')
-rw-r--r--Source/SPSQLExporter.m76
1 files changed, 38 insertions, 38 deletions
diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m
index 66411932..6090b709 100644
--- a/Source/SPSQLExporter.m
+++ b/Source/SPSQLExporter.m
@@ -23,8 +23,6 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
-#import <MCPKit/MCPKit.h>
-
#import "SPSQLExporter.h"
#import "SPTablesList.h"
#import "SPFileHandle.h"
@@ -32,6 +30,7 @@
#import "SPExportFile.h"
#import "SPTableData.h"
#import "RegexKitLite.h"
+#import "SPMySQL.h"
@interface SPSQLExporter ()
@@ -88,8 +87,8 @@
sqlTableDataInstance = [[[SPTableData alloc] init] autorelease];
[sqlTableDataInstance setConnection:connection];
- MCPResult *queryResult;
- MCPStreamingResult *streamingResult;
+ SPMySQLResult *queryResult;
+ SPMySQLStreamingResult *streamingResult;
NSArray *row;
NSString *tableName;
@@ -228,8 +227,8 @@
[queryResult setReturnDataAsStrings:YES];
- if ([queryResult numOfRows]) {
- tableDetails = [[NSDictionary alloc] initWithDictionary:[queryResult fetchRowAsDictionary]];
+ if ([queryResult numberOfRows]) {
+ tableDetails = [[NSDictionary alloc] initWithDictionary:[queryResult getRowAsDictionary]];
if ([tableDetails objectForKey:@"Create View"]) {
[viewSyntaxes setValue:[[[[tableDetails objectForKey:@"Create View"] copy] autorelease] createViewSyntaxPrettifier] forKey:tableName];
@@ -245,9 +244,9 @@
}
if ([connection queryErrored]) {
- [errors appendFormat:@"%@\n", [connection getLastErrorMessage]];
+ [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n\n\n", [connection getLastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n\n\n", [connection lastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
continue;
}
@@ -298,11 +297,11 @@
}
// Retrieve the number of rows in the table for progress bar drawing
- NSArray *rowArray = [[connection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@", [tableName backtickQuotedString]]] fetchRowAsArray];
+ NSArray *rowArray = [[connection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@", [tableName backtickQuotedString]]] getRowAsArray];
if ([connection queryErrored] || ![rowArray count]) {
- [errors appendFormat:@"%@\n", [connection getLastErrorMessage]];
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n\n\n", [connection getLastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
+ [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n\n\n", [connection lastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
continue;
}
@@ -314,7 +313,7 @@
// Set up a result set in streaming mode
streamingResult = [[connection streamingQueryString:[NSString stringWithFormat:@"SELECT * FROM %@", [tableName backtickQuotedString]] useLowMemoryBlockingStreaming:([self exportUsingLowMemoryBlockingStreaming])] retain];
- NSArray *fieldNames = [streamingResult fetchFieldNames];
+ NSArray *fieldNames = [streamingResult fieldNames];
// Inform the delegate that we are about to start writing data for the current table
[delegate performSelectorOnMainThread:@selector(sqlExportProcessWillBeginWritingData:) withObject:self waitUntilDone:NO];
@@ -338,7 +337,7 @@
// Inform the delegate that we are about to start writing the data to disk
[delegate performSelectorOnMainThread:@selector(sqlExportProcessWillBeginWritingData:) withObject:self waitUntilDone:NO];
- while ((row = [streamingResult fetchNextRowAsArray]))
+ while ((row = [streamingResult getRowAsArray]))
{
// Check for cancellation flag
if ([self isCancelled]) {
@@ -380,7 +379,7 @@
id object = NSArrayObjectAtIndex(row, t);
// Add NULL values directly to the output row
- if ([object isMemberOfClass:[NSNull class]]) {
+ if (object == [NSNull null]) {
[sqlString appendString:@"NULL"];
}
// If the field is off type BIT, the values need a binary prefix of b'x'.
@@ -391,7 +390,7 @@
else if ([object isKindOfClass:[NSData class]]) {
if ([self sqlOutputEncodeBLOBasHex]) {
- [sqlString appendFormat:@"X'%@'", [connection prepareBinaryData:object]];
+ [sqlString appendString:[connection escapeAndQuoteData:object]];
}
else {
[sqlString appendString:@"'"];
@@ -411,8 +410,8 @@
}
// GEOMETRY data types directly as hex data
- else if ([object isKindOfClass:[MCPGeometryData class]]) {
- [sqlString appendFormat:@"X'%@'", [connection prepareBinaryData:[object data]]];
+ else if ([object isKindOfClass:[SPMySQLGeometryData class]]) {
+ [sqlString appendString:[connection escapeAndQuoteData:[object data]]];
}
else {
[cellValue setString:[object description]];
@@ -427,9 +426,7 @@
}
// Otherwise add a quoted string with special characters escaped
else {
- [sqlString appendString:@"'"];
- [sqlString appendString:[connection prepareString:cellValue]];
- [sqlString appendString:@"'"];
+ [sqlString appendString:[connection escapeAndQuoteString:cellValue]];
}
}
}
@@ -488,10 +485,10 @@
}
if ([connection queryErrored]) {
- [errors appendFormat:@"%@\n", [connection getLastErrorMessage]];
+ [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
if ([self sqlOutputIncludeErrors]) {
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection getLastErrorMessage]]
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection lastErrorMessage]]
dataUsingEncoding:NSUTF8StringEncoding]];
}
}
@@ -501,12 +498,12 @@
[queryResult setReturnDataAsStrings:YES];
- if ([queryResult numOfRows]) {
+ if ([queryResult numberOfRows]) {
[metaString setString:@"\n"];
[metaString appendString:@"DELIMITER ;;\n"];
- for (s = 0; s < [queryResult numOfRows]; s++)
+ for (s = 0; s < [queryResult numberOfRows]; s++)
{
// Check for cancellation flag
if ([self isCancelled]) {
@@ -516,7 +513,7 @@
return;
}
- NSDictionary *triggers = [[NSDictionary alloc] initWithDictionary:[queryResult fetchRowAsDictionary]];
+ NSDictionary *triggers = [[NSDictionary alloc] initWithDictionary:[queryResult getRowAsDictionary]];
// Definer is user@host but we need to escape it to `user`@`host`
NSArray *triggersDefiner = [[triggers objectForKey:@"Definer"] componentsSeparatedByString:@"@"];
@@ -541,10 +538,10 @@
}
if ([connection queryErrored]) {
- [errors appendFormat:@"%@\n", [connection getLastErrorMessage]];
+ [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
if ([self sqlOutputIncludeErrors]) {
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection getLastErrorMessage]]
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection lastErrorMessage]]
dataUsingEncoding:NSUTF8StringEncoding]];
}
}
@@ -598,7 +595,7 @@
[queryResult setReturnDataAsStrings:YES];
- if ([queryResult numOfRows]) {
+ if ([queryResult numberOfRows]) {
[metaString setString:@"\n"];
[metaString appendFormat:@"--\n-- Dumping routines (%@) for database %@\n--\nDELIMITER ;;\n\n", procedureType,
@@ -606,7 +603,7 @@
// Loop through the definitions, exporting if enabled
- for (s = 0; s < [queryResult numOfRows]; s++)
+ for (s = 0; s < [queryResult numberOfRows]; s++)
{
// Check for cancellation flag
if ([self isCancelled]) {
@@ -616,7 +613,7 @@
return;
}
- NSDictionary *proceduresList = [[NSDictionary alloc] initWithDictionary:[queryResult fetchRowAsDictionary]];
+ NSDictionary *proceduresList = [[NSDictionary alloc] initWithDictionary:[queryResult getRowAsDictionary]];
NSString *procedureName = [NSString stringWithFormat:@"%@", [proceduresList objectForKey:@"Name"]];
// Only proceed if the item is in the list of items
@@ -668,20 +665,20 @@
[NSArrayObjectAtIndex(procedureDefiner, 1) backtickQuotedString]
];
- MCPResult *createProcedureResult = [connection queryString:[NSString stringWithFormat:@"/*!50003 SHOW CREATE %@ %@ */;;", procedureType,
+ SPMySQLResult *createProcedureResult = [connection queryString:[NSString stringWithFormat:@"/*!50003 SHOW CREATE %@ %@ */;;", procedureType,
[procedureName backtickQuotedString]]];
[createProcedureResult setReturnDataAsStrings:YES];
if ([connection queryErrored]) {
- [errors appendFormat:@"%@\n", [connection getLastErrorMessage]];
+ [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
if ([self sqlOutputIncludeErrors]) {
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection getLastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection lastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
}
[proceduresList release];
continue;
}
- NSDictionary *procedureInfo = [[NSDictionary alloc] initWithDictionary:[createProcedureResult fetchRowAsDictionary]];
+ NSDictionary *procedureInfo = [[NSDictionary alloc] initWithDictionary:[createProcedureResult getRowAsDictionary]];
[metaString appendFormat:@"/*!50003 SET SESSION SQL_MODE=\"%@\"*/;;\n", [procedureInfo objectForKey:@"sql_mode"]];
@@ -721,10 +718,10 @@
}
if ([connection queryErrored]) {
- [errors appendFormat:@"%@\n", [connection getLastErrorMessage]];
+ [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
if ([self sqlOutputIncludeErrors]) {
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection getLastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection lastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]];
}
}
@@ -813,7 +810,10 @@
for (j = 0; j < [[column objectForKey:@"values"] count]; j++)
{
- [fieldString appendFormat:@"'%@'%@", [connection prepareString:NSArrayObjectAtIndex([column objectForKey:@"values"], j)], ((j + 1) == [[column objectForKey:@"values"] count]) ? @"" : @","];
+ [fieldString appendString:[connection escapeAndQuoteString:NSArrayObjectAtIndex([column objectForKey:@"values"], j)]];
+ if ((j + 1) != [[column objectForKey:@"values"] count]) {
+ [fieldString appendString:@","];
+ }
}
[fieldString appendString:@")"];
@@ -841,7 +841,7 @@
[fieldString appendString:@" DEFAULT CURRENT_TIMESTAMP"];
}
else {
- [fieldString appendFormat:@" DEFAULT '%@'", [connection prepareString:[column objectForKey:@"default"]]];
+ [fieldString appendFormat:@" DEFAULT %@", [connection escapeAndQuoteString:[column objectForKey:@"default"]]];
}
}