Clear() public method

public Clear ( ) : void
return void
Ejemplo n.º 1
0
        /*
        ** Open a file.
        */
        static int winOpen(
            sqlite3_vfs pVfs,   /* Not used */
            string zName,       /* Name of the file (UTF-8) */
            sqlite3_file pFile, /* Write the SQLite file handle here */
            int flags,          /* Open mode flags */
            ref int pOutFlags   /* Status return flags */
            )
        {
            if (pFile.fs != null)
            {
                return(SQLITE_OK);
            }
            //HANDLE h;
            //pFile.fs = null;
            //fs = null;
            FileAccess    dwDesiredAccess;
            FileShare     dwShareMode;
            FileMode      dwCreationDisposition;
            string        zConverted;                                  /* Filename in OS encoding */
            string        zUtf8Name = zName;                           /* Filename in UTF-8 encoding */
            StringBuilder zTmpname  = new StringBuilder(MAX_PATH + 1); /* Buffer used to create temp filename */

            Debug.Assert(pFile != null);
            UNUSED_PARAMETER(pVfs);

            /* If the second argument to this function is NULL, generate a
            ** temporary file name to use
            */
            if (String.IsNullOrEmpty(zUtf8Name))
            {
                int rc = getTempname(MAX_PATH + 1, zTmpname);
                if (rc != SQLITE_OK)
                {
                    return(rc);
                }
                zUtf8Name = zTmpname.ToString();
            }

            // /* Convert the filename to the system encoding. */
            zConverted = zUtf8Name;// convertUtf8Filename( zUtf8Name );
            if (String.IsNullOrEmpty(zConverted))
            {
                return(SQLITE_NOMEM);
            }

            if ((flags & SQLITE_OPEN_READWRITE) != 0)
            {
                dwDesiredAccess = FileAccess.Read | FileAccess.Write; // GENERIC_READ | GENERIC_WRITE;
            }
            else
            {
                dwDesiredAccess = FileAccess.Read; // GENERIC_READ;
            }

            /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
            ** created. SQLite doesn't use it to indicate "exclusive access"
            ** as it is usually understood.
            */
            Debug.Assert(0 == (flags & SQLITE_OPEN_EXCLUSIVE) || (flags & SQLITE_OPEN_CREATE) != 0);
            if ((flags & SQLITE_OPEN_EXCLUSIVE) != 0)
            {
                /* Creates a new file, only if it does not already exist. */
                /* If the file exists, it fails. */
                dwCreationDisposition = FileMode.CreateNew;// CREATE_NEW;
            }
            else if ((flags & SQLITE_OPEN_CREATE) != 0)
            {
                /* Open existing file, or create if it doesn't exist */
                dwCreationDisposition = FileMode.OpenOrCreate;// OPEN_ALWAYS;
            }
            else
            {
                /* Opens a file, only if it exists. */
                dwCreationDisposition = FileMode.Open;      //OPEN_EXISTING;
            }
            dwShareMode = FileShare.Read | FileShare.Write; // FILE_SHARE_READ | FILE_SHARE_WRITE;
            if ((flags & SQLITE_OPEN_DELETEONCLOSE) != 0)
            {
            }
            else
            {
            }

            /* Reports from the internet are that performance is always
            ** better if FILE_FLAG_RANDOM_ACCESS is used.  Ticket #2699. */
            if (isNT())
            {
                int retries = 3;
                //while ( ( pFile.fs == null ) && ( retries > 0 ) )
                while ((pFile.fs == null) && (retries > 0))
                {
                    try
                    {
                        retries--;
                        //pFile.fs = new IsolatedStorageFileStream(zConverted, dwCreationDisposition, dwDesiredAccess, dwShareMode, pFile.store);
                        //pFile.fs = new IsolatedStorageFileStream(zConverted, dwCreationDisposition, dwDesiredAccess, dwShareMode, store);
                        pFile.fs = new IsolatedStorageFileStream(zConverted, FileMode.OpenOrCreate, dwDesiredAccess, dwShareMode, store);
                    }
                    catch (Exception e)
                    {
                        Thread.Sleep(100);
                    }
                }

                /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
                ** Since the ASCII version of these Windows API do not exist for WINCE,
                ** it's important to not reference them for WINCE builds.
                */
            }
            //if ( pFile.fs == null
            if (pFile.fs == null
                ||
                //!pFile.fs.CanRead
                !pFile.fs.CanRead
                )
            {
                if ((flags & SQLITE_OPEN_READWRITE) != 0)
                {
                    return(winOpen(pVfs, zName, pFile,
                                   ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE), ref pOutFlags));
                }
                else
                {
                    return(SQLITE_CANTOPEN_BKPT());
                }
            }
            if ((flags & SQLITE_OPEN_READWRITE) != 0)
            {
                pOutFlags = SQLITE_OPEN_READWRITE;
            }
            else
            {
                pOutFlags = SQLITE_OPEN_READONLY;
            }
            //}
            pFile.Clear(); // memset(pFile, 0, sizeof(*pFile));
            pFile.pMethods   = winIoMethod;
            pFile.lastErrno  = NO_ERROR;
            pFile.sectorSize = (ulong)getSectorSize(pVfs, zUtf8Name);
            return(SQLITE_OK);
        }
