/ Check-in [bfce9142]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Change the way sqlite3VdbeSetColName() is called so as to remove a few lines of code. This also fixes #3470. (CVS 5853)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bfce91429b1dad6e0ca36929e41a7adfb30f8522
User & Date: danielk1977 2008-10-31 10:53:23
Context
2008-10-31
13:57
Test that single byte corruptions in increasingly larger quantities are handled gracefully. (CVS 5854) check-in: c73d9159 user: shane tags: trunk
10:53
Change the way sqlite3VdbeSetColName() is called so as to remove a few lines of code. This also fixes #3470. (CVS 5853) check-in: bfce9142 user: danielk1977 tags: trunk
2008-10-30
22:13
Fix a faulty assert() in the merge implementation of the UNION operator. Ticket #3467. (CVS 5852) check-in: cd1662e9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/delete.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** in order to generate code for DELETE FROM statements.
    14     14   **
    15         -** $Id: delete.c,v 1.185 2008/10/27 15:34:33 danielk1977 Exp $
           15  +** $Id: delete.c,v 1.186 2008/10/31 10:53:23 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Look up every table that is named in pSrc.  If any table is not found,
    21     21   ** add an error message to pParse->zErrMsg and return NULL.  If all tables
    22     22   ** are found, return a pointer to the last table.
................................................................................
   497    497     ** Return the number of rows that were deleted. If this routine is 
   498    498     ** generating code because of a call to sqlite3NestedParse(), do not
   499    499     ** invoke the callback function.
   500    500     */
   501    501     if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
   502    502       sqlite3VdbeAddOp2(v, OP_ResultRow, memCnt, 1);
   503    503       sqlite3VdbeSetNumCols(v, 1);
   504         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", P4_STATIC);
          504  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
   505    505     }
   506    506   
   507    507   delete_from_cleanup:
   508    508     sqlite3AuthContextPop(&sContext);
   509    509     sqlite3SrcListDelete(db, pTabList);
   510    510     sqlite3ExprDelete(db, pWhere);
   511    511     return;

Changes to src/insert.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle INSERT statements in SQLite.
    14     14   **
    15         -** $Id: insert.c,v 1.249 2008/08/20 16:35:10 drh Exp $
           15  +** $Id: insert.c,v 1.250 2008/10/31 10:53:23 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Set P4 of the most recently inserted opcode to a column affinity
    21     21   ** string for index pIdx. A column affinity string has one character
    22     22   ** for each column in the table, according to the affinity of the column:
................................................................................
   988    988     ** Return the number of rows inserted. If this routine is 
   989    989     ** generating code because of a call to sqlite3NestedParse(), do not
   990    990     ** invoke the callback function.
   991    991     */
   992    992     if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
   993    993       sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
   994    994       sqlite3VdbeSetNumCols(v, 1);
   995         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", P4_STATIC);
          995  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC);
   996    996     }
   997    997   
   998    998   insert_cleanup:
   999    999     sqlite3SrcListDelete(db, pTabList);
  1000   1000     sqlite3ExprListDelete(db, pList);
  1001   1001     sqlite3SelectDelete(db, pSelect);
  1002   1002     sqlite3IdListDelete(db, pColumn);

Changes to src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.191 2008/10/23 05:45:07 danielk1977 Exp $
           14  +** $Id: pragma.c,v 1.192 2008/10/31 10:53:23 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include <ctype.h>
    18     18   
    19     19   /* Ignore this whole file if pragmas are disabled
    20     20   */
    21     21   #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
................................................................................
   147    147   */
   148    148   static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
   149    149     Vdbe *v = sqlite3GetVdbe(pParse);
   150    150     int mem = ++pParse->nMem;
   151    151     sqlite3VdbeAddOp2(v, OP_Integer, value, mem);
   152    152     if( pParse->explain==0 ){
   153    153       sqlite3VdbeSetNumCols(v, 1);
   154         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P4_STATIC);
          154  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
   155    155     }
   156    156     sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
   157    157   }
   158    158   
   159    159   #ifndef SQLITE_OMIT_FLAG_PRAGMAS
   160    160   /*
   161    161   ** Check to see if zRight and zLeft refer to a pragma that queries
................................................................................
   318    318         { OP_ResultRow,   1, 1,        0},
   319    319       };
   320    320       int addr;
   321    321       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   322    322       sqlite3VdbeUsesBtree(v, iDb);
   323    323       if( !zRight ){
   324    324         sqlite3VdbeSetNumCols(v, 1);
   325         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P4_STATIC);
          325  +      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
   326    326         pParse->nMem += 2;
   327    327         addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
   328    328         sqlite3VdbeChangeP1(v, addr, iDb);
   329    329         sqlite3VdbeChangeP1(v, addr+5, SQLITE_DEFAULT_CACHE_SIZE);
   330    330       }else{
   331    331         int size = atoi(zRight);
   332    332         if( size<0 ) size = -size;
................................................................................
   399    399       v = sqlite3GetVdbe(pParse);
   400    400       if( !v || sqlite3ReadSchema(pParse) ) goto pragma_out;
   401    401       sqlite3CodeVerifySchema(pParse, iDb);
   402    402       iReg = ++pParse->nMem;
   403    403       sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
   404    404       sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
   405    405       sqlite3VdbeSetNumCols(v, 1);
   406         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", P4_STATIC);
          406  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", SQLITE_STATIC);
   407    407     }else
   408    408   
   409    409     /*
   410    410     **  PRAGMA [database.]locking_mode
   411    411     **  PRAGMA [database.]locking_mode = (normal|exclusive)
   412    412     */
   413    413     if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
................................................................................
   444    444       }
   445    445   
   446    446       assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
   447    447       if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
   448    448         zRet = "exclusive";
   449    449       }
   450    450       sqlite3VdbeSetNumCols(v, 1);
   451         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P4_STATIC);
          451  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
   452    452       sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
   453    453       sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
   454    454     }else
   455    455   
   456    456     /*
   457    457     **  PRAGMA [database.]journal_mode
   458    458     **  PRAGMA [database.]journal_mode = (delete|persist|memory|off)
................................................................................
   504    504       }
   505    505       assert( eMode==PAGER_JOURNALMODE_DELETE
   506    506                 || eMode==PAGER_JOURNALMODE_TRUNCATE
   507    507                 || eMode==PAGER_JOURNALMODE_PERSIST
   508    508                 || eMode==PAGER_JOURNALMODE_OFF
   509    509                 || eMode==PAGER_JOURNALMODE_MEMORY );
   510    510       sqlite3VdbeSetNumCols(v, 1);
   511         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", P4_STATIC);
          511  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
   512    512       sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, 
   513    513              azModeName[eMode], P4_STATIC);
   514    514       sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
   515    515     }else
   516    516   
   517    517     /*
   518    518     **  PRAGMA [database.]journal_size_limit
................................................................................
   671    671     **
   672    672     */
   673    673     if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
   674    674       if( !zRight ){
   675    675         if( sqlite3_temp_directory ){
   676    676           sqlite3VdbeSetNumCols(v, 1);
   677    677           sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
   678         -            "temp_store_directory", P4_STATIC);
          678  +            "temp_store_directory", SQLITE_STATIC);
   679    679           sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
   680    680           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
   681    681         }
   682    682       }else{
   683    683   #ifndef SQLITE_OMIT_WSD
   684    684         if( zRight[0] ){
   685    685           int rc;
................................................................................
   756    756       pTab = sqlite3FindTable(db, zRight, zDb);
   757    757       if( pTab ){
   758    758         int i;
   759    759         int nHidden = 0;
   760    760         Column *pCol;
   761    761         sqlite3VdbeSetNumCols(v, 6);
   762    762         pParse->nMem = 6;
   763         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P4_STATIC);
   764         -      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
   765         -      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P4_STATIC);
   766         -      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P4_STATIC);
   767         -      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P4_STATIC);
   768         -      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P4_STATIC);
          763  +      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
          764  +      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
          765  +      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
          766  +      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
          767  +      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
          768  +      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
   769    769         sqlite3ViewGetColumnNames(pParse, pTab);
   770    770         for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
   771    771           const Token *pDflt;
   772    772           if( IsHiddenColumn(pCol) ){
   773    773             nHidden++;
   774    774             continue;
   775    775           }
