/ Check-in [610425f1]
Login

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

Overview
Comment:Refine and reform all Windows OSTRACE macro usage. Replace all usage of sqlite3TestErrorName() with sqlite3ErrName() and add missing return codes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:610425f19008b8b5d4bf027c8b14d97ec3115a54
User & Date: mistachkin 2013-05-09 00:40:13
Context
2013-05-09
14:20
Do not move WHERE clause terms inside OR expressions that are contained within an ON clause of a LEFT JOIN. Fix for ticket [f2369304e47167e3e]. check-in: 1128575d user: drh tags: trunk
00:40
Refine and reform all Windows OSTRACE macro usage. Replace all usage of sqlite3TestErrorName() with sqlite3ErrName() and add missing return codes. check-in: 610425f1 user: mistachkin tags: trunk
2013-05-08
17:06
Fix a couple of harmless compiler warnings in the fts3_tokenize virtual table. check-in: 1fa8c457 user: drh tags: trunk
2013-04-30
07:58
Add the #ifdefs for sqlite3ErrName() to sqliteInt.h as well. Closed-Leaf check-in: 400fc4c3 user: mistachkin tags: winOsTrace
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  1025   1025   
  1026   1026     /* If one has been configured, invoke the rollback-hook callback */
  1027   1027     if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
  1028   1028       db->xRollbackCallback(db->pRollbackArg);
  1029   1029     }
  1030   1030   }
  1031   1031   
         1032  +/*
         1033  +** Return a static string containing the name corresponding to the error code
         1034  +** specified in the argument.
         1035  +*/
         1036  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
         1037  +    defined(SQLITE_DEBUG_OS_TRACE)
         1038  +const char *sqlite3ErrName(int rc){
         1039  +  const char *zName = 0;
         1040  +  int i, origRc = rc;
         1041  +  for(i=0; i<2 && zName==0; i++, rc &= 0xff){
         1042  +    switch( rc ){
         1043  +      case SQLITE_OK:                 zName = "SQLITE_OK";                break;
         1044  +      case SQLITE_ERROR:              zName = "SQLITE_ERROR";             break;
         1045  +      case SQLITE_INTERNAL:           zName = "SQLITE_INTERNAL";          break;
         1046  +      case SQLITE_PERM:               zName = "SQLITE_PERM";              break;
         1047  +      case SQLITE_ABORT:              zName = "SQLITE_ABORT";             break;
         1048  +      case SQLITE_ABORT_ROLLBACK:     zName = "SQLITE_ABORT_ROLLBACK";    break;
         1049  +      case SQLITE_BUSY:               zName = "SQLITE_BUSY";              break;
         1050  +      case SQLITE_BUSY_RECOVERY:      zName = "SQLITE_BUSY_RECOVERY";     break;
         1051  +      case SQLITE_LOCKED:             zName = "SQLITE_LOCKED";            break;
         1052  +      case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
         1053  +      case SQLITE_NOMEM:              zName = "SQLITE_NOMEM";             break;
         1054  +      case SQLITE_READONLY:           zName = "SQLITE_READONLY";          break;
         1055  +      case SQLITE_READONLY_RECOVERY:  zName = "SQLITE_READONLY_RECOVERY"; break;
         1056  +      case SQLITE_READONLY_CANTLOCK:  zName = "SQLITE_READONLY_CANTLOCK"; break;
         1057  +      case SQLITE_READONLY_ROLLBACK:  zName = "SQLITE_READONLY_ROLLBACK"; break;
         1058  +      case SQLITE_INTERRUPT:          zName = "SQLITE_INTERRUPT";         break;
         1059  +      case SQLITE_IOERR:              zName = "SQLITE_IOERR";             break;
         1060  +      case SQLITE_IOERR_READ:         zName = "SQLITE_IOERR_READ";        break;
         1061  +      case SQLITE_IOERR_SHORT_READ:   zName = "SQLITE_IOERR_SHORT_READ";  break;
         1062  +      case SQLITE_IOERR_WRITE:        zName = "SQLITE_IOERR_WRITE";       break;
         1063  +      case SQLITE_IOERR_FSYNC:        zName = "SQLITE_IOERR_FSYNC";       break;
         1064  +      case SQLITE_IOERR_DIR_FSYNC:    zName = "SQLITE_IOERR_DIR_FSYNC";   break;
         1065  +      case SQLITE_IOERR_TRUNCATE:     zName = "SQLITE_IOERR_TRUNCATE";    break;
         1066  +      case SQLITE_IOERR_FSTAT:        zName = "SQLITE_IOERR_FSTAT";       break;
         1067  +      case SQLITE_IOERR_UNLOCK:       zName = "SQLITE_IOERR_UNLOCK";      break;
         1068  +      case SQLITE_IOERR_RDLOCK:       zName = "SQLITE_IOERR_RDLOCK";      break;
         1069  +      case SQLITE_IOERR_DELETE:       zName = "SQLITE_IOERR_DELETE";      break;
         1070  +      case SQLITE_IOERR_BLOCKED:      zName = "SQLITE_IOERR_BLOCKED";     break;
         1071  +      case SQLITE_IOERR_NOMEM:        zName = "SQLITE_IOERR_NOMEM";       break;
         1072  +      case SQLITE_IOERR_ACCESS:       zName = "SQLITE_IOERR_ACCESS";      break;
         1073  +      case SQLITE_IOERR_CHECKRESERVEDLOCK:
         1074  +                                zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
         1075  +      case SQLITE_IOERR_LOCK:         zName = "SQLITE_IOERR_LOCK";        break;
         1076  +      case SQLITE_IOERR_CLOSE:        zName = "SQLITE_IOERR_CLOSE";       break;
         1077  +      case SQLITE_IOERR_DIR_CLOSE:    zName = "SQLITE_IOERR_DIR_CLOSE";   break;
         1078  +      case SQLITE_IOERR_SHMOPEN:      zName = "SQLITE_IOERR_SHMOPEN";     break;
         1079  +      case SQLITE_IOERR_SHMSIZE:      zName = "SQLITE_IOERR_SHMSIZE";     break;
         1080  +      case SQLITE_IOERR_SHMLOCK:      zName = "SQLITE_IOERR_SHMLOCK";     break;
         1081  +      case SQLITE_IOERR_SHMMAP:       zName = "SQLITE_IOERR_SHMMAP";      break;
         1082  +      case SQLITE_IOERR_SEEK:         zName = "SQLITE_IOERR_SEEK";        break;
         1083  +      case SQLITE_IOERR_DELETE_NOENT: zName = "SQLITE_IOERR_DELETE_NOENT";break;
         1084  +      case SQLITE_IOERR_MMAP:         zName = "SQLITE_IOERR_MMAP";        break;
         1085  +      case SQLITE_CORRUPT:            zName = "SQLITE_CORRUPT";           break;
         1086  +      case SQLITE_CORRUPT_VTAB:       zName = "SQLITE_CORRUPT_VTAB";      break;
         1087  +      case SQLITE_NOTFOUND:           zName = "SQLITE_NOTFOUND";          break;
         1088  +      case SQLITE_FULL:               zName = "SQLITE_FULL";              break;
         1089  +      case SQLITE_CANTOPEN:           zName = "SQLITE_CANTOPEN";          break;
         1090  +      case SQLITE_CANTOPEN_NOTEMPDIR: zName = "SQLITE_CANTOPEN_NOTEMPDIR";break;
         1091  +      case SQLITE_CANTOPEN_ISDIR:     zName = "SQLITE_CANTOPEN_ISDIR";    break;
         1092  +      case SQLITE_CANTOPEN_FULLPATH:  zName = "SQLITE_CANTOPEN_FULLPATH"; break;
         1093  +      case SQLITE_PROTOCOL:           zName = "SQLITE_PROTOCOL";          break;
         1094  +      case SQLITE_EMPTY:              zName = "SQLITE_EMPTY";             break;
         1095  +      case SQLITE_SCHEMA:             zName = "SQLITE_SCHEMA";            break;
         1096  +      case SQLITE_TOOBIG:             zName = "SQLITE_TOOBIG";            break;
         1097  +      case SQLITE_CONSTRAINT:         zName = "SQLITE_CONSTRAINT";        break;
         1098  +      case SQLITE_CONSTRAINT_UNIQUE:  zName = "SQLITE_CONSTRAINT_UNIQUE"; break;
         1099  +      case SQLITE_CONSTRAINT_TRIGGER: zName = "SQLITE_CONSTRAINT_TRIGGER";break;
         1100  +      case SQLITE_CONSTRAINT_FOREIGNKEY:
         1101  +                                zName = "SQLITE_CONSTRAINT_FOREIGNKEY";   break;
         1102  +      case SQLITE_CONSTRAINT_CHECK:   zName = "SQLITE_CONSTRAINT_CHECK";  break;
         1103  +      case SQLITE_CONSTRAINT_PRIMARYKEY:
         1104  +                                zName = "SQLITE_CONSTRAINT_PRIMARYKEY";   break;
         1105  +      case SQLITE_CONSTRAINT_NOTNULL: zName = "SQLITE_CONSTRAINT_NOTNULL";break;
         1106  +      case SQLITE_CONSTRAINT_COMMITHOOK:
         1107  +                                zName = "SQLITE_CONSTRAINT_COMMITHOOK";   break;
         1108  +      case SQLITE_CONSTRAINT_VTAB:    zName = "SQLITE_CONSTRAINT_VTAB";   break;
         1109  +      case SQLITE_CONSTRAINT_FUNCTION:
         1110  +                                zName = "SQLITE_CONSTRAINT_FUNCTION";     break;
         1111  +      case SQLITE_MISMATCH:           zName = "SQLITE_MISMATCH";          break;
         1112  +      case SQLITE_MISUSE:             zName = "SQLITE_MISUSE";            break;
         1113  +      case SQLITE_NOLFS:              zName = "SQLITE_NOLFS";             break;
         1114  +      case SQLITE_AUTH:               zName = "SQLITE_AUTH";              break;
         1115  +      case SQLITE_FORMAT:             zName = "SQLITE_FORMAT";            break;
         1116  +      case SQLITE_RANGE:              zName = "SQLITE_RANGE";             break;
         1117  +      case SQLITE_NOTADB:             zName = "SQLITE_NOTADB";            break;
         1118  +      case SQLITE_ROW:                zName = "SQLITE_ROW";               break;
         1119  +      case SQLITE_NOTICE:             zName = "SQLITE_NOTICE";            break;
         1120  +      case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
         1121  +      case SQLITE_NOTICE_RECOVER_ROLLBACK:
         1122  +                                zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
         1123  +      case SQLITE_WARNING:            zName = "SQLITE_WARNING";           break;
         1124  +      case SQLITE_DONE:               zName = "SQLITE_DONE";              break;
         1125  +    }
         1126  +  }
         1127  +  if( zName==0 ){
         1128  +    static char zBuf[50];
         1129  +    sqlite3_snprintf(sizeof(zBuf), zBuf, "SQLITE_UNKNOWN(%d)", origRc);
         1130  +    zName = zBuf;
         1131  +  }
         1132  +  return zName;
         1133  +}
         1134  +#endif
         1135  +
  1032   1136   /*
  1033   1137   ** Return a static string that describes the kind of error specified in the
  1034   1138   ** argument.
  1035   1139   */
  1036   1140   const char *sqlite3ErrStr(int rc){
  1037   1141     static const char* const aMsg[] = {
  1038   1142       /* SQLITE_OK          */ "not an error",

Changes to src/os_win.c.

  1519   1519         sqlite3EndBenignMalloc();
  1520   1520         /* free the system buffer allocated by FormatMessage */
  1521   1521         osLocalFree(zTemp);
  1522   1522       }
  1523   1523     }
  1524   1524   #endif
  1525   1525     if( 0 == dwLen ){
  1526         -    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno);
         1526  +    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno);
  1527   1527     }else{
  1528   1528       /* copy a maximum of nBuf chars to output buffer */
  1529   1529       sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
  1530   1530       /* free the UTF8 buffer */
  1531   1531       sqlite3_free(zOut);
  1532   1532     }
  1533   1533     return 0;
................................................................................
  1562   1562     zMsg[0] = 0;
  1563   1563     getLastErrorMsg(lastErrno, sizeof(zMsg), zMsg);
  1564   1564     assert( errcode!=SQLITE_OK );
  1565   1565     if( zPath==0 ) zPath = "";
  1566   1566     for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){}
  1567   1567     zMsg[i] = 0;
  1568   1568     sqlite3_log(errcode,
  1569         -      "os_win.c:%d: (%d) %s(%s) - %s",
         1569  +      "os_win.c:%d: (%lu) %s(%s) - %s",
  1570   1570         iLine, lastErrno, zFunc, zPath, zMsg
  1571   1571     );
  1572   1572   
  1573   1573     return errcode;
  1574   1574   }
  1575   1575   
  1576   1576   /*
................................................................................
  2023   2023   static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
  2024   2024   #if !SQLITE_OS_WINRT
  2025   2025     LONG upperBits;                 /* Most sig. 32 bits of new offset */
  2026   2026     LONG lowerBits;                 /* Least sig. 32 bits of new offset */
  2027   2027     DWORD dwRet;                    /* Value returned by SetFilePointer() */
  2028   2028     DWORD lastErrno;                /* Value returned by GetLastError() */
  2029   2029   
         2030  +  OSTRACE(("SEEK file=%p, offset=%lld\n", pFile->h, iOffset));
         2031  +
  2030   2032     upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
  2031   2033     lowerBits = (LONG)(iOffset & 0xffffffff);
  2032   2034   
  2033   2035     /* API oddity: If successful, SetFilePointer() returns a dword 
  2034   2036     ** containing the lower 32-bits of the new file-offset. Or, if it fails,
  2035   2037     ** it returns INVALID_SET_FILE_POINTER. However according to MSDN, 
  2036   2038     ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine 
................................................................................
  2040   2042     dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
  2041   2043   
  2042   2044     if( (dwRet==INVALID_SET_FILE_POINTER
  2043   2045         && ((lastErrno = osGetLastError())!=NO_ERROR)) ){
  2044   2046       pFile->lastErrno = lastErrno;
  2045   2047       winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
  2046   2048                "seekWinFile", pFile->zPath);
         2049  +    OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
  2047   2050       return 1;
  2048   2051     }
  2049   2052   
         2053  +  OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
  2050   2054     return 0;
  2051   2055   #else
  2052   2056     /*
  2053   2057     ** Same as above, except that this implementation works for WinRT.
  2054   2058     */
  2055   2059   
  2056   2060     LARGE_INTEGER x;                /* The new offset */
................................................................................
  2059   2063     x.QuadPart = iOffset;
  2060   2064     bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);
  2061   2065   
  2062   2066     if(!bRet){
  2063   2067       pFile->lastErrno = osGetLastError();
  2064   2068       winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
  2065   2069                "seekWinFile", pFile->zPath);
         2070  +    OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
  2066   2071       return 1;
  2067   2072     }
  2068   2073   
         2074  +  OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
  2069   2075     return 0;
  2070   2076   #endif
  2071   2077   }
  2072   2078   
  2073   2079   #if SQLITE_MAX_MMAP_SIZE>0
  2074   2080   /* Forward references to VFS methods */
  2075   2081   static int winUnmapfile(winFile*);
................................................................................
  2090   2096     int rc, cnt = 0;
  2091   2097     winFile *pFile = (winFile*)id;
  2092   2098   
  2093   2099     assert( id!=0 );
  2094   2100   #ifndef SQLITE_OMIT_WAL
  2095   2101     assert( pFile->pShm==0 );
  2096   2102   #endif
  2097         -  OSTRACE(("CLOSE %d\n", pFile->h));
  2098   2103     assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
         2104  +  OSTRACE(("CLOSE file=%p\n", pFile->h));
  2099   2105   
  2100   2106   #if SQLITE_MAX_MMAP_SIZE>0
  2101   2107     rc = winUnmapfile(pFile);
  2102   2108     if( rc!=SQLITE_OK ) return rc;
  2103   2109   #endif
  2104   2110   
  2105   2111     do{
................................................................................
  2117   2123           && cnt++ < WINCE_DELETION_ATTEMPTS
  2118   2124       ){
  2119   2125          sqlite3_win32_sleep(100);  /* Wait a little before trying again */
  2120   2126       }
  2121   2127       sqlite3_free(pFile->zDeleteOnClose);
  2122   2128     }
  2123   2129   #endif
  2124         -  OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
  2125   2130     if( rc ){
  2126   2131       pFile->h = NULL;
  2127   2132     }
  2128   2133     OpenCounter(-1);
         2134  +  OSTRACE(("CLOSE file=%p, rc=%s\n", pFile->h, rc ? "ok" : "failed"));
  2129   2135     return rc ? SQLITE_OK
  2130   2136               : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(),
  2131   2137                             "winClose", pFile->zPath);
  2132   2138   }
  2133   2139   
  2134   2140   /*
  2135   2141   ** Read data from a file into a buffer.  Return SQLITE_OK if all
................................................................................
  2148   2154     winFile *pFile = (winFile*)id;  /* file handle */
  2149   2155     DWORD nRead;                    /* Number of bytes actually read from file */
  2150   2156     int nRetry = 0;                 /* Number of retrys */
  2151   2157   
  2152   2158     assert( id!=0 );
  2153   2159     assert( amt>0 );
  2154   2160     SimulateIOError(return SQLITE_IOERR_READ);
  2155         -  OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype));
         2161  +  OSTRACE(("READ file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n",
         2162  +           pFile->h, pBuf, amt, offset, pFile->locktype));
  2156   2163   
  2157   2164   #if SQLITE_MAX_MMAP_SIZE>0
  2158   2165     /* Deal with as much of this read request as possible by transfering
  2159   2166     ** data from the memory mapping using memcpy().  */
  2160   2167     if( offset<pFile->mmapSize ){
  2161   2168       if( offset+amt <= pFile->mmapSize ){
  2162   2169         memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
         2170  +      OSTRACE(("READ-MMAP file=%p, rc=SQLITE_OK\n", pFile->h));
  2163   2171         return SQLITE_OK;
  2164   2172       }else{
  2165   2173         int nCopy = (int)(pFile->mmapSize - offset);
  2166   2174         memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
  2167   2175         pBuf = &((u8 *)pBuf)[nCopy];
  2168   2176         amt -= nCopy;
  2169   2177         offset += nCopy;
  2170   2178       }
  2171   2179     }
  2172   2180   #endif
  2173   2181   
  2174   2182   #if SQLITE_OS_WINCE
  2175   2183     if( seekWinFile(pFile, offset) ){
         2184  +    OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
  2176   2185       return SQLITE_FULL;
  2177   2186     }
  2178   2187     while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
  2179   2188   #else
  2180   2189     memset(&overlapped, 0, sizeof(OVERLAPPED));
  2181   2190     overlapped.Offset = (LONG)(offset & 0xffffffff);
  2182   2191     overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
  2183   2192     while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) &&
  2184   2193            osGetLastError()!=ERROR_HANDLE_EOF ){
  2185   2194   #endif
  2186   2195       DWORD lastErrno;
  2187   2196       if( retryIoerr(&nRetry, &lastErrno) ) continue;
  2188   2197       pFile->lastErrno = lastErrno;
         2198  +    OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h));
  2189   2199       return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
  2190   2200                "winRead", pFile->zPath);
  2191   2201     }
  2192   2202     logIoerr(nRetry);
  2193   2203     if( nRead<(DWORD)amt ){
  2194   2204       /* Unread parts of the buffer must be zero-filled */
  2195   2205       memset(&((char*)pBuf)[nRead], 0, amt-nRead);
         2206  +    OSTRACE(("READ file=%p, rc=SQLITE_IOERR_SHORT_READ\n", pFile->h));
  2196   2207       return SQLITE_IOERR_SHORT_READ;
  2197   2208     }
  2198   2209   
         2210  +  OSTRACE(("READ file=%p, rc=SQLITE_OK\n", pFile->h));
  2199   2211     return SQLITE_OK;
  2200   2212   }
  2201   2213   
  2202   2214   /*
  2203   2215   ** Write data from a buffer into a file.  Return SQLITE_OK on success
  2204   2216   ** or some other error code on failure.
  2205   2217   */
................................................................................
  2214   2226     int nRetry = 0;                 /* Number of retries */
  2215   2227   
  2216   2228     assert( amt>0 );
  2217   2229     assert( pFile );
  2218   2230     SimulateIOError(return SQLITE_IOERR_WRITE);
  2219   2231     SimulateDiskfullError(return SQLITE_FULL);
  2220   2232   
  2221         -  OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
         2233  +  OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n",
         2234  +           pFile->h, pBuf, amt, offset, pFile->locktype));
  2222   2235   
  2223   2236   #if SQLITE_MAX_MMAP_SIZE>0
  2224   2237     /* Deal with as much of this write request as possible by transfering
  2225   2238     ** data from the memory mapping using memcpy().  */
  2226   2239     if( offset<pFile->mmapSize ){
  2227   2240       if( offset+amt <= pFile->mmapSize ){
  2228   2241         memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
         2242  +      OSTRACE(("WRITE-MMAP file=%p, rc=SQLITE_OK\n", pFile->h));
  2229   2243         return SQLITE_OK;
  2230   2244       }else{
  2231   2245         int nCopy = (int)(pFile->mmapSize - offset);
  2232   2246         memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
  2233   2247         pBuf = &((u8 *)pBuf)[nCopy];
  2234   2248         amt -= nCopy;
  2235   2249         offset += nCopy;
................................................................................
  2284   2298         rc = 1;
  2285   2299       }
  2286   2300     }
  2287   2301   
  2288   2302     if( rc ){
  2289   2303       if(   ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
  2290   2304          || ( pFile->lastErrno==ERROR_DISK_FULL )){
         2305  +      OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h));
  2291   2306         return SQLITE_FULL;
  2292   2307       }
         2308  +    OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h));
  2293   2309       return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno,
  2294   2310                "winWrite", pFile->zPath);
  2295   2311     }else{
  2296   2312       logIoerr(nRetry);
  2297   2313     }
         2314  +  OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h));
  2298   2315     return SQLITE_OK;
  2299   2316   }
  2300   2317   
  2301   2318   /*
  2302   2319   ** Truncate an open file to a specified size
  2303   2320   */
  2304   2321   static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
  2305   2322     winFile *pFile = (winFile*)id;  /* File handle object */
  2306   2323     int rc = SQLITE_OK;             /* Return code for this function */
  2307   2324     DWORD lastErrno;
  2308   2325   
  2309   2326     assert( pFile );
  2310         -
  2311         -  OSTRACE(("TRUNCATE %d %lld\n", pFile->h, nByte));
  2312   2327     SimulateIOError(return SQLITE_IOERR_TRUNCATE);
         2328  +  OSTRACE(("TRUNCATE file=%p, size=%lld, lock=%d\n",
         2329  +           pFile->h, nByte, pFile->locktype));
  2313   2330   
  2314   2331     /* If the user has configured a chunk-size for this file, truncate the
  2315   2332     ** file so that it consists of an integer number of chunks (i.e. the
  2316   2333     ** actual file size after the operation may be larger than the requested
  2317   2334     ** size).
  2318   2335     */
  2319   2336     if( pFile->szChunk>0 ){
................................................................................
  2337   2354     ** use read() and write() to access data beyond this point from now on.
  2338   2355     */
  2339   2356     if( pFile->pMapRegion && nByte<pFile->mmapSize ){
  2340   2357       pFile->mmapSize = nByte;
  2341   2358     }
  2342   2359   #endif
  2343   2360   
  2344         -  OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok"));
         2361  +  OSTRACE(("TRUNCATE file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
  2345   2362     return rc;
  2346   2363   }
  2347   2364   
  2348   2365   #ifdef SQLITE_TEST
  2349   2366   /*
  2350   2367   ** Count the number of fullsyncs and normal syncs.  This is used to test
  2351   2368   ** that syncs and fullsyncs are occuring at the right times.
................................................................................
  2377   2394   
  2378   2395     assert( pFile );
  2379   2396     /* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */
  2380   2397     assert((flags&0x0F)==SQLITE_SYNC_NORMAL
  2381   2398         || (flags&0x0F)==SQLITE_SYNC_FULL
  2382   2399     );
  2383   2400   
  2384         -  OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype));
  2385         -
  2386   2401     /* Unix cannot, but some systems may return SQLITE_FULL from here. This
  2387   2402     ** line is to test that doing so does not cause any problems.
  2388   2403     */
  2389   2404     SimulateDiskfullError( return SQLITE_FULL );
         2405  +
         2406  +  OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n",
         2407  +           pFile->h, flags, pFile->locktype));
  2390   2408   
  2391   2409   #ifndef SQLITE_TEST
  2392   2410     UNUSED_PARAMETER(flags);
  2393   2411   #else
  2394   2412     if( (flags&0x0F)==SQLITE_SYNC_FULL ){
  2395   2413       sqlite3_fullsync_count++;
  2396   2414     }
................................................................................
  2402   2420     */
  2403   2421   #ifdef SQLITE_NO_SYNC
  2404   2422     return SQLITE_OK;
  2405   2423   #else
  2406   2424     rc = osFlushFileBuffers(pFile->h);
  2407   2425     SimulateIOError( rc=FALSE );
  2408   2426     if( rc ){
         2427  +    OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h));
  2409   2428       return SQLITE_OK;
  2410   2429     }else{
  2411   2430       pFile->lastErrno = osGetLastError();
         2431  +    OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h));
  2412   2432       return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
  2413   2433                "winSync", pFile->zPath);
  2414   2434     }
  2415   2435   #endif
  2416   2436   }
  2417   2437   
  2418   2438   /*
................................................................................
  2419   2439   ** Determine the current size of a file in bytes
  2420   2440   */
  2421   2441   static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
  2422   2442     winFile *pFile = (winFile*)id;
  2423   2443     int rc = SQLITE_OK;
  2424   2444   
  2425   2445     assert( id!=0 );
         2446  +  assert( pSize!=0 );
  2426   2447     SimulateIOError(return SQLITE_IOERR_FSTAT);
         2448  +  OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
         2449  +
  2427   2450   #if SQLITE_OS_WINRT
  2428   2451     {
  2429   2452       FILE_STANDARD_INFO info;
  2430   2453       if( osGetFileInformationByHandleEx(pFile->h, FileStandardInfo,
  2431   2454                                        &info, sizeof(info)) ){
  2432   2455         *pSize = info.EndOfFile.QuadPart;
  2433   2456       }else{
................................................................................
  2448   2471          && ((lastErrno = osGetLastError())!=NO_ERROR) ){
  2449   2472         pFile->lastErrno = lastErrno;
  2450   2473         rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
  2451   2474                "winFileSize", pFile->zPath);
  2452   2475       }
  2453   2476     }
  2454   2477   #endif
         2478  +  OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n",
         2479  +           pFile->h, pSize, *pSize, sqlite3ErrName(rc)));
  2455   2480     return rc;
  2456   2481   }
  2457   2482   
  2458   2483   /*
  2459   2484   ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
  2460   2485   */
  2461   2486   #ifndef LOCKFILE_FAIL_IMMEDIATELY
................................................................................
  2489   2514   /*
  2490   2515   ** Acquire a reader lock.
  2491   2516   ** Different API routines are called depending on whether or not this
  2492   2517   ** is Win9x or WinNT.
  2493   2518   */
  2494   2519   static int getReadLock(winFile *pFile){
  2495   2520     int res;
         2521  +  OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
  2496   2522     if( isNT() ){
  2497   2523   #if SQLITE_OS_WINCE
  2498   2524       /*
  2499   2525       ** NOTE: Windows CE is handled differently here due its lack of the Win32
  2500   2526       **       API LockFileEx.
  2501   2527       */
  2502   2528       res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
................................................................................
  2514   2540                         SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
  2515   2541     }
  2516   2542   #endif
  2517   2543     if( res == 0 ){
  2518   2544       pFile->lastErrno = osGetLastError();
  2519   2545       /* No need to log a failure to lock */
  2520   2546     }
         2547  +  OSTRACE(("READ-LOCK file=%p, rc=%s\n", pFile->h, sqlite3ErrName(res)));
  2521   2548     return res;
  2522   2549   }
  2523   2550   
  2524   2551   /*
  2525   2552   ** Undo a readlock
  2526   2553   */
  2527   2554   static int unlockReadLock(winFile *pFile){
  2528   2555     int res;
  2529   2556     DWORD lastErrno;
         2557  +  OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
  2530   2558     if( isNT() ){
  2531   2559       res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  2532   2560     }
  2533   2561   #ifdef SQLITE_WIN32_HAS_ANSI
  2534   2562     else{
  2535   2563       res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
  2536   2564     }
  2537   2565   #endif
  2538   2566     if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
  2539   2567       pFile->lastErrno = lastErrno;
  2540   2568       winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
  2541   2569                "unlockReadLock", pFile->zPath);
  2542   2570     }
         2571  +  OSTRACE(("READ-UNLOCK file=%p, rc=%s\n", pFile->h, sqlite3ErrName(res)));
  2543   2572     return res;
  2544   2573   }
  2545   2574   
  2546   2575   /*
  2547   2576   ** Lock the file with the lock specified by parameter locktype - one
  2548   2577   ** of the following:
  2549   2578   **
................................................................................
  2574   2603     int res = 1;           /* Result of a Windows lock call */
  2575   2604     int newLocktype;       /* Set pFile->locktype to this value before exiting */
  2576   2605     int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
  2577   2606     winFile *pFile = (winFile*)id;
  2578   2607     DWORD lastErrno = NO_ERROR;
  2579   2608   
  2580   2609     assert( id!=0 );
  2581         -  OSTRACE(("LOCK %d %d was %d(%d)\n",
  2582         -           pFile->h, locktype, pFile->locktype, pFile->sharedLockByte));
         2610  +  OSTRACE(("LOCK file=%p, oldLock=%d(%d), newLock=%d\n",
         2611  +           pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
  2583   2612   
  2584   2613     /* If there is already a lock of this type or more restrictive on the
  2585   2614     ** OsFile, do nothing. Don't use the end_lock: exit path, as
  2586   2615     ** sqlite3OsEnterMutex() hasn't been called yet.
  2587   2616     */
  2588   2617     if( pFile->locktype>=locktype ){
         2618  +    OSTRACE(("LOCK-HELD file=%p, rc=SQLITE_OK\n", pFile->h));
  2589   2619       return SQLITE_OK;
  2590   2620     }
  2591   2621   
  2592   2622     /* Make sure the locking sequence is correct
  2593   2623     */
  2594   2624     assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
  2595   2625     assert( locktype!=PENDING_LOCK );
................................................................................
  2609   2639                                            PENDING_BYTE, 0, 1, 0))==0 ){
  2610   2640         /* Try 3 times to get the pending lock.  This is needed to work
  2611   2641         ** around problems caused by indexing and/or anti-virus software on
  2612   2642         ** Windows systems.
  2613   2643         ** If you are using this code as a model for alternative VFSes, do not
  2614   2644         ** copy this retry logic.  It is a hack intended for Windows only.
  2615   2645         */
  2616         -      OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt));
         2646  +      OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, rc=%s\n",
         2647  +               pFile->h, cnt, sqlite3ErrName(res)));
  2617   2648         if( cnt ) sqlite3_win32_sleep(1);
  2618   2649       }
  2619   2650       gotPendingLock = res;
  2620   2651       if( !res ){
  2621   2652         lastErrno = osGetLastError();
  2622   2653       }
  2623   2654     }
................................................................................
  2654   2685     }
  2655   2686   
  2656   2687     /* Acquire an EXCLUSIVE lock
  2657   2688     */
  2658   2689     if( locktype==EXCLUSIVE_LOCK && res ){
  2659   2690       assert( pFile->locktype>=SHARED_LOCK );
  2660   2691       res = unlockReadLock(pFile);
  2661         -    OSTRACE(("unreadlock = %d\n", res));
  2662   2692       res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
  2663   2693                         SHARED_SIZE, 0);
  2664   2694       if( res ){
  2665   2695         newLocktype = EXCLUSIVE_LOCK;
  2666   2696       }else{
  2667   2697         lastErrno = osGetLastError();
  2668         -      OSTRACE(("error-code = %d\n", lastErrno));
  2669   2698         getReadLock(pFile);
  2670   2699       }
  2671   2700     }
  2672   2701   
  2673   2702     /* If we are holding a PENDING lock that ought to be released, then
  2674   2703     ** release it now.
  2675   2704     */
................................................................................
  2679   2708   
  2680   2709     /* Update the state of the lock has held in the file descriptor then
  2681   2710     ** return the appropriate result code.
  2682   2711     */
  2683   2712     if( res ){
  2684   2713       rc = SQLITE_OK;
  2685   2714     }else{
  2686         -    OSTRACE(("LOCK FAILED %d trying for %d but got %d\n", pFile->h,
  2687         -           locktype, newLocktype));
         2715  +    OSTRACE(("LOCK-FAIL file=%p, wanted=%d, got=%d\n",
         2716  +             pFile->h, locktype, newLocktype));
  2688   2717       pFile->lastErrno = lastErrno;
  2689   2718       rc = SQLITE_BUSY;
  2690   2719     }
  2691   2720     pFile->locktype = (u8)newLocktype;
         2721  +  OSTRACE(("LOCK file=%p, lock=%d, rc=%s\n",
         2722  +           pFile->h, pFile->locktype, sqlite3ErrName(rc)));
  2692   2723     return rc;
  2693   2724   }
  2694   2725   
  2695   2726   /*
  2696   2727   ** This routine checks if there is a RESERVED lock held on the specified
  2697   2728   ** file by this or any other process. If such a lock is held, return
  2698   2729   ** non-zero, otherwise zero.
  2699   2730   */
  2700   2731   static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
  2701   2732     int rc;
  2702   2733     winFile *pFile = (winFile*)id;
  2703   2734   
  2704   2735     SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
         2736  +  OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
  2705   2737   
  2706   2738     assert( id!=0 );
  2707   2739     if( pFile->locktype>=RESERVED_LOCK ){
  2708   2740       rc = 1;
  2709         -    OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
         2741  +    OSTRACE(("TEST-WR-LOCK file=%p, rc=%d (local)\n", pFile->h, rc));
  2710   2742     }else{
  2711   2743       rc = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0);
  2712   2744       if( rc ){
  2713   2745         winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
  2714   2746       }
  2715   2747       rc = !rc;
  2716         -    OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
         2748  +    OSTRACE(("TEST-WR-LOCK file=%p, rc=%d (remote)\n", pFile->h, rc));
  2717   2749     }
  2718   2750     *pResOut = rc;
         2751  +  OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
         2752  +           pFile->h, pResOut, *pResOut));
  2719   2753     return SQLITE_OK;
  2720   2754   }
  2721   2755   
  2722   2756   /*
  2723   2757   ** Lower the locking level on file descriptor id to locktype.  locktype
  2724   2758   ** must be either NO_LOCK or SHARED_LOCK.
  2725   2759   **
................................................................................
  2732   2766   */
  2733   2767   static int winUnlock(sqlite3_file *id, int locktype){
  2734   2768     int type;
  2735   2769     winFile *pFile = (winFile*)id;
  2736   2770     int rc = SQLITE_OK;
  2737   2771     assert( pFile!=0 );
  2738   2772     assert( locktype<=SHARED_LOCK );
  2739         -  OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
  2740         -          pFile->locktype, pFile->sharedLockByte));
         2773  +  OSTRACE(("UNLOCK file=%p, oldLock=%d(%d), newLock=%d\n",
         2774  +           pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
  2741   2775     type = pFile->locktype;
  2742   2776     if( type>=EXCLUSIVE_LOCK ){
  2743   2777       winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  2744   2778       if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
  2745   2779         /* This should never happen.  We should always be able to
  2746   2780         ** reacquire the read lock */
  2747   2781         rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(),
................................................................................
  2754   2788     if( locktype==NO_LOCK && type>=SHARED_LOCK ){
  2755   2789       unlockReadLock(pFile);
  2756   2790     }
  2757   2791     if( type>=PENDING_LOCK ){
  2758   2792       winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
  2759   2793     }
  2760   2794     pFile->locktype = (u8)locktype;
         2795  +  OSTRACE(("UNLOCK file=%p, lock=%d, rc=%s\n",
         2796  +           pFile->h, pFile->locktype, sqlite3ErrName(rc)));
  2761   2797     return rc;
  2762   2798   }
  2763   2799   
  2764   2800   /*
  2765   2801   ** If *pArg is inititially negative then this is a query.  Set *pArg to
  2766   2802   ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
  2767   2803   **
................................................................................
  2781   2817   static int getTempname(int nBuf, char *zBuf);
  2782   2818   
  2783   2819   /*
  2784   2820   ** Control and query of the open file handle.
  2785   2821   */
  2786   2822   static int winFileControl(sqlite3_file *id, int op, void *pArg){
  2787   2823     winFile *pFile = (winFile*)id;
         2824  +  OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg));
  2788   2825     switch( op ){
  2789   2826       case SQLITE_FCNTL_LOCKSTATE: {
  2790   2827         *(int*)pArg = pFile->locktype;
         2828  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2791   2829         return SQLITE_OK;
  2792   2830       }
  2793   2831       case SQLITE_LAST_ERRNO: {
  2794   2832         *(int*)pArg = (int)pFile->lastErrno;
         2833  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2795   2834         return SQLITE_OK;
  2796   2835       }
  2797   2836       case SQLITE_FCNTL_CHUNK_SIZE: {
  2798   2837         pFile->szChunk = *(int *)pArg;
         2838  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2799   2839         return SQLITE_OK;
  2800   2840       }
  2801   2841       case SQLITE_FCNTL_SIZE_HINT: {
  2802   2842         if( pFile->szChunk>0 ){
  2803   2843           sqlite3_int64 oldSz;
  2804   2844           int rc = winFileSize(id, &oldSz);
  2805   2845           if( rc==SQLITE_OK ){
................................................................................
  2806   2846             sqlite3_int64 newSz = *(sqlite3_int64*)pArg;
  2807   2847             if( newSz>oldSz ){
  2808   2848               SimulateIOErrorBenign(1);
  2809   2849               rc = winTruncate(id, newSz);
  2810   2850               SimulateIOErrorBenign(0);
  2811   2851             }
  2812   2852           }
         2853  +        OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
  2813   2854           return rc;
  2814   2855         }
         2856  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2815   2857         return SQLITE_OK;
  2816   2858       }
  2817   2859       case SQLITE_FCNTL_PERSIST_WAL: {
  2818   2860         winModeBit(pFile, WINFILE_PERSIST_WAL, (int*)pArg);
         2861  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2819   2862         return SQLITE_OK;
  2820   2863       }
  2821   2864       case SQLITE_FCNTL_POWERSAFE_OVERWRITE: {
  2822   2865         winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
         2866  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2823   2867         return SQLITE_OK;
  2824   2868       }
  2825   2869       case SQLITE_FCNTL_VFSNAME: {
  2826   2870         *(char**)pArg = sqlite3_mprintf("win32");
         2871  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2827   2872         return SQLITE_OK;
  2828   2873       }
  2829   2874       case SQLITE_FCNTL_WIN32_AV_RETRY: {
  2830   2875         int *a = (int*)pArg;
  2831   2876         if( a[0]>0 ){
  2832   2877           win32IoerrRetry = a[0];
  2833   2878         }else{
................................................................................
  2834   2879           a[0] = win32IoerrRetry;
  2835   2880         }
  2836   2881         if( a[1]>0 ){
  2837   2882           win32IoerrRetryDelay = a[1];
  2838   2883         }else{
  2839   2884           a[1] = win32IoerrRetryDelay;
  2840   2885         }
         2886  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2841   2887         return SQLITE_OK;
  2842   2888       }
  2843   2889       case SQLITE_FCNTL_TEMPFILENAME: {
  2844   2890         char *zTFile = sqlite3MallocZero( pFile->pVfs->mxPathname );
  2845   2891         if( zTFile ){
  2846   2892           getTempname(pFile->pVfs->mxPathname, zTFile);
  2847   2893           *(char**)pArg = zTFile;
  2848   2894         }
         2895  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2849   2896         return SQLITE_OK;
  2850   2897       }
  2851   2898   #if SQLITE_MAX_MMAP_SIZE>0
  2852   2899       case SQLITE_FCNTL_MMAP_SIZE: {
  2853   2900         i64 newLimit = *(i64*)pArg;
  2854   2901         if( newLimit>sqlite3GlobalConfig.mxMmap ){
  2855   2902           newLimit = sqlite3GlobalConfig.mxMmap;
  2856   2903         }
  2857   2904         *(i64*)pArg = pFile->mmapSizeMax;
  2858   2905         if( newLimit>=0 ) pFile->mmapSizeMax = newLimit;
         2906  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  2859   2907         return SQLITE_OK;
  2860   2908       }
  2861   2909   #endif
  2862   2910     }
         2911  +  OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
  2863   2912     return SQLITE_NOTFOUND;
  2864   2913   }
  2865   2914   
  2866   2915   /*
  2867   2916   ** Return the sector size in bytes of the underlying block device for
  2868   2917   ** the specified file. This is almost always 512 bytes, but may be
  2869   2918   ** larger for some devices.
................................................................................
  3016   3065     int nByte             /* Number of bytes to lock or unlock */
  3017   3066   ){
  3018   3067     int rc = 0;           /* Result code form Lock/UnlockFileEx() */
  3019   3068   
  3020   3069     /* Access to the winShmNode object is serialized by the caller */
  3021   3070     assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
  3022   3071   
         3072  +  OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n",
         3073  +           pFile->hFile.h, lockType, ofst, nByte));
         3074  +
  3023   3075     /* Release/Acquire the system-level lock */
  3024   3076     if( lockType==_SHM_UNLCK ){
  3025   3077       rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
  3026   3078     }else{
  3027   3079       /* Initialize the locking parameters */
  3028   3080       DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
  3029   3081       if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
................................................................................
  3033   3085     if( rc!= 0 ){
  3034   3086       rc = SQLITE_OK;
  3035   3087     }else{
  3036   3088       pFile->lastErrno =  osGetLastError();
  3037   3089       rc = SQLITE_BUSY;
  3038   3090     }
  3039   3091   
  3040         -  OSTRACE(("SHM-LOCK %d %s %s 0x%08lx\n", 
  3041         -           pFile->hFile.h,
  3042         -           rc==SQLITE_OK ? "ok" : "failed",
  3043         -           lockType==_SHM_UNLCK ? "UnlockFileEx" : "LockFileEx",
  3044         -           pFile->lastErrno));
         3092  +  OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n",
         3093  +           pFile->hFile.h, (lockType == _SHM_UNLCK) ? "winUnlockFile" :
         3094  +           "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
  3045   3095   
  3046   3096     return rc;
  3047   3097   }
  3048   3098   
  3049   3099   /* Forward references to VFS methods */
  3050   3100   static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
  3051   3101   static int winDelete(sqlite3_vfs *,const char*,int);
................................................................................
  3057   3107   ** by VFS shared-memory methods.
  3058   3108   */
  3059   3109   static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
  3060   3110     winShmNode **pp;
  3061   3111     winShmNode *p;
  3062   3112     BOOL bRc;
  3063   3113     assert( winShmMutexHeld() );
         3114  +  OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
         3115  +           osGetCurrentProcessId(), deleteFlag));
  3064   3116     pp = &winShmNodeList;
  3065   3117     while( (p = *pp)!=0 ){
  3066   3118       if( p->nRef==0 ){
  3067   3119         int i;
  3068   3120         if( p->mutex ) sqlite3_mutex_free(p->mutex);
  3069   3121         for(i=0; i<p->nRegion; i++){
  3070   3122           bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
  3071         -        OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n",
  3072         -                 (int)osGetCurrentProcessId(), i,
  3073         -                 bRc ? "ok" : "failed"));
         3123  +        OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
         3124  +                 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
  3074   3125           bRc = osCloseHandle(p->aRegion[i].hMap);
  3075         -        OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n",
  3076         -                 (int)osGetCurrentProcessId(), i,
  3077         -                 bRc ? "ok" : "failed"));
         3126  +        OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
         3127  +                 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
  3078   3128         }
  3079   3129         if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
  3080   3130           SimulateIOErrorBenign(1);
  3081   3131           winClose((sqlite3_file *)&p->hFile);
  3082   3132           SimulateIOErrorBenign(0);
  3083   3133         }
  3084   3134         if( deleteFlag ){
................................................................................
  3349   3399         if( rc==SQLITE_OK ){
  3350   3400           assert( (p->sharedMask & mask)==0 );
  3351   3401           p->exclMask |= mask;
  3352   3402         }
  3353   3403       }
  3354   3404     }
  3355   3405     sqlite3_mutex_leave(pShmNode->mutex);
  3356         -  OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x %s\n",
  3357         -           p->id, (int)osGetCurrentProcessId(), p->sharedMask, p->exclMask,
  3358         -           rc ? "failed" : "ok"));
         3406  +  OSTRACE(("SHM-LOCK pid=%lu, id=%d, sharedMask=%03x, exclMask=%03x, rc=%s\n",
         3407  +           osGetCurrentProcessId(), p->id, p->sharedMask, p->exclMask,
         3408  +           sqlite3ErrName(rc)));
  3359   3409     return rc;
  3360   3410   }
  3361   3411   
  3362   3412   /*
  3363   3413   ** Implement a memory barrier or memory fence on shared memory.  
  3364   3414   **
  3365   3415   ** All loads and stores begun before the barrier must complete before
................................................................................
  3472   3522             NULL, PAGE_READWRITE, 0, nByte, NULL
  3473   3523         );
  3474   3524   #elif defined(SQLITE_WIN32_HAS_ANSI)
  3475   3525         hMap = osCreateFileMappingA(pShmNode->hFile.h, 
  3476   3526             NULL, PAGE_READWRITE, 0, nByte, NULL
  3477   3527         );
  3478   3528   #endif
  3479         -      OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
  3480         -               (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
         3529  +      OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
         3530  +               osGetCurrentProcessId(), pShmNode->nRegion, nByte,
  3481   3531                  hMap ? "ok" : "failed"));
  3482   3532         if( hMap ){
  3483   3533           int iOffset = pShmNode->nRegion*szRegion;
  3484   3534           int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
  3485   3535   #if SQLITE_OS_WINRT
  3486   3536           pMap = osMapViewOfFileFromApp(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
  3487   3537               iOffset - iOffsetShift, szRegion + iOffsetShift
  3488   3538           );
  3489   3539   #else
  3490   3540           pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
  3491   3541               0, iOffset - iOffsetShift, szRegion + iOffsetShift
  3492   3542           );
  3493   3543   #endif
  3494         -        OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
  3495         -                 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
         3544  +        OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n",
         3545  +                 osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
  3496   3546                    szRegion, pMap ? "ok" : "failed"));
  3497   3547         }
  3498   3548         if( !pMap ){
  3499   3549           pShmNode->lastErrno = osGetLastError();
  3500   3550           rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno,
  3501   3551                    "winShmMap3", pDbFd->zPath);
  3502   3552           if( hMap ) osCloseHandle(hMap);
................................................................................
  3531   3581   
  3532   3582   /*
  3533   3583   ** Cleans up the mapped region of the specified file, if any.
  3534   3584   */
  3535   3585   #if SQLITE_MAX_MMAP_SIZE>0
  3536   3586   static int winUnmapfile(winFile *pFile){
  3537   3587     assert( pFile!=0 );
         3588  +  OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, hMap=%p, pMapRegion=%p, "
         3589  +           "mmapSize=%lld, mmapSizeActual=%lld, mmapSizeMax=%lld\n",
         3590  +           osGetCurrentProcessId(), pFile, pFile->hMap, pFile->pMapRegion,
         3591  +           pFile->mmapSize, pFile->mmapSizeActual, pFile->mmapSizeMax));
  3538   3592     if( pFile->pMapRegion ){
  3539   3593       if( !osUnmapViewOfFile(pFile->pMapRegion) ){
  3540   3594         pFile->lastErrno = osGetLastError();
         3595  +      OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, pMapRegion=%p, "
         3596  +               "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), pFile,
         3597  +               pFile->pMapRegion));
  3541   3598         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
  3542   3599                            "winUnmap1", pFile->zPath);
  3543   3600       }
  3544   3601       pFile->pMapRegion = 0;
  3545   3602       pFile->mmapSize = 0;
  3546   3603       pFile->mmapSizeActual = 0;
  3547   3604     }
  3548   3605     if( pFile->hMap!=NULL ){
  3549   3606       if( !osCloseHandle(pFile->hMap) ){
  3550   3607         pFile->lastErrno = osGetLastError();
         3608  +      OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, hMap=%p, rc=SQLITE_IOERR_MMAP\n",
         3609  +               osGetCurrentProcessId(), pFile, pFile->hMap));
  3551   3610         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
  3552   3611                            "winUnmap2", pFile->zPath);
  3553   3612       }
  3554   3613       pFile->hMap = NULL;
  3555   3614     }
         3615  +  OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, rc=SQLITE_OK\n",
         3616  +           osGetCurrentProcessId(), pFile));
  3556   3617     return SQLITE_OK;
  3557   3618   }
  3558   3619   
  3559   3620   /*
  3560   3621   ** Memory map or remap the file opened by file-descriptor pFd (if the file
  3561   3622   ** is already mapped, the existing mapping is replaced by the new). Or, if 
  3562   3623   ** there already exists a mapping for this file, and there are still 
................................................................................
  3573   3634   ** code otherwise.
  3574   3635   */
  3575   3636   static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
  3576   3637     sqlite3_int64 nMap = nByte;
  3577   3638     int rc;
  3578   3639   
  3579   3640     assert( nMap>=0 || pFd->nFetchOut==0 );
         3641  +  OSTRACE(("MAP-FILE pid=%lu, pFile=%p, size=%lld\n",
         3642  +           osGetCurrentProcessId(), pFd, nByte));
         3643  +
  3580   3644     if( pFd->nFetchOut>0 ) return SQLITE_OK;
  3581   3645   
  3582   3646     if( nMap<0 ){
  3583   3647       rc = winFileSize((sqlite3_file*)pFd, &nMap);
  3584   3648       if( rc ){
         3649  +      OSTRACE(("MAP-FILE pid=%lu, pFile=%p, rc=SQLITE_IOERR_FSTAT\n",
         3650  +               osGetCurrentProcessId(), pFd));
  3585   3651         return SQLITE_IOERR_FSTAT;
  3586   3652       }
  3587   3653     }
  3588   3654     if( nMap>pFd->mmapSizeMax ){
  3589   3655       nMap = pFd->mmapSizeMax;
  3590   3656     }
  3591   3657     nMap &= ~(sqlite3_int64)(winSysInfo.dwPageSize - 1);
