Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an escape function #4

Closed
goodman-capu opened this issue Feb 20, 2017 · 6 comments
Closed

Provide an escape function #4

goodman-capu opened this issue Feb 20, 2017 · 6 comments
Assignees

Comments

@goodman-capu
Copy link

goodman-capu commented Feb 20, 2017

The building of query string lacks escaping of special characters. I suggest adding a public function like this and apply it to NSString (SQLQueries) functions.

@oleghnidets
Copy link
Owner

I guess I will use the native MySQL C API functions: mysql_real_escape_string and/or mysql_real_escape_string_quote.

@oleghnidets
Copy link
Owner

oleghnidets commented Feb 22, 2017

Hi there,
Check the latest release. I added a public method -escapedUsingEncoding. Although, I am still in progress due to lack of the time. The next step is applying the method to a query.

@goodman-capu
Copy link
Author

goodman-capu commented Feb 22, 2017

There are problem with this function: Not every character's length is 2.
For example, if you run this code:
NSLog(@"%@", [@"好" escapedUsingEncoding:NSUTF8StringEncoding]);
or this:
NSLog(@"%@", [@"😁" escapedUsingEncoding:NSUTF8StringEncoding]);
The app would crash, for some Chinese characters' length is 3, and for some Emoji it's 4.

@oleghnidets
Copy link
Owner

oleghnidets commented Feb 22, 2017

You passed an incorrect enum type. Due to different char sets support I had to define own type CharsetEncoding. Please, try CharsetEncodingUTF8.

@goodman-capu
Copy link
Author

Opps, my bad. It worked fine.

@oleghnidets
Copy link
Owner

Well, public method added. The developer is responsible to call -escapedUsingEncoding if needed (like in MySQL C API mysql_real_escape_string()). The issue is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants