我必须在Coldfusion中确定查询输出的作用域吗? [英] do I have to scope query output in Coldfusion?

查看:85
本文介绍了我必须在Coldfusion中确定查询输出的作用域吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Coldfusion中正在运行数据库查询/存储过程,则引用查询返回的字段的正确方法是什么?

 < cfstoredproc procedure = proc_select_extern datasource = stokkers> 
< cfprocparam type = in value =#Session.Extern# cfsqltype = cf_sql_varchar maxlength = 13>
< cfprocresult name = extern>
< / cfstoredproc>
< cfoutput query = extern>
< cfset variables.some = extern.foo>

< cfset variables.some = foo>
< / cfouput>

extern ,包括foo,bar和foobar。是否允许并且最好写:

  extern.foo; 
extern.bar;
extern.foobar;

因为我正在浏览一个页面,并且经常发现这些裸体变量有些让人困惑:

  foo; 
酒吧;
foobar;

关于范围和适当作用域的信息很多,但是我在查询输出中什么都没找到。



感谢您的澄清!

解决方案

有人会告诉您最好总是习惯范围调整,因为这可以使您避免在真正重要的地方犯下作用域错误。



个人认为,我喜欢在查询中使用cfoutput的方法且无需范围限制-在其他语言中等同于 WITH。由于查询将始终在查询驱动的cfoutput标记内的表单和url范围之前进行评估,因此在该实例中忽略范围不会产生任何问题。请记住,在CFC中,参数和局部作用域都是抢占式的-但这不是查询驱动的cfoutput的最佳位置-cfoutput是为方便显示 display 而设计的。 p>

但是,..其他人也会告诉你与众不同(还有一些热情:)。


If I'm a running a database query/stored procedure in Coldfusion, what is the proper way to reference fields returned from the query?

<cfstoredproc procedure="proc_select_extern" datasource="stokkers">
    <cfprocparam type="in" value="#Session.Extern#" cfsqltype="cf_sql_varchar" maxlength="13">
    <cfprocresult name="extern">
</cfstoredproc>
<cfoutput query="extern">
   <cfset variables.some = extern.foo>
   OR 
   <cfset variables.some = foo>
</cfouput>

Say extern includes foo, bar and foobar. Is it allowed and better to write:

 extern.foo;
 extern.bar;
 extern.foobar;

because I'm running through a page and often find these "naked" variables a little confusing to follow:

 foo;
 bar;
 foobar;

There is a lot of info on scopes and proper scoping but I have not found anything on query-output.

Thanks for clarification!

解决方案

Some will tell you that it is good habitual practice to always scope because it keeps you from making scoping errors where it is really important.

Personally in views I like the approach of using cfoutput with a query and NOT having to scope - it's the equivalent of "WITH" in other languages. Since the query will always be evaluated before form and url scopes within a query driven cfoutput tag I do not see any issues with leaving off the scope in that instance. Keep in mind that in CFCs the "arguments" and local scope will both be preemptive - but that's not the best place for a query driven cfoutput - which is designed (ably designed) for convenient display.

But again.. others will tell you different (with some passion as well :) .

这篇关于我必须在Coldfusion中确定查询输出的作用域吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