Re: MySQL Escaped String
Re: MySQL Escaped String
- Subject: Re: MySQL Escaped String
- From: Robin Hermann <email@hidden>
- Date: Tue, 11 Jan 2005 15:20:48 +0100
Dear Joakim,
Thanks for your solution.
I solved it another way, using mysl_escape_string(), which is probably more complete (taken from the PHP source).
Works perfectly ;-)
- (NSString *)escapeStringWithMySQL:(NSString *)stringToEscape
{
unsigned long len = [stringToEscape length];
unsigned long new_len;
char *new_str;
const char *str = [stringToEscape UTF8String];
new_str = malloc((len*2) + 1);
new_len = mysql_escape_string(new_str, str, len);
new_str = realloc(new_str, new_len + 1);
NSString *escapedString = [NSString stringWithCString:new_str];
return escapedString;
}
Regards,
Robin Hermann
On 11 jan 2005, at 14:44, Joakim Danielson wrote:
Hi
You should insert an extra ' in front of the first ' instead of a \. So your code should be replaceOccurenceOfString:@"'" withString:@"''"...
Joakim
On 2005-01-11, at 08.42, Robin Hermann wrote:
Hi List,
I'm new to the list and a newbie to Cocoa.
Probably an easy one, but couldn't find it on the web: I need een escaped string for MySQL
I tried this:
<x-tad-bigger>
NSMutableString *dataField = [NSMutableString stringWithCapacity:10];
[dataField setString: [dataRecord objectForKey:corrField]];
[dataField replaceOccurrencesOfString:@"'" withString:@"\'" options:NSLiteralSearch range:NSMakeRange(0, [dataField length]) ];</x-tad-bigger>
But that doesn't work. How should I do it?
Robin Hermann _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden