cfquery 名称属性,可选?

发布于 2024-11-26 09:40:14 字数 108 浏览 1 评论 0原文

cfquery 的 name 属性是可选的吗?文档说这是必需的,但即使没有它,我的代码似乎也可以正常运行。如果没有定义的话有默认值吗?如果是这样,我应该将其本地化还是安全地忽略它?

谢谢

Is name attribute of cfquery optional? The doc said it is required, but my code seems to run fine even without it. Is there a default value if not defined? and if so, shall I local var it or safely ignore it?

Thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

树深时见影 2024-12-03 09:40:14

我认为您可以安全地省略名称。它似乎没有向变量或局部作用域添加默认的名称。

然而,我确实注意到CF9下有一些奇怪的地方。如果您没有对结果进行本地作用域,则键cfquery.executiontime将添加到variables作用域中。这是禁用所有调试的情况(除非我错过了一些东西)。

Results:
Before  Variables = 1 Local = 1
After   Variables = 2 Local = 1   (result NOT local scoped)


<cffunction name="myFunction" output="true">
    <b>Before</b>
    Variables = #structCount(variables)#
    Local = #structCount(local)#<br />

    <cfquery datasource="MyDatasource">
        SELECT getDate() AS TestDate
    </cfquery>

    <b>After</b>
    Variables = #structCount(variables)#
    Local = #structCount(local)#<br />
</cffunction>

I think you can safely omit the name. It does not appear to add a default name to the variables or local scopes.

However, I did notice something strange under CF9. If you do not local scope the result, the key cfquery.executiontime is added to the variables scope. This is with all debugging disabled (unless I missed something).

Results:
Before  Variables = 1 Local = 1
After   Variables = 2 Local = 1   (result NOT local scoped)


<cffunction name="myFunction" output="true">
    <b>Before</b>
    Variables = #structCount(variables)#
    Local = #structCount(local)#<br />

    <cfquery datasource="MyDatasource">
        SELECT getDate() AS TestDate
    </cfquery>

    <b>After</b>
    Variables = #structCount(variables)#
    Local = #structCount(local)#<br />
</cffunction>
云醉月微眠 2024-12-03 09:40:14

name 属性是必需的,但我刚刚测试过它&如果缺少 name 属性,它不会抛出错误......多么有趣。但是,如果没有 name 属性,您将如何获得结果集?

多么有趣的问题啊。

更新

刚刚运行了一个快速测试并进行了一些谷歌搜索:

<cfquery  datasource="#dsn#" result="qresult">
select some_stuff from that_table limit a_bunch
</cfquery>

<cfdump var="#qresult#" />

转储结果属性清楚地表明查询已运行并确实获得了结果集 - 尽管似乎无法访问它。
谷歌搜索和文档对默认值或范围没有帮助..也许 ping 这些人: http://www.bennadel.com/ - 我在他们的网站上遇到了很多“实验”。

现在文档确实说 name 属性是必需的,但我想我可以看到可能不需要它的情况 - 显然不存在的 name 变量不会使用内存,但是结果集呢?所以我猜如果您运行任何实际上不需要从中返回信息的查询[除了选择之外的任何东西?]您可以通过使用结果属性来获取您需要的所有信息,并且可能节省一些内存和执行时间?

这不是一个有趣的想法吗?

-肖恩

The name attribute is required, but I just tested it & it does not throw an error if the name attribute is missing... how very interesting. Though, without the name attribute - how are you going to get at the result set?

What an interesting question.

UPDATE

Just ran a quick test and did some googling:

<cfquery  datasource="#dsn#" result="qresult">
select some_stuff from that_table limit a_bunch
</cfquery>

<cfdump var="#qresult#" />

Dumping the result attribute shows clearly that the query has run and did get a result set - though there appears to be no way to access it.
Googling & docs were no help with the defaults or scope.. maybe ping these guys: http://www.bennadel.com/ - I run across a lot of 'experimenting' on their site.

Now the docs do say that the name attribute is required, but I guess I can see situations where it may not be necessary - obviously memory isn't used by the name variable not being there, but what about the result set? so I'm guessing if you run any query where you don't actually need info back from it [anything but a select?] you can get all the info you need by using the result attribute and MAYBE save some memory and execution time?

isn't that a fun thought?

-sean

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文