2011-05-10 4 views

답변

3

글쎄, 원래 코드를 수정하고이 버그를 수정했습니다.

Path.GetTempPath()은 샌드 박스 환경 때문에 작동하지 않습니다. 액세스 권한이 없습니다. 다음 코드로 수정되었습니다. 그리고 지금 작동합니다.

static int getTempname(int nBuf, StringBuilder zBuf) 
{ 
     const string zChars = "abcdefghijklmnopqrstuvwxyz"; 
     StringBuilder zRandom = new StringBuilder(20); 
     i64 iRandom = 0; 
     for (int i = 0; i < 20; i++) 
     { 
     sqlite3_randomness(1, ref iRandom); 
     zRandom.Append((char)zChars[(int)(iRandom % (zChars.Length - 1))]); 
     } 

     //! Modified by Toro, 2011,05,10 
     string tmpDir = "tmpDir"; 
     IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); 
     store.CreateDirectory(tmpDir); 
     //zBuf.Append(Path.GetTempPath() + SQLITE_TEMP_FILE_PREFIX + zRandom.ToString()); 
     zBuf.Append(tmpDir + "/" + SQLITE_TEMP_FILE_PREFIX + zRandom.ToString()); 

     return SQLITE_OK; 
} 

위의 패치는 isolatedstorage에서 별도의 폴더 tmpDir가 발생합니다, 그리고 자기에 의해 삭제 될 필요가 있으므로 임시 파일은 자동으로 삭제되지 않습니다. 나는 에서 winClose 내부의 파일을 삭제하려고 시도했습니다. VACUUM을 실행하면 충돌이 발생합니다. 마지막으로 데이터베이스를 닫을 때 그 tmp 파일을 삭제합니다. 다음은 SQLiteConnection 클래스의 Dispose 메서드입니다.

public void Dispose() 
{ 
    if (_open) 
    { 
     // Original codes for close sqlite database 
     Sqlite3.sqlite3_close(_db); 
     _db = null; 
     _open = false; 

     // Clear tmp files in tmpDir, added by Toro 2011,05,13 
     IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); 
     string tmpDir = "tmpDir"; 
     if (store.DirectoryExists(tmpDir) == false) return; 

     string searchPath = System.IO.Path.Combine(tmpDir, "*.*"); 
     foreach (string file in store.GetFileNames(searchPath)) { 
      store.DeleteFile(System.IO.Path.Combine(tmpDir, file)); 
     } 
    } 
} 
관련 문제