................................................................................
   795    795       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   796    796       pIdx = sqlite3FindIndex(db, zRight, zDb);
   797    797       if( pIdx ){
   798    798         int i;
   799    799         pTab = pIdx->pTable;
   800    800         sqlite3VdbeSetNumCols(v, 3);
   801    801         pParse->nMem = 3;
   802         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P4_STATIC);
   803         -      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P4_STATIC);
   804         -      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P4_STATIC);
          802  +      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
          803  +      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
          804  +      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
   805    805         for(i=0; i<pIdx->nColumn; i++){
   806    806           int cnum = pIdx->aiColumn[i];
   807    807           sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
   808    808           sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
   809    809           assert( pTab->nCol>cnum );
   810    810           sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
   811    811           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
................................................................................
   821    821       if( pTab ){
   822    822         v = sqlite3GetVdbe(pParse);
   823    823         pIdx = pTab->pIndex;
   824    824         if( pIdx ){
   825    825           int i = 0; 
   826    826           sqlite3VdbeSetNumCols(v, 3);
   827    827           pParse->nMem = 3;
   828         -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
   829         -        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
   830         -        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P4_STATIC);
          828  +        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
          829  +        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
          830  +        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
   831    831           while(pIdx){
   832    832             sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
   833    833             sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
   834    834             sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3);
   835    835             sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
   836    836             ++i;
   837    837             pIdx = pIdx->pNext;
................................................................................
   841    841     }else
   842    842   
   843    843     if( sqlite3StrICmp(zLeft, "database_list")==0 ){
   844    844       int i;
   845    845       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   846    846       sqlite3VdbeSetNumCols(v, 3);
   847    847       pParse->nMem = 3;
   848         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
   849         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
   850         -    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P4_STATIC);
          848  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
          849  +    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
          850  +    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
   851    851       for(i=0; i<db->nDb; i++){
   852    852         if( db->aDb[i].pBt==0 ) continue;
   853    853         assert( db->aDb[i].zName!=0 );
   854    854         sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
   855    855         sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
   856    856         sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
   857    857              sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
................................................................................
   860    860     }else
   861    861   
   862    862     if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
   863    863       int i = 0;
   864    864       HashElem *p;
   865    865       sqlite3VdbeSetNumCols(v, 2);
   866    866       pParse->nMem = 2;
   867         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
   868         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
          867  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
          868  +    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
   869    869       for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
   870    870         CollSeq *pColl = (CollSeq *)sqliteHashData(p);
   871    871         sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
   872    872         sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
   873    873         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
   874    874       }
   875    875     }else
