File: bdb_pragmas.test

package info (click to toggle)
db5.3 5.3.28%2Bdfsg2-9
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 158,620 kB
  • sloc: ansic: 448,573; java: 111,824; tcl: 80,544; sh: 44,264; cs: 33,697; cpp: 21,600; perl: 14,557; xml: 10,799; makefile: 4,028; javascript: 1,998; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (498 lines) | stat: -rw-r--r-- 10,778 bytes parent folder | download | duplicates (8)
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#
#    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.
#
#***********************************************************************
# This file implements regression tests for some simple Berkeley DB specific
# pragmas.
#


set testdir [file dirname $argv0]/../../lang/sql/sqlite/test
source $testdir/tester.tcl
reset_db

# Test that pragma trickle works as expected.
#

do_test bdb_pragmas-1.1 {
  execsql {
    PRAGMA trickle;
  }
} {0}

# Test that it's just ignored before an open happens
do_test bdb_pragmas-1.2 {
  execsql {
    PRAGMA trickle=123;
  }
} {0}

do_test bdb_pragmas-1.3 {
  execsql {
    CREATE TABLE t1(n int, log int);
    PRAGMA trickle;
  }
} {0}

do_test bdb_pragmas-1.4 {
  execsql {
    PRAGMA trickle=10;
  }
} {10}

# populate so there will be something to trickle
do_test bdb_pragmas-1.5 {
  for {set i 1} {$i<=2000} {incr i} {
    for {set j 0} {(1<<$j)<$i} {incr j} {}
    execsql "INSERT INTO t1 VALUES($i,$j)"
  }
} {}

do_test bdb_pragmas-1.6 {
  execsql {
    PRAGMA trickle=50;
  }
} {50}

# TODO: Verify that something actually trickled?

do_test bdb_pragmas-1.7 {
  set v [catch { execsql {
    PRAGMA trickle=weoin;
  }} msg]
  lappend v $msg
} {1 {Invalid trickle value weoin, must be a percentage.}}

do_test bdb_pragmas-1.8 {
  set v [catch { execsql {
    PRAGMA trickle=12039;
  }} msg]
  lappend v $msg
} {1 {Invalid trickle value 12039, must be a percentage.}}

integrity_check bdb_pragmas-1.99

reset_db


# Test bdbsql_system_memory pragma
do_test bdb_pragmas-2.1 {
  execsql {
    PRAGMA bdbsql_system_memory;
  }
} {0}

do_test bdb_pragmas-2.2 {
  execsql {
    PRAGMA bdbsql_system_memory=-1;
  }
} {-1}

do_test bdb_pragmas-2.3 {
  set v [catch { execsql {
    PRAGMA bdbsql_system_memory=asdub;
  }} msg]
  lappend v $msg
} {1 {Invalid value bdbsql_system_memory asdub needs to be a base segment id, see DB_ENV->set_shm_key documentation for more information.}}

do_test bdb_pragmas-2.4 {
  execsql {
    PRAGMA bdbsql_system_memory=123;
  }
} {123}

# Verify that turning system mem off actually works.
do_test bdb_pragmas-2.5 {
  execsql {
    PRAGMA bdbsql_system_memory=-1;
  }
} {-1}

do_test bdb_pragmas-2.6 {
  execsql {
    PRAGMA bdbsql_system_memory;
  }
} {0}

do_test bdb_pragmas-2.7 {
  execsql {
    PRAGMA bdbsql_system_memory=123;
  }
} {123}

# Trigger the database create.
do_test bdb_pragmas-2.8 {
  execsql { CREATE TABLE t1(x int, log int); }
  for {set i 1} {$i<=20} {incr i} {
    for {set j 0} {(1<<$j)<$i} {incr j} {}
    execsql "INSERT INTO t1 VALUES($i,$j)"
  }
} {}

# Check to see if the region files were created (if so, it's not working).
do_test bdb_pragmas-2.9 {
  set ::regionfile [lindex [glob test.db-journal/__db.*] 0]
  llength $::regionfile
} {1}

do_test bdb_pragmas-2.10 {
  execsql {
    PRAGMA bdbsql_system_memory;
  }
} {1}

do_test bdb_pragmas-2.11 {
  set v [catch { execsql {
    PRAGMA bdbsql_system_memory=124;
  }} msg]
  lappend v $msg
} {1 {Cannot set bdbsql_system_memory after accessing the database}}

integrity_check bdb_pragmas-2.99

reset_db
# Test bdbsql_error_file pragma
do_test bdb_pragma-3.1 {
    set v [execsql {
    PRAGMA bdbsql_error_file;
  }]
    set v1 [file normalize [regsub -all "\[{}]" $v ""]]
    set v "[pwd]/test.db-journal/sql-errors.txt"
    set v2 [file normalize $v]   
    expr {$v1 == $v2}
} {1}

# Create a sqequence to generate error.
do_test bdb_pragma-3.2 {
    execsql {
    PRAGMA bdbsql_error_file = "a.txt";
    select create_sequence("b", "maxvalue", 3, "cache", 2);
    select nextval("b");
    select nextval("b");
    select nextval("b");
    select nextval("b");
  }
} {a.txt 0 0 1 2 3}

# Trigger a DB sequence error and save the internal error message to a.txt
do_test bdb_pragma-3.3 {
  set v [catch { execsql {
    select nextval("b");
  }} msg]
  lappend v $msg
} {1 {Sequence value out of bounds.}}

# Test set bdbql_error_file pragma after opening env.
do_test bdb_pragma-3.4 {
    execsql {
    PRAGMA bdbsql_error_file = "b.txt";
  }
} {b.txt}

# Trigger a DB sequence error and save the internal error message to b.txt
do_test bdb_pragma-3.5 {
  set v [catch { execsql {
    select nextval("b");
  }} msg]
  lappend v $msg
} {1 {Sequence value out of bounds.}}

#Ensure the error message has been saved to error file as expected. 
do_test bdb_pragma-3.6 {
  set fd [open "./a.txt" r]
  set res [read $fd]
  close $fd
  file delete -force ./a.txt
  set pat {BDB4011 Sequence overflow}
  regexp $pat $res
} {1}

do_test bdb_pragma-3.7 {
  set fd [open "./b.txt" r]
  set res [read $fd]
  close $fd
  db close
  file delete -force ./b.txt
  set pat {BDB4011 Sequence overflow}
  regexp $pat $res
} {1}

# Test the WAL pragma works as expected. #20620.
reset_db
do_test bdb_pragma-4.0 {
  execsql {
    create table t1(x);
    create temporary table t2(x);
    PRAGMA journal_mode=delete;
  }
} {delete}

# Test that pragma bdbsql_lock_tablesize
#
reset_db

# If the handle is not opened, the value is zero
do_test bdb_pragma-5.1 {
  execsql {
    PRAGMA bdbsql_shared_resources;
  }
} {16777216}

# Open db handle and set_shared_resources
do_test bdb_pragma-5.2 {
  db close
  sqlite3 db test.db
  execsql {
    PRAGMA bdbsql_shared_resources=100;
  }
} {100}

# Test get_shared_resources
do_test bdb_pragma-5.3 {
  execsql {
    PRAGMA bdbsql_shared_resources;
  }
} {100}

# Test invalid value
if {$tcl_platform(wordSize) == 4} { 
  # On 32-bits platform, the max memory size is (4GB - 1),
  # Too-large size will be truncated.
  do_test bdb_pragma-5.4 {
    execsql {
      PRAGMA bdbsql_shared_resources=4294967296;
    }
  } {4294967295}
} else {
  # On 64-bits platform, the max acceptable value is
  # 4611686018427387903 (1G * (UINT32_MAX + 1) - 1)
  do_test bdb_pragma-5.4 {
   catchsql {
      PRAGMA bdbsql_shared_resources=4611686018427387904;
    }
  } {1 {Invalid value bdbsql_shared_resources 4611686018427387904}}
}

# Test negative
do_test bdb_pragma-5.5 {
  catchsql {
    PRAGMA bdbsql_shared_resources=-1;
  }
} {1 {Invalid value bdbsql_shared_resources -1}}

# Test invalid value
if {$tcl_platform(wordSize) == 4} { 
  # On 32-bits platform, the max memory size is (4GB - 1)
  do_test bdb_pragma-5.6 {
    execsql {
      PRAGMA bdbsql_shared_resources=4294967295;
    }
  } {4294967295}
} else {
  # On 64-bits platform, the max acceptable value is
  # 4611686018427387903 (1G * (UINT32_MAX + 1) - 1)
  do_test bdb_pragma-5.6 {
    execsql {
      PRAGMA bdbsql_shared_resources=4611686018427387903;
    }
  } {4611686018427387903}
}

# Create the table and environment
do_test bdb_pragma-5.7 {
  db close
  sqlite3 db test.db
  execsql {
    CREATE TABLE t3(x TEXT);
    INSERT INTO t3 VALUES(randstr(10,400));
    INSERT INTO t3 VALUES(randstr(10,400));
    SELECT count(*) FROM t3;
  }
} {2}

# Ensure that can not set shared_resources after accessing the database
do_test bdb_pragma-5.8 {
  catchsql {
    PRAGMA bdbsql_shared_resources=100;
  }
} {1 {Cannot set bdbsql_shared_resources after accessing the database}}

# Close and reopen the exisiting environment again
do_test bdb_pragma-5.9 {
  db close
  sqlite3 db test.db
  catchsql {
    PRAGMA bdbsql_shared_resources=100000;
  }
} {1 {Can't set shared_resources for an open or existing environment}}


# Test that pragma bdbsql_shared_resources
#
reset_db

#If the handle is not opened, the value is zero
do_test bdb_pragma-6.1 {
  execsql {
    PRAGMA bdbsql_lock_tablesize;
  }
} {20000}

#Open db handle and set lock_tablesize
do_test bdb_pragma-6.2 {
  db close
  sqlite3 db test.db
  execsql {
    PRAGMA bdbsql_lock_tablesize=100;
  }
} {100}

#Test get lock_tablesize
do_test bdb_pragma-6.3 {
  execsql {
    PRAGMA bdbsql_lock_tablesize;
  }
} {100}

# Return error if the size is too big:
# The max acceptable value is 2147483647 (INT32_MAX)
do_test bdb_pragma-6.4 {
 catchsql {
    PRAGMA bdbsql_lock_tablesize=2147483648;
  }
} {1 {Invalid value bdbsql_lock_tablesize 2147483648}}

# Test negative
do_test bdb_pragma-6.5 {
 catchsql {
    PRAGMA bdbsql_lock_tablesize=-1;
  }
} {1 {Invalid value bdbsql_lock_tablesize -1}}

# The max acceptable value is 2147483647(INT32_MAX)
do_test bdb_pragma-6.6 {
  execsql {
    PRAGMA bdbsql_lock_tablesize=2147483647;
  }
} {2147483647}

# Create the table and environment
do_test bdb_pragma-6.7 {
  db close
  sqlite3 db test.db
  execsql {
    CREATE TABLE t3(x TEXT);
    INSERT INTO t3 VALUES(randstr(10,400));
    INSERT INTO t3 VALUES(randstr(10,400));
    SELECT count(*) FROM t3;
  }
} {2}

# Ensure that can not set lk_tablesize after accessing the database
do_test bdb_pragma-6.8 {
  catchsql {
    PRAGMA bdbsql_lock_tablesize=100;
  }
} {1 {Cannot set bdbsql_lock_tablesize after accessing the database}}

# Close and reopen the exisiting environment again
do_test bdb_pragma-6.9 {
  db close
  sqlite3 db test.db
  catchsql {
    PRAGMA bdbsql_lock_tablesize=100000;
  }
} {1 {Can't set lk_tablesize for open or existing environment}}


# Test that pragma bdbsql_single_process
#
reset_db

# Check the initial value
do_test bdb_pragma-7.1 {
  execsql {
    PRAGMA bdbsql_single_process;
  }
} {0}

# Open db handle and set single_process
do_test bdb_pragma-7.2 {
  db close
  sqlite3 db test.db
  execsql {
    PRAGMA bdbsql_single_process = 1;
  }
} {1}

# Set again with different format
do_test bdb_pragma-7.3 {
  execsql {
    PRAGMA bdbsql_single_process = on;
  }
} {1}

# Check result
do_test bdb_pragma-7.4 {
 execsql {
    PRAGMA bdbsql_single_process;
  }
} {1}

# Create the table and environment
do_test bdb_pragma-7.5 {
  db close
  sqlite3 db test.db
  execsql {
    PRAGMA bdbsql_single_process = 1;
    CREATE TABLE t3(x TEXT);
    INSERT INTO t3 VALUES(randstr(10,400));
    INSERT INTO t3 VALUES(randstr(10,400));
    SELECT count(*) FROM t3;
  }
} {1 2}

# Check if setting take effect
do_test bdb_pragma-7.6 {
 execsql {
    PRAGMA bdbsql_single_process;
  }
} {1}

# Ensure that can not set single_process after accessing the database
do_test bdb_pragma-7.7 {
  catchsql {
    PRAGMA bdbsql_single_process = 0;
  }
} {1 {Cannot set bdbsql_single_process after accessing the database}}

# Close and reopen the exisiting environment again
do_test bdb_pragma-7.8 {
  db close
  sqlite3 db test.db
  execsql {
    PRAGMA bdbsql_single_process = 1;
  }
} {1}


# Do some actual operations to open db handle
do_test bdb_pragma-7.9 {
  db close
  sqlite3 db test.db
  execsql {
    SELECT count(*) FROM t3;
  }
} {2}

# Ensure that can not set single_process after accessing the database
do_test bdb_pragma-7.10 {
  catchsql {
    PRAGMA bdbsql_single_process = 1;
  }
} {1 {Cannot set bdbsql_single_process after accessing the database}}


finish_test