= <> SQL operators in components

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default = <> SQL operators in components

    If i want to change the "=" of this SQL syntax to "<>" I have to pass the
    operator as an argument is there a better way of doing this? its just its a bit
    messy

    <cfif isdefined("arguments.page_name")>
    AND web_page_name = <cfqueryparam value="#arguments.page_name#"
    cfsqltype="CF_SQL_VARCHAR">
    </cfif>

    Hope you can help

    Thanks

    Matt

    cf_matt Guest

  2. Similar Questions and Discussions

    1. Operators
      Hi everyone, I have lost touch with Flash for quite some time, so there's alot of stuff I do not really understand. Can anyone tell me what...
    2. JOIN operators
      I am querying 2 datasets at once, my first data set is a customers table and the second is a list of contacts for each customer record. my problem...
    3. [PHP-DEV] regex operators
      I was thinking about adding one or two regex-related features to the engine: 1. "preg_case": this would behave just like case but instead of doing...
    4. [PHP-DEV] O.T. [PHP-DEV] regex operators
      Warning: reply is O.T. Adam Maccabee Trachtenberg wrote: "don't see people advocating ..." - Here in php-internals? Read comp.lang.lisp :) I...
    5. What are the !== and === operators for?
      I have seen code with the !== and === operators in it and got confuzed. WTF are those for I asked myself. So I looked around PHP.net... To no...
  3. #2

    Default Re: = <> SQL operators in components

    Well, you have to do an 'if' somewhere. You could always pass 'EQ' or 'NEQ' and
    depending on the value, change the operator. It's a little more user friendly.
    OldCFer Guest

  4. #3

    Default Re: = <> SQL operators in components

    At the moment I have:

    <cfif isdefined("arguments.page_id")>
    AND web_page_id = <cfqueryparam value="#arguments.page_id#"
    cfsqltype="CF_SQL_INTEGER">
    </cfif>
    <cfif isdefined("arguments.page_id_neq")>
    AND web_page_id <> <cfqueryparam value="#arguments.page_id_neq#"
    cfsqltype="CF_SQL_INTEGER">
    </cfif>

    It is a bit more user friendly but it's still a bit messy in my opinion. I
    guess you could pass the operator and argument as a structure but its still a
    bit clunky.
    The problem with passing the operator on its own is you need to know which
    field it relates to. I might want web_page_name to equal 'test' but not equal
    to 'cheese'.

    I just think this is something fairly common and would have thought there was
    a standard way of doing it.

    Matt

    cf_matt Guest

  5. #4

    Default Re: = <> SQL operators in components

    You could pass each argument in as a struct of operator / value:

    arguments.page_name.operator = "=";
    arguments.page_name.value = "foo";

    Possibly accept either a simple value or a struct. If it's a simple value,
    it's just the value. If it's a struct, then expect operator/value pairs.

    But both situations are ugly.

    I'm guessing you're writing a CFC wrapper for a DB table? Our approach
    here was to have separate arguments for equality filtering (which is what
    you're doing most of the time), and then have an addition
    arguments.whereExpressions, which was free-form.

    --

    Adam
    Adam Cameron Guest

  6. #5

    Default Re: = <> SQL operators in components

    If you just want to keep your query cleaner and easier to see, I would
    create variables containing each AND string before the actual query
    and then, I would output them through the query

    Like so:

    <cfscript>
    // AND statement 1
    AND1="";
    if(variable1 EQ "Yes"){
    AND1=" AND Columname = 'value' ";
    }

    // AND statement 2
    AND2="";
    if(Condition){
    AND2=" AND Columname = 'value' ";
    }

    // AND statement 3
    AND3="";
    if(Condition){
    AND3=" AND Columname = 'value' ";
    }

    // ORDER BY statement
    ORDER="";
    if(Condition){
    ORDER=" ORDER BY Columname1,Columname2 ASC ";
    }

    </cfscript>

    <cfquery datasource="test" name="q_name">

    SELECT *
    FROM table
    WHERE 0=0 <!--- To Escape the "Where" statement --->
    #AND1#
    #AND2#
    #AND3#
    #ORDER#

    </cfquery>

    On Mon, 16 May 2005 08:43:39 +0000 (UTC), "cf_matt"
    <webforumsuser@macromedia.com> wrote:
    >If i want to change the "=" of this SQL syntax to "<>" I have to pass the
    >operator as an argument is there a better way of doing this? its just its a bit
    >messy
    >
    > <cfif isdefined("arguments.page_name")>
    > AND web_page_name = <cfqueryparam value="#arguments.page_name#"
    >cfsqltype="CF_SQL_VARCHAR">
    > </cfif>
    >
    > Hope you can help
    >
    > Thanks
    >
    > Matt
    Ro 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