/ Check-in [ecb56b75]
Login

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

Overview
Comment:Add tests to improve code coverage of the RBU module.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ecb56b75a0e66462acdcce285b93f9fc56944c42902d886d6bada419059519a9
User & Date: dan 2019-05-08 18:49:51
Context
2019-05-08
19:06
Avoid an excess register allocation in UPDATE, when possible. This improves speed (slightly) and reduces the code footprint. check-in: 8658574e user: drh tags: trunk
18:49
Add tests to improve code coverage of the RBU module. check-in: ecb56b75 user: dan tags: trunk
17:27
Provide the SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA compile-time option to omit the case_sensitive_like pragma. This change, in combination with documentation changes, is the current solution to ticket [a340eef47b0cad5]. check-in: eabe7f2d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rbu/rbufault3.test.

    79     79     sqlite3rbu_vacuum rbu test.db test.db2
    80     80     rbu step
    81     81     rbu close
    82     82     faultsim_save_and_close
    83     83   
    84     84     do_faultsim_test 3 -faults $fault -prep {
    85     85       faultsim_restore_and_reopen
    86         -    forcedelete test.db2
    87     86     } -body {
    88     87       sqlite3rbu_vacuum rbu test.db test.db2
    89     88       rbu step
    90     89       rbu close
    91     90     } -test {
    92     91       eval [list faultsim_test_result {0 SQLITE_OK} {*}$::errlist]
    93     92     }
    94         -
    95     93   }
    96     94   
    97     95   finish_test

Added ext/rbu/rbumisc.test.

            1  +# 2014 August 30
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +
           13  +source [file join [file dirname [info script]] rbu_common.tcl]
           14  +set ::testprefix rbumisc
           15  +
           16  +db close
           17  +sqlite3_shutdown
           18  +sqlite3_config_uri 1
           19  +reset_db
           20  +
           21  +#-------------------------------------------------------------------------
           22  +# Ensure that RBU is not confused by oddly named tables in an RBU 
           23  +# database.
           24  +#
           25  +do_execsql_test 1.0 {
           26  +  CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY);
           27  +}
           28  +do_test 1.1 {
           29  +  forcedelete rbu.db
           30  +  sqlite3 rbu rbu.db
           31  +  rbu eval {
           32  +    CREATE TABLE data_x1(a, b, c, rbu_control);
           33  +    INSERT INTO data_x1 VALUES(1, 1, 1, 0);
           34  +    INSERT INTO data_x1 VALUES(2, 2, 2, 0);
           35  +
           36  +    CREATE TABLE dat(a, b, c, rbu_control);
           37  +    CREATE TABLE "data x1"(a, b, c, rbu_control);
           38  +    CREATE TABLE datax1(a, b, c, rbu_control);
           39  +    CREATE TABLE data_(a, b, c, rbu_control);
           40  +
           41  +    INSERT INTO "data x1" VALUES(3, 3, 3, 0);
           42  +    INSERT INTO datax1 VALUES(3, 3, 3, 0);
           43  +    INSERT INTO data_ VALUES(3, 3, 3, 0);
           44  +    INSERT INTO dat VALUES(3, 3, 3, 0);
           45  +  }
           46  +} {}
           47  +
           48  +do_test 1.2 {
           49  +  step_rbu test.db rbu.db
           50  +  db eval { SELECT * FROM x1 }
           51  +} {1 1 1 2 2 2}
           52  +
           53  +finish_test