................................................................................
  3615   3681                                   (DWORD)(nMap & 0xffffffff), NULL);
  3616   3682   #endif
  3617   3683       if( pFd->hMap==NULL ){
  3618   3684         pFd->lastErrno = osGetLastError();
  3619   3685         rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
  3620   3686                          "winMapfile", pFd->zPath);
  3621   3687         /* Log the error, but continue normal operation using xRead/xWrite */
         3688  +      OSTRACE(("MAP-FILE-CREATE pid=%lu, pFile=%p, rc=SQLITE_IOERR_MMAP\n",
         3689  +               osGetCurrentProcessId(), pFd));
  3622   3690         return SQLITE_OK;
  3623   3691       }
  3624   3692       assert( (nMap % winSysInfo.dwPageSize)==0 );
  3625   3693   #if SQLITE_OS_WINRT
  3626   3694       pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, nMap);
  3627   3695   #else
  3628   3696       assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
................................................................................
  3630   3698   #endif
  3631   3699       if( pNew==NULL ){
  3632   3700         osCloseHandle(pFd->hMap);
  3633   3701         pFd->hMap = NULL;
  3634   3702         pFd->lastErrno = osGetLastError();
  3635   3703         winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
  3636   3704                     "winMapfile", pFd->zPath);
         3705  +      OSTRACE(("MAP-FILE-MAP pid=%lu, pFile=%p, rc=SQLITE_IOERR_MMAP\n",
         3706  +               osGetCurrentProcessId(), pFd));
  3637   3707         return SQLITE_OK;
  3638   3708       }
  3639   3709       pFd->pMapRegion = pNew;
  3640   3710       pFd->mmapSize = nMap;
  3641   3711       pFd->mmapSizeActual = nMap;
  3642   3712     }
  3643   3713   
         3714  +  OSTRACE(("MAP-FILE pid=%lu, pFile=%p, rc=SQLITE_OK\n",
         3715  +           osGetCurrentProcessId(), pFd));
  3644   3716     return SQLITE_OK;
  3645   3717   }
  3646   3718   #endif /* SQLITE_MAX_MMAP_SIZE>0 */
  3647   3719   
  3648   3720   /*
  3649   3721   ** If possible, return a pointer to a mapping of file fd starting at offset
  3650   3722   ** iOff. The mapping must be valid for at least nAmt bytes.
................................................................................
  3651   3723   **
  3652   3724   ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
  3653   3725   ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
  3654   3726   ** Finally, if an error does occur, return an SQLite error code. The final
  3655   3727   ** value of *pp is undefined in this case.
  3656   3728   **
  3657   3729   ** If this function does return a pointer, the caller must eventually 
  3658         -** release the reference by calling unixUnfetch().
         3730  +** release the reference by calling winUnfetch().
  3659   3731   */
  3660   3732   static int winFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){
  3661   3733   #if SQLITE_MAX_MMAP_SIZE>0
  3662   3734     winFile *pFd = (winFile*)fd;   /* The underlying database file */
  3663   3735   #endif
  3664   3736     *pp = 0;
  3665   3737   
         3738  +  OSTRACE(("FETCH pid=%lu, pFile=%p, offset=%lld, amount=%d, pp=%p\n",
         3739  +           osGetCurrentProcessId(), fd, iOff, nAmt, pp));
         3740  +
  3666   3741   #if SQLITE_MAX_MMAP_SIZE>0
  3667   3742     if( pFd->mmapSizeMax>0 ){
  3668   3743       if( pFd->pMapRegion==0 ){
  3669   3744         int rc = winMapfile(pFd, -1);
  3670         -      if( rc!=SQLITE_OK ) return rc;
         3745  +      if( rc!=SQLITE_OK ){
         3746  +        OSTRACE(("FETCH pid=%lu, pFile=%p, rc=%s\n",
         3747  +                 osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
         3748  +        return rc;
         3749  +      }
  3671   3750       }
  3672   3751       if( pFd->mmapSize >= iOff+nAmt ){
  3673   3752         *pp = &((u8 *)pFd->pMapRegion)[iOff];
  3674   3753         pFd->nFetchOut++;
  3675   3754       }
  3676   3755     }
  3677   3756   #endif
         3757  +
         3758  +  OSTRACE(("FETCH pid=%lu, pFile=%p, pp=%p, *pp=%p, rc=SQLITE_OK\n",
         3759  +           osGetCurrentProcessId(), fd, pp, *pp));
  3678   3760     return SQLITE_OK;
  3679   3761   }
  3680   3762   
  3681   3763   /*
  3682   3764   ** If the third argument is non-NULL, then this function releases a 
  3683         -** reference obtained by an earlier call to unixFetch(). The second
         3765  +** reference obtained by an earlier call to winFetch(). The second
  3684   3766   ** argument passed to this function must be the same as the corresponding
  3685         -** argument that was passed to the unixFetch() invocation. 
         3767  +** argument that was passed to the winFetch() invocation. 
  3686   3768   **
  3687   3769   ** Or, if the third argument is NULL, then this function is being called 
  3688   3770   ** to inform the VFS layer that, according to POSIX, any existing mapping 
  3689   3771   ** may now be invalid and should be unmapped.
  3690   3772   */
  3691   3773   static int winUnfetch(sqlite3_file *fd, i64 iOff, void *p){
  3692   3774   #if SQLITE_MAX_MMAP_SIZE>0
................................................................................
  3696   3778     ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
  3697   3779     ** then there must be at least one outstanding.  */
  3698   3780     assert( (p==0)==(pFd->nFetchOut==0) );
  3699   3781   
  3700   3782     /* If p!=0, it must match the iOff value. */
  3701   3783     assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] );
  3702   3784   
         3785  +  OSTRACE(("UNFETCH pid=%lu, pFile=%p, offset=%lld, p=%p\n",
         3786  +           osGetCurrentProcessId(), pFd, iOff, p));
         3787  +
  3703   3788     if( p ){
  3704   3789       pFd->nFetchOut--;
  3705   3790     }else{
  3706   3791       /* FIXME:  If Windows truly always prevents truncating or deleting a
  3707   3792       ** file while a mapping is held, then the following winUnmapfile() call
  3708   3793       ** is unnecessary can can be omitted - potentially improving
  3709   3794       ** performance.  */
  3710   3795       winUnmapfile(pFd);
  3711   3796     }
  3712   3797   
  3713   3798     assert( pFd->nFetchOut>=0 );
  3714   3799   #endif
         3800  +
         3801  +  OSTRACE(("UNFETCH pid=%lu, pFile=%p, rc=SQLITE_OK\n",
         3802  +           osGetCurrentProcessId(), fd));
  3715   3803     return SQLITE_OK;
  3716   3804   }
  3717   3805   
  3718   3806   /*
  3719   3807   ** Here ends the implementation of all sqlite3_file methods.
  3720   3808   **
  3721   3809   ********************** End sqlite3_file Methods *******************************
................................................................................
  3804   3892       WCHAR zWidePath[MAX_PATH];
  3805   3893       osGetTempPathW(MAX_PATH-30, zWidePath);
  3806   3894       zMulti = unicodeToUtf8(zWidePath);
  3807   3895       if( zMulti ){
  3808   3896         sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
  3809   3897         sqlite3_free(zMulti);
  3810   3898       }else{
         3899  +      OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  3811   3900         return SQLITE_IOERR_NOMEM;
  3812   3901       }
  3813   3902     }
  3814   3903   #ifdef SQLITE_WIN32_HAS_ANSI
  3815   3904     else{
  3816   3905       char *zUtf8;
  3817   3906       char zMbcsPath[MAX_PATH];
  3818   3907       osGetTempPathA(MAX_PATH-30, zMbcsPath);
  3819   3908       zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
  3820   3909       if( zUtf8 ){
  3821   3910         sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
  3822   3911         sqlite3_free(zUtf8);
  3823   3912       }else{
         3913  +      OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  3824   3914         return SQLITE_IOERR_NOMEM;
  3825   3915       }
  3826   3916     }
  3827   3917   #endif
  3828   3918   #endif
  3829   3919   
  3830   3920     /* Check that the output buffer is large enough for the temporary file 
  3831   3921     ** name. If it is not, return SQLITE_ERROR.
  3832   3922     */
  3833   3923     nTempPath = sqlite3Strlen30(zTempPath);
  3834   3924   
  3835   3925     if( (nTempPath + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
         3926  +    OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
  3836   3927       return SQLITE_ERROR;
  3837   3928     }
  3838   3929   
  3839   3930     for(i=nTempPath; i>0 && zTempPath[i-1]=='\\'; i--){}
  3840   3931     zTempPath[i] = 0;
  3841   3932   
  3842   3933     sqlite3_snprintf(nBuf-18, zBuf, (nTempPath > 0) ?
................................................................................
  3846   3937     sqlite3_randomness(15, &zBuf[j]);
  3847   3938     for(i=0; i<15; i++, j++){
  3848   3939       zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
  3849   3940     }
  3850   3941     zBuf[j] = 0;
  3851   3942     zBuf[j+1] = 0;
  3852   3943   
  3853         -  OSTRACE(("TEMP FILENAME: %s\n", zBuf));
  3854         -  return SQLITE_OK; 
         3944  +  OSTRACE(("TEMP-FILENAME name=%s, rc=SQLITE_OK\n", zBuf));
         3945  +  return SQLITE_OK;
  3855   3946   }
  3856   3947   
  3857   3948   /*
  3858   3949   ** Return TRUE if the named file is really a directory.  Return false if
  3859   3950   ** it is something other than a directory, or if there is any kind of memory
  3860   3951   ** allocation failure.
  3861   3952   */
................................................................................
  3926   4017   #ifndef NDEBUG
  3927   4018     int isOpenJournal = (isCreate && (
  3928   4019           eType==SQLITE_OPEN_MASTER_JOURNAL 
  3929   4020        || eType==SQLITE_OPEN_MAIN_JOURNAL 
  3930   4021        || eType==SQLITE_OPEN_WAL
  3931   4022     ));
  3932   4023   #endif
         4024  +
         4025  +  OSTRACE(("OPEN name=%s, pFile=%p, flags=%x, pOutFlags=%p\n",
         4026  +           zUtf8Name, id, flags, pOutFlags));
  3933   4027   
  3934   4028     /* Check the following statements are true: 
  3935   4029     **
  3936   4030     **   (a) Exactly one of the READWRITE and READONLY flags must be set, and 
  3937   4031     **   (b) if CREATE is set, then READWRITE must also be set, and
  3938   4032     **   (c) if EXCLUSIVE is set, then CREATE must also be set.
  3939   4033     **   (d) if DELETEONCLOSE is set, then CREATE must also be set.
................................................................................
  3972   4066     ** temporary file name to use 
  3973   4067     */
  3974   4068     if( !zUtf8Name ){
  3975   4069       assert(isDelete && !isOpenJournal);
  3976   4070       memset(zTmpname, 0, MAX_PATH+2);
  3977   4071       rc = getTempname(MAX_PATH+2, zTmpname);
  3978   4072       if( rc!=SQLITE_OK ){
         4073  +      OSTRACE(("OPEN name=%s, rc=%s", zUtf8Name, sqlite3ErrName(rc)));
  3979   4074         return rc;
  3980   4075       }
  3981   4076       zUtf8Name = zTmpname;
  3982   4077     }
  3983   4078   
  3984   4079     /* Database filenames are double-zero terminated if they are not
  3985   4080     ** URIs with parameters.  Hence, they can always be passed into
................................................................................
  3987   4082     */
  3988   4083     assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) ||
  3989   4084           zUtf8Name[strlen(zUtf8Name)+1]==0 );
  3990   4085   
  3991   4086     /* Convert the filename to the system encoding. */
  3992   4087     zConverted = convertUtf8Filename(zUtf8Name);
  3993   4088     if( zConverted==0 ){
         4089  +    OSTRACE(("OPEN name=%s, rc=SQLITE_IOERR_NOMEM", zUtf8Name));
  3994   4090       return SQLITE_IOERR_NOMEM;
  3995   4091     }
  3996   4092   
  3997   4093     if( winIsDir(zConverted) ){
  3998   4094       sqlite3_free(zConverted);
         4095  +    OSTRACE(("OPEN name=%s, rc=SQLITE_CANTOPEN_ISDIR", zUtf8Name));
  3999   4096       return SQLITE_CANTOPEN_ISDIR;
  4000   4097     }
  4001   4098   
  4002   4099     if( isReadWrite ){
  4003   4100       dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
  4004   4101     }else{
  4005   4102       dwDesiredAccess = GENERIC_READ;
................................................................................
  4082   4179                                 retryIoerr(&cnt, &lastErrno) ){
  4083   4180                  /* Noop */
  4084   4181       }
  4085   4182     }
  4086   4183   #endif
  4087   4184     logIoerr(cnt);
  4088   4185   
  4089         -  OSTRACE(("OPEN %d %s 0x%lx %s\n", 
  4090         -           h, zName, dwDesiredAccess, 
  4091         -           h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
         4186  +  OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name,
         4187  +           dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
  4092   4188   
  4093   4189     if( h==INVALID_HANDLE_VALUE ){
  4094   4190       pFile->lastErrno = lastErrno;
  4095   4191       winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name);
  4096   4192       sqlite3_free(zConverted);
  4097   4193       if( isReadWrite && !isExclusive ){
  4098   4194         return winOpen(pVfs, zName, id, 
................................................................................
  4108   4204       if( isReadWrite ){
  4109   4205         *pOutFlags = SQLITE_OPEN_READWRITE;
  4110   4206       }else{
  4111   4207         *pOutFlags = SQLITE_OPEN_READONLY;
  4112   4208       }
  4113   4209     }
  4114   4210   
         4211  +  OSTRACE(("OPEN file=%p, name=%s, access=%lx, pOutFlags=%p, *pOutFlags=%d, "
         4212  +           "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ?
         4213  +           *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
         4214  +
  4115   4215   #if SQLITE_OS_WINCE
  4116   4216     if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
  4117   4217          && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
  4118   4218     ){
  4119   4219       osCloseHandle(h);
  4120   4220       sqlite3_free(zConverted);
         4221  +    OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc)));
  4121   4222       return rc;
  4122   4223     }
  4123   4224     if( isTemp ){
  4124   4225       pFile->zDeleteOnClose = zConverted;
  4125   4226     }else
  4126   4227   #endif
  4127   4228     {
................................................................................
  4173   4274     DWORD attr;
  4174   4275     DWORD lastErrno;
  4175   4276     void *zConverted;
  4176   4277     UNUSED_PARAMETER(pVfs);
  4177   4278     UNUSED_PARAMETER(syncDir);
  4178   4279   
  4179   4280     SimulateIOError(return SQLITE_IOERR_DELETE);
         4281  +  OSTRACE(("DELETE name=%s, syncDir=%d\n", zFilename, syncDir));
         4282  +
  4180   4283     zConverted = convertUtf8Filename(zFilename);
  4181   4284     if( zConverted==0 ){
  4182   4285       return SQLITE_IOERR_NOMEM;
  4183   4286     }
  4184   4287     if( isNT() ){
  4185   4288       do {
  4186   4289   #if SQLITE_OS_WINRT
................................................................................
  4258   4361     if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){
  4259   4362       rc = winLogError(SQLITE_IOERR_DELETE, lastErrno,
  4260   4363                "winDelete", zFilename);
  4261   4364     }else{
  4262   4365       logIoerr(cnt);
  4263   4366     }
  4264   4367     sqlite3_free(zConverted);
  4265         -  OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" )));
         4368  +  OSTRACE(("DELETE name=%s, rc=%s\n", zFilename, sqlite3ErrName(rc)));
  4266   4369     return rc;
  4267   4370   }
  4268   4371   
  4269   4372   /*
  4270   4373   ** Check the existence and status of a file.
  4271   4374   */
  4272   4375   static int winAccess(
................................................................................
  4278   4381     DWORD attr;
  4279   4382     int rc = 0;
  4280   4383     DWORD lastErrno;
  4281   4384     void *zConverted;
  4282   4385     UNUSED_PARAMETER(pVfs);
  4283   4386   
  4284   4387     SimulateIOError( return SQLITE_IOERR_ACCESS; );
         4388  +  OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
         4389  +           zFilename, flags, pResOut));
         4390  +
  4285   4391     zConverted = convertUtf8Filename(zFilename);
  4286   4392     if( zConverted==0 ){
         4393  +    OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
  4287   4394       return SQLITE_IOERR_NOMEM;
  4288   4395     }
  4289   4396     if( isNT() ){
  4290   4397       int cnt = 0;
  4291   4398       WIN32_FILE_ATTRIBUTE_DATA sAttrData;
  4292   4399       memset(&sAttrData, 0, sizeof(sAttrData));
  4293   4400       while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
................................................................................
  4330   4437         rc = attr!=INVALID_FILE_ATTRIBUTES &&
  4331   4438                (attr & FILE_ATTRIBUTE_READONLY)==0;
  4332   4439         break;
  4333   4440       default:
  4334   4441         assert(!"Invalid flags argument");
  4335   4442     }
  4336   4443     *pResOut = rc;
         4444  +  OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
         4445  +           zFilename, pResOut, *pResOut));
  4337   4446     return SQLITE_OK;
  4338   4447   }
  4339   4448   
  4340   4449   
  4341   4450   /*
  4342   4451   ** Returns non-zero if the specified path name should be used verbatim.  If
  4343   4452   ** non-zero is returned from this function, the calling function must simply

Changes to src/sqliteInt.h.

  3088   3088   int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
  3089   3089   char sqlite3ExprAffinity(Expr *pExpr);
  3090   3090   int sqlite3Atoi64(const char*, i64*, int, u8);
  3091   3091   void sqlite3Error(sqlite3*, int, const char*,...);
  3092   3092   void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
  3093   3093   u8 sqlite3HexToInt(int h);
  3094   3094   int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
         3095  +
         3096  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
         3097  +    defined(SQLITE_DEBUG_OS_TRACE)
         3098  +const char *sqlite3ErrName(int);
         3099  +#endif
         3100  +
  3095   3101   const char *sqlite3ErrStr(int);
  3096   3102   int sqlite3ReadSchema(Parse *pParse);
  3097   3103   CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
  3098   3104   CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
  3099   3105   CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
  3100   3106   Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, Token*);
  3101   3107   Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);

Changes to src/test1.c.

   109    109       *ppDb = p->db;
   110    110     }else{
   111    111       *ppDb = (sqlite3*)sqlite3TestTextToPtr(zA);
   112    112     }
   113    113     return TCL_OK;
   114    114   }
   115    115   
   116         -
   117         -const char *sqlite3TestErrorName(int rc){
   118         -  const char *zName = 0;
   119         -  int i;
   120         -  for(i=0; i<2 && zName==0; i++, rc &= 0xff){
   121         -    switch( rc ){
   122         -      case SQLITE_OK:                  zName = "SQLITE_OK";                break;
   123         -      case SQLITE_ERROR:               zName = "SQLITE_ERROR";             break;
   124         -      case SQLITE_INTERNAL:            zName = "SQLITE_INTERNAL";          break;
   125         -      case SQLITE_PERM:                zName = "SQLITE_PERM";              break;
   126         -      case SQLITE_ABORT:               zName = "SQLITE_ABORT";             break;
   127         -      case SQLITE_BUSY:                zName = "SQLITE_BUSY";              break;
   128         -      case SQLITE_LOCKED:              zName = "SQLITE_LOCKED";            break;
   129         -      case SQLITE_LOCKED_SHAREDCACHE:  zName = "SQLITE_LOCKED_SHAREDCACHE";break;
   130         -      case SQLITE_NOMEM:               zName = "SQLITE_NOMEM";             break;
   131         -      case SQLITE_READONLY:            zName = "SQLITE_READONLY";          break;
   132         -      case SQLITE_INTERRUPT:           zName = "SQLITE_INTERRUPT";         break;
   133         -      case SQLITE_IOERR:               zName = "SQLITE_IOERR";             break;
   134         -      case SQLITE_CORRUPT:             zName = "SQLITE_CORRUPT";           break;
   135         -      case SQLITE_NOTFOUND:            zName = "SQLITE_NOTFOUND";          break;
   136         -      case SQLITE_FULL:                zName = "SQLITE_FULL";              break;
   137         -      case SQLITE_CANTOPEN:            zName = "SQLITE_CANTOPEN";          break;
   138         -      case SQLITE_PROTOCOL:            zName = "SQLITE_PROTOCOL";          break;
   139         -      case SQLITE_EMPTY:               zName = "SQLITE_EMPTY";             break;
   140         -      case SQLITE_SCHEMA:              zName = "SQLITE_SCHEMA";            break;
   141         -      case SQLITE_TOOBIG:              zName = "SQLITE_TOOBIG";            break;
   142         -      case SQLITE_CONSTRAINT:          zName = "SQLITE_CONSTRAINT";        break;
   143         -      case SQLITE_CONSTRAINT_UNIQUE:   zName = "SQLITE_CONSTRAINT_UNIQUE"; break;
   144         -      case SQLITE_CONSTRAINT_TRIGGER:  zName = "SQLITE_CONSTRAINT_TRIGGER";break;
   145         -      case SQLITE_CONSTRAINT_FOREIGNKEY:
   146         -                                   zName = "SQLITE_CONSTRAINT_FOREIGNKEY"; break;
   147         -      case SQLITE_CONSTRAINT_CHECK:    zName = "SQLITE_CONSTRAINT_CHECK";  break;
   148         -      case SQLITE_CONSTRAINT_PRIMARYKEY:
   149         -                                   zName = "SQLITE_CONSTRAINT_PRIMARYKEY"; break;
   150         -      case SQLITE_CONSTRAINT_NOTNULL:  zName = "SQLITE_CONSTRAINT_NOTNULL";break;
   151         -      case SQLITE_CONSTRAINT_COMMITHOOK:
   152         -                                   zName = "SQLITE_CONSTRAINT_COMMITHOOK"; break;
   153         -      case SQLITE_CONSTRAINT_VTAB:     zName = "SQLITE_CONSTRAINT_VTAB";   break;
   154         -      case SQLITE_CONSTRAINT_FUNCTION: zName = "SQLITE_CONSTRAINT_FUNCTION";break;
   155         -      case SQLITE_MISMATCH:            zName = "SQLITE_MISMATCH";          break;
   156         -      case SQLITE_MISUSE:              zName = "SQLITE_MISUSE";            break;
   157         -      case SQLITE_NOLFS:               zName = "SQLITE_NOLFS";             break;
   158         -      case SQLITE_AUTH:                zName = "SQLITE_AUTH";              break;
   159         -      case SQLITE_FORMAT:              zName = "SQLITE_FORMAT";            break;
   160         -      case SQLITE_RANGE:               zName = "SQLITE_RANGE";             break;
   161         -      case SQLITE_NOTADB:              zName = "SQLITE_NOTADB";            break;
   162         -      case SQLITE_ROW:                 zName = "SQLITE_ROW";               break;
   163         -      case SQLITE_NOTICE:              zName = "SQLITE_NOTICE";            break;
   164         -      case SQLITE_WARNING:             zName = "SQLITE_WARNING";           break;
   165         -      case SQLITE_DONE:                zName = "SQLITE_DONE";              break;
   166         -      case SQLITE_IOERR_READ:          zName = "SQLITE_IOERR_READ";        break;
   167         -      case SQLITE_IOERR_SHORT_READ:    zName = "SQLITE_IOERR_SHORT_READ";  break;
   168         -      case SQLITE_IOERR_WRITE:         zName = "SQLITE_IOERR_WRITE";       break;
   169         -      case SQLITE_IOERR_FSYNC:         zName = "SQLITE_IOERR_FSYNC";       break;
   170         -      case SQLITE_IOERR_DIR_FSYNC:     zName = "SQLITE_IOERR_DIR_FSYNC";   break;
   171         -      case SQLITE_IOERR_TRUNCATE:      zName = "SQLITE_IOERR_TRUNCATE";    break;
   172         -      case SQLITE_IOERR_FSTAT:         zName = "SQLITE_IOERR_FSTAT";       break;
   173         -      case SQLITE_IOERR_UNLOCK:        zName = "SQLITE_IOERR_UNLOCK";      break;
   174         -      case SQLITE_IOERR_RDLOCK:        zName = "SQLITE_IOERR_RDLOCK";      break;
   175         -      case SQLITE_IOERR_DELETE:        zName = "SQLITE_IOERR_DELETE";      break;
   176         -      case SQLITE_IOERR_BLOCKED:       zName = "SQLITE_IOERR_BLOCKED";     break;
   177         -      case SQLITE_IOERR_NOMEM:         zName = "SQLITE_IOERR_NOMEM";       break;
   178         -      case SQLITE_IOERR_ACCESS:        zName = "SQLITE_IOERR_ACCESS";      break;
   179         -      case SQLITE_IOERR_CHECKRESERVEDLOCK:
   180         -                                 zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
   181         -      case SQLITE_IOERR_LOCK:          zName = "SQLITE_IOERR_LOCK";        break;
   182         -      case SQLITE_CORRUPT_VTAB:        zName = "SQLITE_CORRUPT_VTAB";      break;
   183         -      case SQLITE_READONLY_RECOVERY:   zName = "SQLITE_READONLY_RECOVERY"; break;
   184         -      case SQLITE_READONLY_CANTLOCK:   zName = "SQLITE_READONLY_CANTLOCK"; break;
   185         -      case SQLITE_READONLY_ROLLBACK:   zName = "SQLITE_READONLY_ROLLBACK"; break;
   186         -    }
   187         -  }
   188         -  if( zName==0 ) zName = "SQLITE_Unknown";
   189         -  return zName;
   190         -}
   191         -#define t1ErrorName sqlite3TestErrorName
          116  +extern const char *sqlite3ErrName(int);
          117  +#define t1ErrorName sqlite3ErrName
   192    118   
   193    119   /*
   194    120   ** Convert an sqlite3_stmt* into an sqlite3*.  This depends on the
   195    121   ** fact that the sqlite3* is the first field in the Vdbe structure.
   196    122   */
   197    123   #define StmtToDb(X)   sqlite3_db_handle(X)
   198    124   
