1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-27 08:52:26 +03:00

Fixes to the temp_store_directory pragma. (CVS 2185)

FossilOrigin-Name: 0a90eaf398aa4a689cd8326cd017951513ca748a
This commit is contained in:
drh
2005-01-08 15:44:25 +00:00
parent 4b238dfb80
commit 268283bc7f
6 changed files with 50 additions and 75 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sa\scomment.\s(CVS\s2184) C Fixes\sto\sthe\stemp_store_directory\spragma.\s(CVS\s2185)
D 2005-01-08T15:43:19 D 2005-01-08T15:44:26
F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4 F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -49,14 +49,14 @@ F src/os_mac.c e2a35e96bdf57a113ae1c446532e3c0924d3d046
F src/os_mac.h 608fdf39eafa1ce25fc8cb223b8b0a073341d4da F src/os_mac.h 608fdf39eafa1ce25fc8cb223b8b0a073341d4da
F src/os_test.c 91e5f22dd89491e5e1554820e715805f43fa4ece F src/os_test.c 91e5f22dd89491e5e1554820e715805f43fa4ece
F src/os_test.h 6a26a4978492e4bbdbf385554958418ff02db162 F src/os_test.h 6a26a4978492e4bbdbf385554958418ff02db162
F src/os_unix.c f3835451ffa69072ea88f30cfd6f3ed12b728cfa F src/os_unix.c 08340c864822115bf87c6c1735780a0996278b81
F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13 F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
F src/os_win.c 39525c414e57ca3f18d860d40d6d38df85689522 F src/os_win.c 3c0b0a3bc33318cf555a1cd130232ad1b9a5a711
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 4a14410a4e67173bb121a919c7f2033b93822186 F src/pager.c 4a14410a4e67173bb121a919c7f2033b93822186
F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862 F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
F src/parse.y ceba179b9703657180963568f54b0e75f33e36e1 F src/parse.y ceba179b9703657180963568f54b0e75f33e36e1
F src/pragma.c 0394f9361a497b7f74c1e5909bfc95a1f5bf0ce4 F src/pragma.c 1b6f9f4caa2c441b18bf0c8793a4b4b8f3214d03
F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357 F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
F src/select.c af6ffcf0201f8f4e2697eea25689077dc61c6109 F src/select.c af6ffcf0201f8f4e2697eea25689077dc61c6109
@@ -161,7 +161,7 @@ F test/pager.test 394455707a079804e8a4e431d12edce831a065f0
F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e
F test/pager3.test 647f696a9cf7409df00a1e0047c2eb55585a1b85 F test/pager3.test 647f696a9cf7409df00a1e0047c2eb55585a1b85
F test/pagesize.test 1b826d1608fd86d2303aa895b5586052ad07eba1 F test/pagesize.test 1b826d1608fd86d2303aa895b5586052ad07eba1
F test/pragma.test 6d6f7db667aabd7cfbb57a8daec6022f3eb68400 F test/pragma.test 3673c0eb920cf2489410dc58f9875384cf4acdce
F test/printf.test 92ba4c510b4fc61120ffa4a01820446ed917ae57 F test/printf.test 92ba4c510b4fc61120ffa4a01820446ed917ae57
F test/progress.test 5ddba78cb6011fba36093973cfb3ac473b8fb96a x F test/progress.test 5ddba78cb6011fba36093973cfb3ac473b8fb96a x
F test/quick.test 91e5b8ae6663dc9e3e754b271f0384f0cae706e6 F test/quick.test 91e5b8ae6663dc9e3e754b271f0384f0cae706e6
@@ -263,7 +263,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746 F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
P fb3bf68d0e83b463c7e2f95b4502ba6f8158c074 P 26fbac8f031b305fe98add4422ab606ed116844a
R 7b899dfdb34524e0b647e71db3f94a04 R f87c924f62a99bca5faef617ba021d39
U drh U drh
Z dc33d0b51c02b0380f298c0fa7efa871 Z 08c214dff6b3942d3cd4bb3f84fb288c

View File

@@ -1 +1 @@
26fbac8f031b305fe98add4422ab606ed116844a 0a90eaf398aa4a689cd8326cd017951513ca748a

View File

