如何从 ColdFusion 查询中丢弃一行?

发布于 2024-11-02 22:46:15 字数 328 浏览 2 评论 0原文

给定一个查询(伪代码):

<cfquery name="myquery">SELECT * FROM stuff</cfquery>

如何删除第一条记录?在这种情况下,更改 SQL 不是一个选项。 我尝试过: myquery.RemoveRows(0,1); 但收到错误:

No matching Method/Function for Query.REMOVEROWS(numeric, numeric) found

顺便说一句,我在 Railo 3 上

Given a query (pseudo-code):

<cfquery name="myquery">SELECT * FROM stuff</cfquery>

How do I get rid of the first record? In this case, altering the SQL is not an option.
I have tried: myquery.RemoveRows(0,1); but received an error:

No matching Method/Function for Query.REMOVEROWS(numeric, numeric) found

I'm on Railo 3 BTW

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

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

发布评论

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

评论(6

淡莣 2024-11-09 22:46:15

你瞧:

myquery.RemoveRow(1);

正是我想要的。让 Railo 来做一些不同的事情吧!

Lo and behold:

myquery.RemoveRow(1);

Does exactly what I wanted. Leave it to Railo to do things a little differently!

多情出卖 2024-11-09 22:46:15

无法立即想出一种方法来从原始对象中删除一行。我能想到的两件事是:

  1. 进行查询的查询。假设您能够识别您不想要的记录并在 WHERE 中指定它们。

  2. 使用queryNew()构造一个新的查询。将执行 querySetCell() 的原始查询循环到新查询中以获取所需的记录。此功能可以很容易地合并到 UDF 中。事实上,这样说让我想到去看看 cflib.org。请参阅 #3

  3. 检查 cflib.org :) 请参阅 http://www.cflib.org/udf/ QueryDeleteRows

Can't think of a way offhand to remove a row from the original object. Two things I can think of are:

  1. do a query of queries. That assumes you'd be able to identify the records you don't want and specify them in the WHERE.

  2. construct a new query with queryNew(). Loop over the original query doing a querySetCell() into the new query for the records that you want. This functionality could be incorporated into a UDF pretty easily. In fact, stating that made me think to check cflib.org. See #3

  3. Check cflib.org :) See http://www.cflib.org/udf/QueryDeleteRows

伴我老 2024-11-09 22:46:15

“RemoveRows”实际上是对底层 Java 方法的调用,因此您必须转换这些数字。像这样:

myquery.RemoveRows(
    JavaCast( "int", 0 ) // starting row, zero-based
    ,JavaCast( "int", 1 ) // number to delete, returns error if too many
)

所以方法可能是“int,int”,如果你不转换它,它看起来像“numeric,numeric”。有人可能会说这是没有记录的,但它非常简洁,您可以(像我一样)将其包装在一个函数中,这样,如果它发生变化,您只需使用替代解决方法替换该函数的内容即可。

"RemoveRows" is actually a call to the underlying Java method, so you have to cast those numbers. like so:

myquery.RemoveRows(
    JavaCast( "int", 0 ) // starting row, zero-based
    ,JavaCast( "int", 1 ) // number to delete, returns error if too many
)

So probably the method is "int,int", and if you don't cast it, it looks like "numeric,numeric". One might argue that this is undocumented, but it's so succinct that you could (as I did) wrap it in a function, so that if it changes you just need to replace the contents of the function with an alternative workaround.

合久必婚 2024-11-09 22:46:15

Railo 添加了removeRows,请参阅此处。我使用此方法的 ACF 代码现在也在 Railo 上运行,没有任何更改。

至此,Railo 实现现在与 ACF 相匹配。 (另请注意,原始 Railo 实现是基于 0 的,而新版本和 ACF 版本都是基于 1 的。)

Railo has added removeRows, see here. My ACF code that uses this method now runs on Railo too, no changes.

With this, the Railo implementation now matches ACF. (Note also that the original Railo implementation was 0 based, while the new one and the ACF version are both 1 based.)

悲凉≈ 2024-11-09 22:46:15

我通常采用的方式是使用如下查询的查询:

SELECT * FROM myquery
LIMIT {1,10000}

这应该在 Railo 中有效。它的作用是将查询偏移 1 并提取 10000 条记录。

您也可以这样做:

SELECT * FROM myquery
WHERE {primarykey} <> {value}

它选择除您传入的主键值之外的所有记录。ColdFusion

的很棒之处在于,有大量方法可以准确地完成您正在寻找的操作。

The way I would normally do it is with a query of queries such as the following:

SELECT * FROM myquery
LIMIT {1,10000}

That should work in Railo. What it does is offset the query by one and pulls 10000 records.

You could also do this:

SELECT * FROM myquery
WHERE {primarykey} <> {value}

Where it selects all records except for the primary key value that you pass in.

The awesome thing about ColdFusion is that there are tons of ways to do exactly what you are looking for.

绅刃 2024-11-09 22:46:15

您可以在处理结果时跳过该行:

<cfoutput query="myquery">
  <cfif myquery.currentrow GT 1>
    <!---Do the work here. --->
  </cfif>
</cfoutput>

You could just skip the row when you process the results:

<cfoutput query="myquery">
  <cfif myquery.currentrow GT 1>
    <!---Do the work here. --->
  </cfif>
</cfoutput>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文