ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 22nd, 2012, 07:21 AM
meanrat meanrat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 13 meanrat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old August 22nd, 2012, 08:54 AM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
Did you try "<cfset variables.pageid = X />"?

Reply With Quote
  #3  
Old August 30th, 2012, 04:48 AM
meanrat meanrat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 13 meanrat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old August 30th, 2012, 08:29 AM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Query columns conflicting with normal variables

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap