具有挑战性的算法的问题

发布于 2024-11-28 11:55:38 字数 1581 浏览 4 评论 0原文

我很困惑。我需要访问查询循环中的下一个第 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 本身。

需要考虑的一些事项:

  1. 修订模式是每个编辑的帖子列占一行;因此,如果您加载帖子并编辑其标题正文,则会在修订模式中创建两条记录;一个用于标题,一个用于正文,位于相同的revisionGUID下。
  2. 查询按revisionGUID 分组。
  3. 它按修订日期排序,从最新到最旧;然后按修订类型(标题简介正文)。

我用 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:

  1. 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.
  2. The query is grouped by revisionGUID.
  3. 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 技术交流群。

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

发布评论

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

评论(2

脸赞 2024-12-05 11:55:38

抱歉,我不了解 Coldfusion,但听起来(Java)可滚动结果集可能很有​​用。

从预言机信息页面:

5.1 滚动
通过执行语句创建的结果集可以
支持通过其向后移动(最后到第一个)的能力
内容,以及前进(从头到尾)。支持的结果集
此功能称为可滚动结果集。结果集
可滚动还支持相对和绝对定位。
绝对定位是直接移动到一行的能力
指定其在结果集中的绝对位置,而相对位置
定位提供了通过指定一个位置移动到一行的能力
相对于当前行的位置。 (链接:结果集增强)

并且 ResultSet api 在顶部简要提到了它:

默认 ResultSet 对象不可更新,并且具有一个游标
只向前移动。因此,您只能迭代一次并且
仅从第一行到最后一行。可以生产
可滚动和/或可更新的 ResultSet 对象。下列
代码片段,其中 con 是一个有效的 Connection 对象,说明了
如何制作可滚动且对更新不敏感的结果集
由其他人提供,并且是可更新的。其他请参见结果集字段
选项。

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:

5.1 Scrolling
A result set created by executing a statement may
support the ability to move backward (last-to-first) through its
contents, as well as forward (first-to-last). Result sets that support
this capability are called scrollable result sets. Result sets that
are scrollable also support relative and absolute positioning.
Absolute positioning is the ability to move directly to a row by
specifying its absolute position in the result set, while relative
positioning gives the ability to move to a row by specifying a
position that is relative to the current row. (link: result set enhancements)

And the ResultSet api briefly mentions it at the top:

A default ResultSet object is not updatable and has a cursor that
moves forward only. Thus, you can iterate through it only once and
only from the first row to the last row. It is possible to produce
ResultSet objects that are scrollable and/or updatable. The following
code fragment, in which con is a valid Connection object, illustrates
how to make a result set that is scrollable and insensitive to updates
by others, and that is updatable. See ResultSet fields for other
options.

http://download.oracle.com/javase/1.4.2/docs/api/java/sql/ResultSet.html

Hope this helps you find what you are looking for =)

甜尕妞 2024-12-05 11:55:38

如果让数据库帮助您并使用以下查询来查找字段以前的值怎么样:

SELECT TITLE AS PREVIOUSTITLE
FROM REVISIONS
WHERE ID < #query.id# AND TITLE <> '#query.title#'
ORDER BY ID DESC

SELECT BRIEF AS PREVIOUSBRIEF
FROM REVISIONS
WHERE ID < #query.id# AND BRIEF <> '#query.brief#'
ORDER BY ID DESC

SELECT BODY AS PREVIOUSBODY
FROM REVISIONS
WHERE ID < #query.id# AND BODY <> '#query.body#'
ORDER BY ID DESC

如果记录计数为 0,则意味着该字段从未更改。

How about if you let the database help you and use the following queries to find out the previous values of your fields:

SELECT TITLE AS PREVIOUSTITLE
FROM REVISIONS
WHERE ID < #query.id# AND TITLE <> '#query.title#'
ORDER BY ID DESC

SELECT BRIEF AS PREVIOUSBRIEF
FROM REVISIONS
WHERE ID < #query.id# AND BRIEF <> '#query.brief#'
ORDER BY ID DESC

SELECT BODY AS PREVIOUSBODY
FROM REVISIONS
WHERE ID < #query.id# AND BODY <> '#query.body#'
ORDER BY ID DESC

If the recordcount is 0, this means that the field has never changed.

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