具有挑战性的算法的问题
我很困惑。我需要访问查询循环中的下一个第 n 行以显示帖子之间的版本差异。
我使用
按组输出修订,这是我的预期输出:
Rev4
diff(rev4.title, original.title)
diff(rev4.brief, rev2.brief)
Rev3
diff(rev3.body, rev2.body)
Rev2
diff(rev2.brief, original.brief)
diff(rev2.body, original.body)
Original
query.title
query.brief
query.body
我最初想到 使用 Java 方法 获取下一个查询行。这是行不通的:
- Rev4 需要显示其自己的brief 行与对该brief 行所做的最后修订之间的差异;在本例中,发生在 Rev2 中;所以它需要跳一行。
- 为了显示其标题行的差异,Rev4需要跳转到自第一次更改标题以来的原始帖子 行发生在 Rev4 本身。
需要考虑的一些事项:
- 修订模式是每个编辑的帖子列占一行;因此,如果您加载帖子并编辑其标题和正文,则会在修订模式中创建两条记录;一个用于标题,一个用于正文,位于相同的revisionGUID下。
- 查询按revisionGUID 分组。
- 它按修订日期排序,从最新到最旧;然后按修订类型(标题、简介、正文)。
我用 Java 标记了它,因为 ColdFusion 允许我们 使用 Java查询对象上的方法,但它没有记录,所以仅仅知道它的存在对我没有帮助。
任何人都可以告诉我一种[更好]的方法来做到这一点?
我想到的代码结构:
<cfoutput query="revisions" group="revisionGUID">
#revision.revisionGUID#
<cfoutput>
// conditional logic to get diff();
<cfoutput>
</cfoutput>
I'm stumped. I need to access the next nth row
in a query loop to show version differences between posts.
I'm using <cfquery>
to output the revisions by group, and this is my expected output:
Rev4
diff(rev4.title, original.title)
diff(rev4.brief, rev2.brief)
Rev3
diff(rev3.body, rev2.body)
Rev2
diff(rev2.brief, original.brief)
diff(rev2.body, original.body)
Original
query.title
query.brief
query.body
I initially thought to use Java methods to get the next query row. This does not work:
- Rev4 needs to show the difference between its own brief row, and the last revision made to the brief row; which, in this case, occurred in Rev2; so it needs to jump one row.
- In order to show the diff for its title row, Rev4 needs to jump to the original post since the first change to the title row occurred in Rev4 itself.
Some things to consider:
- The revisions schema is one row for each edited post column; so if you load a post and edit its title and body, two records will get created in the revisions schema; one for the title and one for the body, under the same revisionGUID.
- The query is grouped by revisionGUID.
- It's ordered by revision date, newest to oldest; then by revision type (title, brief, body).
I tagged this with Java because ColdFusion allows us to use Java methods on queries objects, but it's not documented so merely knowing of its existence does not help me.
Anyone can show me a [better] way to do this?
The code structure I thought of:
<cfoutput query="revisions" group="revisionGUID">
#revision.revisionGUID#
<cfoutput>
// conditional logic to get diff();
<cfoutput>
</cfoutput>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,我不了解 Coldfusion,但听起来(Java)可滚动结果集可能很有用。
从预言机信息页面:
并且 ResultSet api 在顶部简要提到了它:
http://download.oracle.com/ javase/1.4.2/docs/api/java/sql/ResultSet.html
希望这可以帮助您找到您正在寻找的内容 =)
Sorry that I don't know Coldfusion, but it sounds like (Java) scrollable resultSet might be useful.
From the oracle info page:
And the ResultSet api briefly mentions it at the top:
http://download.oracle.com/javase/1.4.2/docs/api/java/sql/ResultSet.html
Hope this helps you find what you are looking for =)
如果让数据库帮助您并使用以下查询来查找字段以前的值怎么样:
如果记录计数为 0,则意味着该字段从未更改。
How about if you let the database help you and use the following queries to find out the previous values of your fields:
If the recordcount is 0, this means that the field has never changed.