aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSQLExporter.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/SPSQLExporter.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/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"]]];
}
}