/ Check-in [163e1522]
Login

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

Overview
Comment:Change SQLITE_TRACE_STMT to return unexpanded SQL text in the X argument. Add documentation on how and when to use sqlite3_expanded_sql(P) to compute the expanded text for legacy sqlite3_trace() compatibility.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 163e15229d837a5471007cffb8d41faafd081737
User & Date: drh 2016-07-25 02:31:48
Context
2016-07-25
02:42
Evidence marks and code reformatting for SQLITE_TRACE_STMT operation. check-in: e1e02238 user: drh tags: trunk
02:31
Change SQLITE_TRACE_STMT to return unexpanded SQL text in the X argument. Add documentation on how and when to use sqlite3_expanded_sql(P) to compute the expanded text for legacy sqlite3_trace() compatibility. check-in: 163e1522 user: drh tags: trunk
00:05
Fix code so that the deprecated sqlite3_trace() and sqlite3_profile() interfaces are not called when SQLITE_OMIT_DEPRECATED is used. check-in: 1c5baae3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqlite.h.in.

  2809   2809   ** <dl>
  2810   2810   ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
  2811   2811   ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
  2812   2812   ** first begins running and possibly at other times during the
  2813   2813   ** execution of the prepared statement, such as at the start of each
  2814   2814   ** trigger subprogram. ^The P argument is a pointer to the
  2815   2815   ** [prepared statement]. ^The X argument is a pointer to a string which
  2816         -** is the expanded SQL text of the prepared statement or a comment that
  2817         -** indicates the invocation of a trigger.
         2816  +** is the unexpanded SQL text of the prepared statement or an SQL comment 
         2817  +** that indicates the invocation of a trigger.  ^The callback can compute
         2818  +** the same text that would have been returned by the legacy [sqlite3_trace()]
         2819  +** interface by using the X argument when X begins with "--" and invoking
         2820  +** [sqlite3_expanded_sql(P)] otherwise.
  2818   2821   **
  2819   2822   ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
  2820   2823   ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
  2821   2824   ** information as is provided by the [sqlite3_profile()] callback.
  2822   2825   ** ^The P argument is a pointer to the [prepared statement] and the
  2823   2826   ** X argument points to a 64-bit integer which is the estimated of
  2824   2827   ** the number of nanosecond that the prepared statement took to run.

Changes to src/vdbe.c.

  6781   6781   ** If P2 is not zero, jump to instruction P2.
  6782   6782   */
  6783   6783   case OP_Init: {          /* jump */
  6784   6784     char *zTrace;
  6785   6785     char *z;
  6786   6786   
  6787   6787   #ifndef SQLITE_OMIT_TRACE
         6788  +  /* If the P4 argument is not NULL, then it must be an SQL comment string.
         6789  +  ** The "--" string is broken up to prevent false-positives with srcck1.c */
         6790  +  assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
  6788   6791     if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
  6789   6792      && !p->doingRerun
  6790   6793      && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
  6791   6794     ){
  6792         -    z = sqlite3VdbeExpandSql(p, zTrace);
  6793   6795   #ifndef SQLITE_OMIT_DEPRECATED
  6794   6796       if( db->mTrace & SQLITE_TRACE_LEGACY ){
  6795   6797         void (*x)(void*,const char*) = (void(*)(void*,const char*))db->xTrace;
         6798  +      z = sqlite3VdbeExpandSql(p, zTrace);
  6796   6799         x(db->pTraceArg, z);
         6800  +      sqlite3_free(z);
  6797   6801       }else
  6798   6802   #endif
  6799   6803       {
  6800         -      (void)db->xTrace(SQLITE_TRACE_STMT,db->pTraceArg,p,z);
         6804  +      (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace);
  6801   6805       }
  6802         -    sqlite3_free(z);
  6803   6806     }
  6804   6807   #ifdef SQLITE_USE_FCNTL_TRACE
  6805   6808     zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
  6806   6809     if( zTrace ){
  6807   6810       int i;
  6808   6811       for(i=0; i<db->nDb; i++){
  6809   6812         if( DbMaskTest(p->btreeMask, i)==0 ) continue;

Changes to tool/srcck1.c.

    54     54              (int)got, (int)n, zFilename);
    55     55       exit(1);
    56     56     }
    57     57     z[n] = 0;
    58     58     return z;
    59     59   }
    60     60   
    61         -/* Change the C code in the argument to see if it might have
           61  +/* Check the C code in the argument to see if it might have
    62     62   ** side effects.  The only accurate way to know this is to do a full
    63     63   ** parse of the C code, which this routine does not do.  This routine
    64     64   ** uses a simple heuristic of looking for:
    65     65   **
    66     66   **    *  '=' not immediately after '>', '<', '!', or '='.
    67     67   **    *  '++'
    68     68   **    *  '--'