/ Check-in [45c6a760]
Login

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

Overview
Comment:Allow the RBU module to read data from appropriately named SQL views created within the RBU database.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:45c6a760ca63d19a7ccc352c7e35d8391025b515
User & Date: dan 2015-07-24 18:58:59
Context
2015-07-24
19:56
Fix the pragma2.test module so that it works with SQLITE_ENABLE_MEMORY_MANAGEMENT. check-in: de281a4f user: drh tags: trunk
18:58
Allow the RBU module to read data from appropriately named SQL views created within the RBU database. check-in: 45c6a760 user: dan tags: trunk
18:22
Fix a test script bug introduced by [562687d9]. check-in: a343745d user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added ext/rbu/rbu14.test.































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 2015 July 25
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Test that an RBU data_xxx table may be a view instead of a regular
# table.
#

if {![info exists testdir]} {
  set testdir [file join [file dirname [info script]] .. .. test]
}
source $testdir/tester.tcl
source $testdir/lock_common.tcl
set ::testprefix rbu14


foreach {tn schema} {
  1 {
    CREATE TABLE t1(a PRIMARY KEY, b, c);
    CREATE TABLE t2(a PRIMARY KEY, b, c);
  }
  2 {
    CREATE TABLE t1(a PRIMARY KEY, b, c);
    CREATE TABLE t2(a PRIMARY KEY, b, c);
    CREATE INDEX i1 ON t1(b, c);
    CREATE INDEX i2 ON t2(b, c);
  }
  3 {
    CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
    CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
  }
  4 {
    CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
    CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
    CREATE INDEX i1 ON t1(b, c);
    CREATE INDEX i2 ON t2(b, c);
  }
} {
  reset_db

  execsql $schema
  execsql {
    INSERT INTO t1 VALUES(50, 50, 50);
    INSERT INTO t1 VALUES(51, 51, 51);
    INSERT INTO t2 VALUES(50, 50, 50);
    INSERT INTO t2 VALUES(51, 51, 51);
  }

  forcedelete rbu.db
  do_execsql_test $tn.1 {
    ATTACH 'rbu.db' AS rbu;
    CREATE TABLE rbu.stuff(tbl, a, b, c, rbu_control);
    INSERT INTO stuff VALUES
      ('t1', 1, 2, 3, 0),                   -- insert into t1
      ('t2', 4, 5, 6, 0),                   -- insert into t2
      ('t1', 50, NULL, NULL, 1),            -- delete from t1
      ('t2', 51, NULL, NULL, 1);            -- delete from t2

    CREATE VIEW rbu.data_t1 AS 
    SELECT a, b, c, rbu_control FROM stuff WHERE tbl='t1';
    CREATE VIEW rbu.data_t2 AS 
    SELECT a, b, c, rbu_control FROM stuff WHERE tbl='t2';
  }

  do_test $tn.2 {
    while 1 {
      sqlite3rbu rbu test.db rbu.db
      set rc [rbu step]
      rbu close
      if {$rc != "SQLITE_OK"} break
    }
    set rc
  } {SQLITE_DONE}

  do_execsql_test $tn.3.1 {
    SELECT * FROM t1 ORDER BY a;
  } {1 2 3 51 51 51}

  do_execsql_test $tn.3.2 {
    SELECT * FROM t2 ORDER BY a;
  } {4 5 6 50 50 50}

  integrity_check $tn.4
}


finish_test

Changes to ext/rbu/sqlite3rbu.c.

564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
*/
static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
  int rc;
  memset(pIter, 0, sizeof(RbuObjIter));

  rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, 
      "SELECT substr(name, 6) FROM sqlite_master "
      "WHERE type='table' AND name LIKE 'data_%'"
  );

  if( rc==SQLITE_OK ){
    rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
        "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
        "  FROM main.sqlite_master "
        "  WHERE type='index' AND tbl_name = ?"







|







564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
*/
static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
  int rc;
  memset(pIter, 0, sizeof(RbuObjIter));

  rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, 
      "SELECT substr(name, 6) FROM sqlite_master "
      "WHERE type IN ('table', 'view') AND name LIKE 'data_%'"
  );

  if( rc==SQLITE_OK ){
    rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
        "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
        "  FROM main.sqlite_master "
        "  WHERE type='index' AND tbl_name = ?"