/ Check-in [a16ffb5a]
Login

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

Overview
Comment:Ensure that the sqlite3_exec() callback gets the correct number of columns for a query, even if the schema changes out from under it.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:a16ffb5a4b30f1ac4a8384fccde0a0f69e49545b6f9be9267928609328c4a151
User & Date: drh 2019-02-04 19:12:54
Context
2019-02-04
19:45
Enhance dbfuzz2 so that with the -v option it shows the return code and error message for any failing SQL statements. check-in: 3a127ef9 user: drh tags: trunk
19:12
Ensure that the sqlite3_exec() callback gets the correct number of columns for a query, even if the schema changes out from under it. check-in: a16ffb5a user: drh tags: trunk
16:42
Do not run shmlock.test as part of the inmemory_journal permutation. check-in: d3fea69c user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/legacy.c.

    42     42   
    43     43     if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
    44     44     if( zSql==0 ) zSql = "";
    45     45   
    46     46     sqlite3_mutex_enter(db->mutex);
    47     47     sqlite3Error(db, SQLITE_OK);
    48     48     while( rc==SQLITE_OK && zSql[0] ){
    49         -    int nCol;
           49  +    int nCol = 0;
    50     50       char **azVals = 0;
    51     51   
    52     52       pStmt = 0;
    53     53       rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
    54     54       assert( rc==SQLITE_OK || pStmt==0 );
    55     55       if( rc!=SQLITE_OK ){
    56     56         continue;
    57     57       }
    58     58       if( !pStmt ){
    59     59         /* this happens for a comment or white-space */
    60     60         zSql = zLeftover;
    61     61         continue;
    62     62       }
    63         -
    64     63       callbackIsInit = 0;
    65         -    nCol = sqlite3_column_count(pStmt);
    66     64   
    67     65       while( 1 ){
    68     66         int i;
    69     67         rc = sqlite3_step(pStmt);
    70     68   
    71     69         /* Invoke the callback function if required */
    72     70         if( xCallback && (SQLITE_ROW==rc || 
    73     71             (SQLITE_DONE==rc && !callbackIsInit
    74     72                              && db->flags&SQLITE_NullCallback)) ){
    75     73           if( !callbackIsInit ){
           74  +          nCol = sqlite3_column_count(pStmt);
    76     75             azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
    77     76             if( azCols==0 ){
    78     77               goto exec_out;
    79     78             }
    80     79             for(i=0; i<nCol; i++){
    81     80               azCols[i] = (char *)sqlite3_column_name(pStmt, i);
    82     81               /* sqlite3VdbeSetColName() installs column names as UTF8