#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Escape brackets in values query


    Hi,
    I need to insert several rows using VALUES, however some fields contain text containing brackets. I cannot seem to escape these. Is there another way without using several separated INSERT statements?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,923
    Rep Power
    1045
    Hi,

    I really wonder what you mean. How would a parenthesis (I guess that's what you mean) in a string literal ever interfere with the surrounding query? Can you write down an example?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,027
    Rep Power
    4210
    Originally Posted by bitstomper
    ...some fields contain text containing brackets. I cannot seem to escape these.
    neither brackets nor parentheses need escaping... in fact, the only character that needs escaping is the same quote that you use to delimit the value

    as jacques said, let's see an example
    r937.com | rudy.ca
    please visit Simply SQL and buy my book
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    Originally Posted by r937
    neither brackets nor parentheses need escaping... in fact, the only character that needs escaping is the same quote that you use to delimit the value

    as jacques said, let's see an example
    INSERT INTO table VALUES ('a','b','(text) text'), ('a','b','(text) text')
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,777
    Rep Power
    348
    Originally Posted by bitstomper
    INSERT INTO table VALUES ('a','b','(text) text'), ('a','b','(text) text')
    Works for me: http://sqlfiddle.com/#!2/cd0d9/1
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    Hmmm, ok thanks. Apparently there is another issue why the query is not executing. I will search further..
    Thank yoiu all for your help and suggestions.
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,923
    Rep Power
    1045
    It might be a good idea to post the exact error message rather than guessing what it means.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    there is no error message
  16. #9
  17. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,923
    Rep Power
    1045
    So what is the problem? Do you want us to guess?

    There's obviously something you don't like about how MySQL reacts to the query. What is that? What makes you think there's a problem?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    never mind. Previously I said the query is not executing. I will work it out now I know it is not the brackets.

IMN logo majestic logo threadwatch logo seochat tools logo