aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableData.m
diff options
context:
space:
mode:
authorjakob <jakob@eggerapps.at>2009-03-24 18:43:58 +0000
committerjakob <jakob@eggerapps.at>2009-03-24 18:43:58 +0000
commita23bb9169015b21191bf072a7da6c668991907df (patch)
treee9077cf72f071f9f46299669f6535987b56ae402 /Source/SPTableData.m
parentd09e3a2a855c80a5a69017a53a7d62e5324f0c26 (diff)
downloadsequelpro-a23bb9169015b21191bf072a7da6c668991907df.tar.gz
sequelpro-a23bb9169015b21191bf072a7da6c668991907df.tar.bz2
sequelpro-a23bb9169015b21191bf072a7da6c668991907df.zip
- fixed issue #203 (backticks in identifiers not supported)
- added a backtickQuotedString: method to SPStringAdditions - created the file SPArrayAdditions for a componentsJoinedAndBacktickQuoted: method In the future, we should use backtickQuotedString: to quote identifiers like this: [NSString stringWithFormat:@"SELECT * FROM %@", [tableName backtickQuotedString]]
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r--Source/SPTableData.m29
1 files changed, 24 insertions, 5 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 7561b1ce..1b4893ae 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -28,6 +28,7 @@
#import "SPSQLParser.h"
#import "TableDocument.h"
#import "TablesList.h"
+#import "SPStringAdditions.h"
@implementation SPTableData
@@ -259,7 +260,9 @@
if ([tableName isEqualToString:@""] || !tableName) return nil;
// Retrieve the CREATE TABLE syntax for the table
- CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE `%@`", tableName]];
+ CMMCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@",
+ [tableName backtickQuotedString]
+ ]];
// Check for any errors, but only display them if a connection still exists
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -302,9 +305,25 @@
// If the first character is a backtick, this is a field definition.
if ([fieldsParser characterAtIndex:0] =='`') {
-
- // Capture the area between the two backticks as the name
- [tableColumn setObject:[fieldsParser trimAndReturnStringFromCharacter:'`' toCharacter:'`' trimmingInclusively:YES returningInclusively:NO ignoringQuotedStrings:NO] forKey:@"name"];
+
+ // Capture the area between the two backticks as the name
+ NSString *fieldName = [fieldsParser trimAndReturnStringFromCharacter: '`'
+ toCharacter: '`'
+ trimmingInclusively: YES
+ returningInclusively: NO
+ ignoringQuotedStrings: NO];
+ //if the next character is again a backtick, we stumbled across an escaped backtick. we have to continue parsing.
+ while ([fieldsParser characterAtIndex:0] =='`') {
+ fieldName = [fieldName stringByAppendingFormat: @"`%@",
+ [fieldsParser trimAndReturnStringFromCharacter: '`'
+ toCharacter: '`'
+ trimmingInclusively: YES
+ returningInclusively: NO
+ ignoringQuotedStrings: NO]
+ ];
+ }
+
+ [tableColumn setObject:fieldName forKey:@"name"];
// Split the remaining field definition string by spaces and process
[tableColumn addEntriesFromDictionary:[self parseFieldDefinitionStringParts:[fieldsParser splitStringByCharacter:' ' skippingBrackets:YES]]];
@@ -416,7 +435,7 @@
if ([viewName isEqualToString:@""] || !viewName) return nil;
// Retrieve the SHOW COLUMNS syntax for the table
- CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM `%@`", viewName]];
+ CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [viewName backtickQuotedString]]];
// Check for any errors, but only display them if a connection still exists
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {