Setting sqlite temp store directory

后端 未结 2 748
眼角桃花
眼角桃花 2021-01-12 00:03

I have a Python binary which uses SQLite as its backend database. SQLite\'s documentation and the code suggests that setting any of the following 3 environment variables sho

相关标签:
2条回答
  • 2021-01-12 00:36

    The environment variables you are referring to are indeed what sqlite looks for but in Windows, not UNIX.

    In Unix, the environment variable you need to set is TMPDIR as shown in the sources:

    static const char *unixTempFileDir(void){
      static const char *azDirs[] = {
         0,
         0,
         "/var/tmp",
         "/usr/tmp",
         "/tmp",
         0        /* List terminator */
      };
      unsigned int i;
      struct stat buf;
      const char *zDir = 0;
    
      azDirs[0] = sqlite3_temp_directory;
      if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
      for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
        if( zDir==0 ) continue;
        if( osStat(zDir, &buf) ) continue;
        if( !S_ISDIR(buf.st_mode) ) continue;
        if( osAccess(zDir, 07) ) continue;
        break;
      }
      return zDir;
    }
    
    0 讨论(0)
  • 2021-01-12 00:39

    For version 3.8.1+ (released October 2013), it's cleaner to use the new SQLITE_TMPDIR environment variable instead of TMPDIR, since the latter is used by Unix software other than SQLite.

    From the release notes:

    The directory used to hold temporary files on unix can now be set using the SQLITE_TMPDIR environment variable, which takes precedence over the TMPDIR environment variable. The sqlite3_temp_directory global variable still has higher precedence than both environment variables, however.

    0 讨论(0)
提交回复
热议问题