/ Check-in [5ed31c82]
Login

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

Overview
Comment:Merge in the latest trunk changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-exp
Files: files | file ages | folders
SHA1:5ed31c8279a4f465b982df5dc20cefc286928b93
User & Date: drh 2013-05-10 02:11:40
Context
2013-05-10
03:30
Factor out common operations into whereLoopAddAll(). Add stubs for missing features. check-in: 0278e420 user: drh tags: nextgen-query-plan-exp
02:11
Merge in the latest trunk changes. check-in: 5ed31c82 user: drh tags: nextgen-query-plan-exp
02:00
Free up bits of wsFlags for reuse. Install the ORDER BY optimization infrastructure for the NGQP. check-in: 82d50e19 user: drh tags: nextgen-query-plan-exp
2013-05-09
18:12
Add assert()s to the implementation of xRead() in the built-in VFSes to verify that the offset parameter is always non-negative. check-in: cf5c3642 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

  3587   3587     rc = sqlite3Fts3InitTerm(db);
  3588   3588     if( rc!=SQLITE_OK ) return rc;
  3589   3589   #endif
  3590   3590   
  3591   3591     rc = sqlite3Fts3InitAux(db);
  3592   3592     if( rc!=SQLITE_OK ) return rc;
  3593   3593   
  3594         -  rc = sqlite3Fts3InitTok(db);
  3595         -  if( rc!=SQLITE_OK ) return rc;
  3596         -
  3597   3594     sqlite3Fts3SimpleTokenizerModule(&pSimple);
  3598   3595     sqlite3Fts3PorterTokenizerModule(&pPorter);
  3599   3596   
  3600   3597     /* Allocate and initialize the hash-table used to store tokenizers. */
  3601   3598     pHash = sqlite3_malloc(sizeof(Fts3Hash));
  3602   3599     if( !pHash ){
  3603   3600       rc = SQLITE_NOMEM;
................................................................................
  3643   3640           db, "fts3", &fts3Module, (void *)pHash, hashDestroy
  3644   3641       );
  3645   3642       if( rc==SQLITE_OK ){
  3646   3643         rc = sqlite3_create_module_v2(
  3647   3644             db, "fts4", &fts3Module, (void *)pHash, 0
  3648   3645         );
  3649   3646       }
         3647  +    if( rc==SQLITE_OK ){
         3648  +      rc = sqlite3Fts3InitTok(db, (void *)pHash);
         3649  +    }
  3650   3650       return rc;
  3651   3651     }
         3652  +
  3652   3653   
  3653   3654     /* An error has occurred. Delete the hash table and return the error code. */
  3654   3655     assert( rc!=SQLITE_OK );
  3655   3656     if( pHash ){
  3656   3657       sqlite3Fts3HashClear(pHash);
  3657   3658       sqlite3_free(pHash);
  3658   3659     }

Changes to ext/fts3/fts3Int.h.

   546    546   int sqlite3Fts3MsrIncrNext(
   547    547       Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *);
   548    548   int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **); 
   549    549   int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
   550    550   int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
   551    551   
   552    552   /* fts3_tokenize_vtab.c */
   553         -int sqlite3Fts3InitTok(sqlite3*);
          553  +int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *);
   554    554   
   555    555   /* fts3_unicode2.c (functions generated by parsing unicode text files) */
   556    556   #ifdef SQLITE_ENABLE_FTS4_UNICODE61
   557    557   int sqlite3FtsUnicodeFold(int, int);
   558    558   int sqlite3FtsUnicodeIsalnum(int);
   559    559   int sqlite3FtsUnicodeIsdiacritic(int);
   560    560   #endif
   561    561   
   562    562   #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
   563    563   #endif /* _FTSINT_H */