................................................................................
   884    884       if( pTab ){
   885    885         v = sqlite3GetVdbe(pParse);
   886    886         pFK = pTab->pFKey;
   887    887         if( pFK ){
   888    888           int i = 0; 
   889    889           sqlite3VdbeSetNumCols(v, 8);
   890    890           pParse->nMem = 8;
   891         -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P4_STATIC);
   892         -        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P4_STATIC);
   893         -        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P4_STATIC);
   894         -        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P4_STATIC);
   895         -        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P4_STATIC);
   896         -        sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", P4_STATIC);
   897         -        sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", P4_STATIC);
   898         -        sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", P4_STATIC);
          891  +        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
          892  +        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
          893  +        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
          894  +        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
          895  +        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
          896  +        sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
          897  +        sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
          898  +        sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
   899    899           while(pFK){
   900    900             int j;
   901    901             for(j=0; j<pFK->nCol; j++){
   902    902               char *zCol = pFK->aCol[j].zCol;
   903    903               char *zOnUpdate = (char *)actionName(pFK->updateConf);
   904    904               char *zOnDelete = (char *)actionName(pFK->deleteConf);
   905    905               sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
................................................................................
   969    969   
   970    970       int isQuick = (zLeft[0]=='q');
   971    971   
   972    972       /* Initialize the VDBE program */
   973    973       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   974    974       pParse->nMem = 6;
   975    975       sqlite3VdbeSetNumCols(v, 1);
   976         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P4_STATIC);
          976  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
   977    977   
   978    978       /* Set the maximum error count */
   979    979       mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
   980    980       if( zRight ){
   981    981         mxErr = atoi(zRight);
   982    982         if( mxErr<=0 ){
   983    983           mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
................................................................................
  1148   1148         { "UTF16",    0                  }, /* SQLITE_UTF16NATIVE */
  1149   1149         { 0, 0 }
  1150   1150       };
  1151   1151       const struct EncName *pEnc;
  1152   1152       if( !zRight ){    /* "PRAGMA encoding" */
  1153   1153         if( sqlite3ReadSchema(pParse) ) goto pragma_out;
  1154   1154         sqlite3VdbeSetNumCols(v, 1);
  1155         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P4_STATIC);
         1155  +      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
  1156   1156         sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
  1157   1157         for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
  1158   1158           if( pEnc->enc==ENC(pParse->db) ){
  1159   1159             sqlite3VdbeChangeP4(v, -1, pEnc->zName, P4_STATIC);
  1160   1160             break;
  1161   1161           }
  1162   1162         }
................................................................................
  1249   1249           { OP_ReadCookie,      0,  1,  0},    /* 0 */
  1250   1250           { OP_ResultRow,       1,  1,  0}
  1251   1251         };
  1252   1252         int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
  1253   1253         sqlite3VdbeChangeP1(v, addr, iDb);
  1254   1254         sqlite3VdbeChangeP3(v, addr, iCookie);
  1255   1255         sqlite3VdbeSetNumCols(v, 1);
  1256         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P4_TRANSIENT);
         1256  +      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
  1257   1257       }
  1258   1258     }else
  1259   1259   #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
  1260   1260   
  1261   1261   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  1262   1262     /*
  1263   1263     ** Report the current state of file logs for all databases
................................................................................
  1266   1266       static const char *const azLockName[] = {
  1267   1267         "unlocked", "shared", "reserved", "pending", "exclusive"
  1268   1268       };
  1269   1269       int i;
  1270   1270       Vdbe *v = sqlite3GetVdbe(pParse);
  1271   1271       sqlite3VdbeSetNumCols(v, 2);
  1272   1272       pParse->nMem = 2;
  1273         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P4_STATIC);
  1274         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P4_STATIC);
         1273  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
         1274  +    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
  1275   1275       for(i=0; i<db->nDb; i++){
  1276   1276         Btree *pBt;
  1277   1277         Pager *pPager;
  1278   1278         const char *zState = "unknown";
  1279   1279         int j;
  1280   1280         if( db->aDb[i].zName==0 ) continue;
  1281   1281         sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);

Changes to src/prepare.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains the implementation of the sqlite3_prepare()
    13     13   ** interface, and routines that contribute to loading the database schema
    14     14   ** from disk.
    15     15   **
    16         -** $Id: prepare.c,v 1.97 2008/09/08 09:06:19 danielk1977 Exp $
           16  +** $Id: prepare.c,v 1.98 2008/10/31 10:53:23 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include <ctype.h>
    20     20   
    21     21   /*
    22     22   ** Fill the InitData structure with an error message that indicates
    23     23   ** that the database is corrupt.
................................................................................
   597    597     }
   598    598     rc = sParse.rc;
   599    599   
   600    600   #ifndef SQLITE_OMIT_EXPLAIN
   601    601     if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
   602    602       if( sParse.explain==2 ){
   603    603         sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
   604         -      sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", P4_STATIC);
   605         -      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P4_STATIC);
   606         -      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P4_STATIC);
          604  +      sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", SQLITE_STATIC);
          605  +      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", SQLITE_STATIC);
          606  +      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", SQLITE_STATIC);
   607    607       }else{
   608    608         sqlite3VdbeSetNumCols(sParse.pVdbe, 8);
   609         -      sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P4_STATIC);
   610         -      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P4_STATIC);
   611         -      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P4_STATIC);
   612         -      sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P4_STATIC);
   613         -      sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P4_STATIC);
   614         -      sqlite3VdbeSetColName(sParse.pVdbe, 5, COLNAME_NAME, "p4", P4_STATIC);
   615         -      sqlite3VdbeSetColName(sParse.pVdbe, 6, COLNAME_NAME, "p5", P4_STATIC);
   616         -      sqlite3VdbeSetColName(sParse.pVdbe, 7, COLNAME_NAME, "comment",P4_STATIC);
          609  +      sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", SQLITE_STATIC);
          610  +      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", SQLITE_STATIC);
          611  +      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", SQLITE_STATIC);
          612  +      sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", SQLITE_STATIC);
          613  +      sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", SQLITE_STATIC);
          614  +      sqlite3VdbeSetColName(sParse.pVdbe, 5, COLNAME_NAME, "p4", SQLITE_STATIC);
          615  +      sqlite3VdbeSetColName(sParse.pVdbe, 6, COLNAME_NAME, "p5", SQLITE_STATIC);
          616  +      sqlite3VdbeSetColName(sParse.pVdbe, 7, COLNAME_NAME, "comment", SQLITE_STATIC);
   617    617       }
   618    618     }
   619    619   #endif
   620    620   
   621    621     if( sqlite3SafetyOff(db) ){
   622    622       rc = SQLITE_MISUSE;
   623    623     }

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.481 2008/10/30 22:13:23 drh Exp $
           15  +** $Id: select.c,v 1.482 2008/10/31 10:53:23 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Delete all the content of a Select structure but do not deallocate
    22     22   ** the select structure itself.
................................................................................
  1029   1029       const char *zOrigCol = 0;
  1030   1030       zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
  1031   1031   
  1032   1032       /* The vdbe must make its own copy of the column-type and other 
  1033   1033       ** column specific strings, in case the schema is reset before this
  1034   1034       ** virtual machine is deleted.
  1035   1035       */
  1036         -    sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, P4_TRANSIENT);
  1037         -    sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, P4_TRANSIENT);
  1038         -    sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, P4_TRANSIENT);
         1036  +    sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT);
         1037  +    sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT);
         1038  +    sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT);
  1039   1039   #else
  1040   1040       zType = columnType(&sNC, p, 0, 0, 0);
  1041   1041   #endif
  1042         -    sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, P4_TRANSIENT);
         1042  +    sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
  1043   1043     }
  1044   1044   #endif /* SQLITE_OMIT_DECLTYPE */
  1045   1045   }
  1046   1046   
  1047   1047   /*
  1048   1048   ** Generate code that will tell the VDBE the names of columns
  1049   1049   ** in the result set.  This information is used to provide the
................................................................................
  1074   1074     sqlite3VdbeSetNumCols(v, pEList->nExpr);
  1075   1075     for(i=0; i<pEList->nExpr; i++){
  1076   1076       Expr *p;
  1077   1077       p = pEList->a[i].pExpr;
  1078   1078       if( p==0 ) continue;
  1079   1079       if( pEList->a[i].zName ){
  1080   1080         char *zName = pEList->a[i].zName;
  1081         -      sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, strlen(zName));
         1081  +      sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
  1082   1082       }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList ){
  1083   1083         Table *pTab;
  1084   1084         char *zCol;
  1085   1085         int iCol = p->iColumn;
  1086   1086         for(j=0; j<pTabList->nSrc && pTabList->a[j].iCursor!=p->iTable; j++){}
  1087   1087         assert( j<pTabList->nSrc );
  1088   1088         pTab = pTabList->a[j].pTab;
................................................................................
  1090   1090         assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
  1091   1091         if( iCol<0 ){
  1092   1092           zCol = "rowid";
  1093   1093         }else{
  1094   1094           zCol = pTab->aCol[iCol].zName;
  1095   1095         }
  1096   1096         if( !shortNames && !fullNames ){
  1097         -        sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
         1097  +        sqlite3VdbeSetColName(v, i, COLNAME_NAME, 
         1098  +            sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
  1098   1099         }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
  1099   1100           char *zName = 0;
  1100   1101           char *zTab;
  1101   1102    
  1102   1103           zTab = pTabList->a[j].zAlias;
  1103   1104           if( fullNames || zTab==0 ) zTab = pTab->zName;
  1104   1105           zName = sqlite3MPrintf(db, "%s.%s", zTab, zCol);
  1105         -        sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, P4_DYNAMIC);
         1106  +        sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
  1106   1107         }else{
  1107         -        sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, strlen(zCol));
         1108  +        sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
  1108   1109         }
  1109   1110       }else{
  1110         -      sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
         1111  +      sqlite3VdbeSetColName(v, i, COLNAME_NAME, 
         1112  +          sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
  1111   1113       }
  1112   1114     }
  1113   1115     generateColumnTypes(pParse, pTabList, pEList);
  1114   1116   }
  1115   1117   
  1116   1118   #ifndef SQLITE_OMIT_COMPOUND_SELECT
  1117   1119   /*

Changes to src/update.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle UPDATE statements.
    14     14   **
    15         -** $Id: update.c,v 1.185 2008/10/09 18:48:31 danielk1977 Exp $
           15  +** $Id: update.c,v 1.186 2008/10/31 10:53:23 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   #ifndef SQLITE_OMIT_VIRTUALTABLE
    20     20   /* Forward declaration */
    21     21   static void updateVirtualTable(
    22     22     Parse *pParse,       /* The parsing context */
................................................................................
   564    564     ** Return the number of rows that were changed. If this routine is 
   565    565     ** generating code because of a call to sqlite3NestedParse(), do not
   566    566     ** invoke the callback function.
   567    567     */
   568    568     if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){
   569    569       sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
   570    570       sqlite3VdbeSetNumCols(v, 1);
   571         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", P4_STATIC);
          571  +    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
   572    572     }
   573    573   
   574    574   update_cleanup:
   575    575     sqlite3AuthContextPop(&sContext);
   576    576     sqlite3DbFree(db, aRegIdx);
   577    577     sqlite3DbFree(db, aXRef);
   578    578     sqlite3SrcListDelete(db, pTabList);

