/ Check-in [a8076aed]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Log all error messages if logging is enabled.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a8076aede33c07e9a2aaa05be8a888f37b45e41c
User & Date: drh 2010-02-22 19:32:32
References
2010-02-25
02:32
Merge in all of the logging enhancements. This is a cherrypick merge of the following check-ins: [103321e37a], [a8076aede3], [6d910245ad], [7c4cca6d1a], [edea3bb740], [1a6d4bb130], [a8c984c1d6], [69a493182f], and [1168763d2c]. check-in: 46f406b2 user: drh tags: branch-3.6.22
Context
2010-02-22
19:37
Merge in the massive clean-up and ANSI-fication of Lemon carried out by Ryan Gordon. There are no functional changes to SQLite itself - Lemon still generates exactly the same parsing automaton from exactly the same grammar. check-in: 1e8b8420 user: drh tags: trunk
19:32
Log all error messages if logging is enabled. check-in: a8076aed user: drh tags: trunk
2010-02-19
04:28
Changes to pragma integrity_check to check rowid order. Tests of same in corruptE.test. check-in: cae47c5b user: shaneh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/backup.c.

    94     94       pParse = sqlite3StackAllocZero(pErrorDb, sizeof(*pParse));
    95     95       if( pParse==0 ){
    96     96         sqlite3Error(pErrorDb, SQLITE_NOMEM, "out of memory");
    97     97         rc = SQLITE_NOMEM;
    98     98       }else{
    99     99         pParse->db = pDb;
   100    100         if( sqlite3OpenTempDatabase(pParse) ){
   101         -        sqlite3ErrorClear(pParse);
   102    101           sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
   103    102           rc = SQLITE_ERROR;
   104    103         }
          104  +      sqlite3DbFree(pErrorDb, pParse->zErrMsg);
   105    105         sqlite3StackFree(pErrorDb, pParse);
   106    106       }
   107    107       if( rc ){
   108    108         return 0;
   109    109       }
   110    110     }
   111    111   

