]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fixes to the temp_store_directory pragma. (CVS 2185)
authordrh <drh@noemail.net>
Sat, 8 Jan 2005 15:44:25 +0000 (15:44 +0000)
committerdrh <drh@noemail.net>
Sat, 8 Jan 2005 15:44:25 +0000 (15:44 +0000)
FossilOrigin-Name: 0a90eaf398aa4a689cd8326cd017951513ca748a

manifest
manifest.uuid
src/os_unix.c
src/os_win.c
src/pragma.c
test/pragma.test

index a0ba1ecb16ccd083cc2f883d1bae0aae170c408a..05bbd89603b87000e7415dd8905c975d697972be 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\scomment.\s(CVS\s2184)
-D 2005-01-08T15:43:19
+C Fixes\sto\sthe\stemp_store_directory\spragma.\s(CVS\s2185)
+D 2005-01-08T15:44:26
 F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -49,14 +49,14 @@ F src/os_mac.c e2a35e96bdf57a113ae1c446532e3c0924d3d046
 F src/os_mac.h 608fdf39eafa1ce25fc8cb223b8b0a073341d4da
 F src/os_test.c 91e5f22dd89491e5e1554820e715805f43fa4ece
 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_win.c 39525c414e57ca3f18d860d40d6d38df85689522
+F src/os_win.c 3c0b0a3bc33318cf555a1cd130232ad1b9a5a711
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
 F src/pager.c 4a14410a4e67173bb121a919c7f2033b93822186
 F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
 F src/parse.y ceba179b9703657180963568f54b0e75f33e36e1
-F src/pragma.c 0394f9361a497b7f74c1e5909bfc95a1f5bf0ce4
+F src/pragma.c 1b6f9f4caa2c441b18bf0c8793a4b4b8f3214d03
 F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
 F src/select.c af6ffcf0201f8f4e2697eea25689077dc61c6109
@@ -161,7 +161,7 @@ F test/pager.test 394455707a079804e8a4e431d12edce831a065f0
 F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e
 F test/pager3.test 647f696a9cf7409df00a1e0047c2eb55585a1b85
 F test/pagesize.test 1b826d1608fd86d2303aa895b5586052ad07eba1
-F test/pragma.test 6d6f7db667aabd7cfbb57a8daec6022f3eb68400
+F test/pragma.test 3673c0eb920cf2489410dc58f9875384cf4acdce
 F test/printf.test 92ba4c510b4fc61120ffa4a01820446ed917ae57
 F test/progress.test 5ddba78cb6011fba36093973cfb3ac473b8fb96a x
 F test/quick.test 91e5b8ae6663dc9e3e754b271f0384f0cae706e6
@@ -263,7 +263,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
-P fb3bf68d0e83b463c7e2f95b4502ba6f8158c074
-R 7b899dfdb34524e0b647e71db3f94a04
+P 26fbac8f031b305fe98add4422ab606ed116844a
+R f87c924f62a99bca5faef617ba021d39
 U drh
-Z dc33d0b51c02b0380f298c0fa7efa871
+Z 08c214dff6b3942d3cd4bb3f84fb288c
index cbf357c7574cc0e13b0cf593d22babec09689e95..eacffdfff51d6df66006bc076e4474ed27151f5f 100644 (file)
@@ -1 +1 @@
-26fbac8f031b305fe98add4422ab606ed116844a
\ No newline at end of file
+0a90eaf398aa4a689cd8326cd017951513ca748a
\ No newline at end of file
index 4d17c632d370ac064f9fe1423cd3506dcc0135d8..3797a82cbfe1f8e4cba89ef0a66ca6229a83d7d2 100644 (file)
@@ -616,6 +616,7 @@ int sqlite3OsTempFileName(char *zBuf){
   return SQLITE_OK; 
 }
 
