From 1b5ba8e022836fa8ab93bc90df1b34a29ea6e134 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 17 Jan 2013 14:18:26 -0500 Subject: Imported Upstream version 2.1.1 --- src/pragma.c | 113 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 40 deletions(-) (limited to 'src/pragma.c') diff --git a/src/pragma.c b/src/pragma.c index 09282a7..e5a9ac2 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -118,7 +118,7 @@ static int invalidateTempStorage(Parse *pParse){ } sqlite3BtreeClose(db->aDb[1].pBt); db->aDb[1].pBt = 0; - sqlite3ResetInternalSchema(db, -1); + sqlite3ResetAllSchemasOfConnection(db); } return SQLITE_OK; } @@ -317,6 +317,12 @@ void sqlite3Pragma( sqlite3 *db = pParse->db; /* The database connection */ Db *pDb; /* The specific database being pragmaed */ Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db); /* Prepared statement */ +/** BEGIN CRYPTO **/ +#ifdef SQLITE_HAS_CODEC + extern int codec_pragma(sqlite3*, int, Parse *, const char *, const char *); +#endif +/** END CRYPTO **/ + if( v==0 ) return; sqlite3VdbeRunOnlyOnce(v); @@ -376,6 +382,13 @@ void sqlite3Pragma( pParse->rc = rc; }else +/** BEGIN CRYPTO **/ +#ifdef SQLITE_HAS_CODEC + if(codec_pragma(db, iDb, pParse, zLeft, zRight)) { + /* codec_pragma executes internal */ + }else + #endif +/** END CRYPTO **/ #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) /* @@ -804,6 +817,50 @@ void sqlite3Pragma( } }else +#if SQLITE_OS_WIN + /* + ** PRAGMA data_store_directory + ** PRAGMA data_store_directory = ""|"directory_name" + ** + ** Return or set the local value of the data_store_directory flag. Changing + ** the value sets a specific directory to be used for database files that + ** were specified with a relative pathname. Setting to a null string reverts + ** to the default database directory, which for database files specified with + ** a relative path will probably be based on the current directory for the + ** process. Database file specified with an absolute path are not impacted + ** by this setting, regardless of its value. + ** + */ + if( sqlite3StrICmp(zLeft, "data_store_directory")==0 ){ + if( !zRight ){ + if( sqlite3_data_directory ){ + sqlite3VdbeSetNumCols(v, 1); + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, + "data_store_directory", SQLITE_STATIC); + sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0); + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); + } + }else{ +#ifndef SQLITE_OMIT_WSD + if( zRight[0] ){ + int res; + rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); + if( rc!=SQLITE_OK || res==0 ){ + sqlite3ErrorMsg(pParse, "not a writable directory"); + goto pragma_out; + } + } + sqlite3_free(sqlite3_data_directory); + if( zRight[0] ){ + sqlite3_data_directory = sqlite3_mprintf("%s", zRight); + }else{ + sqlite3_data_directory = 0; + } +#endif /* SQLITE_OMIT_WSD */ + } + }else +#endif + #if !defined(SQLITE_ENABLE_LOCKING_STYLE) # if defined(__APPLE__) # define SQLITE_ENABLE_LOCKING_STYLE 1 @@ -1116,6 +1173,19 @@ void sqlite3Pragma( int isQuick = (sqlite3Tolower(zLeft[0])=='q'); + /* If the PRAGMA command was of the form "PRAGMA .integrity_check", + ** then iDb is set to the index of the database identified by . + ** In this case, the integrity of database iDb only is verified by + ** the VDBE created below. + ** + ** Otherwise, if the command was simply "PRAGMA integrity_check" (or + ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb + ** to -1 here, to indicate that the VDBE should verify the integrity + ** of all attached databases. */ + assert( iDb>=0 ); + assert( iDb==0 || pId2->z ); + if( pId2->z==0 ) iDb = -1; + /* Initialize the VDBE program */ if( sqlite3ReadSchema(pParse) ) goto pragma_out; pParse->nMem = 6; @@ -1139,6 +1209,7 @@ void sqlite3Pragma( int cnt = 0; if( OMIT_TEMPDB && i==1 ) continue; + if( iDb>=0 && i!=iDb ) continue; sqlite3CodeVerifySchema(pParse, i); addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */ @@ -1150,7 +1221,7 @@ void sqlite3Pragma( ** Begin by filling registers 2, 3, ... with the root pages numbers ** for all tables and indices in the database. */ - assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); + assert( sqlite3SchemaMutexHeld(db, i, 0) ); pTbls = &db->aDb[i].pSchema->tblHash; for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ Table *pTab = sqliteHashData(x); @@ -1534,44 +1605,6 @@ void sqlite3Pragma( sqlite3_rekey(db, zKey, i/2); } }else -/** BEGIN CRYPTO **/ - if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){ - extern void codec_vdbe_return_static_string(Parse *pParse, const char *zLabel, const char *value); - codec_vdbe_return_static_string(pParse, "cipher_version", CIPHER_VERSION); - }else - if( sqlite3StrICmp(zLeft, "cipher")==0 && zRight ){ - extern int codec_set_cipher_name(sqlite3*, int, const char *, int); - codec_set_cipher_name(db, iDb, zRight, 2); // change cipher for both - }else - if( sqlite3StrICmp(zLeft, "rekey_cipher")==0 && zRight ){ - extern int codec_set_cipher_name(sqlite3*, int, const char *, int); - codec_set_cipher_name(db, iDb, zRight, 1); // change write cipher only - }else - if( sqlite3StrICmp(zLeft, "kdf_iter")==0 && zRight ){ - extern int codec_set_kdf_iter(sqlite3*, int, int, int); - codec_set_kdf_iter(db, iDb, atoi(zRight), 2); // change of RW PBKDF2 iteration - }else - if( sqlite3StrICmp(zLeft, "fast_kdf_iter")==0 && zRight ){ - extern int codec_set_fast_kdf_iter(sqlite3*, int, int, int); - codec_set_fast_kdf_iter(db, iDb, atoi(zRight), 2); // change of RW PBKDF2 iteration - }else - if( sqlite3StrICmp(zLeft, "rekey_kdf_iter")==0 && zRight ){ - extern int codec_set_kdf_iter(sqlite3*, int, int, int); - codec_set_kdf_iter(db, iDb, atoi(zRight), 1); // change # if W iterations - }else - if( sqlite3StrICmp(zLeft,"cipher_page_size")==0 ){ - extern int codec_set_page_size(sqlite3*, int, int); - codec_set_page_size(db, iDb, atoi(zRight)); // change page size - }else - if( sqlite3StrICmp(zLeft,"cipher_default_use_hmac")==0 ){ - extern void codec_set_default_use_hmac(int); - codec_set_default_use_hmac(sqlite3GetBoolean(zRight,1)); - }else - if( sqlite3StrICmp(zLeft,"cipher_use_hmac")==0 ){ - extern int codec_set_use_hmac(sqlite3*, int, int); - codec_set_use_hmac(db, iDb, sqlite3GetBoolean(zRight,1)); - }else -/** END CRYPTO **/ #endif #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){ -- cgit v1.2.3