/ Check-in [407830c6]
Login

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

Overview
Comment:Avoid a segfault when running vacuum on an in-memory database. Ticket #3620. (CVS 6221)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:407830c6839a81fa0a1010940740df3011713a88
User & Date: danielk1977 2009-01-31 14:54:07
Context
2009-01-31
22:28
Better error message when coalesce() has too few arguments. Ticket #3623. (CVS 6222) check-in: 9cd43c82 user: drh tags: trunk
14:54
Avoid a segfault when running vacuum on an in-memory database. Ticket #3620. (CVS 6221) check-in: 407830c6 user: danielk1977 tags: trunk
2009-01-30
17:27
Fix a round-off error when moving dates by negative modifier amounts. Ticket #3618. Enhance the "NNN years" modifier to accept fractional years. (CVS 6220) check-in: 86be908c 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
....
7386
7387
7388
7389
7390
7391
7392




7393
7394
7395
7396
7397
7398
7399
** 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.562 2009/01/28 20:21:17 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
** Including a description of file format and an overview of operation.
*/
#include "btreeInt.h"

................................................................................

    /* Commit phase one syncs the journal file associated with pTo 
    ** containing the original data. It does not sync the database file
    ** itself. After doing this it is safe to use OsTruncate() and other
    ** file APIs on the database file directly.
    */
    pBtTo->db = pTo->db;




    rc = sqlite3PagerCommitPhaseOne(pBtTo->pPager, 0, 1);
    if( iSize<iNow && rc==SQLITE_OK ){
      rc = sqlite3OsTruncate(pFile, iSize);
    }

    /* The loop that copied data from database pFrom to pTo did not
    ** populate the locking page of database pTo. If the page-size of







|







 







>
>
>
>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
....
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
** 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.563 2009/01/31 14:54:07 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
** Including a description of file format and an overview of operation.
*/
#include "btreeInt.h"

................................................................................

    /* Commit phase one syncs the journal file associated with pTo 
    ** containing the original data. It does not sync the database file
    ** itself. After doing this it is safe to use OsTruncate() and other
    ** file APIs on the database file directly.
    */
    pBtTo->db = pTo->db;
    if( nFromPageSize==nToPageSize ){
      sqlite3PagerTruncateImage(pBtTo->pPager, nFromPage);
      iNow = iSize;
    }
    rc = sqlite3PagerCommitPhaseOne(pBtTo->pPager, 0, 1);
    if( iSize<iNow && rc==SQLITE_OK ){
      rc = sqlite3OsTruncate(pFile, iSize);
    }

    /* The loop that copied data from database pFrom to pTo did not
    ** populate the locking page of database pTo. If the page-size of

Changes to src/pager.c.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
....
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.560 2009/01/30 05:40:27 shane Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"

/*
** Macros for troubleshooting.  Normally turned off
*/
................................................................................
      pPager->state = (u8)locktype;
      IOTRACE(("LOCK %p %d\n", pPager, locktype))
    }
  }
  return rc;
}

#ifndef SQLITE_OMIT_AUTOVACUUM
/*
** Truncate the in-memory database file image to nPage pages. This 
** function does not actually modify the database file on disk. It 
** just sets the internal state of the pager object so that the 
** truncation will be done when the current transaction is committed.
*/
void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
  assert( pPager->dbSizeValid );
  assert( pPager->dbSize>=nPage );
  assert( pPager->state>=PAGER_RESERVED );
  pPager->dbSize = nPage;
}
#endif  /* ifndef SQLITE_OMIT_AUTOVACUUM */

/*
** Shutdown the page cache.  Free all memory and close all files.
**
** If a transaction was in progress when this routine is called, that
** transaction is rolled back.  All outstanding pages are invalidated
** and their memory is freed.  Any attempt to use a page associated







|







 







<












<







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
....
2571
2572
2573
2574
2575
2576
2577

2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589

2590
2591
2592
2593
2594
2595
2596
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.561 2009/01/31 14:54:07 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"

/*
** Macros for troubleshooting.  Normally turned off
*/
................................................................................
      pPager->state = (u8)locktype;
      IOTRACE(("LOCK %p %d\n", pPager, locktype))
    }
  }
  return rc;
}


