Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Avoid creating a TEMP database unless it is absolutely necessary. (CVS 1890) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
5914a11caa4c6e778cd7ca010427897c |
User & Date: | drh 2004-08-18 02:10:15.000 |
Context
2004-08-18
| ||
15:58 | Be more agressive about not creating or opening the TEMP database if there are no TEMP tables. (CVS 1891) (check-in: 6b2b6b2dbd user: drh tags: trunk) | |
02:10 | Avoid creating a TEMP database unless it is absolutely necessary. (CVS 1890) (check-in: 5914a11caa user: drh tags: trunk) | |
2004-08-17
| ||
10:42 | Fix a typo in a comment. (CVS 1889) (check-in: 9af1d4d145 user: drh tags: trunk) | |
Changes
Changes to src/build.c.
︙ | ︙ | |||
19 20 21 22 23 24 25 | ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** PRAGMA ** | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** PRAGMA ** ** $Id: build.c,v 1.247 2004/08/18 02:10:15 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** This routine is called when a new SQL statement is beginning to ** be parsed. Check to see if the schema for the database needs |
︙ | ︙ | |||
643 644 645 646 647 648 649 | if( sqlite3AuthCheck(pParse, code, zName, 0, zDb) ){ sqliteFree(zName); return; } } #endif | < < < < < < < < < < < < < < < < < < < < < < < < < | 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | if( sqlite3AuthCheck(pParse, code, zName, 0, zDb) ){ sqliteFree(zName); return; } } #endif /* Make sure the new table name does not collide with an existing ** index or table name in the same database. Issue an error message if ** it does. */ if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) return; pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName); if( pTable ){ |
︙ | ︙ | |||
2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 | if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ) return; v = sqlite3GetVdbe(pParse); if( v ){ sqlite3VdbeAddOp(v, OP_AutoCommit, 1, 1); } } /* ** Generate VDBE code that will verify the schema cookie and start ** a read-transaction for all named database files. ** ** It is important that all schema cookies be verified and all ** read transactions be started before anything else happens in | > > > > > > > > > > > > > > > > > > > > > > > > > > > | 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 | if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ) return; v = sqlite3GetVdbe(pParse); if( v ){ sqlite3VdbeAddOp(v, OP_AutoCommit, 1, 1); } } /* ** Make sure the TEMP database is open and available for use. Return ** the number of errors. Leave any error messages in the pParse structure. */ static int sqlite3OpenTempDatabase(Parse *pParse){ sqlite3 *db = pParse->db; if( db->aDb[1].pBt==0 && !pParse->explain ){ int rc = sqlite3BtreeFactory(db, 0, 0, MAX_PAGES, &db->aDb[1].pBt); if( rc!=SQLITE_OK ){ sqlite3ErrorMsg(pParse, "unable to open a temporary database " "file for storing temporary tables"); pParse->rc = rc; return 1; } if( db->flags & !db->autoCommit ){ rc = sqlite3BtreeBeginTrans(db->aDb[1].pBt, 1); if( rc!=SQLITE_OK ){ sqlite3ErrorMsg(pParse, "unable to get a write lock on " "the temporary database file"); pParse->rc = rc; return 1; } } } return 0; } /* ** Generate VDBE code that will verify the schema cookie and start ** a read-transaction for all named database files. ** ** It is important that all schema cookies be verified and all ** read transactions be started before anything else happens in |
︙ | ︙ | |||
2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 | assert( iDb<db->nDb ); assert( db->aDb[iDb].pBt!=0 || iDb==1 ); assert( iDb<32 ); mask = 1<<iDb; if( (pParse->cookieMask & mask)==0 ){ pParse->cookieMask |= mask; pParse->cookieValue[iDb] = db->aDb[iDb].schema_cookie; } } } /* ** Generate VDBE code that prepares for doing an operation that ** might change the database. | > > > | 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 | assert( iDb<db->nDb ); assert( db->aDb[iDb].pBt!=0 || iDb==1 ); assert( iDb<32 ); mask = 1<<iDb; if( (pParse->cookieMask & mask)==0 ){ pParse->cookieMask |= mask; pParse->cookieValue[iDb] = db->aDb[iDb].schema_cookie; if( iDb==1 ){ sqlite3OpenTempDatabase(pParse); } } } } /* ** Generate VDBE code that prepares for doing an operation that ** might change the database. |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** ** $Id: main.c,v 1.252 2004/08/18 02:10:15 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** The following constant value is used by the SQLITE_BIGENDIAN and |
︙ | ︙ | |||
180 181 182 183 184 185 186 | if( pTab ){ pTab->readOnly = 1; } sqlite3SafetyOn(db); /* Create a cursor to hold the database open */ | | > > > | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | if( pTab ){ pTab->readOnly = 1; } sqlite3SafetyOn(db); /* Create a cursor to hold the database open */ if( db->aDb[iDb].pBt==0 ){ if( iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded); return SQLITE_OK; } rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain); if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){ sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); return rc; } /* Get the database meta information. |
︙ | ︙ |
Changes to src/pager.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ** 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. ** | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** 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.155 2004/08/18 02:10:15 drh Exp $ */ #include "os.h" /* Must be first to enable large file support */ #include "sqliteInt.h" #include "pager.h" #include <assert.h> #include <string.h> |
︙ | ︙ | |||
1655 1656 1657 1658 1659 1660 1661 | } /* ** Truncate the file to the number of pages specified. */ int sqlite3pager_truncate(Pager *pPager, Pgno nPage){ int rc; | < | < | 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 | } /* ** Truncate the file to the number of pages specified. */ int sqlite3pager_truncate(Pager *pPager, Pgno nPage){ int rc; sqlite3pager_pagecount(pPager); if( pPager->errMask!=0 ){ rc = pager_errcode(pPager); return rc; } if( nPage>=(unsigned)pPager->dbSize ){ return SQLITE_OK; } |
︙ | ︙ | |||
2207 2208 2209 2210 2211 2212 2213 | if( pPg->pNextHash ){ assert( pPg->pNextHash->pPrevHash==0 ); pPg->pNextHash->pPrevHash = pPg; } if( pPager->nExtra>0 ){ memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); } | | | 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 | if( pPg->pNextHash ){ assert( pPg->pNextHash->pPrevHash==0 ); pPg->pNextHash->pPrevHash = pPg; } if( pPager->nExtra>0 ){ memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); } sqlite3pager_pagecount(pPager); if( pPager->errMask!=0 ){ sqlite3pager_unref(PGHDR_TO_DATA(pPg)); rc = pager_errcode(pPager); return rc; } if( pPager->dbSize<(int)pgno ){ memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize); |
︙ | ︙ | |||
2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 | ** open. A new statement journal is created that can be used to rollback ** changes of a single SQL command within a larger transaction. */ int sqlite3pager_stmt_begin(Pager *pPager){ int rc; char zTemp[SQLITE_TEMPNAME_SIZE]; assert( !pPager->stmtInUse ); TRACE2("STMT-BEGIN %d\n", pPager->fd.h); if( pPager->memDb ){ pPager->stmtInUse = 1; pPager->stmtSize = pPager->dbSize; return SQLITE_OK; } if( !pPager->journalOpen ){ | > | 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 | ** open. A new statement journal is created that can be used to rollback ** changes of a single SQL command within a larger transaction. */ int sqlite3pager_stmt_begin(Pager *pPager){ int rc; char zTemp[SQLITE_TEMPNAME_SIZE]; assert( !pPager->stmtInUse ); assert( pPager->dbSize>=0 ); TRACE2("STMT-BEGIN %d\n", pPager->fd.h); if( pPager->memDb ){ pPager->stmtInUse = 1; pPager->stmtSize = pPager->dbSize; return SQLITE_OK; } if( !pPager->journalOpen ){ |
︙ | ︙ |
Changes to src/util.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** ** $Id: util.c,v 1.113 2004/08/18 02:10:15 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> #if SQLITE_DEBUG>2 && defined(__GLIBC__) #include <execinfo.h> |
︙ | ︙ | |||
785 786 787 788 789 790 791 | /* ** Convert the UTF-8 character to which z points into a 31-bit ** UCS character. This only works right if z points to a well-formed ** UTF-8 string. */ int sqlite3ReadUtf8(const unsigned char *z){ int c; | | | 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | /* ** Convert the UTF-8 character to which z points into a 31-bit ** UCS character. This only works right if z points to a well-formed ** UTF-8 string. */ int sqlite3ReadUtf8(const unsigned char *z){ int c; static const char initVal[] = { 0, 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, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, |
︙ | ︙ |
Changes to test/attach2.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # # $Id: attach2.test,v 1.23 2004/08/18 02:10:15 drh Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl # Ticket #354 |
︙ | ︙ | |||
161 162 163 164 165 166 167 | do_test attach2-4.1 { sqlite3 db test.db sqlite3 db2 test.db execsql {ATTACH 'test2.db' as file2} execsql {ATTACH 'test2.db' as file2} db2 } {} | | | | | | | | | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | do_test attach2-4.1 { sqlite3 db test.db sqlite3 db2 test.db execsql {ATTACH 'test2.db' as file2} execsql {ATTACH 'test2.db' as file2} db2 } {} lock_status 4.1.1 db {main unlocked temp closed file2 unlocked} lock_status 4.1.2 db2 {main unlocked temp closed file2 unlocked} do_test attach2-4.2 { # Handle 'db' read-locks test.db execsql {BEGIN} execsql {SELECT * FROM t1} # Lock status: # db - shared(main) # db2 - } {} lock_status 4.2.1 db {main shared temp closed file2 unlocked} lock_status 4.2.2 db2 {main unlocked temp closed file2 unlocked} do_test attach2-4.3 { # The read lock held by db does not prevent db2 from reading test.db execsql {SELECT * FROM t1} db2 } {} lock_status 4.3.1 db {main shared temp closed file2 unlocked} lock_status 4.3.2 db2 {main unlocked temp closed file2 unlocked} do_test attach2-4.4 { # db is holding a read lock on test.db, so we should not be able # to commit a write to test.db from db2 catchsql { INSERT INTO t1 VALUES(1, 2) } db2 } {1 {database is locked}} lock_status 4.4.1 db {main shared temp closed file2 unlocked} lock_status 4.4.2 db2 {main unlocked temp unlocked file2 unlocked} do_test attach2-4.5 { # Handle 'db2' reserves file2. execsql {BEGIN} db2 execsql {INSERT INTO file2.t1 VALUES(1, 2)} db2 # Lock status: # db - shared(main) # db2 - reserved(file2) } {} lock_status 4.5.1 db {main shared temp closed file2 unlocked} lock_status 4.5.2 db2 {main unlocked temp reserved file2 reserved} do_test attach2-4.6.1 { # Reads are allowed against a reserved database. catchsql { SELECT * FROM file2.t1; } # Lock status: # db - shared(main), shared(file2) # db2 - reserved(file2) } {0 {}} lock_status 4.6.1.1 db {main shared temp closed file2 shared} lock_status 4.6.1.2 db2 {main unlocked temp reserved file2 reserved} do_test attach2-4.6.2 { # Writes against a reserved database are not allowed. catchsql { UPDATE file2.t1 SET a=0; } |
︙ | ︙ |