#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    13
    Rep Power
    0

    Query columns conflicting with normal variables


    Hi all

    In my Variablescope there's a query 'content' with a column 'pageid'. When I want to display this pageid I just use 'content.pageid'. But it's also possible to just use 'pageid' without the name of the query in front of it.

    But that's not handy. For in my opinion this 'pageid' is part of the 'content'-query so if I want to access this 'pageid' I have to access it by using the query name as well. Because of the possibility to not use the queryname, this 'pageid' is conflicting with the normal plain variables.

    The problem is this. So I have a query 'content' with 'pageid' as a column. But outside of it I want to set just a plain 'pageid' for other uses. So I type in "<cfset pageid = 2 />" or something like that. But when I immediately after that line do a <cfdump> of the 'pageid' it is not 2, but 4; the value of the 'content.pageid'.

    Is there a solution to this, or do I have to use another variablename if a query has got a column with the same name?

    Thanks and best regards,
    Maarten B.
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,281
    Rep Power
    968
    Did you try "<cfset variables.pageid = X />"?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    13
    Rep Power
    0
    Thanks for the tip, tried it, worked half...

    I could set variables.pageid to the id i wanted, but I had to access the variable always through the variablescope.

    So it's like this...
    The query 'content' has pageid as a value 4.

    I do this:

    <cfset pageid = 5 />
    <cfdump var="#pageid#"> displays still 4.

    <cfset variables.pageid = 5 />
    <cfdump var="#pageid#"> displays still 4.
    <cfdump var="#variables.pageid#"> displays 5.

    That's not a solution in my opinion. In PHP when you access the variable and set it, it's overwritten. But furthermore, if you have something like an array, you can not access the value just by using the keyvalue like it is in coldfusion. Although we're talking about a query and not a struct/array, I find this very strange and would call it a bug.
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,281
    Rep Power
    968
    It's not a bug. Within the query, when you reference "pageid" without a scope, CF searches through the scopes to find it. When it gets to "query.pageid", it stops. Which is exactly what it is supposed to do. How else could it work? CF can't read your mind and know which pageid in which scope you actually want.

    This is the reason you should scope ALL variables. If you actually mean pageid in the variables scope, use "variables.pageid". Same would go for "request.pageid", "session.pageid", "application.pageid", "url.pageid", "form.pageid", etc.

IMN logo majestic logo threadwatch logo seochat tools logo