Changes to ext/fts3/fts3_expr.c.

   871    871           p = 0;
   872    872           for(i=0; i<nMaxDepth; i++){
   873    873             if( apLeaf[i] ){
   874    874               if( p==0 ){
   875    875                 p = apLeaf[i];
   876    876                 p->pParent = 0;
   877    877               }else{
          878  +              assert( pFree!=0 );
   878    879                 pFree->pRight = p;
   879    880                 pFree->pLeft = apLeaf[i];
   880    881                 pFree->pLeft->pParent = pFree;
   881    882                 pFree->pRight->pParent = pFree;
   882    883   
   883    884                 p = pFree;
   884    885                 pFree = pFree->pParent;

Changes to ext/fts3/fts3_tokenize_vtab.c.

    71     71     int iPos;                       /* Current 'pos' value */
    72     72   };
    73     73   
    74     74   /*
    75     75   ** Query FTS for the tokenizer implementation named zName.
    76     76   */
    77     77   static int fts3tokQueryTokenizer(
    78         -  sqlite3 *db,
           78  +  Fts3Hash *pHash,
    79     79     const char *zName,
    80         -  const sqlite3_tokenizer_module **pp
           80  +  const sqlite3_tokenizer_module **pp,
           81  +  char **pzErr
    81     82   ){
    82         -  int rc;
    83         -  sqlite3_stmt *pStmt;
    84         -  const char *zSql = "SELECT fts3_tokenizer(?)";
           83  +  sqlite3_tokenizer_module *p;
           84  +  int nName = (int)strlen(zName);
    85     85   
    86         -  *pp = 0;
    87         -  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
    88         -  if( rc!=SQLITE_OK ){
    89         -    return rc;
           86  +  p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
           87  +  if( !p ){
           88  +    *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
           89  +    return SQLITE_ERROR;
    90     90     }
    91     91   
    92         -  sqlite3_bind_text(pStmt, 1, zName, -1, SQLITE_STATIC);
    93         -  if( SQLITE_ROW==sqlite3_step(pStmt) ){
    94         -    if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB ){
    95         -      memcpy((void*)pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
    96         -    }
    97         -  }
    98         -
    99         -  return sqlite3_finalize(pStmt);
           92  +  *pp = p;
           93  +  return SQLITE_OK;
   100     94   }
   101     95   
   102     96   /*
   103     97   ** The second argument, argv[], is an array of pointers to nul-terminated
   104     98   ** strings. This function makes a copy of the array and strings into a 
   105     99   ** single block of memory. It then dequotes any of the strings that appear
   106    100   ** to be quoted.
................................................................................
   159    153   **   argv[0]: module name
   160    154   **   argv[1]: database name 
   161    155   **   argv[2]: table name
   162    156   **   argv[3]: first argument (tokenizer name)
   163    157   */
   164    158   static int fts3tokConnectMethod(
   165    159     sqlite3 *db,                    /* Database connection */
   166         -  void *pUnused,                  /* Unused */
          160  +  void *pHash,                    /* Hash table of tokenizers */
   167    161     int argc,                       /* Number of elements in argv array */
   168    162     const char * const *argv,       /* xCreate/xConnect argument array */
   169    163     sqlite3_vtab **ppVtab,          /* OUT: New sqlite3_vtab object */
   170    164     char **pzErr                    /* OUT: sqlite3_malloc'd error message */
   171    165   ){
   172    166     Fts3tokTable *pTab;
   173    167     const sqlite3_tokenizer_module *pMod = 0;
   174    168     sqlite3_tokenizer *pTok = 0;
   175    169     int rc;
   176    170     char **azDequote = 0;
   177    171     int nDequote;
   178         -  UNUSED_PARAMETER(pUnused);
   179    172   
   180    173     rc = sqlite3_declare_vtab(db, FTS3_TOK_SCHEMA);
   181    174     if( rc!=SQLITE_OK ) return rc;
   182    175   
   183    176     nDequote = argc-3;
   184    177     rc = fts3tokDequoteArray(nDequote, &argv[3], &azDequote);
   185    178   
................................................................................
   186    179     if( rc==SQLITE_OK ){
   187    180       const char *zModule;
   188    181       if( nDequote<1 ){
   189    182         zModule = "simple";
   190    183       }else{
   191    184         zModule = azDequote[0];
   192    185       }
   193         -    rc = fts3tokQueryTokenizer(db, zModule, &pMod);
          186  +    rc = fts3tokQueryTokenizer((Fts3Hash*)pHash, zModule, &pMod, pzErr);
   194    187     }
   195    188   
   196         -  if( rc!=SQLITE_OK ){
   197         -    *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
   198         -  }else if( pMod==0 ){
   199         -    rc = SQLITE_ERROR;
   200         -  }else{
          189  +  assert( (rc==SQLITE_OK)==(pMod!=0) );
          190  +  if( rc==SQLITE_OK ){
   201    191       const char * const *azArg = (const char * const *)&azDequote[1];
   202    192       rc = pMod->xCreate((nDequote>1 ? nDequote-1 : 0), azArg, &pTok);
   203    193     }
   204    194   
   205    195     if( rc==SQLITE_OK ){
   206    196       pTab = (Fts3tokTable *)sqlite3_malloc(sizeof(Fts3tokTable));
   207    197       if( pTab==0 ){
................................................................................
   425    415     return SQLITE_OK;
   426    416   }
   427    417   
   428    418   /*
   429    419   ** Register the fts3tok module with database connection db. Return SQLITE_OK
   430    420   ** if successful or an error code if sqlite3_create_module() fails.
   431    421   */
   432         -int sqlite3Fts3InitTok(sqlite3 *db){
          422  +int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){
   433    423     static const sqlite3_module fts3tok_module = {
   434    424        0,                           /* iVersion      */
   435    425        fts3tokConnectMethod,        /* xCreate       */
   436    426        fts3tokConnectMethod,        /* xConnect      */
   437    427        fts3tokBestIndexMethod,      /* xBestIndex    */
   438    428        fts3tokDisconnectMethod,     /* xDisconnect   */
   439    429        fts3tokDisconnectMethod,     /* xDestroy      */
................................................................................
   453    443        0,                           /* xRename       */
   454    444        0,                           /* xSavepoint    */
   455    445        0,                           /* xRelease      */
   456    446        0                            /* xRollbackTo   */
   457    447     };
   458    448     int rc;                         /* Return code */
   459    449   
   460         -  rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, 0);
          450  +  rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
   461    451     return rc;
   462    452   }
   463    453   
   464    454   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */

Added magic.txt.

            1  +# This file contains suggested magic(5) text for the unix file(1)
            2  +# utility for recognizing SQLite3 databases.
            3  +#
            4  +# When SQLite is used as an application file format, it is desirable to
            5  +# have file(1) recognize the database file as being with the specific
            6  +# application.  You can set the application_id for a database file
            7  +# using:
            8  +#
            9  +#     PRAGMA application_id = INTEGER;
           10  +#
           11  +# INTEGER can be any signed 32-bit integer.  That integer is written as
           12  +# a 4-byte big-endian integer into offset 68 of the database header. 
           13  +#
           14  +# The Monotone application used "PRAGMA user_version=1598903374;" to set
           15  +# its identifier long before "PRAGMA application_id" became available.
           16  +# The user_version is very similar to application_id except that it is
           17  +# stored at offset 68 instead of offset 60.  The application_id pragma
           18  +# is preferred.  The rule using offset 60 for Monotone is for historical
           19  +# compatibility only.
           20  +#
           21  +0    string  =SQLite\ format\ 3
           22  +>68  belong  =0x0f055111  Fossil repository -
           23  +>68  belong  =0x0f055112  Fossil checkout - 
           24  +>68  belong  =0x0f055113  Fossil global configuration - 
           25  +>68  belong  =0x42654462  Bentley Systems BeSQLite Database -
           26  +>68  belong  =0x42654c6e  Bentley Systems Localization File -
           27  +>60  belong  =0x5f4d544e  Monotone source repository -
           28  +>0   string  =SQLite      SQLite3 database

Changes to src/btree.h.

   136    136   #define BTREE_SCHEMA_VERSION      1
   137    137   #define BTREE_FILE_FORMAT         2
   138    138   #define BTREE_DEFAULT_CACHE_SIZE  3
   139    139   #define BTREE_LARGEST_ROOT_PAGE   4
   140    140   #define BTREE_TEXT_ENCODING       5
   141    141   #define BTREE_USER_VERSION        6
   142    142   #define BTREE_INCR_VACUUM         7
          143  +#define BTREE_APPLICATION_ID      8
   143    144   
   144    145   /*
   145    146   ** Values that may be OR'd together to form the second argument of an
   146    147   ** sqlite3BtreeCursorHints() call.
   147    148   */
   148    149   #define BTREE_BULKLOAD 0x00000001
   149    150   

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_unix.c.

   122    122   #include <sys/types.h>
   123    123   #include <sys/stat.h>
   124    124   #include <fcntl.h>
   125    125   #include <unistd.h>
   126    126   #include <time.h>
   127    127   #include <sys/time.h>
   128    128   #include <errno.h>
   129         -#ifndef SQLITE_OMIT_WAL
          129  +#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
   130    130   #include <sys/mman.h>
   131    131   #endif
   132    132   
   133    133   
   134    134   #if SQLITE_ENABLE_LOCKING_STYLE
   135    135   # include <sys/ioctl.h>
   136    136   # if OS_VXWORKS
................................................................................
  3148   3148     void *pBuf, 
  3149   3149     int amt,
  3150   3150     sqlite3_int64 offset
  3151   3151   ){
  3152   3152     unixFile *pFile = (unixFile *)id;
  3153   3153     int got;
  3154   3154     assert( id );
         3155  +  assert( offset>=0 );
         3156  +  assert( amt>0 );
  3155   3157   
  3156   3158     /* If this is a database file (not a journal, master-journal or temp
  3157   3159     ** file), the bytes in the locking range should never be read or written. */
  3158   3160   #if 0
  3159   3161     assert( pFile->pUnused==0
  3160   3162          || offset>=PENDING_BYTE+512
  3161   3163          || offset+amt<=PENDING_BYTE 

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

Changes to src/pager.c.

  2867   2867   
  2868   2868     if( NEVER(!isOpen(pPager->fd)) ){
  2869   2869       assert( pPager->tempFile );
  2870   2870       memset(pPg->pData, 0, pPager->pageSize);
  2871   2871       return SQLITE_OK;
  2872   2872     }
  2873   2873   
         2874  +#ifndef SQLITE_OMIT_WAL
  2874   2875     if( iFrame ){
  2875   2876       /* Try to pull the page from the write-ahead log. */
  2876   2877       rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
  2877         -  }else{
         2878  +  }else
         2879  +#endif
         2880  +  {
  2878   2881       i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
  2879   2882       rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
  2880   2883       if( rc==SQLITE_IOERR_SHORT_READ ){
  2881   2884         rc = SQLITE_OK;
  2882   2885       }
  2883   2886     }
  2884   2887   

Changes to src/pragma.c.

  1562   1562   #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
  1563   1563     /*
  1564   1564     **   PRAGMA [database.]schema_version
  1565   1565     **   PRAGMA [database.]schema_version = <integer>
  1566   1566     **
  1567   1567     **   PRAGMA [database.]user_version
  1568   1568     **   PRAGMA [database.]user_version = <integer>
         1569  +  **
         1570  +  **   PRAGMA [database.]freelist_count = <integer>
         1571  +  **
         1572  +  **   PRAGMA [database.]application_id
         1573  +  **   PRAGMA [database.]application_id = <integer>
  1569   1574     **
  1570   1575     ** The pragma's schema_version and user_version are used to set or get
  1571   1576     ** the value of the schema-version and user-version, respectively. Both
  1572   1577     ** the schema-version and the user-version are 32-bit signed integers
  1573   1578     ** stored in the database header.
  1574   1579     **
  1575   1580     ** The schema-cookie is usually only manipulated internally by SQLite. It
................................................................................
  1584   1589     **
  1585   1590     ** The user-version is not used internally by SQLite. It may be used by
  1586   1591     ** applications for any purpose.
  1587   1592     */
  1588   1593     if( sqlite3StrICmp(zLeft, "schema_version")==0 
  1589   1594      || sqlite3StrICmp(zLeft, "user_version")==0 
  1590   1595      || sqlite3StrICmp(zLeft, "freelist_count")==0 
         1596  +   || sqlite3StrICmp(zLeft, "application_id")==0 
  1591   1597     ){
  1592   1598       int iCookie;   /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
  1593   1599       sqlite3VdbeUsesBtree(v, iDb);
  1594   1600       switch( zLeft[0] ){
         1601  +      case 'a': case 'A':
         1602  +        iCookie = BTREE_APPLICATION_ID;
         1603  +        break;
  1595   1604         case 'f': case 'F':
  1596   1605           iCookie = BTREE_FREE_PAGE_COUNT;
  1597   1606           break;
  1598   1607         case 's': case 'S':
  1599   1608           iCookie = BTREE_SCHEMA_VERSION;
  1600   1609           break;
  1601   1610         default:

Changes to src/select.c.

  3256   3256         pParse->checkSchema = 1;
  3257   3257         return SQLITE_ERROR;
  3258   3258       }
  3259   3259       pFrom->pIndex = pIdx;
  3260   3260     }
  3261   3261     return SQLITE_OK;
  3262   3262   }
         3263  +/*
         3264  +** Detect compound SELECT statements that use an ORDER BY clause with 
         3265  +** an alternative collating sequence.
         3266  +**
         3267  +**    SELECT ... FROM t1 EXCEPT SELECT ... FROM t2 ORDER BY .. COLLATE ...
         3268  +**
         3269  +** These are rewritten as a subquery:
         3270  +**
         3271  +**    SELECT * FROM (SELECT ... FROM t1 EXCEPT SELECT ... FROM t2)
         3272  +**     ORDER BY ... COLLATE ...
         3273  +**
         3274  +** This transformation is necessary because the multiSelectOrderBy() routine
         3275  +** above that generates the code for a compound SELECT with an ORDER BY clause
         3276  +** uses a merge algorithm that requires the same collating sequence on the
         3277  +** result columns as on the ORDER BY clause.  See ticket
         3278  +** http://www.sqlite.org/src/info/6709574d2a
         3279  +**
         3280  +** This transformation is only needed for EXCEPT, INTERSECT, and UNION.
         3281  +** The UNION ALL operator works fine with multiSelectOrderBy() even when
         3282  +** there are COLLATE terms in the ORDER BY.
         3283  +*/
         3284  +static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
         3285  +  int i;
         3286  +  Select *pNew;
         3287  +  Select *pX;
         3288  +  sqlite3 *db;
         3289  +  struct ExprList_item *a;
         3290  +  SrcList *pNewSrc;
         3291  +  Parse *pParse;
         3292  +  Token dummy;
         3293  +
         3294  +  if( p->pPrior==0 ) return WRC_Continue;
         3295  +  if( p->pOrderBy==0 ) return WRC_Continue;
         3296  +  for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
         3297  +  if( pX==0 ) return WRC_Continue;
         3298  +  a = p->pOrderBy->a;
         3299  +  for(i=p->pOrderBy->nExpr-1; i>=0; i--){
         3300  +    if( a[i].pExpr->flags & EP_Collate ) break;
         3301  +  }
         3302  +  if( i<0 ) return WRC_Continue;
         3303  +
         3304  +  /* If we reach this point, that means the transformation is required. */
         3305  +
         3306  +  pParse = pWalker->pParse;
         3307  +  db = pParse->db;
         3308  +  pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
         3309  +  if( pNew==0 ) return WRC_Abort;
         3310  +  memset(&dummy, 0, sizeof(dummy));
         3311  +  pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0,0);
         3312  +  if( pNewSrc==0 ) return WRC_Abort;
         3313  +  *pNew = *p;
         3314  +  p->pSrc = pNewSrc;
         3315  +  p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ALL, 0));
         3316  +  p->op = TK_SELECT;
         3317  +  p->pWhere = 0;
         3318  +  pNew->pGroupBy = 0;
         3319  +  pNew->pHaving = 0;
         3320  +  pNew->pOrderBy = 0;
         3321  +  p->pPrior = 0;
         3322  +  pNew->pLimit = 0;
         3323  +  pNew->pOffset = 0;
         3324  +  return WRC_Continue;
         3325  +}
  3263   3326   
  3264   3327   /*
  3265   3328   ** This routine is a Walker callback for "expanding" a SELECT statement.
  3266   3329   ** "Expanding" means to do the following:
  3267   3330   **
  3268   3331   **    (1)  Make sure VDBE cursor numbers have been assigned to every
  3269   3332   **         element of the FROM clause.
................................................................................
  3573   3636   ** If anything goes wrong, an error message is written into pParse.
  3574   3637   ** The calling function can detect the problem by looking at pParse->nErr
  3575   3638   ** and/or pParse->db->mallocFailed.
  3576   3639   */
  3577   3640   static void sqlite3SelectExpand(Parse *pParse, Select *pSelect){
  3578   3641     Walker w;
  3579   3642     memset(&w, 0, sizeof(w));
  3580         -  w.xSelectCallback = selectExpander;
         3643  +  w.xSelectCallback = convertCompoundSelectToSubquery;
  3581   3644     w.xExprCallback = exprWalkNoop;
  3582   3645     w.pParse = pParse;
         3646  +  sqlite3WalkSelect(&w, pSelect);
         3647  +  w.xSelectCallback = selectExpander;
  3583   3648     sqlite3WalkSelect(&w, pSelect);
  3584   3649   }
  3585   3650   
  3586   3651   
  3587   3652   #ifndef SQLITE_OMIT_SUBQUERY
  3588   3653   /*
  3589   3654   ** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()

Changes to src/shell.c.

  2274   2274           rc = sqlite3_exec(p->db,
  2275   2275             "SELECT sql FROM "
  2276   2276             "  (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
  2277   2277             "     FROM sqlite_master UNION ALL"
  2278   2278             "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
  2279   2279             "WHERE lower(tbl_name) LIKE shellstatic()"
  2280   2280             "  AND type!='meta' AND sql NOTNULL "
  2281         -          "ORDER BY substr(type,2,1), "
  2282         -                  " CASE type WHEN 'view' THEN rowid ELSE name END",
         2281  +          "ORDER BY rowid",
  2283   2282             callback, &data, &zErrMsg);
  2284   2283           zShellStatic = 0;
  2285   2284         }
  2286   2285       }else{
  2287   2286         rc = sqlite3_exec(p->db,
  2288   2287            "SELECT sql FROM "
  2289   2288            "  (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
  2290   2289            "     FROM sqlite_master UNION ALL"
  2291   2290            "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
  2292   2291            "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
  2293         -         "ORDER BY substr(type,2,1),"
  2294         -                  " CASE type WHEN 'view' THEN rowid ELSE name END",
         2292  +         "ORDER BY rowid",
  2295   2293            callback, &data, &zErrMsg
  2296   2294         );
  2297   2295       }
  2298   2296       if( zErrMsg ){
  2299   2297         fprintf(stderr,"Error: %s\n", zErrMsg);
  2300   2298         sqlite3_free(zErrMsg);
  2301   2299         rc = 1;
................................................................................
  2409   2407         }
  2410   2408         nPrintCol = 80/(maxlen+2);
  2411   2409         if( nPrintCol<1 ) nPrintCol = 1;
  2412   2410         nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
  2413   2411         for(i=0; i<nPrintRow; i++){
  2414   2412           for(j=i; j<nRow; j+=nPrintRow){
  2415   2413             char *zSp = j<nPrintRow ? "" : "  ";
  2416         -          printf("%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
         2414  +          fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
  2417   2415           }
  2418         -        printf("\n");
         2416  +        fprintf(p->out, "\n");
  2419   2417         }
  2420   2418       }
  2421   2419       for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
  2422   2420       sqlite3_free(azResult);
  2423   2421     }else
  2424   2422   
  2425   2423     if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
................................................................................
  2468   2466   
  2469   2467           /* sqlite3_test_control(int, db, int) */
  2470   2468           case SQLITE_TESTCTRL_OPTIMIZATIONS:
  2471   2469           case SQLITE_TESTCTRL_RESERVE:             
  2472   2470             if( nArg==3 ){
  2473   2471               int opt = (int)strtol(azArg[2], 0, 0);        
  2474   2472               rc = sqlite3_test_control(testctrl, p->db, opt);
  2475         -            printf("%d (0x%08x)\n", rc, rc);
         2473  +            fprintf(p->out, "%d (0x%08x)\n", rc, rc);
  2476   2474             } else {
  2477   2475               fprintf(stderr,"Error: testctrl %s takes a single int option\n",
  2478   2476                       azArg[1]);
  2479   2477             }
  2480   2478             break;
  2481   2479   
  2482   2480           /* sqlite3_test_control(int) */
  2483   2481           case SQLITE_TESTCTRL_PRNG_SAVE:           
  2484   2482           case SQLITE_TESTCTRL_PRNG_RESTORE:        
  2485   2483           case SQLITE_TESTCTRL_PRNG_RESET:
  2486   2484             if( nArg==2 ){
  2487   2485               rc = sqlite3_test_control(testctrl);
  2488         -            printf("%d (0x%08x)\n", rc, rc);
         2486  +            fprintf(p->out, "%d (0x%08x)\n", rc, rc);
  2489   2487             } else {
  2490   2488               fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
  2491   2489             }
  2492   2490             break;
  2493   2491   
  2494   2492           /* sqlite3_test_control(int, uint) */
  2495   2493           case SQLITE_TESTCTRL_PENDING_BYTE:        
  2496   2494             if( nArg==3 ){
  2497   2495               unsigned int opt = (unsigned int)integerValue(azArg[2]);        
  2498   2496               rc = sqlite3_test_control(testctrl, opt);
  2499         -            printf("%d (0x%08x)\n", rc, rc);
         2497  +            fprintf(p->out, "%d (0x%08x)\n", rc, rc);
  2500   2498             } else {
  2501   2499               fprintf(stderr,"Error: testctrl %s takes a single unsigned"
  2502   2500                              " int option\n", azArg[1]);
  2503   2501             }
  2504   2502             break;
  2505   2503             
  2506   2504           /* sqlite3_test_control(int, int) */
  2507   2505           case SQLITE_TESTCTRL_ASSERT:              
  2508   2506           case SQLITE_TESTCTRL_ALWAYS:              
  2509   2507             if( nArg==3 ){
  2510   2508               int opt = atoi(azArg[2]);        
  2511   2509               rc = sqlite3_test_control(testctrl, opt);
  2512         -            printf("%d (0x%08x)\n", rc, rc);
         2510  +            fprintf(p->out, "%d (0x%08x)\n", rc, rc);
  2513   2511             } else {
  2514   2512               fprintf(stderr,"Error: testctrl %s takes a single int option\n",
  2515   2513                               azArg[1]);
  2516   2514             }
  2517   2515             break;
  2518   2516   
  2519   2517           /* sqlite3_test_control(int, char *) */
  2520   2518   #ifdef SQLITE_N_KEYWORD
  2521   2519           case SQLITE_TESTCTRL_ISKEYWORD:           
  2522   2520             if( nArg==3 ){
  2523   2521               const char *opt = azArg[2];        
  2524   2522               rc = sqlite3_test_control(testctrl, opt);
  2525         -            printf("%d (0x%08x)\n", rc, rc);
         2523  +            fprintf(p->out, "%d (0x%08x)\n", rc, rc);
  2526   2524             } else {
  2527   2525               fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
  2528   2526                               azArg[1]);
  2529   2527             }
  2530   2528             break;
  2531   2529   #endif
  2532   2530   