/*
** Truncate the in-memory database file image to nPage pages. This 
** function does not actually modify the database file on disk. It 
** just sets the internal state of the pager object so that the 
** truncation will be done when the current transaction is committed.
*/
void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
  assert( pPager->dbSizeValid );
  assert( pPager->dbSize>=nPage );
  assert( pPager->state>=PAGER_RESERVED );
  pPager->dbSize = nPage;
}


/*
** Shutdown the page cache.  Free all memory and close all files.
**
** If a transaction was in progress when this routine is called, that
** transaction is rolled back.  All outstanding pages are invalidated
** and their memory is freed.  Any attempt to use a page associated

Changes to src/pager.h.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem.  The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
** @(#) $Id: pager.h,v 1.98 2009/01/24 11:30:43 drh Exp $
*/

#ifndef _PAGER_H_
#define _PAGER_H_

/*
** Default maximum size for persistent journal files. A negative 
................................................................................
const char *sqlite3PagerFilename(Pager*);
const sqlite3_vfs *sqlite3PagerVfs(Pager*);
sqlite3_file *sqlite3PagerFile(Pager*);
const char *sqlite3PagerJournalname(Pager*);
int sqlite3PagerNosync(Pager*);
void *sqlite3PagerTempSpace(Pager*);

/* Functions used in auto-vacuum mode to truncate the database file. */
#ifndef SQLITE_OMIT_AUTOVACUUM
  void sqlite3PagerTruncateImage(Pager*,Pgno);
#endif

/* Used by encryption extensions. */
#ifdef SQLITE_HAS_CODEC
  void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
#endif

/* Functions to support testing and debugging. */







|







 







|
<
|
<







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
132
133
134
135
136
137
138
139

140

141
142
143
144
145
146
147
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem.  The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
** @(#) $Id: pager.h,v 1.99 2009/01/31 14:54:07 danielk1977 Exp $
*/

#ifndef _PAGER_H_
#define _PAGER_H_

/*
** Default maximum size for persistent journal files. A negative 
................................................................................
const char *sqlite3PagerFilename(Pager*);
const sqlite3_vfs *sqlite3PagerVfs(Pager*);
sqlite3_file *sqlite3PagerFile(Pager*);
const char *sqlite3PagerJournalname(Pager*);
int sqlite3PagerNosync(Pager*);
void *sqlite3PagerTempSpace(Pager*);

/* Functions used to truncate the database file. */

void sqlite3PagerTruncateImage(Pager*,Pgno);


/* Used by encryption extensions. */
#ifdef SQLITE_HAS_CODEC
  void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
#endif

/* Functions to support testing and debugging. */

Changes to test/vacuum.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
283
284
285
286
287
288
289







290
291
292
293
294
295
296
297
#    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.  The
# focus of this file is testing the VACUUM statement.
#
# $Id: vacuum.test,v 1.42 2009/01/22 23:04:47 drh Exp $

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

# If the VACUUM statement is disabled in the current build, skip all
# the tests in this file.
#
................................................................................
file delete -force :memory:
do_test vacuum-7.0 {
  sqlite3 db2 :memory:
  execsql {
    CREATE TABLE t1(t);
    VACUUM;
  } db2







} {}
db2 close

# Ticket #873.  VACUUM a database that has ' in its name.
#
do_test vacuum-8.1 {
  file delete -force a'z.db
  file delete -force a'z.db-journal







|







 







>
>
>
>
>
>
>
|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#    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.  The
# focus of this file is testing the VACUUM statement.
#
# $Id: vacuum.test,v 1.43 2009/01/31 14:54:07 danielk1977 Exp $

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

# If the VACUUM statement is disabled in the current build, skip all
# the tests in this file.
#
................................................................................
file delete -force :memory:
do_test vacuum-7.0 {
  sqlite3 db2 :memory:
  execsql {
    CREATE TABLE t1(t);
    VACUUM;
  } db2
  execsql {
    CREATE TABLE t2(t);
    CREATE TABLE t3(t);
    DROP TABLE t2;
    VACUUM;
    pragma integrity_check;
  } db2
} {ok}
db2 close

# Ticket #873.  VACUUM a database that has ' in its name.
#
do_test vacuum-8.1 {
  file delete -force a'z.db
  file delete -force a'z.db-journal