/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/where.c.

3920
3921
3922
3923
3924
3925
3926

3927
3928
3929
3930
3931
3932
3933
....
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
....
3965
3966
3967
3968
3969
3970
3971

3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
/*
** Append a representation of term pTerm to the string in zIn and return
** the result. Or, if an OOM occurs, free zIn and return a NULL pointer.
*/
static char *whereAppendSingleTerm(
  Parse *pParse,
  Table *pTab,

  int bOr,
  char *zIn,
  WhereTerm *pTerm
){
  char *zBuf;
  sqlite3 *db = pParse->db;
  Expr *pX = pTerm->pExpr;
................................................................................
  }
  pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);

  if( zOp ){
    const char *zFmt = bOr ? "%z{{%s \"%w\" \"%w\" %lld}}" :
                             "%z{%s \"%w\" \"%w\" %lld}";
    zBuf = whereAppendPrintf(db, zFmt, zIn, 
        zOp, pTab->aCol[pTerm->u.leftColumn].zName, 
        (pColl ? pColl->zName : "BINARY"),
        pTerm->prereqRight
    );
  }else{
    zBuf = zIn;
  }

................................................................................
){
  sqlite3 *db = pParse->db;
  Table *pTab = pItem->pTab;
  char *zBuf = zIn;
  int iCol;
  int ii;
  int bFirst = !bInitialSpace;


  /* List of WO_SINGLE constraints */
  for(iCol=0; iCol<pTab->nCol; iCol++){
    int opMask = WO_SINGLE; 
    WhereScan scan;
    WhereTerm *pTerm;
    for(pTerm=whereScanInit(&scan, pWC, pItem->iCursor, iCol, opMask, 0);
        pTerm;
        pTerm=whereScanNext(&scan)
    ){
      assert( iCol==pTerm->u.leftColumn );
      if( bFirst==0 ) zBuf = whereAppendPrintf(db, "%z ", zBuf);
      zBuf = whereAppendSingleTerm(pParse, pTab, pWC->op==TK_OR, zBuf, pTerm);
      bFirst = 0;
    }
  }

  /* Add composite - (WO_OR|WO_AND) - constraints */
  for(ii=0; ii<pWC->nTerm; ii++){
    WhereTerm *pTerm = &pWC->a[ii];







>







 







|







 







>










|

|







3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
....
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
....
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
/*
** Append a representation of term pTerm to the string in zIn and return
** the result. Or, if an OOM occurs, free zIn and return a NULL pointer.
*/
static char *whereAppendSingleTerm(
  Parse *pParse,
  Table *pTab,
  int iCol,
  int bOr,
  char *zIn,
  WhereTerm *pTerm
){
  char *zBuf;
  sqlite3 *db = pParse->db;
  Expr *pX = pTerm->pExpr;
................................................................................
  }
  pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);

  if( zOp ){
    const char *zFmt = bOr ? "%z{{%s \"%w\" \"%w\" %lld}}" :
                             "%z{%s \"%w\" \"%w\" %lld}";
    zBuf = whereAppendPrintf(db, zFmt, zIn, 
        zOp, pTab->aCol[iCol].zName, 
        (pColl ? pColl->zName : "BINARY"),
        pTerm->prereqRight
    );
  }else{
    zBuf = zIn;
  }

................................................................................
){
  sqlite3 *db = pParse->db;
  Table *pTab = pItem->pTab;
  char *zBuf = zIn;
  int iCol;
  int ii;
  int bFirst = !bInitialSpace;
  int bOr = (pWC->op==TK_OR);

  /* List of WO_SINGLE constraints */
  for(iCol=0; iCol<pTab->nCol; iCol++){
    int opMask = WO_SINGLE; 
    WhereScan scan;
    WhereTerm *pTerm;
    for(pTerm=whereScanInit(&scan, pWC, pItem->iCursor, iCol, opMask, 0);
        pTerm;
        pTerm=whereScanNext(&scan)
    ){
      /* assert( iCol==pTerm->u.leftColumn ); */
      if( bFirst==0 ) zBuf = whereAppendPrintf(db, "%z ", zBuf);
      zBuf = whereAppendSingleTerm(pParse, pTab, iCol, bOr, zBuf, pTerm);
      bFirst = 0;
    }
  }

  /* Add composite - (WO_OR|WO_AND) - constraints */
  for(ii=0; ii<pWC->nTerm; ii++){
    WhereTerm *pTerm = &pWC->a[ii];

Changes to tool/schemalint.tcl.

555
556
557
558
559
560
561












562
563
564
565
566
567
568
  sqlidx_one_test 10.2 {
    CREATE TABLE t4(a, b, c);
  } {
    SELECT * FROM t4 WHERE c = ? COLLATE "a b c"
  } {
    {CREATE INDEX "t4_ca b c" ON t4(c COLLATE "a b c");}
  }













  puts "All $nTest tests passed"
  exit
}
# End of internal test code.
#-------------------------------------------------------------------------








>
>
>
>
>
>
>
>
>
>
>
>







555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
  sqlidx_one_test 10.2 {
    CREATE TABLE t4(a, b, c);
  } {
    SELECT * FROM t4 WHERE c = ? COLLATE "a b c"
  } {
    {CREATE INDEX "t4_ca b c" ON t4(c COLLATE "a b c");}
  }

  # Transitive constraints
  #
  sqlidx_one_test 11.1 {
    CREATE TABLE t5(a, b);
    CREATE TABLE t6(c, d);
  } {
    SELECT * FROM t5, t6 WHERE a=? AND b=c AND c=?
  } {
    {CREATE INDEX t6_c ON t6(c);} 
    {CREATE INDEX t5_a_b ON t5(a, b);}
  }

  puts "All $nTest tests passed"
  exit
}
# End of internal test code.
#-------------------------------------------------------------------------