................................................................................
  1729   1655     if( nByte>0 ){
  1730   1656       zBuf = (unsigned char *)Tcl_Alloc(nByte);
  1731   1657     }
  1732   1658     rc = sqlite3_blob_read(pBlob, zBuf, nByte, iOffset);
  1733   1659     if( rc==SQLITE_OK ){
  1734   1660       Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zBuf, nByte));
  1735   1661     }else{
  1736         -    Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1662  +    Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1737   1663     }
  1738   1664     Tcl_Free((char *)zBuf);
  1739   1665   
  1740   1666     return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);
  1741   1667   }
  1742   1668   
  1743   1669   /*
................................................................................
  1779   1705   
  1780   1706     zBuf = Tcl_GetByteArrayFromObj(objv[3], &nBuf);
  1781   1707     if( objc==5 && Tcl_GetIntFromObj(interp, objv[4], &nBuf) ){
  1782   1708       return TCL_ERROR;
  1783   1709     }
  1784   1710     rc = sqlite3_blob_write(pBlob, zBuf, nBuf, iOffset);
  1785   1711     if( rc!=SQLITE_OK ){
  1786         -    Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1712  +    Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1787   1713     }
  1788   1714   
  1789   1715     return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);
  1790   1716   }
  1791   1717   
  1792   1718   static int test_blob_reopen(
  1793   1719     ClientData clientData, /* Not used */
................................................................................
  1805   1731     }
  1806   1732   
  1807   1733     if( blobHandleFromObj(interp, objv[1], &pBlob) ) return TCL_ERROR;
  1808   1734     if( Tcl_GetWideIntFromObj(interp, objv[2], &iRowid) ) return TCL_ERROR;
  1809   1735   
  1810   1736     rc = sqlite3_blob_reopen(pBlob, iRowid);
  1811   1737     if( rc!=SQLITE_OK ){
  1812         -    Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1738  +    Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1813   1739     }
  1814   1740   
  1815   1741     return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);
  1816   1742   }
  1817   1743   
  1818   1744   #endif
  1819   1745   
................................................................................
  2015   1941         (p->pFunc ? cf2Func : 0),
  2016   1942         (p->pStep ? cf2Step : 0),
  2017   1943         (p->pFinal ? cf2Final : 0),
  2018   1944         cf2Destroy
  2019   1945     );
  2020   1946     if( rc!=SQLITE_OK ){
  2021   1947       Tcl_ResetResult(interp);
  2022         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
         1948  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
  2023   1949       return TCL_ERROR;
  2024   1950     }
  2025   1951     return TCL_OK;
  2026   1952   }
  2027   1953   
  2028   1954   /*
  2029   1955   ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC?
................................................................................
  2691   2617       }
  2692   2618       sqlite3ValueFree(pVal);
  2693   2619       sqlite3_mutex_leave(db->mutex);
  2694   2620     }
  2695   2621     if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
  2696   2622     
  2697   2623     if( rc!=SQLITE_OK ){
  2698         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
         2624  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
  2699   2625       return TCL_ERROR;
  2700   2626     }
  2701   2627     return TCL_OK;
  2702   2628   
  2703   2629   bad_args:
  2704   2630     Tcl_AppendResult(interp, "wrong # args: should be \"",
  2705   2631         Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
................................................................................
  3249   3175     if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
  3250   3176     value = (char*)Tcl_GetByteArrayFromObj(objv[3], &bytes);
  3251   3177     if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
  3252   3178   
  3253   3179     rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
  3254   3180     if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  3255   3181     if( rc!=SQLITE_OK ){
  3256         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
         3182  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
  3257   3183       return TCL_ERROR;
  3258   3184     }
  3259   3185   
  3260   3186     return TCL_OK;
  3261   3187   }
  3262   3188   
  3263   3189   /*
................................................................................
  3297   3223     if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR;
  3298   3224     value = (char*)Tcl_GetByteArrayFromObj(oString, 0);
  3299   3225     if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR;
  3300   3226   
  3301   3227     rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel);
  3302   3228     if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  3303   3229     if( rc!=SQLITE_OK ){
  3304         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
         3230  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
  3305   3231       return TCL_ERROR;
  3306   3232     }
  3307   3233   
  3308   3234   #endif /* SQLITE_OMIT_UTF16 */
  3309   3235     return TCL_OK;
  3310   3236   }
  3311   3237   
