#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    14
    Rep Power
    0

    special characters needing special treatment...


    What special characters do you have to test for or disallow in MySQL? I was rather horrified to discover by accident that ...

    delete from questionnaire where questname like 'EDV_Aug02';

    ...deletes questionnaires with names of both 'EDV_Aug02' and 'EDV Aug02', which I hadn't intended. I don't allow the ' character in questionnaire names as it confuses my javascript, but at the moment, they can include everything else.

    Thanks for any help!
  2. #2
  3. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    30
    The underscore _ has a special meaning in MySQL, which is why what you described happened. The _ is a wildcard for one character. If you escape it with double backslashes it will be treated as a part of the string (\\_). See this for more information -> http://www.mysql.com/doc/en/Pattern_matching.html

    //NoXcuz
    UN*X is sexy!
    who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    22
    And... if you didn't intend to use _ as a wildcard, why are you using 'like' and not =? You didn't use any other wildcards...
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    14
    Rep Power
    0
    Ah, so would it be ok to leave in any symbols if I used = not like? I didn't know about the difference.

    Thanks
  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    22
    Yes. like is for simple pattern matching. = is for comparison

IMN logo majestic logo threadwatch logo seochat tools logo