Escaping characters in MySQL

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Escaping characters in MySQL

    CFMX works fine with MySQL database 99% of the time. However, when a field in
    a query includes an apostrophe, CF is escaping it in the Windows SQL server
    mode, ie by doubling the apostrophe. MySQL requires a backslash to achieve
    this, and consequently any queries involving escaped characters are failing
    although the data might actually tally. There must (surely) be a simple setup
    for this but I cant find it, any helpers please?

    rolty Guest

  2. Similar Questions and Discussions

    1. cf with mysql, escaping chars
      Hi all, I am converting a rather larger parsing program from php to coldfusion. So far so good, until I found where it inserts data into the...
    2. Escaping special characters
      How do I escape ' and other special characters? I use addslashes but that does not seem to prevent the MSSQL db from complianing. Please help. ...
    3. Escaping characters
      I want to make a variable holding the string a href="#" onClick="alert('Are you sure you want to quit?')") But if I do <cfset theURL = "a...
    4. MySQL characters
      As long as Im on the subject... Is there any way I can use characters such as: á,é,í,ó,ú,º,ª, etc in MySQL??? thanks
    5. ESCAPING USER ENTERED CHARACTERS.
      Hi I have some blind users who use voice translation software to enter data into an MSQL 2000 db using ASP (Web) Occasionally I get ' or other...
  3. #2

    Default Re: Escaping characters in MySQL

    rolty wrote:
    > CFMX works fine with MySQL database 99% of the time. However, when a field in
    > a query includes an apostrophe, CF is escaping it in the Windows SQL server
    > mode, ie by doubling the apostrophe. MySQL requires a backslash to achieve
    > this, and consequently any queries involving escaped characters are failing
    > although the data might actually tally. There must (surely) be a simple setup
    > for this but I cant find it, any helpers please?
    Use cfqueryparam.

    Jochem

    --
    Jochem van Dieten
    Team Macromedia Volunteer for ColdFusion, beer and fun.
    Jochem van Dieten - TMM Guest

  4. #3

    Default Re: Escaping characters in MySQL

    thanks Jochem
    that works with regular queries, but I cant get it to work with query of queries.... still get the same problem there... perhaps there's a nice workaround you know for that?
    rolty Guest

  5. #4

    Default Re: Escaping characters in MySQL

    rolty wrote:
    >
    > that works with regular queries, but I cant get it to work with query of queries.... still get the same problem there... perhaps there's a nice workaround you know for that?
    Could you show an example?

    Jochem

    --
    Jochem van Dieten
    Team Macromedia Volunteer for ColdFusion, beer and fun.
    Jochem van Dieten - TMM Guest

  6. #5

    Default Re: Escaping characters in MySQL

    sure! This is the master query: <cfquery name=master datasource=myDB> SELECT
    EstablishmentDetails.RecordID, Name, EstType, EstTypeAlt, EstType2, EstType3,
    Town, CountyName, EstablishmentDetails.description, website, email,
    CountyDetails.Region AS Reg FROM CountyDetails INNER JOIN EstablishmentDetails
    ON County = CountyDetails.RecordID OR County2 = CountyDetails.RecordID WHERE
    List = 1 AND CountyDetails.RecordID = <cfqueryPARAM value = '#county#'
    CFSQLType = 'CF_SQL_INTEGER' maxlength='3'> ORDER BY Name ;</cfquery> this
    works fine. however when i query this query like: <cfquery name=QHotel
    dbtype='query'> SELECT RecordID, Name, Town, description, website, email FROM
    master WHERE Town = <cfqueryPARAM value = '#town#' CFSQLType =
    'CF_SQL_VARCHAR'> AND (EstType = 1 OR EstTypeAlt = 1 OR EstType2 = 1 OR EstType
    = 12) ;</cfquery> It doesnt return any rows, even if I know the data is there.
    It works fine IF the 'town' field does not contain an apostrophe, it only
    fails for towns like King's Lynn... have I got the CFSQLType wrong?

    rolty Guest

  7. #6

    Default Re: Escaping characters in MySQL

    I'm sorry, I have not been able to reproduce this problem.

    Jochem


    --
    Jochem van Dieten
    Team Macromedia Volunteer for ColdFusion, beer and fun.
    Jochem van Dieten - TMM Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139