/ Check-in [40526d83]
Login

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

Overview
Comment:Replicate asserts on unixOpen() to winOpen() in os_win.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 40526d8390896ccb883c45afa70e7adb568d174f
User & Date: shaneh 2010-08-24 20:46:53
Context
2010-08-25
17:53
Test cases to improve coverage of rtree module. Fixes associated with the same. check-in: 865cec04 user: dan tags: trunk
2010-08-24
20:46
Replicate asserts on unixOpen() to winOpen() in os_win.c. check-in: 40526d83 user: shaneh tags: trunk
18:35
Changes to support building with SQLITE_OMIT_WAL. check-in: d1ed743b user: shaneh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

  1464   1464       if( pShmNode->mutex==0 ){
  1465   1465         rc = SQLITE_NOMEM;
  1466   1466         goto shm_open_err;
  1467   1467       }
  1468   1468       rc = winOpen(pDbFd->pVfs,
  1469   1469                    pShmNode->zFilename,             /* Name of the file (UTF-8) */
  1470   1470                    (sqlite3_file*)&pShmNode->hFile,  /* File handle here */
  1471         -                 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
         1471  +                 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
  1472   1472                    0);
  1473   1473       if( SQLITE_OK!=rc ){
  1474   1474         rc = SQLITE_CANTOPEN_BKPT;
  1475   1475         goto shm_open_err;
  1476   1476       }
  1477   1477   
  1478   1478       /* Check to see if another process is holding the dead-man switch.
................................................................................
  2020   2020     DWORD dwShareMode;
  2021   2021     DWORD dwCreationDisposition;
  2022   2022     DWORD dwFlagsAndAttributes = 0;
  2023   2023   #if SQLITE_OS_WINCE
  2024   2024     int isTemp = 0;
  2025   2025   #endif
  2026   2026     winFile *pFile = (winFile*)id;
  2027         -  void *zConverted;                 /* Filename in OS encoding */
  2028         -  const char *zUtf8Name = zName;    /* Filename in UTF-8 encoding */
  2029         -  char zTmpname[MAX_PATH+1];        /* Buffer used to create temp filename */
         2027  +  void *zConverted;              /* Filename in OS encoding */
         2028  +  const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
         2029  +
         2030  +  /* If argument zPath is a NULL pointer, this function is required to open
         2031  +  ** a temporary file. Use this buffer to store the file name in.
         2032  +  */
         2033  +  char zTmpname[MAX_PATH+1];     /* Buffer used to create temp filename */
         2034  +
         2035  +  int rc = SQLITE_OK;            /* Function Return Code */
         2036  +  int eType = flags&0xFFFFFF00;  /* Type of file to open */
         2037  +
         2038  +  int isExclusive  = (flags & SQLITE_OPEN_EXCLUSIVE);
         2039  +  int isDelete     = (flags & SQLITE_OPEN_DELETEONCLOSE);
         2040  +  int isCreate     = (flags & SQLITE_OPEN_CREATE);
         2041  +  int isReadonly   = (flags & SQLITE_OPEN_READONLY);
         2042  +  int isReadWrite  = (flags & SQLITE_OPEN_READWRITE);
         2043  +
         2044  +  int isOpenJournal = (isCreate && (
         2045  +        eType==SQLITE_OPEN_MASTER_JOURNAL 
         2046  +     || eType==SQLITE_OPEN_MAIN_JOURNAL 
         2047  +     || eType==SQLITE_OPEN_WAL
         2048  +  ));
         2049  +
         2050  +  /* Check the following statements are true: 
         2051  +  **
         2052  +  **   (a) Exactly one of the READWRITE and READONLY flags must be set, and 
         2053  +  **   (b) if CREATE is set, then READWRITE must also be set, and
         2054  +  **   (c) if EXCLUSIVE is set, then CREATE must also be set.
         2055  +  **   (d) if DELETEONCLOSE is set, then CREATE must also be set.
         2056  +  */
         2057  +  assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
         2058  +  assert(isCreate==0 || isReadWrite);
         2059  +  assert(isExclusive==0 || isCreate);
         2060  +  assert(isDelete==0 || isCreate);
         2061  +
         2062  +  /* The main DB, main journal, WAL file and master journal are never 
         2063  +  ** automatically deleted. Nor are they ever temporary files.  */
         2064  +  assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
         2065  +  assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
         2066  +  assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
         2067  +  assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
         2068  +
         2069  +  /* Assert that the upper layer has set one of the "file-type" flags. */
         2070  +  assert( eType==SQLITE_OPEN_MAIN_DB      || eType==SQLITE_OPEN_TEMP_DB 
         2071  +       || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL 
         2072  +       || eType==SQLITE_OPEN_SUBJOURNAL   || eType==SQLITE_OPEN_MASTER_JOURNAL 
         2073  +       || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
         2074  +  );
  2030   2075   
  2031   2076     assert( id!=0 );
  2032   2077     UNUSED_PARAMETER(pVfs);
  2033   2078   
  2034   2079     pFile->h = INVALID_HANDLE_VALUE;
  2035   2080   
  2036   2081     /* If the second argument to this function is NULL, generate a 
  2037   2082     ** temporary file name to use 
  2038   2083     */
  2039   2084     if( !zUtf8Name ){
  2040         -    int rc = getTempname(MAX_PATH+1, zTmpname);
         2085  +    assert(isDelete && !isOpenJournal);
         2086  +    rc = getTempname(MAX_PATH+1, zTmpname);
  2041   2087       if( rc!=SQLITE_OK ){
  2042   2088         return rc;
  2043   2089       }
  2044   2090       zUtf8Name = zTmpname;
  2045   2091     }
  2046   2092   
  2047   2093     /* Convert the filename to the system encoding. */
  2048   2094     zConverted = convertUtf8Filename(zUtf8Name);
  2049   2095     if( zConverted==0 ){
  2050   2096       return SQLITE_NOMEM;
  2051   2097     }
  2052   2098   
  2053         -  if( flags & SQLITE_OPEN_READWRITE ){
         2099  +  if( isReadWrite ){
  2054   2100       dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
  2055   2101     }else{
  2056   2102       dwDesiredAccess = GENERIC_READ;
  2057   2103     }
         2104  +
  2058   2105     /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is 
  2059   2106     ** created. SQLite doesn't use it to indicate "exclusive access" 
  2060   2107     ** as it is usually understood.
  2061   2108     */
  2062         -  assert(!(flags & SQLITE_OPEN_EXCLUSIVE) || (flags & SQLITE_OPEN_CREATE));
  2063         -  if( flags & SQLITE_OPEN_EXCLUSIVE ){
         2109  +  if( isExclusive ){
  2064   2110       /* Creates a new file, only if it does not already exist. */
  2065   2111       /* If the file exists, it fails. */
  2066   2112       dwCreationDisposition = CREATE_NEW;
  2067         -  }else if( flags & SQLITE_OPEN_CREATE ){
         2113  +  }else if( isCreate ){
  2068   2114       /* Open existing file, or create if it doesn't exist */
  2069   2115       dwCreationDisposition = OPEN_ALWAYS;
  2070   2116     }else{
  2071   2117       /* Opens a file, only if it exists. */
  2072   2118       dwCreationDisposition = OPEN_EXISTING;
  2073   2119     }
         2120  +
  2074   2121     dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
  2075         -  if( flags & SQLITE_OPEN_DELETEONCLOSE ){
         2122  +
         2123  +  if( isDelete ){
  2076   2124   #if SQLITE_OS_WINCE
  2077   2125       dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
  2078   2126       isTemp = 1;
  2079   2127   #else
  2080   2128       dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
  2081   2129                                  | FILE_ATTRIBUTE_HIDDEN
  2082   2130                                  | FILE_FLAG_DELETE_ON_CLOSE;
................................................................................
  2085   2133       dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
  2086   2134     }
  2087   2135     /* Reports from the internet are that performance is always
  2088   2136     ** better if FILE_FLAG_RANDOM_ACCESS is used.  Ticket #2699. */
  2089   2137   #if SQLITE_OS_WINCE
  2090   2138     dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
  2091   2139   #endif
         2140  +
  2092   2141     if( isNT() ){
  2093   2142       h = CreateFileW((WCHAR*)zConverted,
  2094   2143          dwDesiredAccess,
  2095   2144          dwShareMode,
  2096   2145          NULL,
  2097   2146          dwCreationDisposition,
  2098   2147          dwFlagsAndAttributes,
................................................................................
  2110   2159          NULL,
  2111   2160          dwCreationDisposition,
  2112   2161          dwFlagsAndAttributes,
  2113   2162          NULL
  2114   2163       );
  2115   2164   #endif
  2116   2165     }
         2166  +
  2117   2167     OSTRACE(("OPEN %d %s 0x%lx %s\n", 
  2118   2168              h, zName, dwDesiredAccess, 
  2119   2169              h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
         2170  +
  2120   2171     if( h==INVALID_HANDLE_VALUE ){
  2121   2172       pFile->lastErrno = GetLastError();
  2122   2173       free(zConverted);
  2123         -    if( flags & SQLITE_OPEN_READWRITE ){
         2174  +    if( isReadWrite ){
  2124   2175         return winOpen(pVfs, zName, id, 
  2125         -             ((flags|SQLITE_OPEN_READONLY)&~SQLITE_OPEN_READWRITE), pOutFlags);
         2176  +             ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
  2126   2177       }else{
  2127   2178         return SQLITE_CANTOPEN_BKPT;
  2128   2179       }
  2129   2180     }
         2181  +
  2130   2182     if( pOutFlags ){
  2131         -    if( flags & SQLITE_OPEN_READWRITE ){
         2183  +    if( isReadWrite ){
  2132   2184         *pOutFlags = SQLITE_OPEN_READWRITE;
  2133   2185       }else{
  2134   2186         *pOutFlags = SQLITE_OPEN_READONLY;
  2135   2187       }
  2136   2188     }
         2189  +
  2137   2190     memset(pFile, 0, sizeof(*pFile));
  2138   2191     pFile->pMethod = &winIoMethod;
  2139   2192     pFile->h = h;
  2140   2193     pFile->lastErrno = NO_ERROR;
  2141   2194     pFile->pVfs = pVfs;
  2142   2195     pFile->pShm = 0;
  2143   2196     pFile->zPath = zName;
  2144   2197     pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
         2198  +
  2145   2199   #if SQLITE_OS_WINCE
  2146         -  if( (flags & (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)) ==
  2147         -               (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)
         2200  +  if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
  2148   2201          && !winceCreateLock(zName, pFile)
  2149   2202     ){
  2150   2203       CloseHandle(h);
  2151   2204       free(zConverted);
  2152   2205       return SQLITE_CANTOPEN_BKPT;
  2153   2206     }
  2154   2207     if( isTemp ){
  2155   2208       pFile->zDeleteOnClose = zConverted;
  2156   2209     }else
  2157   2210   #endif
  2158   2211     {
  2159   2212       free(zConverted);
  2160   2213     }
         2214  +
  2161   2215     OpenCounter(+1);
  2162         -  return SQLITE_OK;
         2216  +  return rc;
  2163   2217   }
  2164   2218   
  2165   2219   /*
  2166   2220   ** Delete the named file.
  2167   2221   **
  2168   2222   ** Note that windows does not allow a file to be deleted if some other
  2169   2223   ** process has it open.  Sometimes a virus scanner or indexing program