................................................................................
  2563   2561       }else{
  2564   2562         sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
  2565   2563       }
  2566   2564   #endif
  2567   2565     }else
  2568   2566   
  2569   2567     if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
  2570         -    printf("SQLite %s %s\n" /*extra-version-info*/,
         2568  +    fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
  2571   2569           sqlite3_libversion(), sqlite3_sourceid());
  2572   2570     }else
  2573   2571   
  2574   2572     if( c=='v' && strncmp(azArg[0], "vfsname", n)==0 ){
  2575   2573       const char *zDbName = nArg==2 ? azArg[1] : "main";
  2576   2574       char *zVfsName = 0;
  2577   2575       if( p->db ){
  2578   2576         sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName);
  2579   2577         if( zVfsName ){
  2580         -        printf("%s\n", zVfsName);
         2578  +        fprintf(p->out, "%s\n", zVfsName);
  2581   2579           sqlite3_free(zVfsName);
  2582   2580         }
  2583   2581       }
  2584   2582     }else
  2585   2583   
  2586   2584   #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
  2587   2585     if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){

Changes to src/sqliteInt.h.

  3093   3093   int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
  3094   3094   char sqlite3ExprAffinity(Expr *pExpr);
  3095   3095   int sqlite3Atoi64(const char*, i64*, int, u8);
  3096   3096   void sqlite3Error(sqlite3*, int, const char*,...);
  3097   3097   void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
  3098   3098   u8 sqlite3HexToInt(int h);
  3099   3099   int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
         3100  +
         3101  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
         3102  +    defined(SQLITE_DEBUG_OS_TRACE)
         3103  +const char *sqlite3ErrName(int);
         3104  +#endif
         3105  +
  3100   3106   const char *sqlite3ErrStr(int);
  3101   3107   int sqlite3ReadSchema(Parse *pParse);
  3102   3108   CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
  3103   3109   CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
  3104   3110   CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
  3105   3111   Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, Token*);
  3106   3112   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 src/update.c.

   204    204           }
   205    205           aXRef[j] = i;
   206    206           break;
   207    207         }
   208    208       }
   209    209       if( j>=pTab->nCol ){
   210    210         if( sqlite3IsRowid(pChanges->a[i].zName) ){
          211  +        j = -1;
   211    212           chngRowid = 1;
   212    213           pRowidExpr = pChanges->a[i].pExpr;
   213    214         }else{
   214    215           sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
   215    216           pParse->checkSchema = 1;
   216    217           goto update_cleanup;
   217    218         }
   218    219       }
   219    220   #ifndef SQLITE_OMIT_AUTHORIZATION
   220    221       {
   221    222         int rc;
   222    223         rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
   223         -                           pTab->aCol[j].zName, db->aDb[iDb].zName);
          224  +                            j<0 ? "ROWID" : pTab->aCol[j].zName,
          225  +                            db->aDb[iDb].zName);
   224    226         if( rc==SQLITE_DENY ){
   225    227           goto update_cleanup;
   226    228         }else if( rc==SQLITE_IGNORE ){
   227    229           aXRef[j] = -1;
   228    230         }
   229    231       }
   230    232   #endif