................................................................................
  4571   4497       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 
  4572   4498           " DB", 0);
  4573   4499       return TCL_ERROR;
  4574   4500     }
  4575   4501     if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
  4576   4502     if( Tcl_GetInt(interp, argv[2], &ms) ) return TCL_ERROR;
  4577   4503     rc = sqlite3_busy_timeout(db, ms);
  4578         -  Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
         4504  +  Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
  4579   4505     return TCL_OK;
  4580   4506   }
  4581   4507   
  4582   4508   /*
  4583   4509   ** Usage:  tcl_variable_type VARIABLENAME
  4584   4510   **
  4585   4511   ** Return the name of the internal representation for the
................................................................................
  5092   5018      return TCL_ERROR;
  5093   5019     }
  5094   5020     zDb = Tcl_GetString(objv[2]);
  5095   5021     if( zDb[0]=='\0' ) zDb = NULL;
  5096   5022   
  5097   5023     rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_CHUNK_SIZE, (void *)&nSize);
  5098   5024     if( rc ){
  5099         -    Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         5025  +    Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  5100   5026       return TCL_ERROR;
  5101   5027     }
  5102   5028     return TCL_OK;
  5103   5029   }
  5104   5030   
  5105   5031   /*
  5106   5032   ** tclcmd:   file_control_sizehint_test DB DBNAME SIZE
................................................................................
  5129   5055      return TCL_ERROR;
  5130   5056     }
  5131   5057     zDb = Tcl_GetString(objv[2]);
  5132   5058     if( zDb[0]=='\0' ) zDb = NULL;
  5133   5059   
  5134   5060     rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_SIZE_HINT, (void *)&nSize);
  5135   5061     if( rc ){
  5136         -    Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         5062  +    Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  5137   5063       return TCL_ERROR;
  5138   5064     }
  5139   5065     return TCL_OK;
  5140   5066   }
  5141   5067   
  5142   5068   /*
  5143   5069   ** tclcmd:   file_control_lockproxy_test DB PWD
................................................................................
  5673   5599     Tcl_Interp *pInterp;
  5674   5600     Tcl_Obj *pObj;
  5675   5601   } logcallback = {0, 0};
  5676   5602   static void xLogcallback(void *unused, int err, char *zMsg){
  5677   5603     Tcl_Obj *pNew = Tcl_DuplicateObj(logcallback.pObj);
  5678   5604     Tcl_IncrRefCount(pNew);
  5679   5605     Tcl_ListObjAppendElement(
  5680         -      0, pNew, Tcl_NewStringObj(sqlite3TestErrorName(err), -1)
         5606  +      0, pNew, Tcl_NewStringObj(sqlite3ErrName(err), -1)
  5681   5607     );
  5682   5608     Tcl_ListObjAppendElement(0, pNew, Tcl_NewStringObj(zMsg, -1));
  5683   5609     Tcl_EvalObjEx(logcallback.pInterp, pNew, TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT);
  5684   5610     Tcl_DecrRefCount(pNew);
  5685   5611   }
  5686   5612   static int test_sqlite3_log(
  5687   5613     ClientData clientData,

Changes to src/test2.c.

    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include "tcl.h"
    18     18   #include <stdlib.h>
    19     19   #include <string.h>
    20     20   #include <ctype.h>
    21     21   
    22         -extern const char *sqlite3TestErrorName(int rc);
           22  +extern const char *sqlite3ErrName(int);
    23     23   
    24     24   /*
    25     25   ** Page size and reserved size used for testing.
    26     26   */
    27     27   static int test_pagesize = 1024;
    28     28   
    29     29   /*
................................................................................
    55     55       return TCL_ERROR;
    56     56     }
    57     57     if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
    58     58     rc = sqlite3PagerOpen(sqlite3_vfs_find(0), &pPager, argv[1], 0, 0,
    59     59         SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB,
    60     60         pager_test_reiniter);
    61     61     if( rc!=SQLITE_OK ){
    62         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
           62  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
    63     63       return TCL_ERROR;
    64     64     }
    65     65     sqlite3PagerSetCachesize(pPager, nPage);
    66     66     pageSize = test_pagesize;
    67     67     sqlite3PagerSetPagesize(pPager, &pageSize, -1);
    68     68     sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager);
    69     69     Tcl_AppendResult(interp, zBuf, 0);
................................................................................
    87     87       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    88     88          " ID\"", 0);
    89     89       return TCL_ERROR;
    90     90     }
    91     91     pPager = sqlite3TestTextToPtr(argv[1]);
    92     92     rc = sqlite3PagerClose(pPager);
    93     93     if( rc!=SQLITE_OK ){
    94         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
           94  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
    95     95       return TCL_ERROR;
    96     96     }
    97     97     return TCL_OK;
    98     98   }
    99     99   
   100    100   /*
   101    101   ** Usage:   pager_rollback ID
................................................................................
   114    114       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   115    115          " ID\"", 0);
   116    116       return TCL_ERROR;
   117    117     }
   118    118     pPager = sqlite3TestTextToPtr(argv[1]);
   119    119     rc = sqlite3PagerRollback(pPager);
   120    120     if( rc!=SQLITE_OK ){
   121         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          121  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   122    122       return TCL_ERROR;
   123    123     }
   124    124     return TCL_OK;
   125    125   }
   126    126   
   127    127   /*
   128    128   ** Usage:   pager_commit ID
................................................................................
   141    141       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   142    142          " ID\"", 0);
   143    143       return TCL_ERROR;
   144    144     }
   145    145     pPager = sqlite3TestTextToPtr(argv[1]);
   146    146     rc = sqlite3PagerCommitPhaseOne(pPager, 0, 0);
   147    147     if( rc!=SQLITE_OK ){
   148         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          148  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   149    149       return TCL_ERROR;
   150    150     }
   151    151     rc = sqlite3PagerCommitPhaseTwo(pPager);
   152    152     if( rc!=SQLITE_OK ){
   153         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          153  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   154    154       return TCL_ERROR;
   155    155     }
   156    156     return TCL_OK;
   157    157   }
   158    158   
   159    159   /*
   160    160   ** Usage:   pager_stmt_begin ID
................................................................................
   173    173       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   174    174          " ID\"", 0);
   175    175       return TCL_ERROR;
   176    176     }
   177    177     pPager = sqlite3TestTextToPtr(argv[1]);
   178    178     rc = sqlite3PagerOpenSavepoint(pPager, 1);
   179    179     if( rc!=SQLITE_OK ){
   180         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          180  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   181    181       return TCL_ERROR;
   182    182     }
   183    183     return TCL_OK;
   184    184   }
   185    185   
   186    186   /*
   187    187   ** Usage:   pager_stmt_rollback ID
................................................................................
   201    201          " ID\"", 0);
   202    202       return TCL_ERROR;
   203    203     }
   204    204     pPager = sqlite3TestTextToPtr(argv[1]);
   205    205     rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, 0);
   206    206     sqlite3PagerSavepoint(pPager, SAVEPOINT_RELEASE, 0);
   207    207     if( rc!=SQLITE_OK ){
   208         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          208  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   209    209       return TCL_ERROR;
   210    210     }
   211    211     return TCL_OK;
   212    212   }
   213    213   
   214    214   /*
   215    215   ** Usage:   pager_stmt_commit ID
................................................................................
   228    228       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   229    229          " ID\"", 0);
   230    230       return TCL_ERROR;
   231    231     }
   232    232     pPager = sqlite3TestTextToPtr(argv[1]);
   233    233     rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_RELEASE, 0);
   234    234     if( rc!=SQLITE_OK ){
   235         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          235  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   236    236       return TCL_ERROR;
   237    237     }
   238    238     return TCL_OK;
   239    239   }
   240    240   
   241    241   /*
   242    242   ** Usage:   pager_stats ID
................................................................................
   321    321     pPager = sqlite3TestTextToPtr(argv[1]);
   322    322     if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
   323    323     rc = sqlite3PagerSharedLock(pPager);
   324    324     if( rc==SQLITE_OK ){
   325    325       rc = sqlite3PagerGet(pPager, pgno, &pPage);
   326    326     }
   327    327     if( rc!=SQLITE_OK ){
   328         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          328  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   329    329       return TCL_ERROR;
   330    330     }
   331    331     sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage);
   332    332     Tcl_AppendResult(interp, zBuf, 0);
   333    333     return TCL_OK;
   334    334   }
   335    335   
................................................................................
   475    475       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   476    476          " PAGE DATA\"", 0);
   477    477       return TCL_ERROR;
   478    478     }
   479    479     pPage = (DbPage *)sqlite3TestTextToPtr(argv[1]);
   480    480     rc = sqlite3PagerWrite(pPage);
   481    481     if( rc!=SQLITE_OK ){
   482         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          482  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   483    483       return TCL_ERROR;
   484    484     }
   485    485     pData = sqlite3PagerGetData(pPage);
   486    486     strncpy(pData, argv[2], test_pagesize-1);
   487    487     pData[test_pagesize-1] = 0;
   488    488     return TCL_OK;
   489    489   }
................................................................................
   524    524     if( zFile==0 ) return TCL_ERROR;
   525    525     memcpy(zFile, argv[2], nFile+1);
   526    526     zFile[nFile+1] = 0;
   527    527     rc = sqlite3OsOpenMalloc(pVfs, zFile, &fd, 
   528    528         (SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB), 0
   529    529     );
   530    530     if( rc ){
   531         -    Tcl_AppendResult(interp, "open failed: ", sqlite3TestErrorName(rc), 0);
          531  +    Tcl_AppendResult(interp, "open failed: ", sqlite3ErrName(rc), 0);
   532    532       sqlite3_free(zFile);
   533    533       return TCL_ERROR;
   534    534     }
   535    535     offset = n;
   536    536     offset *= 1024*1024;
   537    537     rc = sqlite3OsWrite(fd, "Hello, World!", 14, offset);
   538    538     sqlite3OsCloseFree(fd);
   539    539     sqlite3_free(zFile);
   540    540     if( rc ){
   541         -    Tcl_AppendResult(interp, "write failed: ", sqlite3TestErrorName(rc), 0);
          541  +    Tcl_AppendResult(interp, "write failed: ", sqlite3ErrName(rc), 0);
   542    542       return TCL_ERROR;
   543    543     }
   544    544     return TCL_OK;
   545    545   }
   546    546   #endif
   547    547   
   548    548   

Changes to src/test3.c.

    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include "btreeInt.h"
    18     18   #include "tcl.h"
    19     19   #include <stdlib.h>
    20     20   #include <string.h>
    21     21   
    22         -extern const char *sqlite3TestErrorName(int rc);
           22  +extern const char *sqlite3ErrName(int);
    23     23   
    24     24   /*
    25     25   ** A bogus sqlite3 connection structure for use in the btree
    26     26   ** tests.
    27     27   */
    28     28   static sqlite3 sDb;
    29     29   static int nRefSqlite3 = 0;
................................................................................
    61     61     if( zFilename==0 ) return TCL_ERROR;
    62     62     memcpy(zFilename, argv[1], n+1);
    63     63     zFilename[n+1] = 0;
    64     64     rc = sqlite3BtreeOpen(sDb.pVfs, zFilename, &sDb, &pBt, 0, 
    65     65        SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB);
    66     66     sqlite3_free(zFilename);
    67     67     if( rc!=SQLITE_OK ){
    68         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
           68  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
    69     69       return TCL_ERROR;
    70     70     }
    71     71     sqlite3BtreeSetCacheSize(pBt, nCache);
    72     72     sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pBt);
    73     73     Tcl_AppendResult(interp, zBuf, 0);
    74     74     return TCL_OK;
    75     75   }
................................................................................
    91     91       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    92     92          " ID\"", 0);
    93     93       return TCL_ERROR;
    94     94     }
    95     95     pBt = sqlite3TestTextToPtr(argv[1]);
    96     96     rc = sqlite3BtreeClose(pBt);
    97     97     if( rc!=SQLITE_OK ){
    98         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
           98  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
    99     99       return TCL_ERROR;
   100    100     }
   101    101     nRefSqlite3--;
   102    102     if( nRefSqlite3==0 ){
   103    103       sqlite3_mutex_leave(sDb.mutex);
   104    104       sqlite3_mutex_free(sDb.mutex);
   105    105       sDb.mutex = 0;
................................................................................
   128    128       return TCL_ERROR;
   129    129     }
   130    130     pBt = sqlite3TestTextToPtr(argv[1]);
   131    131     sqlite3BtreeEnter(pBt);
   132    132     rc = sqlite3BtreeBeginTrans(pBt, 1);
   133    133     sqlite3BtreeLeave(pBt);
   134    134     if( rc!=SQLITE_OK ){
   135         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          135  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   136    136       return TCL_ERROR;
   137    137     }
   138    138     return TCL_OK;
   139    139   }
   140    140   
   141    141   /*
   142    142   ** Usage:   btree_pager_stats ID
................................................................................
   222    222   #endif
   223    223     if( rc==SQLITE_OK ){
   224    224       rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, pCur);
   225    225     }
   226    226     sqlite3BtreeLeave(pBt);
   227    227     if( rc ){
   228    228       ckfree((char *)pCur);
   229         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          229  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   230    230       return TCL_ERROR;
   231    231     }
   232    232     sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur);
   233    233     Tcl_AppendResult(interp, zBuf, 0);
   234    234     return SQLITE_OK;
   235    235   }
   236    236   
................................................................................
   257    257     pCur = sqlite3TestTextToPtr(argv[1]);
   258    258     pBt = pCur->pBtree;
   259    259     sqlite3BtreeEnter(pBt);
   260    260     rc = sqlite3BtreeCloseCursor(pCur);
   261    261     sqlite3BtreeLeave(pBt);
   262    262     ckfree((char *)pCur);
   263    263     if( rc ){
   264         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          264  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   265    265       return TCL_ERROR;
   266    266     }
   267    267     return SQLITE_OK;
   268    268   }
   269    269   
   270    270   /*
   271    271   ** Usage:   btree_next ID
................................................................................
   291    291       return TCL_ERROR;
   292    292     }
   293    293     pCur = sqlite3TestTextToPtr(argv[1]);
   294    294     sqlite3BtreeEnter(pCur->pBtree);
   295    295     rc = sqlite3BtreeNext(pCur, &res);
   296    296     sqlite3BtreeLeave(pCur->pBtree);
   297    297     if( rc ){
   298         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          298  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   299    299       return TCL_ERROR;
   300    300     }
   301    301     sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res);
   302    302     Tcl_AppendResult(interp, zBuf, 0);
   303    303     return SQLITE_OK;
   304    304   }
   305    305   
................................................................................
   326    326       return TCL_ERROR;
   327    327     }
   328    328     pCur = sqlite3TestTextToPtr(argv[1]);
   329    329     sqlite3BtreeEnter(pCur->pBtree);
   330    330     rc = sqlite3BtreeFirst(pCur, &res);
   331    331     sqlite3BtreeLeave(pCur->pBtree);
   332    332     if( rc ){
   333         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
          333  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
   334    334       return TCL_ERROR;
   335    335     }
   336    336     sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res);
   337    337     Tcl_AppendResult(interp, zBuf, 0);
   338    338     return SQLITE_OK;
   339    339   }
   340    340   

Changes to src/test4.c.

    16     16   #if SQLITE_OS_UNIX && SQLITE_THREADSAFE
    17     17   #include <stdlib.h>
    18     18   #include <string.h>
    19     19   #include <pthread.h>
    20     20   #include <sched.h>
    21     21   #include <ctype.h>
    22     22   
    23         -extern const char *sqlite3TestErrorName(int rc);
           23  +extern const char *sqlite3ErrName(int);
    24     24   
    25     25   /*
    26     26   ** Each thread is controlled by an instance of the following
    27     27   ** structure.
    28     28   */
    29     29   typedef struct Thread Thread;
    30     30   struct Thread {
................................................................................
   370    370     i = parse_thread_id(interp, argv[1]);
   371    371     if( i<0 ) return TCL_ERROR;
   372    372     if( !threadset[i].busy ){
   373    373       Tcl_AppendResult(interp, "no such thread", 0);
   374    374       return TCL_ERROR;
   375    375     }
   376    376     thread_wait(&threadset[i]);
   377         -  zName = sqlite3TestErrorName(threadset[i].rc);
          377  +  zName = sqlite3ErrName(threadset[i].rc);
   378    378     Tcl_AppendResult(interp, zName, 0);
   379    379     return TCL_OK;
   380    380   }
   381    381   
   382    382   /*
   383    383   ** Usage: thread_error  ID
   384    384   **

Changes to src/test7.c.

   372    372       Tcl_AppendResult(interp, "column number out of range", 0);
   373    373       return TCL_ERROR;
   374    374     }
   375    375     Tcl_AppendResult(interp, threadset[i].colv[n], 0);
   376    376     return TCL_OK;
   377    377   }
   378    378   
   379         -extern const char *sqlite3TestErrorName(int rc);
          379  +extern const char *sqlite3ErrName(int);
   380    380   
   381    381   /*
   382    382   ** Usage: client_result  ID
   383    383   **
   384    384   ** Wait on the most recent operation to complete, then return the
   385    385   ** result code from that operation.
   386    386   */
