SQLite

Check-in [ebd388e94d]
Login

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

Overview
Comment:Add requirements marks to the sqlite3_trace_v2() interface documentation.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sqlite3_trace_v2
Files: files | file ages | folders
SHA1: ebd388e94da4a2b29c2a546f832d359619803ec5
User & Date: drh 2016-07-23 02:07:26.475
Context
2016-07-23
04:58
Improvements to sqlite3_trace_v2() documentation. Fix the sqlite3VdbeExpandSql() routine to respond better to OOM conditions. (Closed-Leaf check-in: 0400f642d5 user: drh tags: sqlite3_trace_v2)
02:07
Add requirements marks to the sqlite3_trace_v2() interface documentation. (check-in: ebd388e94d user: drh tags: sqlite3_trace_v2)
00:43
Fix sqlite3VdbeExpandSql() so that it handles OOMs by always returning NULL. (check-in: 5a027fe412 user: drh tags: sqlite3_trace_v2)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to src/sqlite.h.in.
2791
2792
2793
2794
2795
2796
2797
2798

2799
2800
2801
2802
2803
2804
2805



2806
2807
2808
2809
2810
2811

2812
2813
2814
2815


2816
2817
2818
2819
2820

2821
2822
2823


2824
2825

2826
2827
2828

2829
2830

2831
2832
2833
2834

2835
2836

2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849

2850
2851

2852
2853
2854
2855
2856

2857
2858
2859
2860


2861
2862
2863
2864
2865


2866
2867

2868
2869
2870
2871
2872
2873
2874
2791
2792
2793
2794
2795
2796
2797

2798
2799
2800
2801
2802



2803
2804
2805
2806
2807
2808
2809
2810

2811
2812
2813


2814
2815
2816
2817
2818
2819

2820
2821


2822
2823
2824

2825
2826
2827

2828
2829

2830
2831
2832
2833

2834
2835

2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848

2849
2850

2851
2852
2853
2854
2855

2856
2857
2858


2859
2860
2861
2862
2863


2864
2865
2866

2867
2868
2869
2870
2871
2872
2873
2874







-
+




-
-
-
+
+
+





-
+


-
-
+
+




-
+

-
-
+
+

-
+


-
+

-
+



-
+

-
+












-
+

-
+




-
+


-
-
+
+



-
-
+
+

-
+







/*
** CAPI3REF: SQL Trace Event Codes
** KEYWORDS: SQLITE_TRACE
**
** These constants identify classes of events that can be monitored
** using the [sqlite3_trace_v2()] tracing logic.  The third argument
** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
** the following constants.  The first argument to the trace callback
** the following constants.  ^The first argument to the trace callback
** is one of the following constants.
**
** New tracing constants may be added in future releases.
**
** A trace callback has four arguments: xCallback(T,C,P,X).
** The T argument is one of the integer type codes above.
** The C argument is a copy of the context pointer passed in as the
** ^A trace callback has four arguments: xCallback(T,C,P,X).
** ^The T argument is one of the integer type codes above.
** ^The C argument is a copy of the context pointer passed in as the
** fourth argument to [sqlite3_trace_v2()].
** The P and X arguments are pointers whose meanings depend on T.
**
** <dl>
** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
** <dd>An SQLITE_TRACE_STMT callback is invoked when a prepared statement
** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
** first begins running and possibly at other times during the
** execution of the prepared statement, such as at the start of each
** trigger subprogram.  The P argument is a pointer to the
** [prepared statement].  The X argument is a pointer to a string which
** trigger subprogram. ^The P argument is a pointer to the
** [prepared statement]. ^The X argument is a pointer to a string which
** is the expanded SQL text of the prepared statement or a comment that
** indicates the invocation of a trigger.
**
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
** <dd>An SQLITE_TRACE_PROFILE callback provides approximately the same
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
** information as is provided by the [sqlite3_profile()] callback.
** The P argument is a pointer to the [prepared statement] and the
** X argument points to a 64-bit integer which is the estimated of
** ^The P argument is a pointer to the [prepared statement] and the
** ^X argument points to a 64-bit integer which is the estimated of
** the number of nanosecond that the prepared statement took to run.
** The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
**
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
** <dd>An SQLITE_TRACE_ROW callback is invoked whenever a prepared
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
** statement generates a single row of result.  
** The P argument is a pointer to the [prepared statement] and the
** ^The P argument is a pointer to the [prepared statement] and the
** X argument is unused.
**
** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
** <dd>An SQLITE_TRACE_CLOSE callback is invoked when a database
** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
** connection closes.
** The P argument is a pointer to the [database connection] object
** ^The P argument is a pointer to the [database connection] object
** and the X argument is unused.
** </dl>
*/
#define SQLITE_TRACE_STMT       0x01
#define SQLITE_TRACE_PROFILE    0x02
#define SQLITE_TRACE_ROW        0x04
#define SQLITE_TRACE_CLOSE      0x08

