How to escape quotes in exp_query?
Posted: 25 November 2008 04:01 PM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  160
Joined  10-25-2007

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]

Profile
 
 
Posted: 29 November 2008 01:16 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  160
Joined  10-25-2007

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

Profile
 
 
Posted: 29 November 2008 03:35 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  91
Joined  01-30-2008

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.

Profile
 
 
Posted: 02 December 2008 03:55 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  160
Joined  10-25-2007

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

Took me 15 min.

Profile
 
 
Posted: 04 December 2008 07:14 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
RankRank
Total Posts:  102
Joined  02-19-2007
juro - 02 December 2008 03:55 PM

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…

Profile
 
 
Posted: 04 December 2008 04:00 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  91
Joined  01-30-2008

Hi goodbytes,

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

Profile
 
 
Posted: 05 December 2008 08:27 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
RankRank
Total Posts:  102
Joined  02-19-2007

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…

Profile
 
 
Posted: 06 December 2008 10:07 AM   [ Ignore ]   [ # 7 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16398
Joined  06-03-2002
juro - 29 November 2008 01:16 PM

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?

 Signature 
Profile
MSG
 
 
Posted: 06 December 2008 12:00 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  160
Joined  10-25-2007

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.

Profile
 
 
Posted: 06 December 2008 12:20 PM   [ Ignore ]   [ # 9 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16398
Joined  06-03-2002

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!

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66391 Total Logged-in Users: 43
Total Topics: 84715 Total Anonymous Users: 20
Total Replies: 454696 Total Guests: 213
Total Posts: 539411    
Members ( View Memberlist )