................................................................................
   401    401     i = parse_client_id(interp, argv[1]);
   402    402     if( i<0 ) return TCL_ERROR;
   403    403     if( !threadset[i].busy ){
   404    404       Tcl_AppendResult(interp, "no such thread", 0);
   405    405       return TCL_ERROR;
   406    406     }
   407    407     client_wait(&threadset[i]);
   408         -  zName = sqlite3TestErrorName(threadset[i].rc);
          408  +  zName = sqlite3ErrName(threadset[i].rc);
   409    409     Tcl_AppendResult(interp, zName, 0);
   410    410     return TCL_OK;
   411    411   }
   412    412   
   413    413   /*
   414    414   ** Usage: client_error  ID
   415    415   **

Changes to src/test8.c.

  1296   1296     echoRollbackTo
  1297   1297   };
  1298   1298   
  1299   1299   /*
  1300   1300   ** Decode a pointer to an sqlite3 object.
  1301   1301   */
  1302   1302   extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
  1303         -extern const char *sqlite3TestErrorName(int rc);
         1303  +extern const char *sqlite3ErrName(int);
  1304   1304   
  1305   1305   static void moduleDestroy(void *p){
  1306   1306     sqlite3_free(p);
  1307   1307   }
  1308   1308   
  1309   1309   /*
  1310   1310   ** Register the echo virtual table module.
................................................................................
  1336   1336       pMod = sqlite3_malloc(sizeof(EchoModule));
  1337   1337       pMod->interp = interp;
  1338   1338       rc = sqlite3_create_module_v2(db, "echo_v2", 
  1339   1339           &echoModuleV2, (void*)pMod, moduleDestroy
  1340   1340       );
  1341   1341     }
  1342   1342   
  1343         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1343  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1344   1344     return TCL_OK;
  1345   1345   }
  1346   1346   
  1347   1347   /*
  1348   1348   ** Tcl interface to sqlite3_declare_vtab, invoked as follows from Tcl:
  1349   1349   **
  1350   1350   ** sqlite3_declare_vtab DB SQL

Changes to src/test_async.c.

    19     19   
    20     20   #ifdef SQLITE_ENABLE_ASYNCIO
    21     21   
    22     22   #include "sqlite3async.h"
    23     23   #include "sqlite3.h"
    24     24   #include <assert.h>
    25     25   
    26         -/* From test1.c */
    27         -const char *sqlite3TestErrorName(int);
           26  +/* From main.c */
           27  +extern const char *sqlite3ErrName(int);
    28     28   
    29     29   
    30     30   struct TestAsyncGlobal {
    31     31     int isInstalled;                     /* True when async VFS is installed */
    32     32   } testasync_g = { 0 };
    33     33   
    34     34   TCL_DECLARE_MUTEX(testasync_g_writerMutex);
................................................................................
    56     56     }
    57     57     if( Tcl_GetBooleanFromObj(interp, objv[2], &isDefault) ){
    58     58       return TCL_ERROR;
    59     59     }
    60     60   
    61     61     rc = sqlite3async_initialize(zParent, isDefault);
    62     62     if( rc!=SQLITE_OK ){
    63         -    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3TestErrorName(rc), -1));
           63  +    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
    64     64       return TCL_ERROR;
    65     65     }
    66     66     return TCL_OK;
    67     67   }
    68     68   
    69     69   /*
    70     70   ** sqlite3async_shutdown
................................................................................
   204    204       rc = sqlite3async_control(
   205    205           eOpt==SQLITEASYNC_HALT ? SQLITEASYNC_GET_HALT :
   206    206           eOpt==SQLITEASYNC_DELAY ? SQLITEASYNC_GET_DELAY :
   207    207           SQLITEASYNC_GET_LOCKFILES, &iVal);
   208    208     }
   209    209   
   210    210     if( rc!=SQLITE_OK ){
   211         -    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3TestErrorName(rc), -1));
          211  +    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
   212    212       return TCL_ERROR;
   213    213     }
   214    214   
   215    215     if( eOpt==SQLITEASYNC_HALT ){
   216    216       Tcl_SetObjResult(interp, Tcl_NewStringObj(az[iVal], -1));
   217    217     }else{
   218    218       Tcl_SetObjResult(interp, Tcl_NewIntObj(iVal));

Changes to src/test_backup.c.

    12     12   ** This file contains test logic for the sqlite3_backup() interface.
    13     13   **
    14     14   */
    15     15   
    16     16   #include "tcl.h"
    17     17   #include <sqlite3.h>
    18     18   #include <assert.h>
           19  +
           20  +/* These functions are implemented in main.c. */
           21  +extern const char *sqlite3ErrName(int);
    19     22   
    20     23   /* These functions are implemented in test1.c. */
    21         -int getDbPointer(Tcl_Interp *, const char *, sqlite3 **);
    22         -const char *sqlite3TestErrorName(int);
           24  +extern int getDbPointer(Tcl_Interp *, const char *, sqlite3 **);
    23     25   
    24     26   static int backupTestCmd(
    25     27     ClientData clientData, 
    26     28     Tcl_Interp *interp, 
    27     29     int objc,
    28     30     Tcl_Obj *const*objv
    29     31   ){
................................................................................
    66     68         zCmdName = Tcl_GetString(objv[0]);
    67     69         Tcl_GetCommandInfo(interp, zCmdName, &cmdInfo);
    68     70         cmdInfo.deleteProc = 0;
    69     71         Tcl_SetCommandInfo(interp, zCmdName, &cmdInfo);
    70     72         Tcl_DeleteCommand(interp, zCmdName);
    71     73   
    72     74         rc = sqlite3_backup_finish(p);
    73         -      Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
           75  +      Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
    74     76         break;
    75     77       }
    76     78   
    77     79       case BACKUP_STEP: {
    78     80         int nPage;
    79     81         if( TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &nPage) ){
    80     82           return TCL_ERROR;
    81     83         }
    82     84         rc = sqlite3_backup_step(p, nPage);
    83         -      Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
           85  +      Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
    84     86         break;
    85     87       }
    86     88   
    87     89       case BACKUP_REMAINING:
    88     90         Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_backup_remaining(p)));
    89     91         break;
    90     92   

Changes to src/test_intarray.c.

   274    274   
   275    275   /*
   276    276   ** Routines to encode and decode pointers
   277    277   */
   278    278   extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
   279    279   extern void *sqlite3TestTextToPtr(const char*);
   280    280   extern int sqlite3TestMakePointerStr(Tcl_Interp*, char *zPtr, void*);
   281         -extern const char *sqlite3TestErrorName(int);
          281  +extern const char *sqlite3ErrName(int);
   282    282   
   283    283   /*
   284    284   **    sqlite3_intarray_create  DB  NAME
   285    285   **
   286    286   ** Invoke the sqlite3_intarray_create interface.  A string that becomes
   287    287   ** the first parameter to sqlite3_intarray_bind.
   288    288   */
................................................................................
   305    305     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
   306    306     zName = Tcl_GetString(objv[2]);
   307    307   #ifndef SQLITE_OMIT_VIRTUALTABLE
   308    308     rc = sqlite3_intarray_create(db, zName, &pArray);
   309    309   #endif
   310    310     if( rc!=SQLITE_OK ){
   311    311       assert( pArray==0 );
   312         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), (char*)0);
          312  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), (char*)0);
   313    313       return TCL_ERROR;
   314    314     }
   315    315     sqlite3TestMakePointerStr(interp, zPtr, pArray);
   316    316     Tcl_AppendResult(interp, zPtr, (char*)0);
   317    317     return TCL_OK;
   318    318   }
   319    319   
................................................................................
   348    348     for(i=0; i<n; i++){
   349    349       Tcl_WideInt x = 0;
   350    350       Tcl_GetWideIntFromObj(0, objv[i+2], &x);
   351    351       a[i] = x;
   352    352     }
   353    353     rc = sqlite3_intarray_bind(pArray, n, a, sqlite3_free);
   354    354     if( rc!=SQLITE_OK ){
   355         -    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), (char*)0);
          355  +    Tcl_AppendResult(interp, sqlite3ErrName(rc), (char*)0);
   356    356       return TCL_ERROR;
   357    357     }
   358    358   #endif
   359    359     return TCL_OK;
   360    360   }
   361    361   
   362    362   /*

Changes to src/test_malloc.c.

   230    230     }
   231    231     return rc;
   232    232   }
   233    233   
   234    234   #ifdef SQLITE_TEST
   235    235   
   236    236   /*
   237         -** This function is implemented in test1.c. Returns a pointer to a static
          237  +** This function is implemented in main.c. Returns a pointer to a static
   238    238   ** buffer containing the symbolic SQLite error code that corresponds to
   239    239   ** the least-significant 8-bits of the integer passed as an argument.
   240    240   ** For example:
   241    241   **
   242         -**   sqlite3TestErrorName(1) -> "SQLITE_ERROR"
          242  +**   sqlite3ErrName(1) -> "SQLITE_ERROR"
   243    243   */
   244         -const char *sqlite3TestErrorName(int);
          244  +extern const char *sqlite3ErrName(int);
   245    245   
   246    246   /*
   247    247   ** Transform pointers to text and back again
   248    248   */
   249    249   static void pointerToText(void *p, char *z){
   250    250     static const char zHex[] = "0123456789abcdef";
   251    251     int i, k;
................................................................................
  1068   1068     Tcl_Obj *CONST objv[]
  1069   1069   ){
  1070   1070     int rc;
  1071   1071     int sz, cnt;
  1072   1072     sqlite3 *db;
  1073   1073     int bufid;
  1074   1074     static char azBuf[2][10000];
  1075         -  int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
         1075  +  extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
  1076   1076     if( objc!=5 ){
  1077   1077       Tcl_WrongNumArgs(interp, 1, objv, "BUFID SIZE COUNT");
  1078   1078       return TCL_ERROR;
  1079   1079     }
  1080   1080     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  1081   1081     if( Tcl_GetIntFromObj(interp, objv[2], &bufid) ) return TCL_ERROR;
  1082   1082     if( Tcl_GetIntFromObj(interp, objv[3], &sz) ) return TCL_ERROR;
................................................................................
  1122   1122       zBuf = 0;
  1123   1123       rc = sqlite3_config(SQLITE_CONFIG_HEAP, (void*)0, 0, 0);
  1124   1124     }else{
  1125   1125       zBuf = realloc(zBuf, nByte);
  1126   1126       rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc);
  1127   1127     }
  1128   1128   
  1129         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1129  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1130   1130     return TCL_OK;
  1131   1131   }
  1132   1132   
  1133   1133   /*
  1134   1134   ** Usage:    sqlite3_config_error  [DB]
  1135   1135   **
  1136   1136   ** Invoke sqlite3_config() or sqlite3_db_config() with invalid
................................................................................
  1139   1139   static int test_config_error(
  1140   1140     void * clientData, 
  1141   1141     Tcl_Interp *interp,
  1142   1142     int objc,
  1143   1143     Tcl_Obj *CONST objv[]
  1144   1144   ){
  1145   1145     sqlite3 *db;
  1146         -  int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
         1146  +  extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
  1147   1147   
  1148   1148     if( objc!=2 && objc!=1 ){
  1149   1149       Tcl_WrongNumArgs(interp, 1, objv, "[DB]");
  1150   1150       return TCL_ERROR;
  1151   1151     }
  1152   1152     if( objc==2 ){
  1153   1153       if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
................................................................................
  1188   1188       return TCL_ERROR;
  1189   1189     }
  1190   1190     if( Tcl_GetBooleanFromObj(interp, objv[1], &bOpenUri) ){
  1191   1191       return TCL_ERROR;
  1192   1192     }
  1193   1193   
  1194   1194     rc = sqlite3_config(SQLITE_CONFIG_URI, bOpenUri);
  1195         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1195  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1196   1196   
  1197   1197     return TCL_OK;
  1198   1198   }
  1199   1199   
  1200   1200   /*
  1201   1201   ** Usage:    sqlite3_config_cis  BOOLEAN
  1202   1202   **
................................................................................
  1217   1217       return TCL_ERROR;
  1218   1218     }
  1219   1219     if( Tcl_GetBooleanFromObj(interp, objv[1], &bUseCis) ){
  1220   1220       return TCL_ERROR;
  1221   1221     }
  1222   1222   
  1223   1223     rc = sqlite3_config(SQLITE_CONFIG_COVERING_INDEX_SCAN, bUseCis);
  1224         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1224  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1225   1225   
  1226   1226     return TCL_OK;
  1227   1227   }
  1228   1228   
  1229   1229   /*
  1230   1230   ** Usage:    sqlite3_dump_memsys3  FILENAME
  1231   1231   **           sqlite3_dump_memsys5  FILENAME
................................................................................
  1331   1331     int objc,
  1332   1332     Tcl_Obj *CONST objv[]
  1333   1333   ){
  1334   1334     int rc, iValue, mxValue;
  1335   1335     int i, op, resetFlag;
  1336   1336     const char *zOpName;
  1337   1337     sqlite3 *db;
  1338         -  int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
         1338  +  extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
  1339   1339     static const struct {
  1340   1340       const char *zName;
  1341   1341       int op;
  1342   1342     } aOp[] = {
  1343   1343       { "LOOKASIDE_USED",      SQLITE_DBSTATUS_LOOKASIDE_USED      },
  1344   1344       { "CACHE_USED",          SQLITE_DBSTATUS_CACHE_USED          },
  1345   1345       { "SCHEMA_USED",         SQLITE_DBSTATUS_SCHEMA_USED         },
................................................................................
  1397   1397       Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
  1398   1398       return TCL_ERROR;
  1399   1399     }
  1400   1400     if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[1], &isInstall) ){
  1401   1401       return TCL_ERROR;
  1402   1402     }
  1403   1403     rc = faultsimInstall(isInstall);
  1404         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1404  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1405   1405     return TCL_OK;
  1406   1406   }
  1407   1407   
  1408   1408   /*
  1409   1409   ** sqlite3_install_memsys3
  1410   1410   */
  1411   1411   static int test_install_memsys3(
................................................................................
  1415   1415     Tcl_Obj *CONST objv[]
  1416   1416   ){
  1417   1417     int rc = SQLITE_MISUSE;
  1418   1418   #ifdef SQLITE_ENABLE_MEMSYS3
  1419   1419     const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
  1420   1420     rc = sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetMemsys3());
  1421   1421   #endif
  1422         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
         1422  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1423   1423     return TCL_OK;
  1424   1424   }
  1425   1425   
  1426   1426   static int test_vfs_oom_test(
  1427   1427     void * clientData,
  1428   1428     Tcl_Interp *interp,
  1429   1429     int objc,

Changes to src/test_multiplex.c.

  1179   1179     memset(&gMultiplex, 0, sizeof(gMultiplex));
  1180   1180     return SQLITE_OK;
  1181   1181   }
  1182   1182   
  1183   1183   /***************************** Test Code ***********************************/
  1184   1184   #ifdef SQLITE_TEST
  1185   1185   #include <tcl.h>
  1186         -extern const char *sqlite3TestErrorName(int);
         1186  +extern const char *sqlite3ErrName(int);
  1187   1187   
  1188   1188   
  1189   1189   /*
  1190   1190   ** tclcmd: sqlite3_multiplex_initialize NAME MAKEDEFAULT
  1191   1191   */
  1192   1192   static int test_multiplex_initialize(
  1193   1193     void * clientData,
................................................................................
  1208   1208     }
  1209   1209     zName = Tcl_GetString(objv[1]);
  1210   1210     if( Tcl_GetBooleanFromObj(interp, objv[2], &makeDefault) ) return TCL_ERROR;
  1211   1211     if( zName[0]=='\0' ) zName = 0;
  1212   1212   
  1213   1213     /* Call sqlite3_multiplex_initialize() */
  1214   1214     rc = sqlite3_multiplex_initialize(zName, makeDefault);
  1215         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1215  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1216   1216   
  1217   1217     return TCL_OK;
  1218   1218   }
  1219   1219   
  1220   1220   /*
  1221   1221   ** tclcmd: sqlite3_multiplex_shutdown
  1222   1222   */