Changes to src/vacuum.c.

   285    285       ** connections to the same database will know to reread the schema.
   286    286       */
   287    287       static const unsigned char aCopy[] = {
   288    288          BTREE_SCHEMA_VERSION,     1,  /* Add one to the old schema cookie */
   289    289          BTREE_DEFAULT_CACHE_SIZE, 0,  /* Preserve the default page cache size */
   290    290          BTREE_TEXT_ENCODING,      0,  /* Preserve the text encoding */
   291    291          BTREE_USER_VERSION,       0,  /* Preserve the user version */
          292  +       BTREE_APPLICATION_ID,     0,  /* Preserve the application id */
   292    293       };
   293    294   
   294    295       assert( 1==sqlite3BtreeIsInTrans(pTemp) );
   295    296       assert( 1==sqlite3BtreeIsInTrans(pMain) );
   296    297   
   297    298       /* Copy Btree meta values */
   298    299       for(i=0; i<ArraySize(aCopy); i+=2){

Changes to src/wal.h.

    39     39   # define sqlite3WalSavepointUndo(y,z)            0
    40     40   # define sqlite3WalFrames(u,v,w,x,y,z)           0
    41     41   # define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0
    42     42   # define sqlite3WalCallback(z)                   0
    43     43   # define sqlite3WalExclusiveMode(y,z)            0
    44     44   # define sqlite3WalHeapMemory(z)                 0
    45     45   # define sqlite3WalFramesize(z)                  0
           46  +# define sqlite3WalFindFrame(x,y,z)              0
    46     47   #else
    47     48   
    48     49   #define WAL_SAVEPOINT_NDATA 4
    49     50   
    50     51   /* Connection to a write-ahead log (WAL) file. 
    51     52   ** There is one object of this type for each pager. 
    52     53   */

Changes to src/where.c.

  4851   4851       ** That way, terms in y that are factored into the disjunction will
  4852   4852       ** be picked up by the recursive calls to sqlite3WhereBegin() below.
  4853   4853       **
  4854   4854       ** Actually, each subexpression is converted to "xN AND w" where w is
  4855   4855       ** the "interesting" terms of z - terms that did not originate in the
  4856   4856       ** ON or USING clause of a LEFT JOIN, and terms that are usable as 
  4857   4857       ** indices.
         4858  +    **
         4859  +    ** This optimization also only applies if the (x1 OR x2 OR ...) term
         4860  +    ** is not contained in the ON clause of a LEFT JOIN.
         4861  +    ** See ticket http://www.sqlite.org/src/info/f2369304e4
  4858   4862       */
  4859   4863       if( pWC->nTerm>1 ){
  4860   4864         int iTerm;
  4861   4865         for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
  4862   4866           Expr *pExpr = pWC->a[iTerm].pExpr;
  4863   4867           if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
  4864   4868           if( pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_ORINFO) ) continue;
................................................................................
  4872   4876       }
  4873   4877   
  4874   4878       for(ii=0; ii<pOrWc->nTerm; ii++){
  4875   4879         WhereTerm *pOrTerm = &pOrWc->a[ii];
  4876   4880         if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
  4877   4881           WhereInfo *pSubWInfo;          /* Info for single OR-term scan */
  4878   4882           Expr *pOrExpr = pOrTerm->pExpr;
  4879         -        if( pAndExpr ){
         4883  +        if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
  4880   4884             pAndExpr->pLeft = pOrExpr;
  4881   4885             pOrExpr = pAndExpr;
  4882   4886           }
  4883   4887           /* Loop through table entries that match term pOrTerm. */
  4884   4888           pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
  4885   4889                           WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
  4886   4890                           WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur);

