/ Check-in [cf9eeba7]
Login

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

Overview
Comment:Fix a bug where accessPayload() was calling PagerWrite() on the wrong page handle. Ticket #2332. (CVS 3906)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: cf9eeba7be64ad29cddd320832db10c799fb6e8e
User & Date: danielk1977 2007-05-03 13:11:32
Context
2007-05-03
16:31
Test cases and minor bugfixes for incremental blob APIs. (CVS 3907) check-in: e12c5223 user: danielk1977 tags: trunk
13:11
Fix a bug where accessPayload() was calling PagerWrite() on the wrong page handle. Ticket #2332. (CVS 3906) check-in: cf9eeba7 user: danielk1977 tags: trunk
13:02
Use memmove() instead of memcpy() when moving between memory regions that might overlap. Ticket #2334. (CVS 3905) check-in: 678d672b user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/btree.c.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
....
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
** 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.
**
*************************************************************************
** $Id: btree.c,v 1.369 2007/05/03 11:43:33 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
**     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
**     "Sorting And Searching", pages 473-480. Addison-Wesley
**     Publishing Company, Reading, Massachusetts.
................................................................................
        aPayload = sqlite3PagerGetData(pDbPage);
        nextPage = get4byte(aPayload);
        if( a + offset > ovflSize ){
          a = ovflSize - offset;
        }
        if( eOp ){
          /* A write operation. */
          rc = sqlite3PagerWrite(pPage->pDbPage);
          if( rc!=SQLITE_OK ){
            sqlite3PagerUnref(pDbPage);
            return rc;
          }
          memcpy(&aPayload[offset+4], pBuf, a);
        }else{
          /* A read operation */







|







 







|







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
....
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
** 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.
**
*************************************************************************
** $Id: btree.c,v 1.370 2007/05/03 13:11:32 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
**     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
**     "Sorting And Searching", pages 473-480. Addison-Wesley
**     Publishing Company, Reading, Massachusetts.
................................................................................
        aPayload = sqlite3PagerGetData(pDbPage);
        nextPage = get4byte(aPayload);
        if( a + offset > ovflSize ){
          a = ovflSize - offset;
        }
        if( eOp ){
          /* A write operation. */
          rc = sqlite3PagerWrite(pDbPage);
          if( rc!=SQLITE_OK ){
            sqlite3PagerUnref(pDbPage);
            return rc;
          }
          memcpy(&aPayload[offset+4], pBuf, a);
        }else{
          /* A read operation */

Changes to test/incrblob.test.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
75
76
77
78
79
80
81
82





83
84
85
86
87
88
89
...
127
128
129
130
131
132
133
134
135
136
137
138
139
#
#    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.
#
#***********************************************************************
#
# $Id: incrblob.test,v 1.3 2007/05/03 11:43:35 danielk1977 Exp $
#

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

do_test incrblob-1.1 {
  execsql {
................................................................................
} {....123456}
do_test incrblob-1.3.10 {
  close $::blob
} {}


#------------------------------------------------------------------------
# incrblob-2.*: Test seeking in an incremental blob can use ptrmap pages.





#
proc nRead {db} {
  set bt [btree_from_db $db]
  array set stats [btree_pager_stats $bt]
  return $stats(read)
}

................................................................................
    # If the database is not in auto-vacuum mode, the whole of
    # the overflow-chain must be scanned. In auto-vacuum mode,
    # sqlite uses the ptrmap pages to avoid reading the other pages.
    #
    nRead db
  } [expr $AutoVacuumMode ? 4 : 30]

  do_test incrblob-2.3 {
    string range [db one {SELECT v FROM blobs}] end-19 end
  } $::fragment
}

finish_test







|







 







|
>
>
>
>
>







 







|





5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
132
133
134
135
136
137
138
139
140
141
142
143
144
#
#    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.
#
#***********************************************************************
#
# $Id: incrblob.test,v 1.4 2007/05/03 13:11:32 danielk1977 Exp $
#

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

do_test incrblob-1.1 {
  execsql {
................................................................................
} {....123456}
do_test incrblob-1.3.10 {
  close $::blob
} {}


#------------------------------------------------------------------------
# incrblob-2.*: Test that the following operations use ptrmap pages:
#
#     * Reading near the end of a blob,
#     * Writing near the end of a blob (TODO),
#     * SELECT a column value that is located on an overflow page (TODO).
#
#
proc nRead {db} {
  set bt [btree_from_db $db]
  array set stats [btree_pager_stats $bt]
  return $stats(read)
}

................................................................................
    # If the database is not in auto-vacuum mode, the whole of
    # the overflow-chain must be scanned. In auto-vacuum mode,
    # sqlite uses the ptrmap pages to avoid reading the other pages.
    #
    nRead db
  } [expr $AutoVacuumMode ? 4 : 30]

  do_test incrblob-2.$AutoVacuumMode.3 {
    string range [db one {SELECT v FROM blobs}] end-19 end
  } $::fragment
}

finish_test

Added test/tkt2332.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
# 2007 May 3
#
# 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.
#
#***********************************************************************
#
# $Id: tkt2332.test,v 1.1 2007/05/03 13:11:32 danielk1977 Exp $
#

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

do_test tkt2332.1 {
  execsql {
    CREATE TABLE blobs (k INTEGER PRIMARY KEY, v BLOB);
    PRAGMA cache_size = 100;
  }
} {}

set ::iKey 1
foreach Len [list 10000 100000 1000000] {
  do_test tkt2332.$Len.1 {
    set val "[expr rand()][expr rand()][expr rand()][expr rand()][expr rand()]"
    set ::blobstr [string range \
      [string repeat $val [expr ($Len/[string length $val])+1]] 0 [expr $Len-1]
    ]

    db eval { INSERT INTO blobs VALUES($::iKey, zeroblob($Len)) }
  } {}

  do_test tkt2332.$Len.2 {
    execsql {
      SELECT length(v) FROM blobs WHERE k = $::iKey;
    }
  } $Len

  do_test tkt2332.$Len.3 {
    set ::fd [db incrblob blobs v $::iKey]
    puts -nonewline $::fd $::blobstr
    close $::fd
  } {}

  do_test tkt2332.$Len.4 {
    execsql { SELECT length(v) FROM blobs WHERE k = $::iKey; }
  } $Len

  do_test tkt2332.$Len.5 {
    lindex [execsql {SELECT v FROM blobs WHERE k = $::iKey}] 0
  } $::blobstr

  incr ::iKey
}

finish_test