................................................................................
  1233   1233     if( objc!=1 ){
  1234   1234       Tcl_WrongNumArgs(interp, 1, objv, "");
  1235   1235       return TCL_ERROR;
  1236   1236     }
  1237   1237   
  1238   1238     /* Call sqlite3_multiplex_shutdown() */
  1239   1239     rc = sqlite3_multiplex_shutdown();
  1240         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1240  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1241   1241   
  1242   1242     return TCL_OK;
  1243   1243   }
  1244   1244   
  1245   1245   /*
  1246   1246   ** tclcmd:  sqlite3_multiplex_dump
  1247   1247   */
................................................................................
  1351   1351         break;
  1352   1352       default:
  1353   1353         Tcl_WrongNumArgs(interp, 4, objv, "SUB-COMMAND");
  1354   1354         return TCL_ERROR;
  1355   1355     }
  1356   1356   
  1357   1357     rc = sqlite3_file_control(db, Tcl_GetString(objv[2]), aSub[idx].op, pArg);
  1358         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1358  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1359   1359     return (rc==SQLITE_OK) ? TCL_OK : TCL_ERROR;
  1360   1360   }
  1361   1361   
  1362   1362   /*
  1363   1363   ** This routine registers the custom TCL commands defined in this
  1364   1364   ** module.  This should be the only procedure visible from outside
  1365   1365   ** of this module.

Changes to src/test_mutex.c.

    15     15   #include "tcl.h"
    16     16   #include "sqlite3.h"
    17     17   #include "sqliteInt.h"
    18     18   #include <stdlib.h>
    19     19   #include <assert.h>
    20     20   #include <string.h>
    21     21   
    22         -/* defined in test1.c */
    23         -const char *sqlite3TestErrorName(int);
           22  +/* defined in main.c */
           23  +extern const char *sqlite3ErrName(int);
    24     24   
    25     25   /* A countable mutex */
    26     26   struct sqlite3_mutex {
    27     27     sqlite3_mutex *pReal;
    28     28     int eType;
    29     29   };
    30     30   
................................................................................
   144    144   
   145    145     if( objc!=1 ){
   146    146       Tcl_WrongNumArgs(interp, 1, objv, "");
   147    147       return TCL_ERROR;
   148    148     }
   149    149   
   150    150     rc = sqlite3_shutdown();
   151         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
          151  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
   152    152     return TCL_OK;
   153    153   }
   154    154   
   155    155   /*
   156    156   ** sqlite3_initialize
   157    157   */
   158    158   static int test_initialize(
................................................................................
   165    165   
   166    166     if( objc!=1 ){
   167    167       Tcl_WrongNumArgs(interp, 1, objv, "");
   168    168       return TCL_ERROR;
   169    169     }
   170    170   
   171    171     rc = sqlite3_initialize();
   172         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
          172  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
   173    173     return TCL_OK;
   174    174   }
   175    175   
   176    176   /*
   177    177   ** install_mutex_counters BOOLEAN
   178    178   */
   179    179   static int test_install_mutex_counters(
................................................................................
   226    226       memset(&g.m, 0, sizeof(sqlite3_mutex_methods));
   227    227     }
   228    228   
   229    229     if( rc==SQLITE_OK ){
   230    230       g.isInstalled = isInstall;
   231    231     }
   232    232   
   233         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
          233  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
   234    234     return TCL_OK;
   235    235   }
   236    236   
   237    237   /*
   238    238   ** read_mutex_counters
   239    239   */
   240    240   static int test_read_mutex_counters(
................................................................................
   350    350         return TCL_ERROR;
   351    351       }
   352    352     }else{
   353    353       i = aOpt[i].iValue;
   354    354     }
   355    355   
   356    356     rc = sqlite3_config(i);
   357         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
          357  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
   358    358     return TCL_OK;
   359    359   }
   360    360   
   361    361   static sqlite3 *getDbPointer(Tcl_Interp *pInterp, Tcl_Obj *pObj){
   362    362     sqlite3 *db;
   363    363     Tcl_CmdInfo info;
   364    364     char *zCmd = Tcl_GetString(pObj);

Changes to src/test_quota.c.

  1321   1321   */
  1322   1322   typedef struct TclQuotaCallback TclQuotaCallback;
  1323   1323   struct TclQuotaCallback {
  1324   1324     Tcl_Interp *interp;    /* Interpreter in which to run the script */
  1325   1325     Tcl_Obj *pScript;      /* Script to be run */
  1326   1326   };
  1327   1327   
  1328         -extern const char *sqlite3TestErrorName(int);
         1328  +extern const char *sqlite3ErrName(int);
  1329   1329   
  1330   1330   
  1331   1331   /*
  1332   1332   ** This is the callback from a quota-over-limit.
  1333   1333   */
  1334   1334   static void tclQuotaCallback(
  1335   1335     const char *zFilename,          /* Name of file whose size increases */
................................................................................
  1403   1403     }
  1404   1404     zName = Tcl_GetString(objv[1]);
  1405   1405     if( Tcl_GetBooleanFromObj(interp, objv[2], &makeDefault) ) return TCL_ERROR;
  1406   1406     if( zName[0]=='\0' ) zName = 0;
  1407   1407   
  1408   1408     /* Call sqlite3_quota_initialize() */
  1409   1409     rc = sqlite3_quota_initialize(zName, makeDefault);
  1410         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1410  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1411   1411   
  1412   1412     return TCL_OK;
  1413   1413   }
  1414   1414   
  1415   1415   /*
  1416   1416   ** tclcmd: sqlite3_quota_shutdown
  1417   1417   */
................................................................................
  1426   1426     if( objc!=1 ){
  1427   1427       Tcl_WrongNumArgs(interp, 1, objv, "");
  1428   1428       return TCL_ERROR;
  1429   1429     }
  1430   1430   
  1431   1431     /* Call sqlite3_quota_shutdown() */
  1432   1432     rc = sqlite3_quota_shutdown();
  1433         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1433  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1434   1434   
  1435   1435     return TCL_OK;
  1436   1436   }
  1437   1437   
  1438   1438   /*
  1439   1439   ** tclcmd: sqlite3_quota_set PATTERN LIMIT SCRIPT
  1440   1440   */
................................................................................
  1481   1481       xDestroy = 0;
  1482   1482       xCallback = 0;
  1483   1483     }
  1484   1484   
  1485   1485     /* Invoke sqlite3_quota_set() */
  1486   1486     rc = sqlite3_quota_set(zPattern, iLimit, xCallback, (void*)p, xDestroy);
  1487   1487   
  1488         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1488  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1489   1489     return TCL_OK;
  1490   1490   }
  1491   1491   
  1492   1492   /*
  1493   1493   ** tclcmd: sqlite3_quota_file FILENAME
  1494   1494   */
  1495   1495   static int test_quota_file(
................................................................................
  1507   1507       return TCL_ERROR;
  1508   1508     }
  1509   1509     zFilename = Tcl_GetString(objv[1]);
  1510   1510   
  1511   1511     /* Invoke sqlite3_quota_file() */
  1512   1512     rc = sqlite3_quota_file(zFilename);
  1513   1513   
  1514         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
         1514  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
  1515   1515     return TCL_OK;
  1516   1516   }
  1517   1517   
  1518   1518   /*
  1519   1519   ** tclcmd:  sqlite3_quota_dump
  1520   1520   */
  1521   1521   static int test_quota_dump(

Changes to src/test_rtree.c.

   250    250   #ifndef SQLITE_ENABLE_RTREE
   251    251     UNUSED_PARAMETER(clientData);
   252    252     UNUSED_PARAMETER(interp);
   253    253     UNUSED_PARAMETER(objc);
   254    254     UNUSED_PARAMETER(objv);
   255    255   #else
   256    256     extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
   257         -  extern const char *sqlite3TestErrorName(int);
          257  +  extern const char *sqlite3ErrName(int);
   258    258     sqlite3 *db;
   259    259     int rc;
   260    260   
   261    261     if( objc!=2 ){
   262    262       Tcl_WrongNumArgs(interp, 1, objv, "DB");
   263    263       return TCL_ERROR;
   264    264     }
   265    265     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
   266    266     rc = sqlite3_rtree_geometry_callback(db, "cube", cube_geom, (void *)&gHere);
   267         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
          267  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
   268    268   #endif
   269    269     return TCL_OK;
   270    270   }
   271    271   
   272    272   static int register_circle_geom(
   273    273     void * clientData,
   274    274     Tcl_Interp *interp,
................................................................................
   278    278   #ifndef SQLITE_ENABLE_RTREE
   279    279     UNUSED_PARAMETER(clientData);
   280    280     UNUSED_PARAMETER(interp);
   281    281     UNUSED_PARAMETER(objc);
   282    282     UNUSED_PARAMETER(objv);
   283    283   #else
   284    284     extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
   285         -  extern const char *sqlite3TestErrorName(int);
          285  +  extern const char *sqlite3ErrName(int);
   286    286     sqlite3 *db;
   287    287     int rc;
   288    288   
   289    289     if( objc!=2 ){
   290    290       Tcl_WrongNumArgs(interp, 1, objv, "DB");
   291    291       return TCL_ERROR;
   292    292     }
   293    293     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
   294    294     rc = sqlite3_rtree_geometry_callback(db, "circle", circle_geom, 0);
   295         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
          295  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
   296    296   #endif
   297    297     return TCL_OK;
   298    298   }
   299    299   
   300    300   int Sqlitetestrtree_Init(Tcl_Interp *interp){
   301    301     Tcl_CreateObjCommand(interp, "register_cube_geom", register_cube_geom, 0, 0);
   302    302     Tcl_CreateObjCommand(interp, "register_circle_geom",register_circle_geom,0,0);
   303    303     return TCL_OK;
   304    304   }

Changes to src/test_syscall.c.

    74     74   #include <stdlib.h>
    75     75   #include <string.h>
    76     76   #include <assert.h>
    77     77   
    78     78   #include "sqliteInt.h"
    79     79   #if SQLITE_OS_UNIX
    80     80   
    81         -/* From test1.c */
    82         -extern const char *sqlite3TestErrorName(int);
           81  +/* From main.c */
           82  +extern const char *sqlite3ErrName(int);
    83     83   
    84     84   #include <sys/mman.h>
    85     85   #include <sys/types.h>
    86     86   #include <errno.h>
    87     87   
    88     88   static struct TestSyscallGlobal {
    89     89     int bPersist;                   /* 1 for persistent errors, 0 for transient */
................................................................................
   494    494       for(i=0; rc==SQLITE_OK && aSyscall[i].zName; i++){
   495    495         if( strlen(aSyscall[i].zName)!=nFunc ) continue;
   496    496         if( memcmp(aSyscall[i].zName, zFunc, nFunc) ) continue;
   497    497         aSyscall[i].xOrig = 0;
   498    498       }
   499    499     }
   500    500     if( rc!=SQLITE_OK ){
   501         -    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3TestErrorName(rc), -1));
          501  +    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
   502    502       return TCL_ERROR;
   503    503     }
   504    504   
   505    505     Tcl_ResetResult(interp);
   506    506     return TCL_OK;
   507    507   }
   508    508   

Changes to src/test_thread.c.

    56     56   #if SQLITE_OS_UNIX && defined(SQLITE_ENABLE_UNLOCK_NOTIFY)
    57     57   static Tcl_ObjCmdProc blocking_step_proc;
    58     58   static Tcl_ObjCmdProc blocking_prepare_v2_proc;
    59     59   #endif
    60     60   int Sqlitetest1_Init(Tcl_Interp *);
    61     61   int Sqlite3_Init(Tcl_Interp *);
    62     62   
           63  +/* Functions from main.c */
           64  +extern const char *sqlite3ErrName(int);
           65  +
    63     66   /* Functions from test1.c */
    64         -void *sqlite3TestTextToPtr(const char *);
    65         -const char *sqlite3TestErrorName(int);
    66         -int getDbPointer(Tcl_Interp *, const char *, sqlite3 **);
    67         -int sqlite3TestMakePointerStr(Tcl_Interp *, char *, void *);
    68         -int sqlite3TestErrCode(Tcl_Interp *, sqlite3 *, int);
           67  +extern void *sqlite3TestTextToPtr(const char *);
           68  +extern int getDbPointer(Tcl_Interp *, const char *, sqlite3 **);
           69  +extern int sqlite3TestMakePointerStr(Tcl_Interp *, char *, void *);
           70  +extern int sqlite3TestErrCode(Tcl_Interp *, sqlite3 *, int);
    69     71   
    70     72   /*
    71     73   ** Handler for events of type EvalEvent.
    72     74   */
    73     75   static int tclScriptEvent(Tcl_Event *evPtr, int flags){
    74     76     int rc;
    75     77     EvalEvent *p = (EvalEvent *)evPtr;
................................................................................
   555    557       Tcl_WrongNumArgs(interp, 1, objv, "STMT");
   556    558       return TCL_ERROR;
   557    559     }
   558    560   
   559    561     pStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
   560    562     rc = sqlite3_blocking_step(pStmt);
   561    563   
   562         -  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), 0);
          564  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), 0);
   563    565     return TCL_OK;
   564    566   }
   565    567   
   566    568   /*
   567    569   ** Usage: sqlite3_blocking_prepare_v2 DB sql bytes ?tailvar?
   568    570   ** Usage: sqlite3_nonblocking_prepare_v2 DB sql bytes ?tailvar?
   569    571   */
................................................................................
   602    604       if( bytes>=0 ){
   603    605         bytes = bytes - (zTail-zSql);
   604    606       }
   605    607       Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
   606    608     }
   607    609     if( rc!=SQLITE_OK ){
   608    610       assert( pStmt==0 );
   609         -    sprintf(zBuf, "%s ", (char *)sqlite3TestErrorName(rc));
          611  +    sprintf(zBuf, "%s ", (char *)sqlite3ErrName(rc));
   610    612       Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0);
   611    613       return TCL_ERROR;
   612    614     }
   613    615   
   614    616     if( pStmt ){
   615    617       if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
   616    618       Tcl_AppendResult(interp, zBuf, 0);

Changes to test/wal.test.

  1511   1511     set ::log [list]
  1512   1512     faultsim_restore_and_reopen
  1513   1513     execsql { SELECT * FROM t1 }
  1514   1514   } {1 2 3 4}
  1515   1515   set nPage [expr 2+$AUTOVACUUM]
  1516   1516   do_test wal-23.4 { 
  1517   1517     set ::log 
  1518         -} [list SQLITE_NOTICE "recovered $nPage frames from WAL file $walfile"]
         1518  +} [list SQLITE_NOTICE_RECOVER_WAL \
         1519  +    "recovered $nPage frames from WAL file $walfile"]
  1519   1520   
  1520   1521   
  1521   1522   ifcapable autovacuum {
  1522   1523     # This block tests that if the size of a database is reduced by a 
  1523   1524     # transaction (because of an incremental or auto-vacuum), that no
  1524   1525     # data is written to the WAL file for the truncated pages as part
  1525   1526     # of the commit. e.g. if a transaction reduces the size of a database