Changes to ext/rbu/rbutemplimit.test.

    61     61   }
    62     62   
    63     63   proc step_rbu_cachesize {target rbu stepsize cachesize temp_limit} {
    64     64     set res ""
    65     65     while 1 {
    66     66       sqlite3rbu rbu $target $rbu
    67     67       rbu temp_size_limit $temp_limit
           68  +    if { [rbu temp_size_limit -1]!=$temp_limit } { error "round trip problem!" }
    68     69       sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
    69     70       for {set i 0} {$i < $stepsize} {incr i} {
    70     71         set rc [rbu step]
    71     72         set ::A([rbu temp_size]) 1
    72     73         if {$rc!="SQLITE_OK"} break
    73     74       }
    74     75       set res [list [catch {rbu close} msg] $msg]

Changes to ext/rbu/rbuvacuum4.test.

    46     46   
    47     47   do_execsql_test 3.0 {
    48     48     CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
    49     49     CREATE INDEX i1 oN t1(b, c);
    50     50     INSERT INTO t1 VALUES(1, 2, 3);
    51     51     INSERT INTO t1 VALUES(4, 5, 6);
    52     52     INSERT INTO t1 VALUES(7, 8, 9);
           53  +
           54  +  CREATE TABLE t2(a, b, c INTEGER, PRIMARY KEY(c));
           55  +  CREATE INDEX i2 oN t2(b, a);
           56  +  INSERT INTO t2 VALUES('a', 'b', -1);
           57  +  INSERT INTO t2 VALUES('c', 'd', -2);
           58  +  INSERT INTO t2 VALUES('e', 'f', -3);
    53     59   }
    54     60   
    55     61   do_rbu_vacuum_test 3.1 1
    56     62   
    57     63   do_execsql_test 3.2 {
    58     64     SELECT * FROM t1;
    59         -} {1 2 3 4 5 6 7 8 9}
           65  +  SELECT * FROM t2;
           66  +} {1 2 3 4 5 6 7 8 9 e f -3 c d -2 a b -1}
    60     67   
    61     68   #-------------------------------------------------------------------------
    62     69   reset_db
    63     70   do_execsql_test 4.0 {
    64     71     CREATE TABLE x1(a, b, c, d, PRIMARY KEY(c, b)) WITHOUT ROWID;
    65     72     INSERT INTO x1 VALUES(1, 1, 1, 1);
    66     73     INSERT INTO x1 VALUES(1, 1, 2, 1);
................................................................................
    91     98     INSERT INTO "a b c" VALUES(NULL, 'a', NULL);
    92     99     INSERT INTO "a b c" VALUES(NULL, 'b', NULL);
    93    100     INSERT INTO "a b c" VALUES(NULL, 'c', NULL);
    94    101   
    95    102     INSERT INTO "a b c" VALUES(1, 2, 3);
    96    103     INSERT INTO "a b c" VALUES(3, 9, 1);
    97    104     INSERT INTO "a b c" VALUES('aaa', 'bbb', 'ccc');
          105  +
          106  +  CREATE INDEX abc2 ON "a b c"("c c" DESC, a);
    98    107   
    99    108     CREATE TABLE x(a);
   100    109     INSERT INTO x VALUES('a'), ('b'), ('d');
   101    110     CREATE UNIQUE INDEX y ON x(a);
   102    111   }
   103    112   
   104    113   do_rbu_vacuum_test 5.1 1
   105    114   
   106    115   finish_test
   107    116   

Changes to ext/rbu/sqlite3rbu.c.

  1542   1542   ){
  1543   1543     char *zOrder = 0;
  1544   1544     char *zLhs = 0;
  1545   1545     char *zSelect = 0;
  1546   1546     char *zVector = 0;
  1547   1547     char *zRet = 0;
  1548   1548     int bFailed = 0;
  1549         -
  1550         -  if( p->rc==SQLITE_OK ){
  1551         -    const char *zSep = "";
  1552         -    int iCol = 0;
  1553         -    sqlite3_stmt *pXInfo = 0;
  1554         -    p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
  1555         -        sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", pIter->zIdx)
  1556         -    );
  1557         -    while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
  1558         -      int iCid = sqlite3_column_int(pXInfo, 1);
  1559         -      const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
  1560         -      const char *zCol;
  1561         -      if( sqlite3_column_int(pXInfo, 3) ){
  1562         -        bFailed = 1;
  1563         -        break;
  1564         -      }
  1565         -
  1566         -      if( iCid<0 ){
  1567         -        if( pIter->eType==RBU_PK_IPK ){
  1568         -          int i;
  1569         -          for(i=0; pIter->abTblPk[i]==0; i++);
  1570         -          assert( i<pIter->nTblCol );
  1571         -          zCol = pIter->azTblCol[i];
  1572         -        }else{
  1573         -          zCol = "_rowid_";
  1574         -        }
         1549  +  const char *zSep = "";
         1550  +  int iCol = 0;
         1551  +  sqlite3_stmt *pXInfo = 0;
         1552  +
         1553  +  p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
         1554  +      sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", pIter->zIdx)
         1555  +  );
         1556  +  while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
         1557  +    int iCid = sqlite3_column_int(pXInfo, 1);
         1558  +    const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
         1559  +    const char *zCol;
         1560  +    if( sqlite3_column_int(pXInfo, 3) ){
         1561  +      bFailed = 1;
         1562  +      break;
         1563  +    }
         1564  +
         1565  +    if( iCid<0 ){
         1566  +      if( pIter->eType==RBU_PK_IPK ){
         1567  +        int i;
         1568  +        for(i=0; pIter->abTblPk[i]==0; i++);
         1569  +        assert( i<pIter->nTblCol );
         1570  +        zCol = pIter->azTblCol[i];
  1575   1571         }else{
  1576         -        zCol = pIter->azTblCol[iCid];
         1572  +        zCol = "_rowid_";
  1577   1573         }
         1574  +    }else{
         1575  +      zCol = pIter->azTblCol[iCid];
         1576  +    }
  1578   1577   
  1579         -      zLhs = rbuMPrintf(p, "%z%s \"%w\" COLLATE %Q",
  1580         -          zLhs, zSep, zCol, zCollate
  1581         -      );
  1582         -      zOrder = rbuMPrintf(p, "%z%s \"rbu_imp_%d%w\" COLLATE %Q DESC",
  1583         -          zOrder, zSep, iCol, zCol, zCollate
  1584         -      );
  1585         -      zSelect = rbuMPrintf(p, "%z%s quote(\"rbu_imp_%d%w\")",
  1586         -          zSelect, zSep, iCol, zCol
  1587         -      );
  1588         -      zSep = ", ";
  1589         -      iCol++;
  1590         -    }
  1591         -    rbuFinalize(p, pXInfo);
         1578  +    zLhs = rbuMPrintf(p, "%z%s \"%w\" COLLATE %Q",
         1579  +        zLhs, zSep, zCol, zCollate
         1580  +        );
         1581  +    zOrder = rbuMPrintf(p, "%z%s \"rbu_imp_%d%w\" COLLATE %Q DESC",
         1582  +        zOrder, zSep, iCol, zCol, zCollate
         1583  +        );
         1584  +    zSelect = rbuMPrintf(p, "%z%s quote(\"rbu_imp_%d%w\")",
         1585  +        zSelect, zSep, iCol, zCol
         1586  +        );
         1587  +    zSep = ", ";
         1588  +    iCol++;
  1592   1589     }
         1590  +  rbuFinalize(p, pXInfo);
  1593   1591     if( bFailed ) goto index_start_out;
  1594   1592   
  1595   1593     if( p->rc==SQLITE_OK ){
  1596         -    int iCol;
  1597   1594       sqlite3_stmt *pSel = 0;
  1598   1595   
  1599         -    if( p->rc==SQLITE_OK ){
  1600         -      p->rc = prepareFreeAndCollectError(p->dbMain, &pSel, &p->zErrmsg,
  1601         -          sqlite3_mprintf("SELECT %s FROM \"rbu_imp_%w\" ORDER BY %s LIMIT 1",
  1602         -            zSelect, pIter->zTbl, zOrder
  1603         -          )
  1604         -      );
  1605         -    }
         1596  +    p->rc = prepareFreeAndCollectError(p->dbMain, &pSel, &p->zErrmsg,
         1597  +        sqlite3_mprintf("SELECT %s FROM \"rbu_imp_%w\" ORDER BY %s LIMIT 1",
         1598  +          zSelect, pIter->zTbl, zOrder
         1599  +        )
         1600  +    );
  1606   1601       if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSel) ){
  1607         -      const char *zSep = "";
         1602  +      zSep = "";
  1608   1603         for(iCol=0; iCol<pIter->nCol; iCol++){
  1609   1604           const char *zQuoted = (const char*)sqlite3_column_text(pSel, iCol);
  1610   1605           if( zQuoted[0]=='N' ){
  1611   1606             bFailed = 1;
  1612   1607             break;
  1613   1608           }
  1614   1609           zVector = rbuMPrintf(p, "%z%s%s", zVector, zSep, zQuoted);