/ Check-in [b6563647]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem in the xInverse callback for the built-in sum() window function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b6563647382634588ebe5c6a3c35c65a321dc1b3732c809d48ce46759b9dd80f
User & Date: dan 2018-07-02 17:45:59
Context
2018-07-03
20:17
Test that a race condition can cause a "BEGIN EXCLUSIVE" to return SQLITE_BUSY_SNAPSHOT in wal mode. check-in: 5a12db75 user: dan tags: trunk
2018-07-02
17:45
Fix a problem in the xInverse callback for the built-in sum() window function. check-in: b6563647 user: dan tags: trunk
17:14
Fix a segfault caused by having identical window functions in the select-list and ORDER BY clause of a SELECT statement. check-in: 693b4350 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

  1526   1526       if( type==SQLITE_INTEGER ){
  1527   1527         i64 v = sqlite3_value_int64(argv[0]);
  1528   1528         p->rSum -= v;
  1529   1529         if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, -1*v) ){
  1530   1530           p->overflow = 1;
  1531   1531         }
  1532   1532       }else{
  1533         -      p->rSum += sqlite3_value_double(argv[0]);
         1533  +      p->rSum -= sqlite3_value_double(argv[0]);
  1534   1534         p->approx = 1;
  1535   1535       }
  1536   1536     }
  1537   1537   }
  1538   1538   #else
  1539   1539   # define sumInverse 0
  1540   1540   #endif /* SQLITE_OMIT_WINDOWFUNC */

Changes to test/window6.test.

   187    187     SELECT "counter", "value", RANK() OVER w AS "rank" 
   188    188     FROM "sample"
   189    189     WINDOW w AS (PARTITION BY "counter" ORDER BY "value" DESC) 
   190    190     ORDER BY "counter", RANK() OVER w
   191    191   } {
   192    192     1 20.0 1   1 10.0 2   2 3.0 1   2 1.0 2  3 100.0 1
   193    193   }
          194  +
          195  +do_execsql_test 8.2 {
          196  +  SELECT "counter", "value", SUM("value") OVER 
          197  +  (ORDER BY "id" ROWS 2 PRECEDING) 
          198  +    FROM "sample" 
          199  +  ORDER BY "id"
          200  +} {
          201  +  1 10.0 10.0   1 20.0 30.0   2 1.0 31.0   2 3.0 24.0   3 100.0 104.0
          202  +}
          203  +
          204  +do_execsql_test 8.3 {
          205  +  SELECT SUM("value") OVER 
          206  +  (ORDER BY "id" ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) 
          207  +    FROM "sample" 
          208  +  ORDER BY "id"
          209  +} {
          210  +  10.0   30.0   31.0   24.0   104.0
          211  +}
   194    212   
   195    213   finish_test