cross is now running Foswiki 2.1.3 Beta 1. Please open a task for any issues.

Item5440: FormQueryPlugin: SUMFIELD broken for negative numbers

Priority: Normal
Current State: Closed
Released In:
Target Release: n/a
Applies To: Extension
Component: DBCacheContrib
Reported By: TWiki:Main.ScottClaridge
Waiting For:
Last Change By: CrawfordCurrie
Using negative numbers with SUMFIELD doesn't work. And I think it probably should. I first noticed this in 4.1.2, and just having updated to 4.2.0, find it stills exists. Plugin version is 0 (21 May 2007)

I've broken down a test case from my own use tracking expenses. it is basically as follows:

| *Item* | *Amount* |
| item | -3 |
| foo | 5 |

%TABLEFORMAT{ name=ATBLFMT header="| *Topic* | *Item* | *Amount* | "  format="| [[$_up.topic][$percntICON{tag}$percnt]]   | $Item |    $Amount |" sort="Amount"}%
%FORMQUERY{name="fqptest" extract="FqpTestTable" search="topic=~'FqpTest' "}%
%SHOWQUERY{query="fqptest" format=ATBLFMT }%
| |  %MATCHCOUNT{ query="PurchaseItemsAllocated" moan="off"}% items |  %CALC{"$SUM($ABOVE())"}% Total %SUMFIELD{ query="fqptest" field="Amount"}% | |

 %EDITTABLE{header="| *Item* | *Amount* |" format="| text, 20, item | text, 10, amount |" }%
| *Item* | *Amount* |

The CALC at the bottom of the table in FqpTestSum has no problem dealing with the negatives. I have tried different variations of negative specification, including using () around values, but to no avail.

I should also add that the negative number is just ignored; not added as a positive or anything. It seems to treat it as a non-number, and just skips over it.

-- TWiki:Main.ScottClaridge - 14 Mar 2008

The problem actally lies in the DBCacheContrib which underlies FormQueryPlugin. There's a line of code in

197:   } elsif ( $fieldval =~ m/^\s*\d+/o ) {

which is frankly pretty brainless (I can say that because I wrote it). This line should be fixed to recognise a generic number format (including floating point)

197:   } elsif ( $fieldval =~ m/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ ) {



Ahh - yes that makes all the difference.

-- TWiki:Main.ScottClaridge - 26 Mar 2008

About bleeding time I fixed this....

-- CrawfordCurrie - 07 Apr 2009
Topic revision: r7 - 08 Apr 2009, CrawfordCurrie - This page was cached on 22 Jan 2017 - 01:00.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License