/ Check-in [0a90eaf3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixes to the temp_store_directory pragma. (CVS 2185)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0a90eaf398aa4a689cd8326cd017951513ca748a
User & Date: drh 2005-01-08 15:44:26
Context
2005-01-08
18:42
Tcl interface does as sqlite3 or as sqlite. A compile-time option allows duel linking. Also fix a bug in the pragma change from earlier today. (CVS 2186) check-in: ad109537 user: drh tags: trunk
15:44
Fixes to the temp_store_directory pragma. (CVS 2185) check-in: 0a90eaf3 user: drh tags: trunk
15:43
Fix a comment. (CVS 2184) check-in: 26fbac8f user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

612
613
614
615
616
617
618

619
620
621
622
623
624
625
626
627
628
629
630
631

632
633
634
635
636
637
638
      zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
    }
    zBuf[j] = 0;
  }while( access(zBuf,0)==0 );
  return SQLITE_OK; 
}


/*
** Check that a given pathname is a directory and is writable 
**
*/
int sqlite3OsIsDirWritable(char *zBuf){
  struct stat buf;
  if( zBuf==0 ) return 0;
  if( strlen(zBuf)==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;
}


/*
** Read data from a file into a buffer.  Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
*/
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){







>







|





>







612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
      zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
    }
    zBuf[j] = 0;
  }while( access(zBuf,0)==0 );
  return SQLITE_OK; 
}

#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/*
** Check that a given pathname is a directory and is writable 
**
*/
int sqlite3OsIsDirWritable(char *zBuf){
  struct stat buf;
  if( 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
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
*/
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){

Changes to src/os_win.c.

405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421
422
423
424

425

426
427
428
429
430
431
432
    res = UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  }else{
    res = UnlockFile(id->h, SHARED_FIRST + id->sharedLockByte, 0, 1, 0);
  }
  return res;
}


/*
** Check that a given pathname is a directory and is writable 
**
*/
int sqlite3OsIsDirWritable(char *zBuf){
  int fileAttr;
  if(! zBuf ) return 0;
  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;
  return 1;
}




/*
** Lock the file with the lock specified by parameter locktype - one
** of the following:
**
**     (1) SHARED_LOCK
**     (2) RESERVED_LOCK







>










|
|
|
>
|
>







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
    res = UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  }else{
    res = UnlockFile(id->h, SHARED_FIRST + id->sharedLockByte, 0, 1, 0);
  }
  return res;
}

#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/*
** Check that a given pathname is a directory and is writable 
**
*/
int sqlite3OsIsDirWritable(char *zBuf){
  int fileAttr;
  if(! zBuf ) return 0;
  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;
  }
  return 1;
}
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */

/*
** Lock the file with the lock specified by parameter locktype - one
** of the following:
**
**     (1) SHARED_LOCK
**     (2) RESERVED_LOCK

Changes to src/pragma.c.

7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
...
369
370
371
372
373
374
375
376
377
378
379

380

381
382

383
384
385
386
387
388

389
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
**    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.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.81 2004/12/25 01:03:14 drh Exp $
*/
#include "sqliteInt.h"

#include <ctype.h>

/* Ignore this whole file if pragmas are disabled
*/
#ifndef SQLITE_OMIT_PRAGMA

#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
................................................................................
      if( sqlite3_temp_directory ){
        sqlite3VdbeSetNumCols(v, 1);
        sqlite3VdbeSetColName(v, 0, "temp_store_directory", P3_STATIC);
        sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
        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;
      }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

  /*
  **   PRAGMA [database.]synchronous
  **   PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL







|


>







 







|
|
|
<
>
|
>
|
<
>
|
|
<
|
<
<
>
|
<
<
<
<
<
<
<
<
>
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
370
371
372
373
374
375
376
377
378
379

380
381
382
383

384
385
386

387


388
389








390
391

392














393
394
395
396
397
398
399
**    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.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $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
*/
#ifndef SQLITE_OMIT_PRAGMA

#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
................................................................................
      if( sqlite3_temp_directory ){
        sqlite3VdbeSetNumCols(v, 1);
        sqlite3VdbeSetColName(v, 0, "temp_store_directory", P3_STATIC);
        sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
        sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
      }
    }else{
      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{

        sqlite3_temp_directory = 0;














      }
    }
  }else

  /*
  **   PRAGMA [database.]synchronous
  **   PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL

Changes to test/pragma.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
582
583
584
585
586
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
...
613
614
615
616
617
618
619

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637

638
639
640
641
642
643
644
...
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661

662
663
664
665
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the PRAGMA command.
#
# $Id: pragma.test,v 1.29 2005/01/07 10:42:48 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Test organization:
#
# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
................................................................................
  }
} {}
do_test pragma-8.2.15 {
  execsql {
    PRAGMA user_version;
  }
} {-450}

} ; # ifcapable schema_version


# Test temp_store and temp_store_directory pragmas
#

do_test pragma-9.1 {
  db close
  sqlite3 db test.db
  execsql {
    PRAGMA temp_store;
  }
} {0}
................................................................................
} {2}
do_test pragma-9.4 {
  execsql {
    PRAGMA temp_store_directory;
  }
} {}
do_test pragma-9.5 {

  execsql " \
    PRAGMA temp_store_directory='[pwd]'; \
  "
} {}
do_test pragma-9.6 {
  execsql { 
    PRAGMA temp_store_directory;
  }
} [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}

do_test pragma-9.8 {
  execsql { 
    PRAGMA temp_store_directory='';
  }
} {}
do_test pragma-9.9 {
  execsql { 
................................................................................
    PRAGMA temp_store=FILE;
    CREATE TEMP TABLE temp_store_directory_test(a integer);
    INSERT INTO temp_store_directory_test values (2);
    SELECT * FROM temp_store_directory_test;
  }
} {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}




finish_test







|







 







<





>







 







>
|
|








<
|
<
|
|
<
<
<
>







 







<
|
<
|
|
|
<
<
|
>

<
<

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598
599
600
601
...
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

631

632
633



634
635
636
637
638
639
640
641
...
643
644
645
646
647
648
649

650

651
652
653


654
655
656


657
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the PRAGMA command.
#
# $Id: pragma.test,v 1.30 2005/01/08 15:44:26 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Test organization:
#
# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
................................................................................
  }
} {}
do_test pragma-8.2.15 {
  execsql {
    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
  execsql {
    PRAGMA temp_store;
  }
} {0}
................................................................................
} {2}
do_test pragma-9.4 {
  execsql {
    PRAGMA temp_store_directory;
  }
} {}
do_test pragma-9.5 {
  set pwd [string map {' ''} [pwd]]
  execsql "
    PRAGMA temp_store_directory='$pwd';
  "
} {}
do_test pragma-9.6 {
  execsql { 
    PRAGMA temp_store_directory;
  }
} [pwd]
do_test pragma-9.7 {

  catchsql { 

    PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
  }



} {1 {not a writable directory}}
do_test pragma-9.8 {
  execsql { 
    PRAGMA temp_store_directory='';
  }
} {}
do_test pragma-9.9 {
  execsql { 
................................................................................
    PRAGMA temp_store=FILE;
    CREATE TEMP TABLE temp_store_directory_test(a integer);
    INSERT INTO temp_store_directory_test values (2);
    SELECT * FROM temp_store_directory_test;
  }
} {2}
do_test pragma-9.10 {

  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