/ Check-in [35a88935]
Login

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

Overview
Comment:Prevent the sqlite3_pagecount() function from ever returning the pending-byte page. (CVS 2702)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 35a8893537ae5faed6ee49270ac9c01a6010993f
User & Date: danielk1977 2005-09-16 10:18:46
Context
2005-09-16
11:32
Do not journal the file locking page when doing a database copy as part of a VACUUM. Ticket #1432. (CVS 2703) check-in: 248f7797 user: drh tags: trunk
10:18
Prevent the sqlite3_pagecount() function from ever returning the pending-byte page. (CVS 2702) check-in: 35a88935 user: danielk1977 tags: trunk
10:13
Move the definition of sqlite3_pending_byte from test2.c to os_common.h. (CVS 2701) check-in: bedf702f user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/pager.c.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
....
1748
1749
1750
1751
1752
1753
1754
1755





1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777




1778
1779
1780
1781
1782
1783
1784
** 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.212 2005/09/09 01:32:06 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
................................................................................
    sqlite3OsSeek(&pPager->fd, 0);
    sqlite3OsRead(&pPager->fd, pDest, N);
  }
}

/*
** Return the total number of pages in the disk file associated with
** pPager.





*/
int sqlite3pager_pagecount(Pager *pPager){
  i64 n;
  assert( pPager!=0 );
  if( pPager->dbSize>=0 ){
    return pPager->dbSize;
  }
  if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){
    pPager->errMask |= PAGER_ERR_DISK;
    return 0;
  }
  if( n>0 && n<pPager->pageSize ){
    n = 1;
  }else{
    n /= pPager->pageSize;
  }
  if( !MEMDB && n==PENDING_BYTE/pPager->pageSize ){
    n++;
  }
  if( pPager->state!=PAGER_UNLOCK ){
    pPager->dbSize = n;
  }




  return n;
}

/*
** Forward declaration
*/
static int syncJournal(Pager*);







|







 







|
>
>
>
>
>





|
|
|
|
|
|
|
|
|
|
|
<
<
<
|
|
|
>
>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
....
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776



1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
** 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.213 2005/09/16 10:18:46 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
................................................................................
    sqlite3OsSeek(&pPager->fd, 0);
    sqlite3OsRead(&pPager->fd, pDest, N);
  }
}

/*
** Return the total number of pages in the disk file associated with
** pPager. 
**
** If the PENDING_BYTE lies on the page directly after the end of the
** file, then consider this page part of the file too. For example, if
** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the
** file is 4096 bytes, 5 is returned instead of 4.
*/
int sqlite3pager_pagecount(Pager *pPager){
  i64 n;
  assert( pPager!=0 );
  if( pPager->dbSize>=0 ){
    n = pPager->dbSize;
  } else {
    if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){
      pPager->errMask |= PAGER_ERR_DISK;
      return 0;
    }
    if( n>0 && n<pPager->pageSize ){
      n = 1;
    }else{
      n /= pPager->pageSize;
    }



    if( pPager->state!=PAGER_UNLOCK ){
      pPager->dbSize = n;
    }
  }
  if( n==(PENDING_BYTE/pPager->pageSize) ){
    n++;
  }
  return n;
}

/*
** Forward declaration
*/
static int syncJournal(Pager*);