CFMX7 and dynamic query --Need to maintain single quotes

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

  1. #1

    Default CFMX7 and dynamic query --Need to maintain single quotes

    I have a cfquery select that is built from a search form.

    When the form is processed, it builds a searchstring like this:
    <cfset searchstring = searchstring & " and dbcolumn1 like '%#form.field1#%'
    ">
    <cfset searchstring = searchstring & " and dbcolumn2 like '%#form.field2#%'
    ">

    (checking to for non-empty form fields to when building the search string)

    So my searchstring is a str var containing values similar to this:
    and dbcolumn1 like '%#form.field1#%' and dbcolumn2 like '%#form.field2#%'


    My query is:
    <cfquery name='myquery' datasource=....>
    select * from table where displayme=1 and #searchstring#
    </cfquery>

    It all seems to resolve well, except at the SQL level, the command gets
    converted from single quotes ('%#form.field1#%') to double quotes
    ("%#form.field2#%").
    Using the doublequotes hozes up the select and the query isn't evaluated
    properly.

    Is there an elegant way to maintain the single quotes? I could plug in the
    ASCII value for them, but
    this doesn't seem to be an issue in CFML5 so I wasn't prepared for it in
    this new version...
    Please respond here or email me.. I am definitely stuck :)
    --
    Tami
    aka DixieGal

    **************************
    So it is that the gods to dno give all men gifts of grace - neither good
    looks not intelligence nor eloquence...
    --Homer, The Odyssey
    **************************

    DixieGal Guest

  2. Similar Questions and Discussions

    1. CFMX7 duplicating single quotes in sql statement
      Hello, Macromedia released a hotfix for the issue I'm experiencing but the fix is for MX 6.1. I'm running MX 7.0.2. ...
    2. CF double quoting my single quotes in query string
      I'm building my query string on the fly. So I have something like this: <cfset szQuery = "SELECT id FROM tblFoo WHERE id=' " &...
    3. Single Quotes vs Double Quotes
      With all that's been said in mind ('$var' unparsed "$var" parsed). The rule of thumb I follow is, if it needs to be parsed (has a $variable or \n...
    4. [PHP] Single Quotes vs Double Quotes
      Hi, Tuesday, September 9, 2003, 2:03:34 PM, you wrote: mb> Hi everyone, mb> Could somebody please explain to me the difference mb> between...
    5. Recommend pse: Quotes, Single Quotes, etc. basics
      I've been fooling with this stuff for awhile and I still have problems with quotes, double quotes, etc. I have no programming or database...
  3. #2

    Default Re: CFMX7 and dynamic query --Need to maintain single quotes

    PreserveSingleQuotes()
    better yet: cfqueryparam
    HTH
    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  4. #3

    Default Re: CFMX7 and dynamic query --Need to maintain single quotes

    duh!
    I tried cfqueryparam, but the query still got choked
    Thanks Tim!
    LOL, Tami
    "Mountain Lover" <info@NOSPAMrecfusion.com> wrote in message
    news:di6i07$ltf$1@forums.macromedia.com...
    | PreserveSingleQuotes()
    | better yet: cfqueryparam
    | HTH
    | --
    | Tim Carley
    | [url]www.recfusion.com[/url]
    | [email]info@NOSPAMINGrecfusion.com[/email]

    DixieGal Guest

  5. #4

    Default Re: CFMX7 and dynamic query --Need to maintain singlequotes

    Mountain Lover's right. Use cfqueryparam if you can because although
    PreserveSingleQuotes() works, it can pose a sql injection risk. Using
    cfqueryparam may also increase performance in certain situations.

    mxstu Guest

  6. #5

    Default Re: CFMX7 and dynamic query --Need to maintain single quotes

    Yep, let me try again. I use cfqueryparam for all my other sql stmts,so
    am very familiar with it.... if I have to bang the statement out with
    a preservesinglequotes() inside cfqueryparam, I will ...

    Thanks guys... too little coffee... and too little brain power today. Must
    be all
    the rain outside :)
    Tami
    "mxstu" <webforumsuser@macromedia.com> wrote in message
    news:di6kv0$q2t$1@forums.macromedia.com...
    | Mountain Lover's right. Use cfqueryparam if you can because although
    | PreserveSingleQuotes() works, it can pose a sql injection risk. Using
    | cfqueryparam may also increase performance in certain situations.
    |

    DixieGal 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