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

Escaping Strings with Single Quotes #4

Open
mphasize opened this issue Sep 6, 2012 · 2 comments
Open

Escaping Strings with Single Quotes #4

mphasize opened this issue Sep 6, 2012 · 2 comments

Comments

@mphasize
Copy link

mphasize commented Sep 6, 2012

Hi,

I'm using this php client and I want to insert some new data records into my CartoDB table which contain single-quotes. I have seen, that the classes don't provide any solutions for this yet, so I'm trying to work out my own escaping solution.

As discussed here, a simple Backspace-Escape should work for single quotes (and from what I know this usually works fine):
http://support.cartodb.com/discussions/problems/50-problem-with-apostrophe

But something seems to get messed up anyway and I just get a syntax error.

Here's the query I'm passing to the runSql Function:

INSERT INTO handel_v2 (the_geom,crm_id,firma) VALUES(GEOMETRYFROMTEXT('POINT(3.7941725 41.9231994)', 4326),'internal ID','Name with' single-quote');
SELECT handel_v2.cartodb_id as id, handel_v2.* FROM handel_v2 WHERE cartodb_id = currval('public.handel_v2_cartodb_id_seq');

Any Ideas? (Anything else I can provide to track this down?)
Thanks!
M

@mphasize
Copy link
Author

mphasize commented Sep 6, 2012

Ok, I just found a similar (and already fixed) issue in the Ruby client for CartoDB and the solution seems to be to escape single quotes with another single quote.

function escape_query($str) {
    return strtr($str, array(
        "'"  => "''"
        // which other characters need to be escaped?
    ));
}

It would be nice, when the client classes could handle this automatically, at least in function like insertRow()

Best!
M

@jatorre
Copy link
Contributor

jatorre commented Sep 6, 2012

The library I think is quite outdated now on probably is missing lot of these things.

Actually if you want to propose pull requests that would be awesome!

On Sep 6, 2012, at 8:45 AM, Marcus wrote:

Ok, I just found a similar (and already fixed) issue in the Ruby client for CartoDB and the solution seems to be to escape single quotes with another single quote.

function escape_query($str) {
return strtr($str, array(
"'" => "''"
// which other characters need to be escaped?
));
}

Reply to this email directly or view it on GitHub.

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

No branches or pull requests

2 participants