Changes to src/vdbe.h.

    11     11   *************************************************************************
    12     12   ** Header file for the Virtual DataBase Engine (VDBE)
    13     13   **
    14     14   ** This header defines the interface to the virtual database engine
    15     15   ** or VDBE.  The VDBE implements an abstract machine that runs a
    16     16   ** simple program to access and modify the underlying database.
    17     17   **
    18         -** $Id: vdbe.h,v 1.138 2008/08/20 22:06:48 drh Exp $
           18  +** $Id: vdbe.h,v 1.139 2008/10/31 10:53:23 danielk1977 Exp $
    19     19   */
    20     20   #ifndef _SQLITE_VDBE_H_
    21     21   #define _SQLITE_VDBE_H_
    22     22   #include <stdio.h>
    23     23   
    24     24   /*
    25     25   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
................................................................................
   174    174   int sqlite3VdbeCurrentAddr(Vdbe*);
   175    175   #ifdef SQLITE_DEBUG
   176    176     void sqlite3VdbeTrace(Vdbe*,FILE*);
   177    177   #endif
   178    178   void sqlite3VdbeResetStepResult(Vdbe*);
   179    179   int sqlite3VdbeReset(Vdbe*);
   180    180   void sqlite3VdbeSetNumCols(Vdbe*,int);
   181         -int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
          181  +int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
   182    182   void sqlite3VdbeCountChanges(Vdbe*);
   183    183   sqlite3 *sqlite3VdbeDb(Vdbe*);
   184    184   void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
   185    185   void sqlite3VdbeSwap(Vdbe*,Vdbe*);
   186    186   
   187    187   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   188    188   int sqlite3VdbeReleaseMemory(int);

Changes to src/vdbeaux.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used for creating, destroying, and populating
    13     13   ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)  Prior
    14     14   ** to version 2.8.7, all this code was combined into the vdbe.c source file.
    15     15   ** But that file was getting too big so this subroutines were split out.
    16     16   **
    17         -** $Id: vdbeaux.c,v 1.412 2008/10/11 17:51:39 danielk1977 Exp $
           17  +** $Id: vdbeaux.c,v 1.413 2008/10/31 10:53:23 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   #include "vdbeInt.h"
    22     22   
    23     23   
    24     24   
................................................................................
  1197   1197   
  1198   1198   /*
  1199   1199   ** Set the name of the idx'th column to be returned by the SQL statement.
  1200   1200   ** zName must be a pointer to a nul terminated string.
  1201   1201   **
  1202   1202   ** This call must be made after a call to sqlite3VdbeSetNumCols().
  1203   1203   **
  1204         -** If N==P4_STATIC  it means that zName is a pointer to a constant static
  1205         -** string and we can just copy the pointer. If it is P4_DYNAMIC, then 
  1206         -** the string is freed using sqlite3DbFree(db, ) when the vdbe is finished with
  1207         -** it. Otherwise, N bytes of zName are copied.
         1204  +** The final parameter, xDel, must be one of SQLITE_DYNAMIC, SQLITE_STATIC
         1205  +** or SQLITE_TRANSIENT. If it is SQLITE_DYNAMIC, then the buffer pointed
         1206  +** to by zName will be freed by sqlite3DbFree() when the vdbe is destroyed.
  1208   1207   */
  1209         -int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){
         1208  +int sqlite3VdbeSetColName(
         1209  +  Vdbe *p,                         /* Vdbe being configured */
         1210  +  int idx,                         /* Index of column zName applies to */
         1211  +  int var,                         /* One of the COLNAME_* constants */
         1212  +  const char *zName,               /* Pointer to buffer containing name */
         1213  +  void (*xDel)(void*)              /* Memory management strategy for zName */
         1214  +){
  1210   1215     int rc;
  1211   1216     Mem *pColName;
  1212   1217     assert( idx<p->nResColumn );
  1213   1218     assert( var<COLNAME_N );
  1214         -  if( p->db->mallocFailed ) return SQLITE_NOMEM;
         1219  +  if( p->db->mallocFailed ){
         1220  +    assert( !zName || xDel!=SQLITE_DYNAMIC );
         1221  +    return SQLITE_NOMEM;
         1222  +  }
  1215   1223     assert( p->aColName!=0 );
  1216   1224     pColName = &(p->aColName[idx+var*p->nResColumn]);
  1217         -  if( N==P4_DYNAMIC || N==P4_STATIC ){
  1218         -    rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, SQLITE_STATIC);
  1219         -  }else{
  1220         -    rc = sqlite3VdbeMemSetStr(pColName, zName, N, SQLITE_UTF8,SQLITE_TRANSIENT);
  1221         -  }
  1222         -  if( rc==SQLITE_OK && N==P4_DYNAMIC ){
  1223         -    pColName->flags &= (~MEM_Static);
  1224         -    pColName->zMalloc = pColName->z;
  1225         -  }
         1225  +  rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, xDel);
         1226  +  assert( p->db->mallocFailed || !zName || pColName->flags&MEM_Term );
  1226   1227     return rc;
  1227   1228   }
  1228   1229   
  1229   1230   /*
  1230   1231   ** A read or write transaction may or may not be active on database handle
  1231   1232   ** db. If a transaction is active, commit it. If there is a
  1232   1233   ** write-transaction spanning more than one database file, this routine