/ Check-in [c02f77b1]
Login

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

Overview
Comment:Revert the OP_MustBeInt opcode implementation on this branch so that it again matches trunk. The extra functionality is no longer required.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | window-functions
Files: files | file ages | folders
SHA3-256: c02f77b1b4d025d4243f883d6f3a2b3abcaf4944e0209f641b62c576415343dc
User & Date: dan 2019-03-19 11:56:39
Wiki:window-functions
Context
2019-03-19
16:49
Add missing VdbeCoverage() macros to new code in window.c. check-in: 4f9b93e6 user: dan tags: window-functions
11:56
Revert the OP_MustBeInt opcode implementation on this branch so that it again matches trunk. The extra functionality is no longer required. check-in: c02f77b1 user: dan tags: window-functions
11:17
Update this branch with latest trunk changes. check-in: 98cc2659 user: dan tags: window-functions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  1719   1719     pIn1 = &aMem[pOp->p1];
  1720   1720     memAboutToChange(p, pIn1);
  1721   1721     sqlite3VdbeMemIntegerify(pIn1);
  1722   1722     pIn1->u.i += pOp->p2;
  1723   1723     break;
  1724   1724   }
  1725   1725   
  1726         -/* Opcode: MustBeInt P1 P2 * * P5
         1726  +/* Opcode: MustBeInt P1 P2 * * *
  1727   1727   ** 
  1728         -** If P5 is 0, force the value in register P1 to be an integer. If 
  1729         -** the value in P1 is not an integer and cannot be converted into an 
  1730         -** integer without data loss, then jump immediately to P2, or if P2==0
         1728  +** Force the value in register P1 to be an integer.  If the value
         1729  +** in P1 is not an integer and cannot be converted into an integer
         1730  +** without data loss, then jump immediately to P2, or if P2==0
  1731   1731   ** raise an SQLITE_MISMATCH exception.
  1732         -**
  1733         -** Or, if P5 is non-zero, then force the register in P1 to be a number
  1734         -** (real or integer). Jump to P2 if this cannot be accomplished without
  1735         -** data loss. P2 must be non-zero in this case.
  1736   1732   */
  1737   1733   case OP_MustBeInt: {            /* jump, in1 */
  1738         -  u8 f;
  1739         -  f = (pOp->p5 ? (MEM_Int|MEM_Real) : MEM_Int);
  1740   1734     pIn1 = &aMem[pOp->p1];
  1741         -  if( (pIn1->flags & f)==0 ){
         1735  +  if( (pIn1->flags & MEM_Int)==0 ){
  1742   1736       applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
  1743         -    VdbeBranchTaken((pIn1->flags&f)==0, 2);
  1744         -    if( (pIn1->flags & f)==0 ){
         1737  +    VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
         1738  +    if( (pIn1->flags & MEM_Int)==0 ){
  1745   1739         if( pOp->p2==0 ){
  1746   1740           rc = SQLITE_MISMATCH;
  1747   1741           goto abort_due_to_error;
  1748   1742         }else{
  1749   1743           goto jump_to_p2;
  1750   1744         }
  1751   1745       }
  1752   1746     }
  1753         -  if( f==MEM_Int ) MemSetTypeFlag(pIn1, MEM_Int);
         1747  +  MemSetTypeFlag(pIn1, MEM_Int);
  1754   1748     break;
  1755   1749   }
  1756   1750   
  1757   1751   #ifndef SQLITE_OMIT_FLOATING_POINT
  1758   1752   /* Opcode: RealAffinity P1 * * * *
  1759   1753   **
  1760   1754   ** If register P1 holds an integer convert it to a real value.

Changes to src/window.c.

  1298   1298       "frame ending offset must be a non-negative number",
  1299   1299     };
  1300   1300     static int aOp[] = { OP_Ge, OP_Ge, OP_Gt, OP_Ge, OP_Ge };
  1301   1301     Vdbe *v = sqlite3GetVdbe(pParse);
  1302   1302     int regZero = sqlite3GetTempReg(pParse);
  1303   1303     assert( eCond>=0 && eCond<ArraySize(azErr) );
  1304   1304     sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
  1305         -  sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
  1306         -  if( eCond>=WINDOW_STARTING_NUM ) sqlite3VdbeChangeP5(v, 1);
         1305  +  if( eCond>=WINDOW_STARTING_NUM ){
         1306  +    int regString = sqlite3GetTempReg(pParse);
         1307  +    sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
         1308  +    sqlite3VdbeAddOp3(v, OP_Ge, regString, sqlite3VdbeCurrentAddr(v)+2, reg);
         1309  +    sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC);
         1310  +  }else{
         1311  +    sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
         1312  +  }
  1307   1313     VdbeCoverageIf(v, eCond==0);
  1308   1314     VdbeCoverageIf(v, eCond==1);
  1309   1315     VdbeCoverageIf(v, eCond==2);
  1310   1316     sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
  1311   1317     VdbeCoverageNeverNullIf(v, eCond==0);
  1312   1318     VdbeCoverageNeverNullIf(v, eCond==1);
  1313   1319     VdbeCoverageNeverNullIf(v, eCond==2);

Changes to test/window1.test.

   933    933   }
   934    934   do_execsql_test 21.1 {
   935    935     SELECT
   936    936       current, exclude, filter, following, groups, no, others, over,
   937    937       partition, preceding, range, ties, unbounded, window
   938    938     FROM keyword_tab
   939    939   }
          940  +
          941  +#-------------------------------------------------------------------------
          942  +foreach {tn expr err} {
          943  +  1   4.5      0
          944  +  2   NULL     1
          945  +  3   0.0      0
          946  +  4   0.1      0
          947  +  5  -0.1      1
          948  +  6  ''        1
          949  +  7  '2.0'     0
          950  +  8  '2.0x'    1
          951  +  9  x'1234'   1
          952  + 10  '1.2'     0
          953  +} {
          954  +  set res {0 1}
          955  +  if {$err} {set res {1 {frame starting offset must be a non-negative number}} }
          956  +  do_catchsql_test 22.$tn.1 "
          957  +    WITH a(x, y) AS ( VALUES(1, 2) )
          958  +    SELECT sum(x) OVER (
          959  +      ORDER BY y RANGE BETWEEN $expr PRECEDING AND UNBOUNDED FOLLOWING
          960  +    ) FROM a
          961  +  " $res
          962  +
          963  +  set res {0 1}
          964  +  if {$err} {set res {1 {frame ending offset must be a non-negative number}} }
          965  +  do_catchsql_test 22.$tn.2 "
          966  +    WITH a(x, y) AS ( VALUES(1, 2) )
          967  +    SELECT sum(x) OVER (
          968  +      ORDER BY y RANGE BETWEEN UNBOUNDED PRECEDING AND $expr FOLLOWING
          969  +    ) FROM a
          970  +  " $res
          971  +}
   940    972   
   941    973   finish_test
   942    974   
   943    975