Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix a bug involving balance_shallow() and the sqlite_master table. (CVS 2143) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
557be3ff5b1c46a3f3836ea3a9d9dede |
User & Date: | danielk1977 2004-11-23 09:06:56 |
Context
2004-11-23
| ||
10:13 | Have tests pass when SQLITE_OMIT_SCHEMA_PRAGMAS is defined. (CVS 2144) check-in: 6ccb589b user: danielk1977 tags: trunk | |
09:06 | Fix a bug involving balance_shallow() and the sqlite_master table. (CVS 2143) check-in: 557be3ff user: danielk1977 tags: trunk | |
01:47 | More work on the implementation of cursors, but they are still not functioning. (CVS 2142) check-in: 8b61d1ae user: drh tags: trunk | |
Changes
Changes to src/btree.c.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
....
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
|
** 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.224 2004/11/22 19:07:10 drh 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. ................................................................................ int i; zeroPage(pPage, pChild->aData[0]); for(i=0; i<pChild->nCell; i++){ apCell[i] = findCell(pChild,i); szCell[i] = cellSizePtr(pChild, apCell[i]); } assemblePage(pPage, pChild->nCell, apCell, szCell); freePage(pChild); TRACE(("BALANCE: child %d transfer to page 1\n", pChild->pgno)); }else{ /* The child has more information that will fit on the root. ** The tree is already balanced. Do nothing. */ TRACE(("BALANCE: child %d will not fit on page 1\n", pChild->pgno)); } |
|
>
>
>
|
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
....
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
|
** 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.225 2004/11/23 09:06:56 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. ................................................................................ int i; zeroPage(pPage, pChild->aData[0]); for(i=0; i<pChild->nCell; i++){ apCell[i] = findCell(pChild,i); szCell[i] = cellSizePtr(pChild, apCell[i]); } assemblePage(pPage, pChild->nCell, apCell, szCell); /* Copy the right-pointer of the child to the parent. */ put4byte(&pPage->aData[pPage->hdrOffset+8], get4byte(&pChild->aData[pChild->hdrOffset+8])); freePage(pChild); TRACE(("BALANCE: child %d transfer to page 1\n", pChild->pgno)); }else{ /* The child has more information that will fit on the root. ** The tree is already balanced. Do nothing. */ TRACE(("BALANCE: child %d will not fit on page 1\n", pChild->pgno)); } |
Changes to src/pager.c.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 .... 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 .... 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 .... 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 |
** 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.177 2004/11/10 15:27:38 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include "pager.h" #include <assert.h> #include <string.h> ................................................................................ TRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", PAGERID(pPager), pPg->pgno, pPg->needSync, pgno); if( pPg->needSync ){ needSyncPgno = pPg->pgno; assert( pPg->inJournal ); assert( pPg->dirty ); } /* Unlink pPg from it's hash-chain */ unlinkHashChain(pPager, pPg); /* If the cache contains a page with page-number pgno, remove it ** from it's hash chain. Also, if the PgHdr.needSync was set for ................................................................................ assert( pPgOld->nRef==0 ); unlinkHashChain(pPager, pPgOld); pPgOld->dirty = 0; if( pPgOld->needSync ){ assert( pPgOld->inJournal ); pPg->inJournal = 1; pPg->needSync = 1; } } /* Change the page number for pPg and insert it into the new hash-chain. */ pPg->pgno = pgno; h = pager_hash(pgno); if( pPager->aHash[h] ){ ................................................................................ if( needSyncPgno ){ /* If needSyncPgno is non-zero, then the journal file needs to be ** sync()ed before any data is written to database file page needSyncPgno. ** Currently, no such page exists in the page-cache and the ** Pager.aInJournal bit has been set. This needs to be remedied by loading ** the page into the pager-cache and setting the PgHdr.needSync flag. */ int rc; void *pNeedSync; rc = sqlite3pager_get(pPager, needSyncPgno, &pNeedSync); if( rc!=SQLITE_OK ) return rc; DATA_TO_PGHDR(pNeedSync)->needSync = 1; DATA_TO_PGHDR(pNeedSync)->inJournal = 1; DATA_TO_PGHDR(pNeedSync)->dirty = 1; sqlite3pager_unref(pNeedSync); } return SQLITE_OK; |
| > > > > > > > |
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 .... 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 .... 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 .... 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 |
** 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.178 2004/11/23 09:06:56 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include "pager.h" #include <assert.h> #include <string.h> ................................................................................ TRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", PAGERID(pPager), pPg->pgno, pPg->needSync, pgno); if( pPg->needSync ){ needSyncPgno = pPg->pgno; assert( pPg->inJournal ); assert( pPg->dirty ); assert( pPager->needSync ); } /* Unlink pPg from it's hash-chain */ unlinkHashChain(pPager, pPg); /* If the cache contains a page with page-number pgno, remove it ** from it's hash chain. Also, if the PgHdr.needSync was set for ................................................................................ assert( pPgOld->nRef==0 ); unlinkHashChain(pPager, pPgOld); pPgOld->dirty = 0; if( pPgOld->needSync ){ assert( pPgOld->inJournal ); pPg->inJournal = 1; pPg->needSync = 1; assert( pPager->needSync ); } } /* Change the page number for pPg and insert it into the new hash-chain. */ pPg->pgno = pgno; h = pager_hash(pgno); if( pPager->aHash[h] ){ ................................................................................ if( needSyncPgno ){ /* If needSyncPgno is non-zero, then the journal file needs to be ** sync()ed before any data is written to database file page needSyncPgno. ** Currently, no such page exists in the page-cache and the ** Pager.aInJournal bit has been set. This needs to be remedied by loading ** the page into the pager-cache and setting the PgHdr.needSync flag. ** ** The sqlite3pager_get() call may cause the journal to sync. So make ** sure the Pager.needSync flag is set too. */ int rc; void *pNeedSync; assert( pPager->needSync ); rc = sqlite3pager_get(pPager, needSyncPgno, &pNeedSync); if( rc!=SQLITE_OK ) return rc; pPager->needSync = 1; DATA_TO_PGHDR(pNeedSync)->needSync = 1; DATA_TO_PGHDR(pNeedSync)->inJournal = 1; DATA_TO_PGHDR(pNeedSync)->dirty = 1; sqlite3pager_unref(pNeedSync); } return SQLITE_OK; |
Changes to test/table.test.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
622
623
624
625
626
627
628
629
630
631
|
# 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 CREATE TABLE statement. # # $Id: table.test,v 1.33 2004/11/10 11:55:15 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic table and verify it is added to sqlite_master # do_test table-1.1 { ................................................................................ db eval {SELECT * FROM tablet8 LIMIT 1} {} { db eval {DROP TABLE aux.t1;} } } msg ] set result [list $rc $msg] } {1 {database table is locked}} finish_test |
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
# 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 CREATE TABLE statement. # # $Id: table.test,v 1.34 2004/11/23 09:06:56 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic table and verify it is added to sqlite_master # do_test table-1.1 { ................................................................................ db eval {SELECT * FROM tablet8 LIMIT 1} {} { db eval {DROP TABLE aux.t1;} } } msg ] set result [list $rc $msg] } {1 {database table is locked}} # Create and drop 2000 tables. This is to check that the balance_shallow() # routine works correctly on the sqlite_master table. At one point it # contained a bug that would prevent the right-child pointer of the # child page from being copied to the root page. # do_test table-15.1 { execsql {BEGIN} for {set i 0} {$i<2000} {incr i} { execsql "CREATE TABLE tbl$i (a, b, c)" } execsql {COMMIT} } {} do_test table-15.2 { execsql {BEGIN} for {set i 0} {$i<2000} {incr i} { execsql "DROP TABLE tbl$i" } execsql {COMMIT} } {} finish_test |