+#ifndef SQLITE_OMIT_PAGER_PRAGMAS
 /*
 ** Check that a given pathname is a directory and is writable 
 **
@@ -623,12 +624,13 @@ int sqlite3OsTempFileName(char *zBuf){
 int sqlite3OsIsDirWritable(char *zBuf){
   struct stat buf;
   if( zBuf==0 ) return 0;
-  if( strlen(zBuf)==0 ) return 0;
+  if( zBuf[0]==0 ) return 0;
   if( stat(zBuf, &buf) ) return 0;
   if( !S_ISDIR(buf.st_mode) ) return 0;
   if( access(zBuf, 07) ) return 0;
   return 1;
 }
+#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
 
 /*
 ** Read data from a file into a buffer.  Return SQLITE_OK if all
index 732b796563cbc5667c3fd173af40c0b1a47ead8c..e2c09d250d1b20e16bd76d7460dc4d5017a3adac 100644 (file)
@@ -409,6 +409,7 @@ static int unlockReadLock(OsFile *id){
   return res;
 }
 
+#ifndef SQLITE_OMIT_PAGER_PRAGMAS
 /*
 ** 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;
   fileAttr = GetFileAttributesA(zBuf);
   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;
 }
-
+#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
 
 /*
 ** Lock the file with the lock specified by parameter locktype - one
index 51f7f43a20049c3314832a7e50e5a5ecceb2ac0c..53cdf663f0d80f8d1a9b29ec55dfa68492f7f4fe 100644 (file)
 *************************************************************************
 ** 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 "os.h"
 #include <ctype.h>
 
 /* Ignore this whole file if pragmas are disabled
@@ -373,45 +374,22 @@ void sqlite3Pragma(
         sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
       }
     }else{
-      if( strlen(zRight)==0 ){
-        /* empty path, set to default. allows os_{unix,win}.c to choose directory */
-        if( sqlite3_temp_directory ){
-          /* previous temp_store_directory defined, free and invalidate */
-          sqlite3FreeX(sqlite3_temp_directory);
-          if( db->temp_store==1 ) {
-            /* temp storage is "file", so invalidate temp */
-            invalidateTempStorage( pParse );
-          }
-        }
-        sqlite3_temp_directory = 0;
+      if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
+        sqlite3ErrorMsg(pParse, "not a writable directory");
+        goto pragma_out;
+      }
+      if( TEMP_STORE==0
+       || (TEMP_STORE==1 && db->temp_store<=1)
+       || (TEMP_STORE==2 && db->temp_store==1)
+      ){
+        invalidateTempStorage(pParse);
+      }
+      sqliteFree(sqlite3_temp_directory);
+      if( zRight[0] ){
+        sqlite3_temp_directory = zRight;
+        zRight = 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");
-        }
+        sqlite3_temp_directory = 0;
       }
     }
   }else
index f03d7030efcf5c4cb94962d04f81c67d4769a7ab..6b7396a86a3e79bf907fe16a479edbacea0cfa52 100644 (file)
@@ -12,7 +12,7 @@
 #
 # 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]
 source $testdir/tester.tcl
@@ -586,12 +586,12 @@ do_test pragma-8.2.15 {
     PRAGMA user_version;
   }
 } {-450}
-
 } ; # ifcapable schema_version
 
 
 # Test temp_store and temp_store_directory pragmas
 #
+ifcapable pager_pragmas {
 do_test pragma-9.1 {
   db close
   sqlite3 db test.db
@@ -617,8 +617,9 @@ do_test pragma-9.4 {
   }
 } {}
 do_test pragma-9.5 {
-  execsql " \
-    PRAGMA temp_store_directory='[pwd]'; \
+  set pwd [string map {' ''} [pwd]]
+  execsql "
+    PRAGMA temp_store_directory='$pwd';
   "
 } {}
 do_test pragma-9.6 {
@@ -627,14 +628,10 @@ do_test pragma-9.6 {
   }
 } [pwd]
 do_test pragma-9.7 {
-  set result ""
-  catch {
-    execsql { 
-      PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
-    }
-  } result
-  set result
-} {not a directory, or not writable}
+  catchsql { 
+    PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
+  }
+} {1 {not a writable directory}}
 do_test pragma-9.8 {
   execsql { 
     PRAGMA temp_store_directory='';
@@ -650,16 +647,11 @@ do_test pragma-9.9 {
   }
 } {2}
 do_test pragma-9.10 {
-  set result ""
-  catch {
-    execsql " \
-      PRAGMA temp_store_directory='[pwd]'; \
-      SELECT * FROM temp_store_directory_test;
-    "
-  } result
-  set result
-} {no such table: temp_store_directory_test}
-
-
+  catchsql "
+    PRAGMA temp_store_directory='$pwd';
+    SELECT * FROM temp_store_directory_test;
+  "
+} {1 {no such table: temp_store_directory_test}}
+} ;# ifcapable pager_pragmas
 
 finish_test