Configuring the SQL file storage directory

I have a Python binary that uses SQLite as its base database. The SQLite documentation and code suggest that setting up any of the following three environment variables should work:

export TMP=/var/tmp/sqlite/ export TEMP=/var/tmp/sqlite/ export TEMPDIR=/var/tmp/sqlite/ 

If I export the above variables in my bash script just before I run my Python binary, this will not help.

Another option I tried calls putenv() by setting os.environ :

 os.environ['TMP'] = /var/tmp/sqlite/ os.environ['TEMP'] = /var/tmp/sqlite/ os.environ['TEMPDIR'] = /var/tmp/sqlite/ 

None of the above options helped convince SQLite to use /var/tmp/sqlite as the temp repository directory. The only option that worked - in the SQLite documentation - deprecated - sets the temp_store_directory pragma temp_store_directory :

 PRAGMA temp_store_directory = '/egnyte/.work/sqlite_temp' 

Since using the pragma instruction is not the choice I would like to make, is there any other trick?

+7
source share
2 answers

The environment variables you are referencing are indeed what sqlite is looking for, but on Windows, not on UNIX.

On Unix, the environment variable you must 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; } 
+7
source

Instead of using TMPDIR for cleaner version 3.8.1+ (released in October 2013), the new SQLITE_TMPDIR environment variable is SQLITE_TMPDIR , since the latter is used by Unix software other than SQLite.

From the release note :

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

+1
source

All Articles