dbSize calculation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

dbSize calculation

zhiting zhu-2
Hi,

I send this email to the dev mailing list but no response. It seems this
mailing list has more activity and attention. I have a question about how
dbSize is calculated when I was reading the source code of sqlite3. In the
description of the dbSize, it said: "If the size of the file is not an
integer multiple of the page-size, the value stored in dbSize is rounded
down (i.e. a 5KB file with 2K page-size has dbSize==2).
Except, any file that is greater than 0 bytes in size is considered to have
at least one page. (i.e. a 1KB file with 2K page-size leads to dbSize==1)."

But in the pagerPagecount function: the comment said: " If the size of the
database file is not an integer multiple of the page-size, round up the
result." The pagerPagecount function is used to set dbSize in
sqlite3PagerSharedLock function.

The comment at the top is contradicted with the latter. I wonder which way
should be correct? Should it be round up or round down? Thanks!

Best,
Zhiting
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: dbSize calculation

Richard Hipp-3
On 9/4/17, zhiting zhu <[hidden email]> wrote:

> Hi,
>
> I send this email to the dev mailing list but no response. It seems this
> mailing list has more activity and attention. I have a question about how
> dbSize is calculated when I was reading the source code of sqlite3. In the
> description of the dbSize, it said: "If the size of the file is not an
> integer multiple of the page-size, the value stored in dbSize is rounded
> down (i.e. a 5KB file with 2K page-size has dbSize==2).
> Except, any file that is greater than 0 bytes in size is considered to have
> at least one page. (i.e. a 1KB file with 2K page-size leads to dbSize==1)."
>
> But in the pagerPagecount function: the comment said: " If the size of the
> database file is not an integer multiple of the page-size, round up the
> result." The pagerPagecount function is used to set dbSize in
> sqlite3PagerSharedLock function.
>
> The comment at the top is contradicted with the latter. I wonder which way
> should be correct? Should it be round up or round down? Thanks!

If the file size is not an integer multiple of the page size, then the
database is corrupt.  So I'm not sure it matters if it rounds up or
down.

I do not recall what the code does or what it should do.  I will need
to do some research to figure out the answer.  I am on travel this
week and do not have time to work on that at the moment.  I will
strive to fix the discrepency next week some time.
--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users