/*
** CAPI3REF: SQL Trace Hook
** METHOD: sqlite3
**
** The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
** function X against [database connection] D, using property mask M
** and context pointer P.  If the X callback is
** and context pointer P.  ^If the X callback is
** NULL or if the M mask is zero, then tracing is disabled.  The
** M argument must be one or more of the [SQLITE_TRACE]
** constants.
**
** Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides 
** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides 
** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
**
** The X callback is invoked whenever any of the events identified by 
** mask M occur.  The integer return value from the callback is currently
** ^The X callback is invoked whenever any of the events identified by 
** mask M occur.  ^The integer return value from the callback is currently
** ignored, though this may change in future releases.  Callback
** implementations should return zero to ensure future compatibility.
**
** A trace callback is invoked with four arguments: callback(T,C,P,X).
** The T argument is one of the [SQLITE_TRACE]
** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
** ^The T argument is one of the [SQLITE_TRACE]
** constants to indicate why the callback was invoked.
** The C argument is a copy of the context pointer.
** ^The C argument is a copy of the context pointer.
** The P and X arguments are pointers whose meanings depend on T.
**
** The sqlite3_trace_v2() interface is intended to replace the legacy
** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
** are deprecated.
*/
int sqlite3_trace_v2(
Changes to src/vdbeapi.c.
1607
1608
1609
1610
1611
1612
1613

































1614
1615
1616
1617
1618
1619
1620
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    return 0;
  }
#endif
  v = pVdbe->aCounter[op];
  if( resetFlag ) pVdbe->aCounter[op] = 0;
  return (int)v;
}

/*
** Return the SQL associated with a prepared statement
*/
const char *sqlite3_sql(sqlite3_stmt *pStmt){
  Vdbe *p = (Vdbe *)pStmt;
  return p ? p->zSql : 0;
}

/*
** Return the SQL associated with a prepared statement with
** bound parameters expanded.  Space to hold the returned string is
** obtained from sqlite3_malloc().  The caller is responsible for
** freeing the returned string by passing it to sqlite3_free().
**
** The SQLITE_TRACE_SIZE_LIMIT puts an upper bound on the size of
** expanded bound parameters.
*/
char *sqlite3_expanded_sql(sqlite3_stmt *pStmt){
#ifdef SQLITE_OMIT_TRACE
  return 0;
#else
  char *z = 0;
  const char *zSql = sqlite3_sql(pStmt);
  if( zSql ){
    Vdbe *p = (Vdbe *)pStmt;
    sqlite3_mutex_enter(p->db->mutex);
    z = sqlite3VdbeExpandSql(p, zSql);
    sqlite3_mutex_leave(p->db->mutex);
  }
  return z;
#endif
}

#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
/*
** Allocate and populate an UnpackedRecord structure based on the serialized
** record in nKey/pKey. Return a pointer to the new UnpackedRecord structure
** if successful, or a NULL pointer if an OOM error is encountered.
*/
Changes to src/vdbeaux.c.
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
60
61
62
63
64
65
66

































67
68
69
70
71
72
73







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







  if( !isPrepareV2 ) return;
#endif
  assert( p->zSql==0 );
  p->zSql = sqlite3DbStrNDup(p->db, z, n);
  p->isPrepareV2 = (u8)isPrepareV2;
}

/*
** Return the SQL associated with a prepared statement
*/
const char *sqlite3_sql(sqlite3_stmt *pStmt){
  Vdbe *p = (Vdbe *)pStmt;
  return p ? p->zSql : 0;
}

/*
** Return the SQL associated with a prepared statement with
** bound parameters expanded.  Space to hold the returned string is
** obtained from sqlite3_malloc().  The caller is responsible for
** freeing the returned string by passing it to sqlite3_free().
**
** The SQLITE_TRACE_SIZE_LIMIT puts an upper bound on the size of
** expanded bound parameters.
*/
char *sqlite3_expanded_sql(sqlite3_stmt *pStmt){
#ifdef SQLITE_OMIT_TRACE
  return 0;
#else
  char *z = 0;
  const char *zSql = sqlite3_sql(pStmt);
  if( zSql ){
    Vdbe *p = (Vdbe *)pStmt;
    sqlite3_mutex_enter(p->db->mutex);
    z = sqlite3VdbeExpandSql(p, zSql);
    sqlite3_mutex_leave(p->db->mutex);
  }
  return z;
#endif
}

/*
** Swap all content between two VDBE structures.
*/
void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
  Vdbe tmp, *pTmp;
  char *zTmp;
  assert( pA->db==pB->db );
Changes to src/vdbetrace.c.
137
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
137
138
139
140
141
142
143


144
145
146
147
148
149
150
151
152







-
-
+
+







      }else if( pVar->flags & MEM_Str ){
        int nOut;  /* Number of bytes of the string text to include in output */
#ifndef SQLITE_OMIT_UTF16
        u8 enc = ENC(db);
        if( enc!=SQLITE_UTF8 ){
          memset(&utf8, 0, sizeof(utf8));
          utf8.db = db;
          if( SQLITE_NOMEM== sqlite3VdbeMemSetStr(&utf8,pVar->z,pVar->n,enc,SQLITE_STATIC)
           || SQLITE_NOMEM== sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8)
          if( SQLITE_NOMEM==sqlite3VdbeMemSetStr(&utf8,pVar->z,pVar->n,enc,SQLITE_STATIC)
           || SQLITE_NOMEM==sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8)
          ){
            sqlite3StrAccumReset(&out);
            sqlite3VdbeMemRelease(&utf8);
            return 0;
          }
          pVar = &utf8;
        }