The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
Query columns conflicting with normal variables
Discuss Query columns conflicting with normal variables in the ColdFusion Development forum on Dev Shed. Query columns conflicting with normal variables ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 22nd, 2012, 07:21 AM
|
|
Registered User
|
|
Join Date: Dec 2006
Posts: 13
Time spent in forums: 3 h 15 m 7 sec
Reputation 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.
|

August 22nd, 2012, 08:54 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
Did you try "<cfset variables.pageid = X />"?
|

August 30th, 2012, 04:48 AM
|
|
Registered User
|
|
Join Date: Dec 2006
Posts: 13
Time spent in forums: 3 h 15 m 7 sec
Reputation 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.
|

August 30th, 2012, 08:29 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|