Ejemplo n.º 2
0
    /*
    ** Open a file.
    */
    static int winOpen(
    sqlite3_vfs pVfs,       /* Not used */
    string zName,           /* Name of the file (UTF-8) */
    sqlite3_file pFile, /* Write the SQLite file handle here */
    int flags,              /* Open mode flags */
    ref int pOutFlags       /* Status return flags */
    )
    {
        if (pFile.fs != null)
            return SQLITE_OK;
      //HANDLE h;
      //pFile.fs = null;
      //fs = null;
      FileAccess dwDesiredAccess;
      FileShare dwShareMode;
      FileMode dwCreationDisposition;
      string zConverted;                 /* Filename in OS encoding */
      string zUtf8Name = zName;    /* Filename in UTF-8 encoding */
      StringBuilder zTmpname = new StringBuilder( MAX_PATH + 1 );        /* Buffer used to create temp filename */

      Debug.Assert( pFile != null );
      UNUSED_PARAMETER( pVfs );

      /* If the second argument to this function is NULL, generate a
      ** temporary file name to use
      */
      if ( String.IsNullOrEmpty( zUtf8Name ) )
      {
        int rc = getTempname( MAX_PATH + 1, zTmpname );
        if ( rc != SQLITE_OK )
        {
          return rc;
        }
        zUtf8Name = zTmpname.ToString();
      }

      // /* Convert the filename to the system encoding. */
      zConverted = zUtf8Name;// convertUtf8Filename( zUtf8Name );
      if ( String.IsNullOrEmpty( zConverted ) )
      {
        return SQLITE_NOMEM;
      }

      if ( ( flags & SQLITE_OPEN_READWRITE ) != 0 )
      {
        dwDesiredAccess = FileAccess.Read | FileAccess.Write; // GENERIC_READ | GENERIC_WRITE;
      }
      else
      {
        dwDesiredAccess = FileAccess.Read; // GENERIC_READ;
      }
      /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
      ** created. SQLite doesn't use it to indicate "exclusive access"
      ** as it is usually understood.
      */
      Debug.Assert( 0 == ( flags & SQLITE_OPEN_EXCLUSIVE ) || ( flags & SQLITE_OPEN_CREATE ) != 0 );
      if ( ( flags & SQLITE_OPEN_EXCLUSIVE ) != 0 )
      {
        /* Creates a new file, only if it does not already exist. */
        /* If the file exists, it fails. */
        dwCreationDisposition = FileMode.CreateNew;// CREATE_NEW;
      }
      else if ( ( flags & SQLITE_OPEN_CREATE ) != 0 )
      {
        /* Open existing file, or create if it doesn't exist */
        dwCreationDisposition = FileMode.OpenOrCreate;// OPEN_ALWAYS;
      }
      else
      {
        /* Opens a file, only if it exists. */
        dwCreationDisposition = FileMode.Open;//OPEN_EXISTING;
      }
      dwShareMode = FileShare.Read | FileShare.Write;// FILE_SHARE_READ | FILE_SHARE_WRITE;
      if ( ( flags & SQLITE_OPEN_DELETEONCLOSE ) != 0 )
      {
      }
      else
      {
      }
      /* Reports from the internet are that performance is always
      ** better if FILE_FLAG_RANDOM_ACCESS is used.  Ticket #2699. */
      if ( isNT() )
      {
        int retries = 3;
        //while ( ( pFile.fs == null ) && ( retries > 0 ) )
        while ((pFile.fs == null) && (retries > 0))
          try
          {
            retries--;
            //pFile.fs = new IsolatedStorageFileStream(zConverted, dwCreationDisposition, dwDesiredAccess, dwShareMode, pFile.store);
            pFile.fs = new IsolatedStorageFileStream(zConverted, dwCreationDisposition, dwDesiredAccess, dwShareMode, store);
          }
          catch ( Exception e )
          {
            Thread.Sleep( 100 );
          }

        /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
        ** Since the ASCII version of these Windows API do not exist for WINCE,
        ** it's important to not reference them for WINCE builds.
        */
     }
      //if ( pFile.fs == null 
      if (pFile.fs == null 
          ||
          //!pFile.fs.CanRead
          !pFile.fs.CanRead
          ) 
      {
        if ( ( flags & SQLITE_OPEN_READWRITE ) != 0 )
        {
          return winOpen( pVfs, zName, pFile,
          ( ( flags | SQLITE_OPEN_READONLY ) & ~SQLITE_OPEN_READWRITE ), ref pOutFlags );
        }
        else
        {
          return SQLITE_CANTOPEN_BKPT();
        }
      }
      if ( ( flags & SQLITE_OPEN_READWRITE ) != 0 )
      {
        pOutFlags = SQLITE_OPEN_READWRITE;
      }
      else
      {
        pOutFlags = SQLITE_OPEN_READONLY;
      }
      //}
      pFile.Clear(); // memset(pFile, 0, sizeof(*pFile));
      pFile.pMethods = winIoMethod;
      pFile.lastErrno = NO_ERROR;
      pFile.sectorSize = (ulong)getSectorSize( pVfs, zUtf8Name );
      return SQLITE_OK;
    }