File: 19_backup_test.patch

package info (click to toggle)
db5.3 5.3.28%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 158,500 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,264; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; javascript: 1,998; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (371 lines) | stat: -rw-r--r-- 10,340 bytes parent folder | download | duplicates (10)
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
--- test/backup.test
+++ test/backup.test
@@ -164,12 +164,12 @@
   set file_dest temp
 }] {
 foreach rows_dest {0 3 10} {
-foreach pgsz_dest {512 1024 2048} {
+foreach pgsz_dest {1024} {
 foreach nPagePerStep {1 200} {
 
   # Open the databases.
-  catch { file delete test.db }
-  catch { file delete test2.db }
+  catch { file delete -force -- test.db }
+  catch { file delete -force -- test2.db }
   eval $zOpenScript
 
   # Set to true if copying to an in-memory destination. Copying to an 
@@ -191,6 +191,7 @@
     # Set up the content of the source database.
     execsql {
       PRAGMA page_size = 1024;
+      PRAGMA cache_size = 4000;
       BEGIN;
       CREATE TABLE t1(a, b);
       CREATE INDEX i1 ON t1(a, b);
@@ -206,9 +207,9 @@
 
     # Set up the content of the target database.
     execsql "PRAGMA ${file_dest}.page_size = ${pgsz_dest}" $db_dest
+    execsql "PRAGMA ${file_dest}.cache_size = 4000" $db_dest
     if {$rows_dest != 0} {
       execsql "
-        BEGIN; 
         CREATE TABLE ${file_dest}.t1(a, b);
         CREATE INDEX ${file_dest}.i1 ON t1(a, b);
       " $db_dest
@@ -244,119 +245,6 @@
 # End of backup-2.* tests.
 #---------------------------------------------------------------------
 
-#---------------------------------------------------------------------
-# These tests, backup-3.*, ensure that nothing goes wrong if either 
-# the source or destination database are large enough to include the
-# the locking-page (the page that contains the range of bytes that
-# the locks are applied to). These tests assume that the pending
-# byte is at offset 0x00010000 (64KB offset), as set by tester.tcl, 
-# not at the 1GB offset as it usually is.
-#
-# The test procedure is as follows (same procedure as used for 
-# the backup-2.* tests):
-#
-#   1) Populate the source database.
-#   2) Populate the destination database.
-#   3) Run the backup to completion. (backup-3.*.1)
-#   4) Integrity check the destination db. (backup-3.*.2)
-#   5) Check that the contents of the destination db is the same as that
-#      of the source db. (backup-3.*.3)
-#
-# The test procedure is run with the following parameters varied: 
-#
-#   * Source database includes pending-byte page.
-#   * Source database does not include pending-byte page.
-#
-#   * Target database includes pending-byte page.
-#   * Target database does not include pending-byte page.
-#
-#   * Target database page-size is the same as the source, OR
-#   * Target database page-size is larger than the source, OR
-#   * Target database page-size is smaller than the source.
-#
-set iTest 1
-foreach nSrcPg {10 64 65 66 100} {
-foreach nDestRow {10 100} {
-foreach nDestPgsz {512 1024 2048 4096} {
-
-  catch { file delete test.db }
-  catch { file delete test2.db }
-  sqlite3 db test.db
-  sqlite3 db2 test2.db
-
-  # Set up the content of the two databases.
-  #
-  execsql { PRAGMA page_size = 1024 }
-  execsql "PRAGMA page_size = $nDestPgsz" db2
-  foreach db {db db2} {
-    execsql {
-      BEGIN; 
-      CREATE TABLE t1(a, b);
-      CREATE INDEX i1 ON t1(a, b);
-      COMMIT;
-    } $db
-  }
-  while {[file size test.db]/1024 < $nSrcPg} {
-    execsql { INSERT INTO t1 VALUES($ii, randstr(200,200)) }
-  }
-
-  for {set ii 0} {$ii < $nDestRow} {incr ii} {
-    execsql { INSERT INTO t1 VALUES($ii, randstr(1000,1000)) } db2
-  }
-
-  # Backup the source database.
-  do_test backup-3.$iTest.1 {
-    sqlite3_backup B db main db2 main
-    while {[B step 10]=="SQLITE_OK"} {}
-    B finish
-  } {SQLITE_OK}
-    
-  # Run integrity check on the backup.
-  do_test backup-3.$iTest.2 {
-    execsql "PRAGMA integrity_check" db2
-  } {ok}
-  
-  test_contents backup-3.$iTest.3 db main db2 main
-
-  db close
-  db2 close
-  incr iTest
-}
-}
-}
-
-#--------------------------------------------------------------------
-do_test backup-3.$iTest.1 {
-  catch { file delete -force test.db }
-  catch { file delete -force test2.db }
-  sqlite3 db test.db
-  set iTab 1
-
-  db eval { PRAGMA page_size = 512 }
-  while {[file size test.db] <= $::sqlite_pending_byte} {
-    db eval "CREATE TABLE t${iTab}(a, b, c)"
-    incr iTab
-  }
-
-  sqlite3 db2 test2.db
-  db2 eval { PRAGMA page_size = 4096 }
-  while {[file size test2.db] < $::sqlite_pending_byte} {
-    db2 eval "CREATE TABLE t${iTab}(a, b, c)"
-    incr iTab
-  }
-
-  sqlite3_backup B db2 main db main
-  B step -1
-} {SQLITE_DONE}
-
-do_test backup-3.$iTest.2 {
-  B finish
-} {SQLITE_OK}
-
-#
-# End of backup-3.* tests.
-#---------------------------------------------------------------------
-
 
 #---------------------------------------------------------------------
 # The following tests, backup-4.*, test various error conditions:
@@ -439,7 +327,7 @@
 db2 close
 
 do_test backup-4.5.1 {
-  catch { file delete -force test.db }
+  catch { file delete -force -- test.db }
   sqlite3 db test.db
   sqlite3 db2 :memory:
   execsql {
@@ -492,11 +380,11 @@
 #
 set iTest 0
 file delete -force bak.db-wal
-foreach {writer file} {db test.db db3 test.db db :memory:} {
+foreach {writer file} {db test.db db :memory:} {
   incr iTest
-  catch { file delete bak.db }
+  catch { file delete -force bak.db }
   sqlite3 db2 bak.db
-  catch { file delete $file }
+  catch { file delete -force $file }
   sqlite3 db $file
   sqlite3 db3 $file
 
@@ -520,7 +408,7 @@
   } {SQLITE_OK}
   do_test backup-5.$iTest.1.3 {
     execsql { UPDATE t1 SET a = a + 1 } $writer
-    B step 50
+    B step 500
   } {SQLITE_DONE}
   do_test backup-5.$iTest.1.4 {
     B finish
@@ -597,9 +485,9 @@
   catch {db close}
   catch {db2 close}
   catch {db3 close}
-  catch { file delete bak.db }
+  catch { file delete -force -- bak.db }
   sqlite3 db2 bak.db
-  catch { file delete $file }
+  catch { file delete -force -- $file }
   sqlite3 db $file
   sqlite3 db3 $file
   do_test backup-5.$iTest.5.1 {
@@ -631,7 +519,6 @@
     B finish
   } {SQLITE_OK} 
   integrity_check backup-5.$iTest.5.5 db2
-  test_contents backup-5.$iTest.5.6 db main db2 main
   catch {db close}
   catch {db2 close}
   catch {db3 close}
@@ -644,8 +531,8 @@
 # Test the sqlite3_backup_remaining() and backup_pagecount() APIs.
 #
 do_test backup-6.1 {
-  catch { file delete -force test.db }
-  catch { file delete -force test2.db }
+  catch { file delete -force -- test.db }
+  catch { file delete -force -- test2.db }
   sqlite3 db test.db
   sqlite3 db2 test2.db
   execsql {
@@ -701,10 +588,11 @@
 # backup-7.3.*: Destination database is externally locked (return SQLITE_BUSY).
 #
 do_test backup-7.0 {
-  catch { file delete -force test.db }
-  catch { file delete -force test2.db }
+  catch { file delete -force -- test.db }
+  catch { file delete -force -- test2.db }
   sqlite3 db2 test2.db
   sqlite3 db test.db
+  sqlite3 db3 test.db
   execsql {
     CREATE TABLE t1(a, b);
     CREATE INDEX i1 ON t1(a, b);
@@ -723,24 +611,12 @@
   sqlite3_backup B db2 main db main
   B step 5
 } {SQLITE_OK}
-do_test backup-7.1.2 {
-  sqlite3 db3 test.db
-  execsql { BEGIN EXCLUSIVE } db3
-  B step 5
-} {SQLITE_BUSY}
-do_test backup-7.1.3 {
-  execsql { ROLLBACK } db3
-  B step 5
-} {SQLITE_OK}
 do_test backup-7.2.1 {
   execsql { 
     BEGIN;
     INSERT INTO t1 VALUES(1, 4);
   }
 } {}
-do_test backup-7.2.2 {
-  B step 5000
-} {SQLITE_BUSY}
 do_test backup-7.2.3 {
   execsql { ROLLBACK }
   B step 5000
@@ -754,17 +630,17 @@
 do_test backup-7.3.1 {
   db2 close
   db3 close
-  file delete -force test2.db
+  file delete -force -- test2.db
   sqlite3 db2 test2.db
   sqlite3 db3 test2.db
 
   sqlite3_backup B db2 main db main
-  execsql { BEGIN ; CREATE TABLE t2(a, b); } db3
-
+  execsql { BEGIN ; CREATE TABLE t2(a, b); COMMIT; } db3
+ 
   B step 5
 } {SQLITE_BUSY}
 do_test backup-7.3.2 {
-  execsql { COMMIT } db3
+  catch { db3 close }
   B step 5000
 } {SQLITE_DONE}
 do_test backup-7.3.3 {
@@ -773,7 +649,6 @@
 test_contents backup-7.3.4 db main db2 main
 integrity_check backup-7.3.5 db2
 catch { db2 close }
-catch { db3 close }
 
 #-----------------------------------------------------------------------
 # The following tests, backup-8.*, test attaching multiple backup
@@ -783,8 +658,8 @@
 # These tests reuse the database "test.db" left over from backup-7.*.
 #
 do_test backup-8.1 {
-  catch { file delete -force test2.db }
-  catch { file delete -force test3.db }
+  catch { file delete -force -- test2.db }
+  catch { file delete -force -- test3.db }
   sqlite3 db2 test2.db
   sqlite3 db3 test3.db
 
@@ -865,8 +740,8 @@
 
 ifcapable memorymanage {
   db close
-  file delete -force test.db
-  file delete -force bak.db
+  file delete -force -- test.db
+  file delete -force -- bak.db
 
   sqlite3 db test.db
   sqlite3 db2 test.db
@@ -915,17 +790,24 @@
 # used as the source by a backup operation:
 #
 #   10.1.*: If the db is in-memory, the backup is restarted.
-#   10.2.*: If the db is a file, the backup is not restarted.
+#   10.2.*: If the db is a file, the backup is restarted.
+#   10.3.*: If the db is in-memory, and not updated, the backup is not
+#           restarted
+#   10.4.*: If the db is a file,and not updated, the backup is not
+#           restarted
 #
 db close
-file delete -force test.db test.db-journal
-foreach {tn file rc} {
-  1 test.db  SQLITE_DONE
-  2 :memory: SQLITE_OK
+file delete -force -- test.db test.db-journal
+foreach {tn file update rc} {
+  1 test.db  1 SQLITE_OK
+  2 :memory: 1 SQLITE_OK
+  1 test.db  0 SQLITE_DONE
+  2 :memory: 0 SQLITE_DONE
 } {
   do_test backup-10.$tn.1 {
     sqlite3 db $file
     execsql { 
+      DROP TABLE IF EXISTS t1;
       CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB);
       BEGIN;
         INSERT INTO t1 VALUES(NULL, randomblob(200));
@@ -942,21 +824,18 @@
     }
   } {256}
 
-  do_test backup-10.$tn.2 {
-    set pgs [execsql {pragma page_count}]
-    expr {$pgs > 50 && $pgs < 75}
-  } {1}
-
   do_test backup-10.$tn.3 {
-    file delete -force bak.db bak.db-journal
+    file delete -force -- bak.db bak.db-journal
     sqlite3 db2 bak.db
     sqlite3_backup B db2 main db main
     B step 50
   } {SQLITE_OK}
 
-  do_test backup-10.$tn.4 {
-    execsql { UPDATE t1 SET b = randomblob(200) WHERE a IN (1, 250) }
-  } {}
+  if { $update == 1 } {
+    do_test backup-10.$tn.4 {
+      execsql { UPDATE t1 SET b = randomblob(200) WHERE a IN (1, 250) }
+    } {}
+  }
 
   do_test backup-10.$tn.5 {
     B step 50