ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to escape quotes in exp_query?

November 25, 2008 6:01pm

Subscribe [3]
  • #1 / Nov 25, 2008 6:01pm

    juro

    118 posts

    Hi,
    I am using the exp_query to pull information for a csv. Now some fields have quotes, that I have to replace them, so that PHP does not throw errors. How can I escape the necessary quotes in the query? This is my exp_query tag:

    exp:query sql="SELECT replace(company, '\\"', '\\\"') AS com 
    FROM exp_freeform_entries WHERE form_name='someform'" disable="search"}

    Using this I get this error

    SELECT replace(company, ‘\

    So obviously EE is not escaping the quote.

    How can I force it to?

    juro

    [Mod edit: moved to Technical Support forum]

  • #2 / Nov 29, 2008 3:16pm

    juro

    118 posts

    I have spent money on this product and I would appreciate an answer.

  • #3 / Nov 29, 2008 5:35pm

    Erdal Demirtas

    84 posts

    I had the same problem two weeks ago.

    I tried lots of things and read the manual, but without success.

    At the end I used pure php-mysql.

    I hope you will get an answer which enables you to use query module.

  • #4 / Dec 02, 2008 5:55pm

    juro

    118 posts

    Thankx for the answer. That is what I did as well.

    Took me 15 min.

  • #5 / Dec 04, 2008 9:14am

    goodbytes

    49 posts

    Thankx for the answer. That is what I did as well.

    Took me 15 min.

    Can you let me know how to best do this using php/mysql?
    I’m having the exact same problem…

  • #6 / Dec 04, 2008 6:00pm

    Erdal Demirtas

    84 posts

    Hi goodbytes,

    I don’t know if it is the best way, but here is how I have done with php/mysql.

  • #7 / Dec 05, 2008 10:27am

    goodbytes

    49 posts

    I see. Thanks for the link.

    The problem is that my query is as follows:
    {exp:query sql="select cat_id from exp_gallery_categories where cat_name='{child_category_name}’”}

    the child_cateogory_name needs to be filtered for single quotes…

  • #8 / Dec 06, 2008 12:07pm

    Derek Jones

    7561 posts

    I have spent money on this product and I would appreciate an answer.

    As noted in the heading of the community forums, EllisLab does not provide technical support in these forums.  Just thought I’d mention so you do not have mistaken expectations.  For your support issues as a license holder, you should post to the Technical Support forums.

    The template parser does not recognize escaped quotes.  e.g.

    {exp:foo bar="\\""}

    Will be read with the parameter bar set to \.  It’s very flexible, but the template parser is not a full-blown scripting engine - the overhead that would be required to parse such things would be prohibitive, as it’s using using an external library (PCRE) of an interpreted language (PHP) to do these things on the fly.  In your case with this type of query, using PHP as Erdal suggested, though you could greatly simplify things by using EE’s built in Database class, is one option.  Another option is to not escape the quotes in the query with REPLACE, but to handle it on output, either with a plugin or with PHP in your template, operating on the contents that the query outputs.

    As an aside, aren’t double quotes in CSV escaped by putting two quotes together, and not by using backslashes?

  • #9 / Dec 06, 2008 2:00pm

    juro

    118 posts

    Thank you for the answer, Derek. Last time I put a “general” support question into the technical forum, I was told it belongs in the “How-To” and it was moved.

    Anyway, as I wrote, I have solved it without using any EE.

  • #10 / Dec 06, 2008 2:20pm

    Derek Jones

    7561 posts

    It’s fine, juro, we don’t mind moving threads out of the official support forums if they happen to not be something we can provide staff support for.  But staff does not provide support in the community forums, so getting upset because you aren’t receiving support there is nonproductive.  As this question involved an error you were receiving using a first party module, it would have been fine to post here.

    In any case, I’m glad you found a solution!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases