SQLite

Check-in [e28a2870b4]
Login

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

Overview
Comment:Deferring file descriptor closing to avoid trashing locks when directly manipulating sqlite db file contents (causes errors on AFP testing) (CVS 5587)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e28a2870b49509502529892ff8ddb9fcf3a27173
User & Date: aswift 2008-08-22 00:25:53.000
Context
2008-08-22
00:47
Fix os_unix.c so that it will compile on Linux again. (CVS 5588) (check-in: 2416708208 user: drh tags: trunk)
00:25
Deferring file descriptor closing to avoid trashing locks when directly manipulating sqlite db file contents (causes errors on AFP testing) (CVS 5587) (check-in: e28a2870b4 user: aswift tags: trunk)
00:22
Added SQLITE_IOERR_LOCK extended error code and support for detecting and returning errors in the os_unix lock, unlock and check reserved lock variants, also added support for populating and returning system error codes so that they can be accessed via xGetLastError, unfortunately xGetLastError can't seem to access the unixFile structure where the lastErrno is recorded. (CVS 5586) (check-in: c1af14e2b6 user: aswift tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/exclusive2.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
# 2007 March 24
#
# 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: exclusive2.test,v 1.8 2007/08/12 20:07:59 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {!pager_pragmas} {
  finish_test
  return
}

# This module does not work right if the cache spills at unexpected
# moments.  So disable the soft-heap-limit.
#
sqlite3_soft_heap_limit 0

proc pagerChangeCounter {filename {new ""}} {

  set fd [open $filename RDWR]
  fconfigure $fd -translation binary -encoding binary




  if {$new ne ""} {
    seek $fd 24
    set a [expr {($new&0xFF000000)>>24}]
    set b [expr {($new&0x00FF0000)>>16}]
    set c [expr {($new&0x0000FF00)>>8}]
    set d [expr {($new&0x000000FF)}]
    puts -nonewline $fd [binary format cccc $a $b $c $d]
    flush $fd
  }

  seek $fd 24
  foreach {a b c d} [list 0 0 0 0] {}
  binary scan [read $fd 4] cccc a b c d
  set  ret [expr ($a&0x000000FF)<<24]
  incr ret [expr ($b&0x000000FF)<<16]
  incr ret [expr ($c&0x000000FF)<<8]
  incr ret [expr ($d&0x000000FF)<<0]

  close $fd
  return $ret
}

proc readPagerChangeCounter {filename} {
  set fd [open $filename RDONLY]
  fconfigure $fd -translation binary -encoding binary













|














|
>
|
|
>
>
>
>


















|







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
# 2007 March 24
#
# 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: exclusive2.test,v 1.9 2008/08/22 00:25:53 aswift Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {!pager_pragmas} {
  finish_test
  return
}

# This module does not work right if the cache spills at unexpected
# moments.  So disable the soft-heap-limit.
#
sqlite3_soft_heap_limit 0

proc pagerChangeCounter {filename new {fd ""}} {
  if {$fd==""} {
    set fd [open $filename RDWR]
    fconfigure $fd -translation binary -encoding binary
    set needClose 1
  } else {
    set needClose 0
  }
  if {$new ne ""} {
    seek $fd 24
    set a [expr {($new&0xFF000000)>>24}]
    set b [expr {($new&0x00FF0000)>>16}]
    set c [expr {($new&0x0000FF00)>>8}]
    set d [expr {($new&0x000000FF)}]
    puts -nonewline $fd [binary format cccc $a $b $c $d]
    flush $fd
  }

  seek $fd 24
  foreach {a b c d} [list 0 0 0 0] {}
  binary scan [read $fd 4] cccc a b c d
  set  ret [expr ($a&0x000000FF)<<24]
  incr ret [expr ($b&0x000000FF)<<16]
  incr ret [expr ($c&0x000000FF)<<8]
  incr ret [expr ($d&0x000000FF)<<0]

  if {$needClose} {close $fd}
  return $ret
}

proc readPagerChangeCounter {filename} {
  set fd [open $filename RDONLY]
  fconfigure $fd -translation binary -encoding binary

203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  readPagerChangeCounter test.db
} {3}
do_test exclusive2-2.3 {
  t1sig
} $::sig

do_test exclusive2-2.4 {
  set fd [open test.db RDWR]

  seek $fd 1024
  puts -nonewline $fd [string repeat [binary format c 0] 10000]
  flush $fd
  close $fd
  t1sig
} $::sig

do_test exclusive2-2.5 {
  pagerChangeCounter test.db 5
} {5}
do_test exclusive2-2.6 {
  t1sig
} $::sig
do_test exclusive2-2.7 {
  execsql {PRAGMA locking_mode = normal}
  t1sig







|
>
|
|
|
<




|







208
209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
  readPagerChangeCounter test.db
} {3}
do_test exclusive2-2.3 {
  t1sig
} $::sig

do_test exclusive2-2.4 {
  set ::fd [open test.db RDWR]
  fconfigure $::fd -translation binary
  seek $::fd 1024
  puts -nonewline $::fd [string repeat [binary format c 0] 10000]
  flush $::fd

  t1sig
} $::sig

do_test exclusive2-2.5 {
  pagerChangeCounter test.db 5 $::fd
} {5}
do_test exclusive2-2.6 {
  t1sig
} $::sig
do_test exclusive2-2.7 {
  execsql {PRAGMA locking_mode = normal}
  t1sig
236
237
238
239
240
241
242

243
244
245
246
247
248
249
# is only incremented by the first change when in exclusive access
# mode. In normal mode, the change-counter is incremented once
# per write-transaction.
#

db close
db2 close

file delete -force test.db
file delete -force test.db-journal

do_test exclusive2-3.0 {
  sqlite3 db test.db
  execsql {
    BEGIN;







>







241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# is only incremented by the first change when in exclusive access
# mode. In normal mode, the change-counter is incremented once
# per write-transaction.
#

db close
db2 close
catch {close $::fd}
file delete -force test.db
file delete -force test.db-journal

do_test exclusive2-3.0 {
  sqlite3 db test.db
  execsql {
    BEGIN;