/ Check-in [44edc1aa]
Login

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

Overview
Comment:Fix handling of transitive constraints in schemalint.tcl.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | schemalint
Files: files | file ages | folders
SHA1:44edc1aa3b412ddbe2a242075e2bf36a99437688
User & Date: dan 2016-01-22 14:44:02
Context
2016-01-22
14:46
Merge latest trunk changes into this branch. check-in: 9341491c user: dan tags: schemalint
14:44
Fix handling of transitive constraints in schemalint.tcl. check-in: 44edc1aa user: dan tags: schemalint
14:32
Update the schemalint.tcl script so that the argument to a -select option may be either an SQL statement or the name of a file containing an SQL statement check-in: d4e37767 user: dan tags: schemalint
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  3920   3920   /*
  3921   3921   ** Append a representation of term pTerm to the string in zIn and return
  3922   3922   ** the result. Or, if an OOM occurs, free zIn and return a NULL pointer.
  3923   3923   */
  3924   3924   static char *whereAppendSingleTerm(
  3925   3925     Parse *pParse,
  3926   3926     Table *pTab,
         3927  +  int iCol,
  3927   3928     int bOr,
  3928   3929     char *zIn,
  3929   3930     WhereTerm *pTerm
  3930   3931   ){
  3931   3932     char *zBuf;
  3932   3933     sqlite3 *db = pParse->db;
  3933   3934     Expr *pX = pTerm->pExpr;
................................................................................
  3941   3942     }
  3942   3943     pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
  3943   3944   
  3944   3945     if( zOp ){
  3945   3946       const char *zFmt = bOr ? "%z{{%s \"%w\" \"%w\" %lld}}" :
  3946   3947                                "%z{%s \"%w\" \"%w\" %lld}";
  3947   3948       zBuf = whereAppendPrintf(db, zFmt, zIn, 
  3948         -        zOp, pTab->aCol[pTerm->u.leftColumn].zName, 
         3949  +        zOp, pTab->aCol[iCol].zName, 
  3949   3950           (pColl ? pColl->zName : "BINARY"),
  3950   3951           pTerm->prereqRight
  3951   3952       );
  3952   3953     }else{
  3953   3954       zBuf = zIn;
  3954   3955     }
  3955   3956   
................................................................................
  3965   3966   ){
  3966   3967     sqlite3 *db = pParse->db;
  3967   3968     Table *pTab = pItem->pTab;
  3968   3969     char *zBuf = zIn;
  3969   3970     int iCol;
  3970   3971     int ii;
  3971   3972     int bFirst = !bInitialSpace;
         3973  +  int bOr = (pWC->op==TK_OR);
  3972   3974   
  3973   3975     /* List of WO_SINGLE constraints */
  3974   3976     for(iCol=0; iCol<pTab->nCol; iCol++){
  3975   3977       int opMask = WO_SINGLE; 
  3976   3978       WhereScan scan;
  3977   3979       WhereTerm *pTerm;
  3978   3980       for(pTerm=whereScanInit(&scan, pWC, pItem->iCursor, iCol, opMask, 0);
  3979   3981           pTerm;
  3980   3982           pTerm=whereScanNext(&scan)
  3981   3983       ){
  3982         -      assert( iCol==pTerm->u.leftColumn );
         3984  +      /* assert( iCol==pTerm->u.leftColumn ); */
  3983   3985         if( bFirst==0 ) zBuf = whereAppendPrintf(db, "%z ", zBuf);
  3984         -      zBuf = whereAppendSingleTerm(pParse, pTab, pWC->op==TK_OR, zBuf, pTerm);
         3986  +      zBuf = whereAppendSingleTerm(pParse, pTab, iCol, bOr, zBuf, pTerm);
  3985   3987         bFirst = 0;
  3986   3988       }
  3987   3989     }
  3988   3990   
  3989   3991     /* Add composite - (WO_OR|WO_AND) - constraints */
  3990   3992     for(ii=0; ii<pWC->nTerm; ii++){
  3991   3993       WhereTerm *pTerm = &pWC->a[ii];

Changes to tool/schemalint.tcl.

   555    555     sqlidx_one_test 10.2 {
   556    556       CREATE TABLE t4(a, b, c);
   557    557     } {
   558    558       SELECT * FROM t4 WHERE c = ? COLLATE "a b c"
   559    559     } {
   560    560       {CREATE INDEX "t4_ca b c" ON t4(c COLLATE "a b c");}
   561    561     }
          562  +
          563  +  # Transitive constraints
          564  +  #
          565  +  sqlidx_one_test 11.1 {
          566  +    CREATE TABLE t5(a, b);
          567  +    CREATE TABLE t6(c, d);
          568  +  } {
          569  +    SELECT * FROM t5, t6 WHERE a=? AND b=c AND c=?
          570  +  } {
          571  +    {CREATE INDEX t6_c ON t6(c);} 
          572  +    {CREATE INDEX t5_a_b ON t5(a, b);}
          573  +  }
   562    574   
   563    575     puts "All $nTest tests passed"
   564    576     exit
   565    577   }
   566    578   # End of internal test code.
   567    579   #-------------------------------------------------------------------------
   568    580