/ Check-in [1f7afb6e]
Login

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

Overview
Comment:Update the sqldiff tool so that it generates an rbu_count table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rbu-percent-progress
Files: files | file ages | folders
SHA1: 1f7afb6e9be9f549a91bf2ab492df15698df89fd
User & Date: dan 2016-03-19 16:21:26
Context
2016-03-19
17:09
Fix a problem detecting invalid values in the rbu_control column of an rbu database table. Closed-Leaf check-in: a1132dd9 user: dan tags: rbu-percent-progress
16:21
Update the sqldiff tool so that it generates an rbu_count table. check-in: 1f7afb6e user: dan tags: rbu-percent-progress
15:34
Merge latest trunk changes, including fixes to test script rbudiff.test, into this branch. check-in: 734fc68f user: dan tags: rbu-percent-progress
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rbu/rbudiff.test.

    32     32       rbu close
    33     33       if {$rc != "SQLITE_OK"} break
    34     34     }
    35     35     set rc
    36     36   }
    37     37   
    38     38   proc apply_rbudiff {sql target} {
           39  +  test_rbucount $sql
    39     40     forcedelete rbu.db
    40     41     sqlite3 rbudb rbu.db
    41     42     rbudb eval $sql
    42     43     rbudb close
    43     44     step_rbu $target rbu.db
    44     45   }
           46  +
           47  +# The only argument is the output of an [sqldiff -rbu] run. This command
           48  +# tests that the contents of the rbu_count table is correct. An exception
           49  +# is thrown if it is not.
           50  +#
           51  +proc test_rbucount {sql} {
           52  +  sqlite3 tmpdb ""
           53  +  tmpdb eval $sql
           54  +  tmpdb eval {
           55  +    SELECT name FROM sqlite_master WHERE name LIKE 'data%' AND type='table'
           56  +  } {
           57  +    set a [tmpdb eval "SELECT count(*) FROM $name"]
           58  +    set b [tmpdb eval {SELECT cnt FROM rbu_count WHERE tbl = $name}]
           59  +    if {$a != $b} { 
           60  +      tmpdb close
           61  +      error "rbu_count error - tbl = $name" 
           62  +    }
           63  +  }
           64  +  tmpdb close
           65  +  return ""
           66  +}
    45     67   
    46     68   proc rbudiff_cksum {db1} {
    47     69     set txt ""
    48     70   
    49     71     sqlite3 dbtmp $db1
    50     72     foreach tbl [dbtmp eval {SELECT name FROM sqlite_master WHERE type='table'}] {
    51     73       set cols [list]

Changes to ext/rbu/rbuprogress.test.

   375    375         2 {
   376    376           CREATE TABLE data0_t1(rbu_rowid, a, b, c, rbu_control);
   377    377           INSERT INTO data0_t1 VALUES(0, 7, 7, 7, 2);
   378    378           INSERT INTO data0_t1 VALUES(2, 10, 10, 10, 2);
   379    379           CREATE TABLE rbu_count(tbl, cnt);
   380    380           INSERT INTO rbu_count VALUES('data0_t1', 2); 
   381    381         } 
          382  +      {2500 4000 6000 8000 10000}
          383  +      {5000 10000}
          384  +
          385  +      3 {
          386  +        CREATE TABLE data0_t1(rbu_rowid, a, b, c, rbu_control);
          387  +        INSERT INTO data0_t1 VALUES(1, NULL, NULL, NULL, 1);
          388  +        INSERT INTO data0_t1 VALUES(2, NULL, NULL, 7, '..x');
          389  +        CREATE TABLE rbu_count(tbl, cnt);
          390  +        INSERT INTO rbu_count VALUES('data0_t1', 2); 
          391  +      } 
   382    392         {2500 4000 6000 8000 10000}
   383    393         {5000 10000}
   384    394       } {
   385    395   
   386    396         reset_db ; execsql $tbl
   387    397         do_test 5.$tn.$bReopen.$tn2.0 {
   388    398           execsql {

Changes to tool/sqldiff.c.

  1240   1240     char **azCol;                   /* NULL terminated array of col names */
  1241   1241     int i;
  1242   1242     int nCol;
  1243   1243     Str ct = {0, 0, 0};             /* The "CREATE TABLE data_xxx" statement */
  1244   1244     Str sql = {0, 0, 0};            /* Query to find differences */
  1245   1245     Str insert = {0, 0, 0};         /* First part of output INSERT statement */
  1246   1246     sqlite3_stmt *pStmt = 0;
         1247  +  int nRow = 0;                   /* Total rows in data_xxx table */
  1247   1248   
  1248   1249     /* --rbu mode must use real primary keys. */
  1249   1250     g.bSchemaPK = 1;
  1250   1251   
  1251   1252     /* Check that the schemas of the two tables match. Exit early otherwise. */
  1252   1253     checkSchemasMatch(zTab);
  1253   1254   
................................................................................
  1285   1286       if( ct.z ){
  1286   1287         fprintf(out, "%s\n", ct.z);
  1287   1288         strFree(&ct);
  1288   1289       }
  1289   1290   
  1290   1291       /* Output the first part of the INSERT statement */
  1291   1292       fprintf(out, "%s", insert.z);
         1293  +    nRow++;
  1292   1294   
  1293   1295       if( sqlite3_column_type(pStmt, nCol)==SQLITE_INTEGER ){
  1294   1296         for(i=0; i<=nCol; i++){
  1295   1297           if( i>0 ) fprintf(out, ", ");
  1296   1298           printQuoted(out, sqlite3_column_value(pStmt, i));
  1297   1299         }
  1298   1300       }else{
................................................................................
  1338   1340       }
  1339   1341   
  1340   1342       /* And the closing bracket of the insert statement */
  1341   1343       fprintf(out, ");\n");
  1342   1344     }
  1343   1345   
  1344   1346     sqlite3_finalize(pStmt);
         1347  +  if( nRow>0 ){
         1348  +    Str cnt = {0, 0, 0};
         1349  +    strPrintf(&cnt, "INSERT INTO rbu_count VALUES('data_%q', %d);", zTab, nRow);
         1350  +    fprintf(out, "%s\n", cnt.z);
         1351  +    strFree(&cnt);
         1352  +  }
  1345   1353   
  1346   1354     strFree(&ct);
  1347   1355     strFree(&sql);
  1348   1356     strFree(&insert);
  1349   1357   }
  1350   1358   
  1351   1359   /*
................................................................................
  1852   1860     }
  1853   1861     rc = sqlite3_exec(g.db, "SELECT * FROM aux.sqlite_master", 0, 0, &zErrMsg);
  1854   1862     if( rc || zErrMsg ){
  1855   1863       cmdlineError("\"%s\" does not appear to be a valid SQLite database", zDb2);
  1856   1864     }
  1857   1865   
  1858   1866     if( neverUseTransaction ) useTransaction = 0;
  1859         -  if( useTransaction ) printf("BEGIN TRANSACTION;\n");
         1867  +  if( useTransaction ) fprintf(out, "BEGIN TRANSACTION;\n");
         1868  +  if( xDiff==rbudiff_one_table ){
         1869  +    fprintf(out, "CREATE TABLE IF NOT EXISTS rbu_count"
         1870  +           "(tbl TEXT PRIMARY KEY COLLATE NOCASE, cnt INTEGER) "
         1871  +           "WITHOUT ROWID;\n"
         1872  +    );
         1873  +  }
  1860   1874     if( zTab ){
  1861   1875       xDiff(zTab, out);
  1862   1876     }else{
  1863   1877       /* Handle tables one by one */
  1864   1878       pStmt = db_prepare(
  1865   1879         "SELECT name FROM main.sqlite_master\n"
  1866   1880         " WHERE type='table' AND sql NOT LIKE 'CREATE VIRTUAL%%'\n"