Changes to test/auth.test.

  2364   2364             SQLITE_READ t5 x main t5_tr1   \
  2365   2365       ]
  2366   2366     do_test auth-5.3.2 {
  2367   2367       execsql { SELECT * FROM t5 }
  2368   2368     } {1}
  2369   2369   }
  2370   2370   
         2371  +# Ticket [0eb70d77cb05bb22720]:  Invalid pointer passsed to the authorizer
         2372  +# callback when updating a ROWID.
         2373  +#
         2374  +do_test auth-6.1 {
         2375  +  execsql {
         2376  +    CREATE TABLE t6(a,b,c,d,e,f,g,h);
         2377  +    INSERT INTO t6 VALUES(1,2,3,4,5,6,7,8);
         2378  +  }
         2379  +} {}
         2380  +set ::authargs [list]
         2381  +proc auth {args} {
         2382  +  eval lappend ::authargs $args
         2383  +  return SQLITE_OK
         2384  +}
         2385  +do_test auth-6.2 {
         2386  +  execsql {UPDATE t6 SET rowID=rowID+100}
         2387  +  set ::authargs
         2388  +} [list SQLITE_READ   t6 ROWID main {} \
         2389  +        SQLITE_UPDATE t6 ROWID main {} \
         2390  +]
         2391  +do_test auth-6.3 {
         2392  +  execsql {SELECT rowid, * FROM t6}
         2393  +} {101 1 2 3 4 5 6 7 8}
  2371   2394   
  2372   2395   rename proc {}
  2373   2396   rename proc_real proc
  2374   2397   
  2375   2398   
  2376   2399   finish_test

