SQLite

Check-in [01d5451af0]
Login

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

Overview
Comment:Get trace with parameter insertion working for UTF16 databases.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 01d5451af0bd2743eb74b98f2e77dd2c75f403b6
User & Date: drh 2009-11-25 19:35:23.000
Context
2009-11-25
21:05
Support zeroblob in trace output. (check-in: 5086bf8e83 user: drh tags: trunk)
19:35
Get trace with parameter insertion working for UTF16 databases. (check-in: 01d5451af0 user: drh tags: trunk)
18:03
Initial check-in of code that inserts tokenizations of the values for bound parameters into the output of sqlite3_trace(). (check-in: 545cfb3b63 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbetrace.c.
89
90
91
92
93
94
95



96
97
98
99
100
101
102
          zRawSql++;
        }
      }else{
        idx = nextIndex;
      }
    }else{
      assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );



      n = sqlite3GetToken((u8*)zRawSql, &dummy);
      idx = 0;
      for(i=0, pOp=p->aOp; ALWAYS(i<p->nOp); i++, pOp++){
        if( pOp->opcode!=OP_Variable ) continue;
        if( pOp->p3>1 ) continue;
        if( memcmp(pOp->p4.z, zRawSql, n)==0 && pOp->p4.z[n]==0 ){
          idx = pOp->p1;







>
>
>







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
          zRawSql++;
        }
      }else{
        idx = nextIndex;
      }
    }else{
      assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
      testcase( zRawSql[0]==':' );
      testcase( zRawSql[0]=='$' );
      testcase( zRawSql[0]=='@' );
      n = sqlite3GetToken((u8*)zRawSql, &dummy);
      idx = 0;
      for(i=0, pOp=p->aOp; ALWAYS(i<p->nOp); i++, pOp++){
        if( pOp->opcode!=OP_Variable ) continue;
        if( pOp->p3>1 ) continue;
        if( memcmp(pOp->p4.z, zRawSql, n)==0 && pOp->p4.z[n]==0 ){
          idx = pOp->p1;
112
113
114
115
116
117
118












119

120
121
122
123
124
125
126
127
128
129
130
131
132
    if( pVar->flags & MEM_Null ){
      sqlite3StrAccumAppend(&out, "NULL", 4);
    }else if( pVar->flags & MEM_Int ){
      sqlite3XPrintf(&out, "%lld", pVar->u.i);
    }else if( pVar->flags & MEM_Real ){
      sqlite3XPrintf(&out, "%!.15g", pVar->r);
    }else if( pVar->flags & MEM_Str ){












      sqlite3XPrintf(&out, "'%.*q'", pVar->n, pVar->z);

    }else{
      assert( pVar->flags & MEM_Blob );
      sqlite3StrAccumAppend(&out, "x'", 2);
      for(i=0; i<pVar->n; i++){
        sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
      }
      sqlite3StrAccumAppend(&out, "'", 1);
    }
  }
  return sqlite3StrAccumFinish(&out);
}

#endif /* #ifndef SQLITE_OMIT_TRACE */







>
>
>
>
>
>
>
>
>
>
>
>
|
>













115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    if( pVar->flags & MEM_Null ){
      sqlite3StrAccumAppend(&out, "NULL", 4);
    }else if( pVar->flags & MEM_Int ){
      sqlite3XPrintf(&out, "%lld", pVar->u.i);
    }else if( pVar->flags & MEM_Real ){
      sqlite3XPrintf(&out, "%!.15g", pVar->r);
    }else if( pVar->flags & MEM_Str ){
#ifndef SQLITE_OMIT_UTF16
      if( ENC(db)!=SQLITE_UTF8 ){
        Mem utf8;
        memset(&utf8, 0, sizeof(utf8));
        utf8.db = db;
        sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, ENC(db), SQLITE_STATIC);
        sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8);
        sqlite3XPrintf(&out, "'%.*q'", utf8.n, utf8.z);
        sqlite3VdbeMemRelease(&utf8);
      }else
#endif
      {
        sqlite3XPrintf(&out, "'%.*q'", pVar->n, pVar->z);
      }
    }else{
      assert( pVar->flags & MEM_Blob );
      sqlite3StrAccumAppend(&out, "x'", 2);
      for(i=0; i<pVar->n; i++){
        sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
      }
      sqlite3StrAccumAppend(&out, "'", 1);
    }
  }
  return sqlite3StrAccumFinish(&out);
}

#endif /* #ifndef SQLITE_OMIT_TRACE */
Changes to test/trace.test.
179
180
181
182
183
184
185


















































186
187
  unset -nocomplain t6null
  set TRACE_OUT {}
  execsql {SELECT $::t6int, $::t6real, $t6str, $t6blob, $t6null}
} {6 6.0 {test-six y'all} 01234 {}}
do_test trace-6.2 {
  set TRACE_OUT
} {{SELECT 6, 6.0, 'test-six y''all', x'3031323334', NULL}}



















































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  unset -nocomplain t6null
  set TRACE_OUT {}
  execsql {SELECT $::t6int, $::t6real, $t6str, $t6blob, $t6null}
} {6 6.0 {test-six y'all} 01234 {}}
do_test trace-6.2 {
  set TRACE_OUT
} {{SELECT 6, 6.0, 'test-six y''all', x'3031323334', NULL}}
do_test trace-6.3 {
  set TRACE_OUT {}
  execsql {SELECT $::t6int, ?1, $::t6int}
} {6 6 6}
do_test trace-6.4 {
  set TRACE_OUT
} {{SELECT 6, 6, 6}}
do_test trace-6.5 {
  execsql {CREATE TABLE t6([$::t6int],"?1"); INSERT INTO t6 VALUES(1,2)}
  set TRACE_OUT {}
  execsql {SELECT '$::t6int', [$::t6int], $::t6int, ?1, "?1", $::t6int FROM t6}
} {{$::t6int} 1 6 6 2 6}
do_test trace-6.6 {
  set TRACE_OUT
} {{SELECT '$::t6int', [$::t6int], 6, 6, "?1", 6 FROM t6}}

# Do these same tests with a UTF16 database.
#
do_test trace-6.100 {
  db close
  sqlite3 db :memory:
  db eval {
     PRAGMA encoding=UTF16be;
     CREATE TABLE t6([$::t6str],"?1");
     INSERT INTO t6 VALUES(1,2);
  }
  db trace trace_proc
  set TRACE_OUT {}
  execsql {SELECT '$::t6str', [$::t6str], $::t6str, ?1, "?1", $::t6str FROM t6}
} {{$::t6str} 1 {test-six y'all} {test-six y'all} 2 {test-six y'all}}
do_test trace-6.101 {
  set TRACE_OUT
} {{SELECT '$::t6str', [$::t6str], 'test-six y''all', 'test-six y''all', "?1", 'test-six y''all' FROM t6}}

do_test trace-6.200 {
  db close
  sqlite3 db :memory:
  db eval {
     PRAGMA encoding=UTF16le;
     CREATE TABLE t6([$::t6str],"?1");
     INSERT INTO t6 VALUES(1,2);
  }
  db trace trace_proc
  set TRACE_OUT {}
  execsql {SELECT '$::t6str', [$::t6str], $::t6str, ?1, "?1", $::t6str FROM t6}
} {{$::t6str} 1 {test-six y'all} {test-six y'all} 2 {test-six y'all}}
do_test trace-6.101 {
  set TRACE_OUT
} {{SELECT '$::t6str', [$::t6str], 'test-six y''all', 'test-six y''all', "?1", 'test-six y''all' FROM t6}}


finish_test