Okay. Then it's kind of required. Ha!
I always fulfill it these days anyway, just curious as to whether
there would be an error thrown. I'm wondering, since someone out there
threw an error by eliminating it, if there are certain cases where CF
will allow the omission. When I have some time this
.
Jonathon
-Original Message-
From: Brian Kotek [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 31, 2007 1:39 PM
To: CF-Talk
Subject: Re: CFC defining vars
The unnamed query still goes into the variables scope if you don't var scope
it. I would definitely name them and var scope them.
On 7/31/07
Ugh. I wondered what had happened to those posts. I sent them a few hours ago
and they never showed up. Mystery solved ;-)
~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers
On Monday 30 Jul 2007, [EMAIL PROTECTED] wrote:
Why? Is this just good programming practice?
Yes, because if you don't the variable isn't 'thread safe' and as soon as the
CFC is under load, you'll get random errors saying it's undefined or has an
impossible value.
No one knows why Adobe have
The unnamed query still goes into the variables scope if you don't
var scope it
So does anyone know the answer to the question If the query is unnamed,
_what_ is being put into the variables scope?
~|
ColdFusion is
I poked around by dumping the variables scope, as well as getting into the
underlying Java class that represents the variables scope of a CFC. On both
CF7 and CF8 it appears that an unnamed query does NOT go into the variables
scope. I was thinking it would go in as an unnamed variable, but as far
I haven't loaded CF8 yet, or I'd try it myself, but didn't I see
someone post last week that name is a required attribute to cfquery
in CF8?
I poked around by dumping the variables scope, as well as getting into the
underlying Java class that represents the variables scope of a CFC. On both
didn't I see someone post last week that name is a required
attribute to cfquery in CF8?
Yes, according to the documentation name is now required
http://livedocs.adobe.com/coldfusion/8/Tags_p-q_17.html#1102316
~|
Create
When I tried it, it worked without name. Adobe is very careful about
backward compatibility, so it's unlikely they would break something like
this which probably exists (for better or worse) in a lot of existing code.
On 8/1/07, Kris Jones [EMAIL PROTECTED] wrote:
I haven't loaded CF8 yet, or
On 8/1/07, Janet MacKay [EMAIL PROTECTED] wrote:
Yes, according to the documentation name is now required
http://livedocs.adobe.com/coldfusion/8/Tags_p-q_17.html#1102316
According to the CFMX7 docs, name was required (at least on cfquickdocs).
--
Sean A Corfield -- (904) 302-SEAN
An
So it looks like you're safe. Personally I'd still name it and
var scope it anyway, but then I'm paranoid.
Yes, I agree with you about naming and var scoping. I'm paranoid too. I was
just curious since I'd dumped the variables scope and didn't see anything other
than cfquery.executionTime.
According to the CFMX7 docs, name was required (at least on cfquickdocs).
LMAO. Time for new glasses ;) I found some old documentation that says it was
required as far back as CF4.5
~|
Enterprise web applications, build
Time for new glasses
I meant for me of course :-) I've always assumed name was listed as an
optional attribute because CF treats it as optional. Learn something new every
day.
~|
Create robust enterprise, web RIAs.
This is because CF8 needs somewhere to store the new return variables
like the inserted RowID (if you're doing an insert) etc.
On 8/2/07, Janet MacKay [EMAIL PROTECTED] wrote:
didn't I see someone post last week that name is a required
attribute to cfquery in CF8?
Yes, according to the
Odd, because the query runs fine without a name defined. Still, it's one
more reason to var scope and name the query. This may be an oversight that
will be fixed in a patch or something.
On 8/2/07, Janet MacKay [EMAIL PROTECTED] wrote:
didn't I see someone post last week that name is a required
]
Sent: Monday, July 30, 2007 3:06 PM
To: CF-Talk
Subject: Re: CFC defining vars
Yes, name it and var scope it.
On 7/30/07, Chad Gray [EMAIL PROTECTED] wrote:
I tend to do this on updates or inserts of a database records when I
don't
care what the query returns
it was it.
Would it really be necessary to supply, let alone var a cfquery which
was only an update?
~Brad
-Original Message-
From: Brian Kotek [mailto:[EMAIL PROTECTED]
Sent: Monday, July 30, 2007 3:06 PM
To: CF-Talk
Subject: Re: CFC defining vars
Yes, name it and var scope
The unnamed query still goes into the variables scope if you don't var scope
it. I would definitely name them and var scope them.
Okay, I don't quite understand that comment. If the query is unnamed, _what_ is
being put into the variables scope?
The unnamed query still goes into the variables scope if you don't var scope
it. I would definitely name them and var scope them.
I always name/var my queries but I don't understand that comment :) If the
query is unnamed, _what_ is being put into the variables scope?
I have noticed in a lot of people's code for CFCs they set all of the variables
being used in the CFC like this:
cfset var foo =
Why? Is this just good programming practice?
Also what scope are these variables in? variables.foo?
the use of var keyword is very important.
Bye
Gualtiero
- Original Message -
From: Chad Gray [EMAIL PROTECTED]
To: CF-Talk cf-talk@houseoffusion.com
Sent: Monday, July 30, 2007 3:46 PM
Subject: CFC defining vars
I have noticed in a lot of people's code for CFCs they set all
, 2007 8:46 AM
To: CF-Talk
Subject: CFC defining vars
I have noticed in a lot of people's code for CFCs they set all of the
variables being used in the CFC like this:
cfset var foo =
Why? Is this just good programming practice?
Also what scope are these variables in? variables.foo
The 'var' scope is for function-specific variables, that you don't want
carried into the VARIABLES scope. They exist only for the lifetime of
the function itself, whereas the VARIABLES scope will maintain
throughout the life of the CFC instance.
Steve Cutter Blades
Adobe Certified Professional
The var keyword declares the variable as local to the method, and this is
probably the most critical thing that you absolutely MUST do when writing
and using CFCs. Failure to do this will result in bugs and concurrency
issues that will be extremely difficult to track down. So, use the var
keyword
Gualtiero hit the nail on the head - it allows you to define a variable (or a
variable scope aka struct) who only exists for the duration of the function's
processing.
'What scope is it in?' - it's in the same scope as if you omitted the 'var'
keyword.
cfset myVar = 'purple' /
cfset var
using the 'var' keyword scopes the variable into the local scope *for
that function/method*.
so cfset var foo = / means 'foo' is available to only that method
call and you don't have the potential issue of another method with a
similarly named variable stomping the expected value.
it's good
defining vars
The var keyword declares the variable as local to the method, and this
is
probably the most critical thing that you absolutely MUST do when
writing
and using CFCs. Failure to do this will result in bugs and concurrency
issues that will be extremely difficult to track down. So, use the var
On 7/30/07, Jake Pilgrim [EMAIL PROTECTED] wrote:
'What scope is it in?' - it's in the same scope as if you omitted the
'var' keyword.
cfset myVar = 'purple' /
cfset var myVar = 'purple' /
In both cases, your variable would be in the 'variables' scope.
Jake this is not only incorrect
On 7/30/07, Jake Pilgrim [EMAIL PROTECTED] wrote:
'What scope is it in?' - it's in the same scope as if you omitted the 'var'
keyword.
Nope, they are in separate scopes.
cfset myVar = 'purple' /
cfset var myVar = 'purple' /
In both cases, your variable would be in the 'variables' scope.
Yes, name it and var scope it.
On 7/30/07, Chad Gray [EMAIL PROTECTED] wrote:
Thanks for all of the info on this subject. I have fixed most of my
existing code.
One question I have is what happens if I don't declare a name= attribute
for a cfquery?
IE:
cfquery
REALLY?
Oh boy, I have some code to fix. :)
Glad I just started using CFCs... not much code to fix.
-Original Message-
From: Brad Wood [mailto:[EMAIL PROTECTED]
Sent: Monday, July 30, 2007 11:00 AM
To: CF-Talk
Subject: RE: CFC defining vars
That makes the variable exist only
Thanks for all of the info on this subject. I have fixed most of my existing
code.
One question I have is what happens if I don't declare a name= attribute for
a cfquery?
IE:
cfquery datasource=#application.dsn#
Lots of sql here
/cfquery
I tend to do this on updates or inserts of a database
32 matches
Mail list logo