/ Check-in [01d5451a]
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 | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 01d5451af0bd2743eb74b98f2e77dd2c75f403b6
User & Date: drh 2009-11-25 19:35:23
Context
2009-11-25
21:05
Support zeroblob in trace output. check-in: 5086bf8e user: drh tags: trunk
19:35
Get trace with parameter insertion working for UTF16 databases. check-in: 01d5451a 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: 545cfb3b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbetrace.c.

    89     89             zRawSql++;
    90     90           }
    91     91         }else{
    92     92           idx = nextIndex;
    93     93         }
    94     94       }else{
    95     95         assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
           96  +      testcase( zRawSql[0]==':' );
           97  +      testcase( zRawSql[0]=='$' );
           98  +      testcase( zRawSql[0]=='@' );
    96     99         n = sqlite3GetToken((u8*)zRawSql, &dummy);
    97    100         idx = 0;
    98    101         for(i=0, pOp=p->aOp; ALWAYS(i<p->nOp); i++, pOp++){
    99    102           if( pOp->opcode!=OP_Variable ) continue;
   100    103           if( pOp->p3>1 ) continue;
   101    104           if( memcmp(pOp->p4.z, zRawSql, n)==0 && pOp->p4.z[n]==0 ){
   102    105             idx = pOp->p1;
................................................................................
   112    115       if( pVar->flags & MEM_Null ){
   113    116         sqlite3StrAccumAppend(&out, "NULL", 4);
   114    117       }else if( pVar->flags & MEM_Int ){
   115    118         sqlite3XPrintf(&out, "%lld", pVar->u.i);
   116    119       }else if( pVar->flags & MEM_Real ){
   117    120         sqlite3XPrintf(&out, "%!.15g", pVar->r);
   118    121       }else if( pVar->flags & MEM_Str ){
   119         -      sqlite3XPrintf(&out, "'%.*q'", pVar->n, pVar->z);
          122  +#ifndef SQLITE_OMIT_UTF16
          123  +      if( ENC(db)!=SQLITE_UTF8 ){
          124  +        Mem utf8;
          125  +        memset(&utf8, 0, sizeof(utf8));
          126  +        utf8.db = db;
          127  +        sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, ENC(db), SQLITE_STATIC);
          128  +        sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8);
          129  +        sqlite3XPrintf(&out, "'%.*q'", utf8.n, utf8.z);
          130  +        sqlite3VdbeMemRelease(&utf8);
          131  +      }else
          132  +#endif
          133  +      {
          134  +        sqlite3XPrintf(&out, "'%.*q'", pVar->n, pVar->z);
          135  +      }
   120    136       }else{
   121    137         assert( pVar->flags & MEM_Blob );
   122    138         sqlite3StrAccumAppend(&out, "x'", 2);
   123    139         for(i=0; i<pVar->n; i++){
   124    140           sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
   125    141         }
   126    142         sqlite3StrAccumAppend(&out, "'", 1);
   127    143       }
   128    144     }
   129    145     return sqlite3StrAccumFinish(&out);
   130    146   }
   131    147   
   132    148   #endif /* #ifndef SQLITE_OMIT_TRACE */

Changes to test/trace.test.

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