Changes to src/build.c.

  1970   1970     int iDb;
  1971   1971   
  1972   1972     if( db->mallocFailed ){
  1973   1973       goto exit_drop_table;
  1974   1974     }
  1975   1975     assert( pParse->nErr==0 );
  1976   1976     assert( pName->nSrc==1 );
         1977  +  if( noErr ) db->suppressErr++;
  1977   1978     pTab = sqlite3LocateTable(pParse, isView, 
  1978   1979                               pName->a[0].zName, pName->a[0].zDatabase);
         1980  +  if( noErr ) db->suppressErr--;
  1979   1981   
  1980   1982     if( pTab==0 ){
  1981         -    if( noErr ){
  1982         -      sqlite3ErrorClear(pParse);
  1983         -    }
  1984   1983       goto exit_drop_table;
  1985   1984     }
  1986   1985     iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  1987   1986     assert( iDb>=0 && iDb<db->nDb );
  1988   1987   
  1989   1988     /* If pTab is a virtual table, call ViewGetColumnNames() to ensure
  1990   1989     ** it is initialized.

Changes to src/printf.c.

   938    938     z = sqlite3StrAccumFinish(&acc);
   939    939     return z;
   940    940   }
   941    941   
   942    942   /*
   943    943   ** Format and write a message to the log if logging is enabled.
   944    944   */
   945         -void sqlite3_log(int iPriority, const char *zFormat, ...){
          945  +void sqlite3_log(int iErrCode, const char *zFormat, ...){
   946    946     void (*xLog)(void*, int, const char*);  /* The global logger function */
   947    947     void *pLogArg;                          /* First argument to the logger */
   948    948     va_list ap;                             /* Vararg list */
   949    949     char *zMsg;                             /* Complete log message */
   950    950     
   951    951     xLog = sqlite3GlobalConfig.xLog;
   952         -  if( xLog ){
          952  +  if( xLog && zFormat ){
   953    953       va_start(ap, zFormat);
   954    954       sqlite3BeginBenignMalloc();
   955    955       zMsg = sqlite3_vmprintf(zFormat, ap);
   956    956       sqlite3EndBenignMalloc();
   957    957       va_end(ap);
   958    958       pLogArg = sqlite3GlobalConfig.pLogArg;
   959         -    xLog(pLogArg, iPriority, zMsg ? zMsg : zFormat);
          959  +    xLog(pLogArg, iErrCode, zMsg ? zMsg : zFormat);
   960    960       sqlite3_free(zMsg);
   961    961     }
   962    962   }
   963    963   
   964    964   #if defined(SQLITE_DEBUG)
   965    965   /*
   966    966   ** A version of printf() that understands %lld.  Used for debugging.

Changes to src/resolve.c.

   660    660     Parse *pParse,     /* Parsing context for error messages */
   661    661     Select *pSelect,   /* The SELECT statement with the ORDER BY clause */
   662    662     Expr *pE           /* The specific ORDER BY term */
   663    663   ){
   664    664     int i;             /* Loop counter */
   665    665     ExprList *pEList;  /* The columns of the result set */
   666    666     NameContext nc;    /* Name context for resolving pE */
          667  +  sqlite3 *db;       /* Database connection */
          668  +  int rc;            /* Return code from subprocedures */
          669  +  u8 savedSuppErr;   /* Saved value of db->suppressErr */
   667    670   
   668    671     assert( sqlite3ExprIsInteger(pE, &i)==0 );
   669    672     pEList = pSelect->pEList;
   670    673   
   671    674     /* Resolve all names in the ORDER BY term expression
   672    675     */
   673    676     memset(&nc, 0, sizeof(nc));
   674    677     nc.pParse = pParse;
   675    678     nc.pSrcList = pSelect->pSrc;
   676    679     nc.pEList = pEList;
   677    680     nc.allowAgg = 1;
   678    681     nc.nErr = 0;
   679         -  if( sqlite3ResolveExprNames(&nc, pE) ){
   680         -    sqlite3ErrorClear(pParse);
   681         -    return 0;
   682         -  }
          682  +  db = pParse->db;
          683  +  savedSuppErr = db->suppressErr;
          684  +  db->suppressErr = 1;
          685  +  rc = sqlite3ResolveExprNames(&nc, pE);
          686  +  db->suppressErr = savedSuppErr;
          687  +  if( rc ) return 0;
   683    688   
   684    689     /* Try to match the ORDER BY expression against an expression
   685    690     ** in the result set.  Return an 1-based index of the matching
   686    691     ** result-set entry.
   687    692     */
   688    693     for(i=0; i<pEList->nExpr; i++){
   689    694       if( sqlite3ExprCompare(pEList->a[i].pExpr, pE)<2 ){

Changes to src/sqlite.h.in.

  5671   5671   ** established by the [SQLITE_CONFIG_ERRORLOG] option to [sqlite3_config()].
  5672   5672   **
  5673   5673   ** The sqlite3_log() interface is intended for use by extensions such as
  5674   5674   ** virtual tables, collating functions, and SQL functions.  While there is
  5675   5675   ** nothing to prevent an application from calling sqlite3_log(), doing so
  5676   5676   ** is considered bad form.
  5677   5677   */
  5678         -void sqlite3_log(int iPriority, const char *zFormat, ...);
         5678  +void sqlite3_log(int iErrCode, const char *zFormat, ...);
  5679   5679   
  5680   5680   /*
  5681   5681   ** Undo the hack that converts floating point types to integer for
  5682   5682   ** builds on processors without floating point support.
  5683   5683   */
  5684   5684   #ifdef SQLITE_OMIT_FLOATING_POINT
  5685   5685   # undef double
  5686   5686   #endif
  5687   5687   
  5688   5688   #ifdef __cplusplus
  5689   5689   }  /* End of the 'extern "C"' block */
  5690   5690   #endif
  5691   5691   #endif

Changes to src/sqliteInt.h.

   790    790     int errMask;                  /* & result codes with this before returning */
   791    791     u8 autoCommit;                /* The auto-commit flag. */
   792    792     u8 temp_store;                /* 1: file 2: memory 0: default */
   793    793     u8 mallocFailed;              /* True if we have seen a malloc failure */
   794    794     u8 dfltLockMode;              /* Default locking-mode for attached dbs */
   795    795     u8 dfltJournalMode;           /* Default journal mode for attached dbs */
   796    796     signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
          797  +  u8 suppressErr;               /* Do not issue error messages if true */
   797    798     int nextPagesize;             /* Pagesize after VACUUM if >0 */
   798    799     int nTable;                   /* Number of tables in the database */
   799    800     CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
   800    801     i64 lastRowid;                /* ROWID of most recent insert (see above) */
   801    802     u32 magic;                    /* Magic number for detect library misuse */
   802    803     int nChange;                  /* Value returned by sqlite3_changes() */
   803    804     int nTotalChange;             /* Value returned by sqlite3_total_changes() */
................................................................................
  2550   2551     void sqlite3DebugPrintf(const char*, ...);
  2551   2552   #endif
  2552   2553   #if defined(SQLITE_TEST)
  2553   2554     void *sqlite3TestTextToPtr(const char*);
  2554   2555   #endif
  2555   2556   void sqlite3SetString(char **, sqlite3*, const char*, ...);
  2556   2557   void sqlite3ErrorMsg(Parse*, const char*, ...);
  2557         -void sqlite3ErrorClear(Parse*);
  2558   2558   int sqlite3Dequote(char*);
  2559   2559   int sqlite3KeywordCode(const unsigned char*, int);
  2560   2560   int sqlite3RunParser(Parse*, const char*, char **);
  2561   2561   void sqlite3FinishCoding(Parse*);
  2562   2562   int sqlite3GetTempReg(Parse*);
  2563   2563   void sqlite3ReleaseTempReg(Parse*,int);
  2564   2564   int sqlite3GetTempRange(Parse*,int);

Changes to src/util.c.

   119    119       db->errCode = err_code;
   120    120       if( zFormat ){
   121    121         char *z;
   122    122         va_list ap;
   123    123         va_start(ap, zFormat);
   124    124         z = sqlite3VMPrintf(db, zFormat, ap);
   125    125         va_end(ap);
          126  +      sqlite3_log(err_code, z);
   126    127         sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
   127    128       }else{
   128    129         sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
   129    130       }
   130    131     }
   131    132   }
   132    133   
................................................................................
   144    145   ** compiling an SQL statement (i.e. within sqlite3_prepare()). The
   145    146   ** last thing the sqlite3_prepare() function does is copy the error
   146    147   ** stored by this function into the database handle using sqlite3Error().
   147    148   ** Function sqlite3Error() should be used during statement execution
   148    149   ** (sqlite3_step() etc.).
   149    150   */
   150    151   void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
          152  +  char *zMsg;
   151    153     va_list ap;
   152    154     sqlite3 *db = pParse->db;
   153         -  pParse->nErr++;
   154         -  sqlite3DbFree(db, pParse->zErrMsg);
   155    155     va_start(ap, zFormat);
   156         -  pParse->zErrMsg = sqlite3VMPrintf(db, zFormat, ap);
          156  +  zMsg = sqlite3VMPrintf(db, zFormat, ap);
   157    157     va_end(ap);
   158         -  pParse->rc = SQLITE_ERROR;
   159         -}
   160         -
   161         -/*
   162         -** Clear the error message in pParse, if any
   163         -*/
   164         -void sqlite3ErrorClear(Parse *pParse){
   165         -  sqlite3DbFree(pParse->db, pParse->zErrMsg);
   166         -  pParse->zErrMsg = 0;
   167         -  pParse->nErr = 0;
          158  +  if( db->suppressErr ){
          159  +    sqlite3DbFree(db, zMsg);
          160  +  }else{
          161  +    pParse->nErr++;
          162  +    sqlite3DbFree(db, pParse->zErrMsg);
          163  +    pParse->zErrMsg = zMsg;
          164  +    pParse->rc = SQLITE_ERROR;
          165  +    sqlite3_log(SQLITE_ERROR, pParse->zErrMsg);
          166  +  }
   168    167   }
   169    168   
   170    169   /*
   171    170   ** Convert an SQL-style quoted string into a normal string by removing
   172    171   ** the quote characters.  The conversion is done in-place.  If the
   173    172   ** input does not begin with a quote character, then this routine
   174    173   ** is a no-op.