SQLite

Check-in [961e79da73]
Login

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

Overview
Comment:Add test script ext/rbu/rbu_round_trip.tcl. Uses "dbselftest" to test that "rbu" and "sqldiff" work together.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 961e79da73b4550b3e5b0f9a617133a76485db67
User & Date: dan 2017-03-07 20:03:25.030
Context
2017-03-08
11:44
Add the --preserve-rowids option to the ".dump" command in the CLI. (check-in: c60aee2471 user: drh tags: trunk)
2017-03-07
20:03
Add test script ext/rbu/rbu_round_trip.tcl. Uses "dbselftest" to test that "rbu" and "sqldiff" work together. (check-in: 961e79da73 user: dan tags: trunk)
14:38
Performance optimization in the tokenizer/parser loop. (check-in: 2cb71583d6 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Added ext/rbu/rbu_round_trip.tcl.


























































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
##########################################################################
# 2016 Mar 8
#
# 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.
#
proc process_cmdline {} { 
  cmdline::process ::A $::argv {
    {make                 "try to build missing tools"}
    {verbose              "make more noise"}
    database
    database2
  } {
 This script uses/tests the following tools:

   dbselftest
   rbu
   sqldiff
   sqlite3
 
 The user passes the names of two database files - a.db and b.db below - as
 arguments. This program:

 1. Runs [dbselftest --init] against both databases.
 2. Runs [sqldiff --rbu --vtab a.db b.db | sqlite3 <tmpname>.db] to create an 
    RBU database.
 3. Runs [rbu b.db <tmpname>.db] to patch b.db to a.db.
 4. Runs [sqldiff --table selftest a.db b.db] to check that the selftest
    tables are now identical.
 5. Runs [dbselftest] against both databases.
  }
}

###########################################################################
###########################################################################
# Command line options processor. This is generic code that can be copied
# between scripts.
#
namespace eval cmdline {
  proc cmdline_error {O E {msg ""}} {
    if {$msg != ""} {
      puts stderr "Error: $msg"
      puts stderr ""
    }
  
    set L [list]
    foreach o $O {
      if {[llength $o]==1} {
        lappend L [string toupper $o]
      }
    }
  
    puts stderr "Usage: $::argv0 ?SWITCHES? $L"
    puts stderr ""
    puts stderr "Switches are:"
    foreach o $O {
      if {[llength $o]==3} {
        foreach {a b c} $o {}
        puts stderr [format "    -%-15s %s (default \"%s\")" "$a VAL" $c $b]
      } elseif {[llength $o]==2} {
        foreach {a b} $o {}
        puts stderr [format "    -%-15s %s" $a $b]
      }
    }
    puts stderr ""
    puts stderr $E
    exit -1
  }
  
  proc process {avar lArgs O E} {
    upvar $avar A
    set zTrailing ""       ;# True if ... is present in $O
    set lPosargs [list]
  
    # Populate A() with default values. Also, for each switch in the command
    # line spec, set an entry in the idx() array as follows:
    #
    #  {tblname t1 "table name to use"}  
    #      -> [set idx(-tblname) {tblname t1 "table name to use"}  
    #
    # For each position parameter, append its name to $lPosargs. If the ...
    # specifier is present, set $zTrailing to the name of the prefix.
    #
    foreach o $O {
      set nm [lindex $o 0]
      set nArg [llength $o]
      switch -- $nArg {
        1 {
          if {[string range $nm end-2 end]=="..."} {
            set zTrailing [string range $nm 0 end-3]
          } else {
            lappend lPosargs $nm
          }
        }
        2 {
          set A($nm) 0
          set idx(-$nm) $o
        }
        3 {
          set A($nm) [lindex $o 1]
          set idx(-$nm) $o
        }
        default {
          error "Error in command line specification"
        }
      }
    }
  
    # Set explicitly specified option values
    #
    set nArg [llength $lArgs]
    for {set i 0} {$i < $nArg} {incr i} {
      set opt [lindex $lArgs $i]
      if {[string range $opt 0 0]!="-" || $opt=="--"} break
      set c [array names idx "${opt}*"]
      if {[llength $c]==0} { cmdline_error $O $E "Unrecognized option: $opt"}
      if {[llength $c]>1}  { cmdline_error $O $E "Ambiguous option: $opt"}
  
      if {[llength $idx($c)]==3} {
        if {$i==[llength $lArgs]-1} {
          cmdline_error $O $E "Option requires argument: $c" 
        }
        incr i
        set A([lindex $idx($c) 0]) [lindex $lArgs $i]
      } else {
        set A([lindex $idx($c) 0]) 1
      }
    }
  
    # Deal with position arguments.
    #
    set nPosarg [llength $lPosargs]
    set nRem [expr $nArg - $i]
    if {$nRem < $nPosarg || ($zTrailing=="" && $nRem > $nPosarg)} {
      cmdline_error $O $E
    }
    for {set j 0} {$j < $nPosarg} {incr j} {
      set A([lindex $lPosargs $j]) [lindex $lArgs [expr $j+$i]]
    }
    if {$zTrailing!=""} {
      set A($zTrailing) [lrange $lArgs [expr $j+$i] end]
    }
  }
} ;# namespace eval cmdline
# End of command line options processor.
###########################################################################
###########################################################################

process_cmdline

# Check that the specified tool is present.
#
proc check_for_tool {tool} {
  if {[file exists $tool]==0 || [file executable $tool]==0} {
    puts stderr "Missing $tool... exiting. (run \[make $tool\])"
    exit -1
  }
}

if {$A(make)} {
  if {$A(verbose)} { puts "building tools..." }
  exec make dbselftest rbu sqlite3 sqldiff
}

check_for_tool dbselftest
check_for_tool rbu
check_for_tool sqlite3
check_for_tool sqldiff

exec ./sqlite3 $A(database) "DROP TABLE selftest;"
exec ./sqlite3 $A(database2) "DROP TABLE selftest;"

# Run [dbselftest --init] on both databases
if {$A(verbose)} { puts "Running \[dbselftest --init\]" }
exec ./dbselftest --init $A(database)
exec ./dbselftest --init $A(database2)

# Create an RBU patch.
set tmpname "./rrt-[format %x [expr int(rand()*0x7FFFFFFF)]].db"
if {$A(verbose)} { puts "rbu database is $tmpname" }
exec ./sqldiff --rbu --vtab $A(database2) $A(database) | ./sqlite3 $tmpname

# Run the [rbu] patch.
if {$A(verbose)} { puts "Running \[rbu]" }
exec ./rbu $A(database2) $tmpname

set selftest_diff [exec ./sqldiff --table selftest $A(database) $A(database2)]
if {$selftest_diff != ""} {
  puts stderr "patching table \"selftest\" failed: $selftest_diff"
  exit -1
}

# Run [dbselftest] on both databases
if {$A(verbose)} { puts "Running \[dbselftest]" }
exec ./dbselftest $A(database)
exec ./dbselftest $A(database2)

# Remove the RBU database
file delete $tmpname
puts "round trip test successful."