The problem with the complex algorithm

I'm at a dead end. I need to access the next nth row in a query loop to show version differences between posts.

I use <cfquery> to output changes in groups, and this is my expected result:

 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 that using Java methods to get the next line of query. This does not work:

  • Rev4 should show the difference between its own short line and the last revision made in a short line; which in this case occurred in Rev2 ; so he needs to jump one line.
  • To show diff for your title bar, Rev4 needs to go to the original record, since the first change in the title bar occurred in Rev4 .

Some things to consider:

  • The revision scheme is one row for each edited column; therefore, if you download a message and edit its title and body, two entries are created in the revision scheme; one for the header and one for the body, under the same version of GUID.
  • The request is grouped by version of GUID.
  • It is ordered by revision date, latest and oldest; then by type of revision (name, short, body).

I noted this with Java because ColdFusion allows you to use Java methods for query objects , but it is not documented, so just knowing about its existence does not help me.

Can anyone show me the [best] way to do this?

The code structure I was thinking about:

 <cfoutput query="revisions" group="revisionGUID"> #revision.revisionGUID# <cfoutput> // conditional logic to get diff(); <cfoutput> </cfoutput> 
+4
source share
2 answers

Sorry I don't know Coldfusion, but that sounds like a (Java) scrollable resultSet might be useful.

From oracle info page:

5.1 Scrolling
The result set created by executing the instruction can support the ability to move backward (last to first) through its contents, as well as forward (from the first to the last). The result sets that support this feature are called scrollable result sets . The result sets that they scroll and support relative and absolute positioning. Absolute positioning is the ability to move directly to a line by indicating its absolute position in the result set, while relative positioning makes it possible to jump to a line by specifying a position relative to the current line. (link: result set improvements)

And the ResultSet api briefly mentions it at the top:

The ResultSet object is not updated by default and has a cursor that is only moving forward. Thus, you can go through it only once and only from the first line to the last line. You can produce ResultSet Objects that can be scrolled and / or updated. The following code snippet, 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 it 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 =)

+1
source

How to access the database 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 record metric is 0, this means that the field has never changed.

+1
source

All Articles