Changes to test/fts3tok1.test.

   102    102   #-------------------------------------------------------------------------
   103    103   # Error cases.
   104    104   #
   105    105   do_catchsql_test 2.0 {
   106    106     CREATE VIRTUAL TABLE tX USING fts3tokenize(nosuchtokenizer);
   107    107   } {1 {unknown tokenizer: nosuchtokenizer}}
   108    108   
   109         -proc fts3_tokenizer {args} { return 1 }
   110         -db function fts3_tokenizer -argcount 1 fts3_tokenizer
   111    109   do_catchsql_test 2.1 {
   112         -  CREATE VIRTUAL TABLE tX USING fts3tokenize(simple);
   113         -} {1 {vtable constructor failed: tX}}
   114         -
   115         -db close
   116         -sqlite3 db test.db
   117         -do_catchsql_test 2.2 {
   118    110     CREATE VIRTUAL TABLE t4 USING fts3tokenize;
   119    111     SELECT * FROM t4;
   120    112   } {1 {SQL logic error or missing database}}
   121    113   
   122    114   
   123    115   finish_test
   124    116   
   125    117   

Changes to test/pragma.test.

   932    932         }
   933    933         return "disk"
   934    934       }
   935    935     }
   936    936     return "unknown"
   937    937   }
   938    938   
          939  +# Application_ID
          940  +#
          941  +do_test pragma-8.3.1 {
          942  +  execsql {
          943  +    PRAGMA application_id;
          944  +  }
          945  +} {0}
          946  +do_test pragma-8.3.2 {
          947  +  execsql {PRAGMA Application_ID(12345); PRAGMA application_id;}
          948  +} {12345}
   939    949   
   940    950   # Test temp_store and temp_store_directory pragmas
   941    951   #
   942    952   ifcapable pager_pragmas {
   943    953   do_test pragma-9.1 {
   944    954     db close
   945    955     sqlite3 db test.db

Changes to test/selectA.test.

   277    277       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   278    278       ORDER BY b,a,c
   279    279     }
   280    280   } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
   281    281   do_test selectA-2.35 {
   282    282     execsql {
   283    283       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   284         -    ORDER BY b COLLATE NOCASE,a,c
          284  +    ORDER BY y COLLATE NOCASE,x,z
   285    285     }
   286    286   } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
   287    287   do_test selectA-2.36 {
   288    288     execsql {
   289    289       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   290         -    ORDER BY b COLLATE NOCASE DESC,a,c
          290  +    ORDER BY y COLLATE NOCASE DESC,x,z
   291    291     }
   292    292   } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
   293    293   do_test selectA-2.37 {
   294    294     execsql {
   295    295       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   296    296       ORDER BY c,b,a
   297    297     }
................................................................................
   307    307       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   308    308       ORDER BY c DESC,a,b
   309    309     }
   310    310   } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
   311    311   do_test selectA-2.40 {
   312    312     execsql {
   313    313       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   314         -    ORDER BY c COLLATE BINARY DESC,a,b
          314  +    ORDER BY z COLLATE BINARY DESC,x,y
   315    315     }
   316    316   } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
   317    317   do_test selectA-2.41 {
   318    318     execsql {
   319    319       SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
   320    320       ORDER BY a,b,c
   321    321     }
................................................................................
   598    598       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
   599    599       ORDER BY b,a,c
   600    600     }
   601    601   } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
   602    602   do_test selectA-2.86 {
   603    603     execsql {
   604    604       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
   605         -    ORDER BY b COLLATE NOCASE,a,c
          605  +    ORDER BY y COLLATE NOCASE,x,z
   606    606     }
   607    607   } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
   608    608   do_test selectA-2.87 {
   609    609     execsql {
   610    610       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
   611    611       ORDER BY y COLLATE NOCASE DESC,x,z
   612    612     }
................................................................................
   628    628       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
   629    629       ORDER BY c DESC,a,b
   630    630     }
   631    631   } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
   632    632   do_test selectA-2.91 {
   633    633     execsql {
   634    634       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
   635         -    ORDER BY c COLLATE BINARY DESC,a,b
          635  +    ORDER BY z COLLATE BINARY DESC,x,y
   636    636     }
   637    637   } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
   638    638   do_test selectA-2.92 {
   639    639     execsql {
   640    640       SELECT x,y,z FROM t2
   641    641       INTERSECT SELECT a,b,c FROM t3
   642    642       EXCEPT SELECT c,b,a FROM t1
................................................................................
   889    889       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   890    890       ORDER BY b,a,c
   891    891     }
   892    892   } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
   893    893   do_test selectA-3.35 {
   894    894     execsql {
   895    895       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   896         -    ORDER BY b COLLATE NOCASE,a,c
          896  +    ORDER BY y COLLATE NOCASE,x,z
   897    897     }
   898    898   } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
   899    899   do_test selectA-3.36 {
   900    900     execsql {
   901    901       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   902         -    ORDER BY b COLLATE NOCASE DESC,a,c
          902  +    ORDER BY y COLLATE NOCASE DESC,x,z
   903    903     }
   904    904   } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
   905    905   do_test selectA-3.37 {
   906    906     execsql {
   907    907       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   908    908       ORDER BY c,b,a
   909    909     }
................................................................................
   919    919       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   920    920       ORDER BY c DESC,a,b
   921    921     }
   922    922   } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
   923    923   do_test selectA-3.40 {
   924    924     execsql {
   925    925       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
   926         -    ORDER BY c COLLATE BINARY DESC,a,b
          926  +    ORDER BY z COLLATE BINARY DESC,x,y
   927    927     }
   928    928   } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
   929    929   do_test selectA-3.41 {
   930    930     execsql {
   931    931       SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
   932    932       ORDER BY a,b,c
   933    933     }
................................................................................
  1210   1210       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
  1211   1211       ORDER BY b,a,c
  1212   1212     }
  1213   1213   } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
  1214   1214   do_test selectA-3.86 {
  1215   1215     execsql {
  1216   1216       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
  1217         -    ORDER BY b COLLATE NOCASE,a,c
         1217  +    ORDER BY y COLLATE NOCASE,x,z
  1218   1218     }
  1219   1219   } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
  1220   1220   do_test selectA-3.87 {
  1221   1221     execsql {
  1222   1222       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
  1223   1223       ORDER BY y COLLATE NOCASE DESC,x,z
  1224   1224     }
................................................................................
  1240   1240       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
  1241   1241       ORDER BY c DESC,a,b
  1242   1242     }
  1243   1243   } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
  1244   1244   do_test selectA-3.91 {
  1245   1245     execsql {
  1246   1246       SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
  1247         -    ORDER BY c COLLATE BINARY DESC,a,b
         1247  +    ORDER BY z COLLATE BINARY DESC,x,y
  1248   1248     }
  1249   1249   } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
  1250   1250   do_test selectA-3.92 {
  1251   1251     execsql {
  1252   1252       SELECT x,y,z FROM t2
  1253   1253       INTERSECT SELECT a,b,c FROM t3
  1254   1254       EXCEPT SELECT c,b,a FROM t1

Added test/selectE.test.

            1  +# 2013-05-07
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for compound SELECT statements
           12  +# that have ORDER BY clauses with collating sequences that differ
           13  +# from the collating sequence used for comparison in the compound.
           14  +# 
           15  +# Ticket 6709574d2a8d8b9be3a9cb1afbf4ff2de48ea4e7:
           16  +# drh added on 2013-05-06 15:21:16:
           17  +#
           18  +# In the code shown below (which is intended to be run from the
           19  +# sqlite3.exe command-line tool) the three SELECT statements should all
           20  +# generate the same answer. But the third one does not. It is as if the
           21  +# COLLATE clause on the ORDER BY somehow got pulled into the EXCEPT
           22  +# operator. Note that the ".print" commands are instructions to the
           23  +# sqlite3.exe shell program to output delimiter lines so that you can more
           24  +# easily tell where the output of one query ends and the next query
           25  +# begins. 
           26  +# 
           27  +#     CREATE TABLE t1(a);
           28  +#     INSERT INTO t1 VALUES('abc'),('def');
           29  +#     CREATE TABLE t2(a);
           30  +#     INSERT INTO t2 VALUES('DEF');
           31  +# 
           32  +#     SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a;
           33  +#     .print -----
           34  +#     SELECT a FROM (SELECT a FROM t1 EXCEPT SELECT a FROM t2)
           35  +#      ORDER BY a COLLATE nocase;
           36  +#     .print -----
           37  +#     SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a COLLATE nocase;
           38  +# 
           39  +# Bisecting shows that this problem was introduced in SQLite version 3.6.0
           40  +# by check-in [8bbfa97837a74ef] on 2008-06-15. 
           41  +#
           42  +
           43  +set testdir [file dirname $argv0]
           44  +source $testdir/tester.tcl
           45  +
           46  +do_test selectE-1.0 {
           47  +  db eval {
           48  +    CREATE TABLE t1(a);
           49  +    INSERT INTO t1 VALUES('abc'),('def'),('ghi');
           50  +    CREATE TABLE t2(a);
           51  +    INSERT INTO t2 VALUES('DEF'),('abc');
           52  +    CREATE TABLE t3(a);
           53  +    INSERT INTO t3 VALUES('def'),('jkl');
           54  +
           55  +    SELECT a FROM t1 EXCEPT SELECT a FROM t2
           56  +     ORDER BY a COLLATE nocase;
           57  +  }
           58  +} {def ghi}
           59  +do_test selectE-1.1 {
           60  +  db eval {
           61  +    SELECT a FROM t2 EXCEPT SELECT a FROM t3
           62  +     ORDER BY a COLLATE nocase;
           63  +  }
           64  +} {abc DEF}
           65  +do_test selectE-1.2 {
           66  +  db eval {
           67  +    SELECT a FROM t2 EXCEPT SELECT a FROM t3
           68  +     ORDER BY a COLLATE binary;
           69  +  }
           70  +} {DEF abc}
           71  +do_test selectE-1.3 {
           72  +  db eval {
           73  +    SELECT a FROM t2 EXCEPT SELECT a FROM t3
           74  +     ORDER BY a;
           75  +  }
           76  +} {DEF abc}
           77  +
           78  +do_test selectE-2.1 {
           79  +  db eval {
           80  +    DELETE FROM t2;
           81  +    DELETE FROM t3;
           82  +    INSERT INTO t2 VALUES('ABC'),('def'),('GHI'),('jkl');
           83  +    INSERT INTO t3 SELECT lower(a) FROM t2;
           84  +    SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
           85  +     ORDER BY 1
           86  +  }
           87  +} {}
           88  +do_test selectE-2.2 {
           89  +  db eval {
           90  +    SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
           91  +     ORDER BY 1 COLLATE binary
           92  +  }
           93  +} {}
           94  +
           95  +finish_test

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

Changes to test/where9.test.

   888    888     db eval {
   889    889       SELECT *
   890    890         FROM (t81) LEFT JOIN (main.t82) ON y=b JOIN t83
   891    891        WHERE c==p OR d==p
   892    892        ORDER BY +a;
   893    893     }
   894    894   } {2 3 4 5 {} {} 5 55 3 4 5 6 2 4 5 55}
          895  +
          896  +# Fix for ticket [f2369304e47167e3e644e2f1fe9736063391d7b7]
          897  +# Incorrect results when OR is used in the ON clause of a LEFT JOIN 
          898  +#
          899  +do_test where9-9.1 {
          900  +  db eval {
          901  +    CREATE TABLE t91(x); INSERT INTO t91 VALUES(1);
          902  +    CREATE TABLE t92(y INTEGER PRIMARY KEY,a,b);
          903  +    INSERT INTO t92 VALUES(1,2,3);
          904  +    SELECT 1 FROM t91 LEFT JOIN t92 ON a=2 OR b=3;
          905  +    SELECT 2 FROM t91 LEFT JOIN t92 ON a=2 AND b=3;
          906  +    SELECT 3 FROM t91 LEFT JOIN t92 ON (a=2 OR b=3) AND y IS NULL;
          907  +    SELECT 4 FROM t91 LEFT JOIN t92 ON (a=2 AND b=3) AND y IS NULL;
          908  +    CREATE TEMP TABLE x9 AS SELECT * FROM t91 LEFT JOIN t92 ON a=2 OR b=3;
          909  +    SELECT 5 FROM x9 WHERE y IS NULL;
          910  +    SELECT 6 FROM t91 LEFT JOIN t92 ON a=2 OR b=3 WHERE y IS NULL;
          911  +    SELECT 7 FROM t91 LEFT JOIN t92 ON a=2 AND b=3 WHERE y IS NULL;
          912  +    SELECT 8 FROM t91 LEFT JOIN t92 ON a=22 OR b=33 WHERE y IS NULL;
          913  +    SELECT 9 FROM t91 LEFT JOIN t92 ON a=22 AND b=33 WHERE y IS NULL;
          914  +  }
          915  +} {1 2 3 4 8 9}
   895    916   
   896    917   finish_test

Changes to tool/showdb.c.

   172    172     print_decode_line(aData, 40, 4, "Schema cookie");
   173    173     print_decode_line(aData, 44, 4, "Schema format version");
   174    174     print_decode_line(aData, 48, 4, "Default page cache size");
   175    175     print_decode_line(aData, 52, 4, "Largest auto-vac root page");
   176    176     print_decode_line(aData, 56, 4, "Text encoding");
   177    177     print_decode_line(aData, 60, 4, "User version");
   178    178     print_decode_line(aData, 64, 4, "Incremental-vacuum mode");
   179         -  print_decode_line(aData, 68, 4, "meta[7]");
          179  +  print_decode_line(aData, 68, 4, "Application ID");
   180    180     print_decode_line(aData, 72, 4, "meta[8]");
   181    181     print_decode_line(aData, 76, 4, "meta[9]");
   182    182     print_decode_line(aData, 80, 4, "meta[10]");
   183    183     print_decode_line(aData, 84, 4, "meta[11]");
   184    184     print_decode_line(aData, 88, 4, "meta[12]");
   185    185     print_decode_line(aData, 92, 4, "Change counter for version number");
   186    186     print_decode_line(aData, 96, 4, "SQLite version number");