@@ -616,6 +616,7 @@ int sqlite3OsTempFileName(char *zBuf){
return SQLITE_OK; return SQLITE_OK;
} }
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/* /*
** Check that a given pathname is a directory and is writable ** Check that a given pathname is a directory and is writable
** **
@@ -623,12 +624,13 @@ int sqlite3OsTempFileName(char *zBuf){
int sqlite3OsIsDirWritable(char *zBuf){ int sqlite3OsIsDirWritable(char *zBuf){
struct stat buf; struct stat buf;
if( zBuf==0 ) return 0; if( zBuf==0 ) return 0;
if( strlen(zBuf)==0 ) return 0; if( zBuf[0]==0 ) return 0;
if( stat(zBuf, &buf) ) return 0; if( stat(zBuf, &buf) ) return 0;
if( !S_ISDIR(buf.st_mode) ) return 0; if( !S_ISDIR(buf.st_mode) ) return 0;
if( access(zBuf, 07) ) return 0; if( access(zBuf, 07) ) return 0;
return 1; return 1;
} }
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
/* /*
** Read data from a file into a buffer. Return SQLITE_OK if all ** Read data from a file into a buffer. Return SQLITE_OK if all

View File

@@ -409,6 +409,7 @@ static int unlockReadLock(OsFile *id){
return res; return res;
} }
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/* /*
** Check that a given pathname is a directory and is writable ** Check that a given pathname is a directory and is writable
** **
@@ -419,10 +420,12 @@ int sqlite3OsIsDirWritable(char *zBuf){
if(! isNT() && strlen(zBuf) > MAX_PATH ) return 0; if(! isNT() && strlen(zBuf) > MAX_PATH ) return 0;
fileAttr = GetFileAttributesA(zBuf); fileAttr = GetFileAttributesA(zBuf);
if( fileAttr == 0xffffffff ) return 0; if( fileAttr == 0xffffffff ) return 0;
if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) return 0; if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){
return 0;
}
return 1; return 1;
} }
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
/* /*
** Lock the file with the lock specified by parameter locktype - one ** Lock the file with the lock specified by parameter locktype - one

View File

@@ -11,9 +11,10 @@
************************************************************************* *************************************************************************
** This file contains code used to implement the PRAGMA command. ** This file contains code used to implement the PRAGMA command.
** **
** $Id: pragma.c,v 1.81 2004/12/25 01:03:14 drh Exp $ ** $Id: pragma.c,v 1.82 2005/01/08 15:44:26 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h"
#include <ctype.h> #include <ctype.h>
/* Ignore this whole file if pragmas are disabled /* Ignore this whole file if pragmas are disabled
@@ -373,45 +374,22 @@ void sqlite3Pragma(
sqlite3VdbeAddOp(v, OP_Callback, 1, 0); sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
} }
}else{ }else{
if( strlen(zRight)==0 ){ if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
/* empty path, set to default. allows os_{unix,win}.c to choose directory */ sqlite3ErrorMsg(pParse, "not a writable directory");
if( sqlite3_temp_directory ){ goto pragma_out;
/* previous temp_store_directory defined, free and invalidate */ }
sqlite3FreeX(sqlite3_temp_directory); if( TEMP_STORE==0
if( db->temp_store==1 ) { || (TEMP_STORE==1 && db->temp_store<=1)
/* temp storage is "file", so invalidate temp */ || (TEMP_STORE==2 && db->temp_store==1)
){
invalidateTempStorage(pParse); invalidateTempStorage(pParse);
} }
} sqliteFree(sqlite3_temp_directory);
if( zRight[0] ){
sqlite3_temp_directory = zRight;
zRight = 0;
}else{
sqlite3_temp_directory = 0; sqlite3_temp_directory = 0;
}else{
/* check if previous directory defined, free and alloc if needed */
if( sqlite3_temp_directory ){
if( strlen(sqlite3_temp_directory) < strlen(zRight) + 1){
sqlite3FreeX(sqlite3_temp_directory);
sqlite3_temp_directory = sqliteMalloc( strlen(zRight) + 1 );
if( sqlite3_temp_directory==0 ){
goto pragma_out;
}
sqlite3_temp_directory[0] = '\0';
}
}else{
sqlite3_temp_directory = sqliteMalloc( strlen(zRight) + 1 );
if( sqlite3_temp_directory==0 ){
goto pragma_out;
}
sqlite3_temp_directory[0] = '\0';
}
/* check that directory exists and is writable */
if( sqlite3OsIsDirWritable( zRight ) ){
strcpy(sqlite3_temp_directory, zRight);
if( db->temp_store==1 ) {
/* temp storage is "file", so invalidate temp */
invalidateTempStorage( pParse );
}
}else{
sqlite3ErrorMsg(pParse, "not a directory, or not writable");
}
} }
} }
}else }else

View File

@@ -12,7 +12,7 @@
# #
# This file implements tests for the PRAGMA command. # This file implements tests for the PRAGMA command.
# #
# $Id: pragma.test,v 1.29 2005/01/07 10:42:48 danielk1977 Exp $ # $Id: pragma.test,v 1.30 2005/01/08 15:44:26 drh Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@@ -586,12 +586,12 @@ do_test pragma-8.2.15 {
PRAGMA user_version; PRAGMA user_version;
} }
} {-450} } {-450}
} ; # ifcapable schema_version } ; # ifcapable schema_version
# Test temp_store and temp_store_directory pragmas # Test temp_store and temp_store_directory pragmas
# #
ifcapable pager_pragmas {
do_test pragma-9.1 { do_test pragma-9.1 {
db close db close
sqlite3 db test.db sqlite3 db test.db
@@ -617,8 +617,9 @@ do_test pragma-9.4 {
} }
} {} } {}
do_test pragma-9.5 { do_test pragma-9.5 {
execsql " \ set pwd [string map {' ''} [pwd]]
PRAGMA temp_store_directory='[pwd]'; \ execsql "
PRAGMA temp_store_directory='$pwd';
" "
} {} } {}
do_test pragma-9.6 { do_test pragma-9.6 {
@@ -627,14 +628,10 @@ do_test pragma-9.6 {
} }
} [pwd] } [pwd]
do_test pragma-9.7 { do_test pragma-9.7 {
set result "" catchsql {
catch {
execsql {
PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
} }
} result } {1 {not a writable directory}}
set result
} {not a directory, or not writable}
do_test pragma-9.8 { do_test pragma-9.8 {
execsql { execsql {
PRAGMA temp_store_directory=''; PRAGMA temp_store_directory='';
@@ -650,16 +647,11 @@ do_test pragma-9.9 {
} }
} {2} } {2}
do_test pragma-9.10 { do_test pragma-9.10 {
set result "" catchsql "
catch { PRAGMA temp_store_directory='$pwd';
execsql " \
PRAGMA temp_store_directory='[pwd]'; \
SELECT * FROM temp_store_directory_test; SELECT * FROM temp_store_directory_test;
" "
} result } {1 {no such table: temp_store_directory_test}}
set result } ;# ifcapable pager_pragmas
} {no such table: temp_store_directory_test}
finish_test finish_test