Re: MySQL Escaped String
Re: MySQL Escaped String
- Subject: Re: MySQL Escaped String
- From: Robin Hermann <email@hidden>
- Date: Tue, 11 Jan 2005 18:31:44 +0100
Thanks. My head spins...
I just followed the documentation, which states that cString is or will
be deprecated and that I should use UTF8String instead. And so I did
;-)
stringWithCString works fine for me though. Is there a way to catch
this kind of thing?
Robin Hermann
On 11 jan 2005, at 17:08, Will Mason wrote:
I think you have an encoding problem in your code.
- (NSString *)escapeStringWithMySQL:(NSString *)stringToEscape
{
unsigned long len = [stringToEscape length];
unsigned long new_len;
char *new_str;
const char *str = [stringToEscape UTF8String];
Here you're getting a UTF-8 encoded sequence of bytes. That's good.
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];
Now, you're claiming that the UTF-8 sequence is actually encoded using
the default encoding of whatever system is running the code. You could
have a conflict between the two encodings. Why not just continue to
claim that the sequence is UTF-8 here? Like:
NSString* escapedString = [NSString stringWithUTF8String: new_str];
return escapedString;
}
Will
_______________________________________________
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