MX & SQL "In" statement

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

  1. #1

    Default MX & SQL "In" statement

    Hi - basically when a user chooses one choice (drop-down menu) "foo" this is
    correctly passed to SQL statement:

    CF Code:

    widget_type IN ('#trim(foo)#')

    SQL that results:

    widget_type IN ('foo')

    but when multiple sections are made (e.g. foo1 & foo2) this is passed as:

    widget_type IN ('foo1,foo2')

    which fails because each chosen variable is not enclosed by a single quote
    ('). The correct SQL syntax apparently is:

    widget_type IN ('foo1', 'foo2')

    Can anyone explain how to have this work (that is having each chosen variable
    be enclosed in correct SQL syntax) in a JDBC MX7 environment?

    Thank you.

    science_of_information Guest

  2. Similar Questions and Discussions

    1. How can I callError ocurring when Event Listener methodein "for statement" is called
      Hy guys, I would be gratefull if somebody could answer me how can I call a method from flex in "for statement", that is actually in my remote...
    2. What is postgresql doing for "statement: commit;begin;"
      Hi All I've turned on slow query reporting via log_min_duration_statement, and I've been looking through the log files. Quite a lot, I'm...
    3. Is Win32::OLE qw(EVENTS) ~ to the VBA "Impliments" statement?
      Hey, I need to export a client interface into a Win32 COM server, to interact w/ an API. VB apparently does this by saying "Impliments foo" or...
    4. "Statement not protected!" in db2diag.log??
      It happens every time Quest tools are used. Tested it again and again and found that it can be easily reproduced. Obviously something/ some query...
    5. execute + ArraySearch causes "Expected end of statement" error - Why?
      Here is the function ArraySearch: '-------------------------------------------------------------------------------------- 'ArraySearch will...
  3. #2

    Default MX & SQL "In" statement

    Hi - basically when a user chooses one choice (drop-down menu) "foo" this is
    correctly passed to SQL statement:

    CF Code:

    widget_type IN ('#trim(foo)#')

    SQL that results:

    widget_type IN ('foo')

    but when multiple sections are made (e.g. foo1 & foo2) this is passed as:

    widget_type IN ('foo1,foo2')

    which fails because each chosen variable is not enclosed by a single quote
    ('). The correct SQL syntax apparently is:

    widget_type IN ('foo1', 'foo2')

    Can anyone explain how to have this work (that is having each chosen variable
    be enclosed in correct SQL syntax) in a JDBC MX7 environment?

    Thank you.

    science_of_information Guest

  4. #3

    Default Re: MX & SQL "In" statement

    You're going to want to look at the ListQualify function:
    [url]http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functb17.htm#wp1107886[/url]

    Kronin555 Guest

  5. #4

    Default Re: MX & SQL "In" statement

    Use the listqualify function.
    Dan Bracuk Guest

  6. #5

    Default Re: MX & SQL "In" statement

    Thank you for the reply. I'm close to solving this but want to run this by you
    (all) for further clarification. Right now I have a multiselection list on one
    page. The user selects as many as they want.

    The code for the UI (note the single quote around the option value):

    ###

    <select name="selections" size="5" multiple="Y">
    <cfoutput query="GetSelections">
    <option
    value='#GetSelections.selection#'>#GetSelection.se lection#</option>
    </cfoutput>
    </select>
    ## EOF ##

    This is passed to the query page:

    On the query page these selections are pumped through the ListQualify f(x):

    <cfset userlist = ListQualify(selections,"'",",","CHAR")>

    Then in the SQL statement this is passed through as:

    and stuffIwant IN (#userlist#)

    But this keeps on rejecting because the variables have double quotes around
    them (the progress is now each variable is enclosed by something)!

    If I merely output the ListQualified variable outside of SQL the variables
    indeed have a single quote.

    Ideas, suggestions?

    science_of_information Guest

  7. #6

    Default Re: MX & SQL "In" statement

    Hi Science,

    and stuffIwant IN (#PreserveSingleQuotes(userlist)#)

    HTH,
    philh Guest

  8. #7

    Default Re: MX & SQL "In" statement

    Thank you to the both of you for unearthing an answer! My deepest thanks and respect.
    science_of_information Guest

  9. #8

    Default Re: MX & SQL "In" statement

    science_of_information,

    You can also use cfqueryparam with the "list" attribute and it should
    automatically handle the quoting of the selections: foo1, foo2.

    <cfset selections = "foo1,foo2">
    ....
    WHERE widget_type IN
    (
    <cfqueryparam value="#selections#" cfsqltype="cf_sql_varchar" list="yes">
    )


    mxstu 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