/ Check-in [8467d84f]
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:Version 2.0.6 (CVS 291)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8467d84fc6e67bd93051f54338a8f6c9b1711ee1
User & Date: drh 2001-10-19 16:44:56
Context
2001-10-19
16:45
Version 2.0.6 (CVS 464) check-in: c8535a0d user: drh tags: trunk
16:44
Version 2.0.6 (CVS 291) check-in: 8467d84f user: drh tags: trunk
2001-10-18
12:34
Support for UTF-8 and ISO8859 characters in identifiers. Bug fix in the column name generator for selects (was coreing). (CVS 290) check-in: 22948fc6 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to VERSION.

     1         -2.0.5
            1  +2.0.6

Changes to src/build.c.

    21     21   **     COPY
    22     22   **     VACUUM
    23     23   **     BEGIN TRANSACTION
    24     24   **     COMMIT
    25     25   **     ROLLBACK
    26     26   **     PRAGMA
    27     27   **
    28         -** $Id: build.c,v 1.50 2001/10/15 00:44:36 drh Exp $
           28  +** $Id: build.c,v 1.51 2001/10/19 16:44:57 drh Exp $
    29     29   */
    30     30   #include "sqliteInt.h"
    31     31   #include <ctype.h>
    32     32   
    33     33   /*
    34     34   ** This routine is called after a single SQL statement has been
    35     35   ** parsed and we want to execute the VDBE code to implement 
................................................................................
  1444   1444     if( sqliteStrICmp(zLeft, "count_changes")==0 ){
  1445   1445       if( getBoolean(zRight) ){
  1446   1446         db->flags |= SQLITE_CountRows;
  1447   1447       }else{
  1448   1448         db->flags &= ~SQLITE_CountRows;
  1449   1449       }
  1450   1450     }else
         1451  +
         1452  +  if( sqliteStrICmp(zLeft, "empty_result_callbacks")==0 ){
         1453  +    if( getBoolean(zRight) ){
         1454  +      db->flags |= SQLITE_NullCallback;
         1455  +    }else{
         1456  +      db->flags &= ~SQLITE_NullCallback;
         1457  +    }
         1458  +  }else
  1451   1459   
  1452   1460     if( sqliteStrICmp(zLeft, "table_info")==0 ){
  1453   1461       Table *pTab;
  1454   1462       Vdbe *v;
  1455   1463       pTab = sqliteFindTable(db, zRight);
  1456   1464       if( pTab ) v = sqliteGetVdbe(pParse);
  1457   1465       if( pTab && v ){

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.41 2001/10/18 12:34:47 drh Exp $
           15  +** $Id: select.c,v 1.42 2001/10/19 16:44:57 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Allocate a new Select structure and return a pointer to that
    21     21   ** structure.
    22     22   */
................................................................................
   990    990     /* If there is an ORDER BY clause, then we need to sort the results
   991    991     ** and send them to the callback one by one.
   992    992     */
   993    993     if( pOrderBy ){
   994    994       generateSortTail(v, pEList->nExpr);
   995    995     }
   996    996     pParse->nTab = base;
          997  +
          998  +
          999  +  /* Issue a null callback if that is what the user wants.
         1000  +  */
         1001  +  if( (pParse->db->flags & SQLITE_NullCallback)!=0 && eDest==SRT_Callback ){
         1002  +    sqliteVdbeAddOp(v, OP_NullCallback, pEList->nExpr, 0);
         1003  +  }
         1004  +
   997   1005     return 0;
   998   1006   }

Changes to src/shell.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 code to implement the "sqlite" command line
    13     13   ** utility for accessing SQLite databases.
    14     14   **
    15         -** $Id: shell.c,v 1.36 2001/10/06 16:33:03 drh Exp $
           15  +** $Id: shell.c,v 1.37 2001/10/19 16:44:57 drh Exp $
    16     16   */
    17     17   #include <stdlib.h>
    18     18   #include <string.h>
    19     19   #include <stdio.h>
    20     20   #include "sqlite.h"
    21     21   #include <ctype.h>
    22     22   #ifdef OS_UNIX
................................................................................
   240    240   */
   241    241   static int callback(void *pArg, int nArg, char **azArg, char **azCol){
   242    242     int i;
   243    243     struct callback_data *p = (struct callback_data*)pArg;
   244    244     switch( p->mode ){
   245    245       case MODE_Line: {
   246    246         int w = 5;
          247  +      if( azArg==0 ) break;
   247    248         for(i=0; i<nArg; i++){
   248    249           int len = strlen(azCol[i]);
   249    250           if( len>w ) w = len;
   250    251         }
   251    252         if( p->cnt++>0 ) fprintf(p->out,"\n");
   252    253         for(i=0; i<nArg; i++){
   253    254           fprintf(p->out,"%*s = %s\n", w, azCol[i], azArg[i] ? azArg[i] : 0);
................................................................................
   262    263                w = p->colWidth[i];
   263    264             }else{
   264    265                w = 0;
   265    266             }
   266    267             if( w<=0 ){
   267    268               w = strlen(azCol[i] ? azCol[i] : "");
   268    269               if( w<10 ) w = 10;
   269         -            n = strlen(azArg[i] ? azArg[i] : "");
          270  +            n = strlen(azArg && azArg[i] ? azArg[i] : "");
   270    271               if( w<n ) w = n;
   271    272             }
   272    273             if( i<ArraySize(p->actualWidth) ){
   273    274               p->actualWidth[i] = w; 
   274    275             }
   275    276             if( p->showHeader ){
   276    277               fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": "  ");
................................................................................
   286    287               }
   287    288               fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
   288    289                      "----------------------------------------------------------",
   289    290                       i==nArg-1 ? "\n": "  ");
   290    291             }
   291    292           }
   292    293         }
          294  +      if( azArg==0 ) break;
   293    295         for(i=0; i<nArg; i++){
   294    296           int w;
   295    297           if( i<ArraySize(p->actualWidth) ){
   296    298              w = p->actualWidth[i];
   297    299           }else{
   298    300              w = 10;
   299    301           }
................................................................................
   305    307       case MODE_Semi:
   306    308       case MODE_List: {
   307    309         if( p->cnt++==0 && p->showHeader ){
   308    310           for(i=0; i<nArg; i++){
   309    311             fprintf(p->out,"%s%s",azCol[i], i==nArg-1 ? "\n" : p->separator);
   310    312           }
   311    313         }
          314  +      if( azArg==0 ) break;
   312    315         for(i=0; i<nArg; i++){
   313    316           char *z = azArg[i];
   314    317           if( z==0 ) z = "";
   315    318           while( *z ){
   316    319             int j;
   317    320             for(j=0; z[j] && z[j]!=p->escape && z[j]!='\\'; j++){}
   318    321             if( j>0 ){
................................................................................
   338    341         if( p->cnt++==0 && p->showHeader ){
   339    342           fprintf(p->out,"<TR>");
   340    343           for(i=0; i<nArg; i++){
   341    344             fprintf(p->out,"<TH>%s</TH>",azCol[i]);
   342    345           }
   343    346           fprintf(p->out,"</TR>\n");
   344    347         }
          348  +      if( azArg==0 ) break;
   345    349         fprintf(p->out,"<TR>");
   346    350         for(i=0; i<nArg; i++){
   347    351           fprintf(p->out,"<TD>");
   348    352           output_html_string(p->out, azArg[i] ? azArg[i] : "");
   349    353           fprintf(p->out,"</TD>\n");
   350    354         }
   351    355         fprintf(p->out,"</TD></TR>\n");
   352    356         break;
   353    357       }
   354    358       case MODE_Insert: {
          359  +      if( azArg==0 ) break;
   355    360         fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
   356    361         for(i=0; i<nArg; i++){
   357    362           char *zSep = i>0 ? ",": "";
   358    363           if( azArg[i]==0 ){
   359    364             fprintf(p->out,"%sNULL",zSep);
   360    365           }else if( is_numeric(azArg[i]) ){
   361    366             fprintf(p->out,"%s%s",zSep, azArg[i]);
   362    367           }else{
   363    368             if( zSep[0] ) fprintf(p->out,"%s",zSep);
   364    369             output_quoted_string(p->out, azArg[i]);
   365    370           }
   366    371         }
   367    372         fprintf(p->out,");\n");
          373  +      break;
   368    374       }
   369    375     }      
   370    376     return 0;
   371    377   }
   372    378   
   373    379   /*
   374    380   ** Set the destination table field of the callback_data structure to

Changes to src/sqliteInt.h.

     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.63 2001/10/18 12:34:47 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.64 2001/10/19 16:44:57 drh Exp $
    15     15   */
    16     16   #include "sqlite.h"
    17     17   #include "hash.h"
    18     18   #include "vdbe.h"
    19     19   #include "parse.h"
    20     20   #include "btree.h"
    21     21   #include <stdio.h>
................................................................................
   162    162   #define SQLITE_Interrupt      0x00000004  /* Cancel current operation */
   163    163   #define SQLITE_InTrans        0x00000008  /* True if in a transaction */
   164    164   #define SQLITE_InternChanges  0x00000010  /* Uncommitted Hash table changes */
   165    165   #define SQLITE_FullColNames   0x00000020  /* Show full column names on SELECT */
   166    166   #define SQLITE_CountRows      0x00000040  /* Count rows changed by INSERT, */
   167    167                                             /*   DELETE, or UPDATE and return */
   168    168                                             /*   the count using a callback. */
          169  +#define SQLITE_NullCallback   0x00000080  /* Invoke the callback once if the */
          170  +                                          /*   result set is empty */
   169    171   
   170    172   /*
   171    173   ** Current file format version
   172    174   */
   173    175   #define SQLITE_FileFormat 2
   174    176   
   175    177   /*

Changes to src/table.c.

    43     43     int need;
    44     44     int i;
    45     45     char *z;
    46     46   
    47     47     /* Make sure there is enough space in p->azResult to hold everything
    48     48     ** we need to remember from this invocation of the callback.
    49     49     */
    50         -  if( p->nRow==0 ){
           50  +  if( p->nRow==0 && argv!=0 ){
    51     51       p->nColumn = nCol;
    52     52       need = nCol*2;
    53     53     }else{
    54     54       need = nCol;
    55     55     }
    56     56     if( p->nData + need >= p->nAlloc ){
    57     57       p->nAlloc = p->nAlloc*2 + need + 1;
................................................................................
    79     79         }
    80     80         p->azResult[p->nData++] = z;
    81     81       }
    82     82     }
    83     83   
    84     84     /* Copy over the row data
    85     85     */
    86         -  for(i=0; i<nCol; i++){
    87         -    if( argv[i]==0 ){
    88         -      z = 0;
    89         -    }else{
    90         -      z = malloc( strlen(argv[i])+1 );
    91         -      if( z==0 ){
    92         -        p->rc = SQLITE_NOMEM;
    93         -        return 1;
           86  +  if( argv!=0 ){
           87  +    for(i=0; i<nCol; i++){
           88  +      if( argv[i]==0 ){
           89  +        z = 0;
           90  +      }else{
           91  +        z = malloc( strlen(argv[i])+1 );
           92  +        if( z==0 ){
           93  +          p->rc = SQLITE_NOMEM;
           94  +          return 1;
           95  +        }
           96  +        strcpy(z, argv[i]);
    94     97         }
    95         -      strcpy(z, argv[i]);
           98  +      p->azResult[p->nData++] = z;
    96     99       }
    97         -    p->azResult[p->nData++] = z;
          100  +    p->nRow++;
    98    101     }
    99         -  p->nRow++;
   100    102     return 0;
   101    103   }
   102    104   
   103    105   /*
   104    106   ** Query the database.  But instead of invoking a callback for each row,
   105    107   ** malloc() for space to hold the result and return the entire results
   106    108   ** at the conclusion of the call.

Changes to src/tclsqlite.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   ** A TCL Interface to SQLite
    13     13   **
    14         -** $Id: tclsqlite.c,v 1.25 2001/10/18 12:34:47 drh Exp $
           14  +** $Id: tclsqlite.c,v 1.26 2001/10/19 16:44:57 drh Exp $
    15     15   */
    16     16   #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
    17     17   
    18     18   #include "sqlite.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
................................................................................
    68     68     char ** azN            /* Name for each column */
    69     69   ){
    70     70     CallbackData *cbData = (CallbackData*)clientData;
    71     71     int i, rc;
    72     72   #ifdef UTF_TRANSLATION_NEEDED
    73     73     Tcl_DString dCol;
    74     74   #endif
    75         -  if( cbData->zArray[0] ){
    76         -    if( cbData->once ){
    77         -      Tcl_SetVar2(cbData->interp, cbData->zArray, "*", "", 0);
           75  +  if( azCol==0 || (cbData->once && cbData->zArray[0]) ){
           76  +    Tcl_SetVar2(cbData->interp, cbData->zArray, "*", "", 0);
           77  +    for(i=0; i<nCol; i++){
           78  +      Tcl_SetVar2(cbData->interp, cbData->zArray, "*", azN[i],
           79  +         TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
           80  +    }
           81  +    cbData->once = 0;
           82  +  }
           83  +  if( azCol!=0 ){
           84  +    if( cbData->zArray[0] ){
    78     85         for(i=0; i<nCol; i++){
    79         -        Tcl_SetVar2(cbData->interp, cbData->zArray, "*", azN[i],
    80         -           TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
    81         -      }
    82         -    }
    83         -    for(i=0; i<nCol; i++){
    84         -      char *z = azCol[i];
    85         -      if( z==0 ) z = "";
           86  +        char *z = azCol[i];
           87  +        if( z==0 ) z = "";
    86     88   #ifdef UTF_TRANSLATION_NEEDED
    87         -      Tcl_DStringInit(&dCol);
    88         -      Tcl_ExternalToUtfDString(NULL, z, -1, &dCol);
    89         -      Tcl_SetVar2(cbData->interp, cbData->zArray, azN[i], 
    90         -            Tcl_DStringValue(&dCol), 0);
    91         -      Tcl_DStringFree(&dCol);
           89  +        Tcl_DStringInit(&dCol);
           90  +        Tcl_ExternalToUtfDString(NULL, z, -1, &dCol);
           91  +        Tcl_SetVar2(cbData->interp, cbData->zArray, azN[i], 
           92  +              Tcl_DStringValue(&dCol), 0);
           93  +        Tcl_DStringFree(&dCol);
    92     94   #else
    93         -      Tcl_SetVar2(cbData->interp, cbData->zArray, azN[i], z, 0);
           95  +        Tcl_SetVar2(cbData->interp, cbData->zArray, azN[i], z, 0);
    94     96   #endif
    95         -    }
    96         -  }else{
    97         -    for(i=0; i<nCol; i++){
    98         -      char *z = azCol[i];
    99         -      if( z==0 ) z = "";
           97  +      }
           98  +    }else{
           99  +      for(i=0; i<nCol; i++){
          100  +        char *z = azCol[i];
          101  +        if( z==0 ) z = "";
   100    102   #ifdef UTF_TRANSLATION_NEEDED
   101         -      Tcl_DStringInit(&dCol);
   102         -      Tcl_ExternalToUtfDString(NULL, z, -1, &dCol);
   103         -      Tcl_SetVar(cbData->interp, azN[i], Tcl_DStringValue(&dCol), 0);
   104         -      Tcl_DStringFree(&dCol);
          103  +        Tcl_DStringInit(&dCol);
          104  +        Tcl_ExternalToUtfDString(NULL, z, -1, &dCol);
          105  +        Tcl_SetVar(cbData->interp, azN[i], Tcl_DStringValue(&dCol), 0);
          106  +        Tcl_DStringFree(&dCol);
   105    107   #else
   106         -      Tcl_SetVar(cbData->interp, azN[i], z, 0);
          108  +        Tcl_SetVar(cbData->interp, azN[i], z, 0);
   107    109   #endif
          110  +      }
   108    111       }
   109    112     }
   110         -  cbData->once = 0;
   111    113     rc = Tcl_EvalObj(cbData->interp, cbData->pCode);
   112    114     if( rc==TCL_CONTINUE ) rc = TCL_OK;
   113    115     cbData->tcl_rc = rc;
   114    116     return rc!=TCL_OK;
   115    117   }
   116    118   
   117    119   /*
................................................................................
   124    126     void *clientData,      /* An instance of CallbackData */
   125    127     int nCol,              /* Number of columns in the result */
   126    128     char ** azCol,         /* Data for each column */
   127    129     char ** azN            /* Name for each column */
   128    130   ){
   129    131     Tcl_Obj *pList = (Tcl_Obj*)clientData;
   130    132     int i;
          133  +  if( azCol==0 ) return 0;
   131    134     for(i=0; i<nCol; i++){
   132    135       Tcl_Obj *pElem;
   133    136       if( azCol[i] && *azCol[i] ){
   134    137   #ifdef UTF_TRANSLATION_NEEDED
   135    138         Tcl_DString dCol;
   136    139         Tcl_DStringInit(&dCol);
   137    140         Tcl_ExternalToUtfDString(NULL, azCol[i], -1, &dCol);

Changes to src/tokenize.c.

    11     11   *************************************************************************
    12     12   ** An tokenizer for SQL
    13     13   **
    14     14   ** This file contains C code that splits an SQL input string up into
    15     15   ** individual tokens and sends those tokens one-by-one over to the
    16     16   ** parser for analysis.
    17     17   **
    18         -** $Id: tokenize.c,v 1.28 2001/10/18 12:34:48 drh Exp $
           18  +** $Id: tokenize.c,v 1.29 2001/10/19 16:44:57 drh Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   #include "os.h"
    22     22   #include <ctype.h>
    23     23   #include <stdlib.h>
    24     24   
    25     25   /*
................................................................................
   327    327         return i;
   328    328       }
   329    329       default: {
   330    330         if( !isIdChar[*z] ){
   331    331           break;
   332    332         }
   333    333         for(i=1; isIdChar[z[i]]; i++){}
   334         -      *tokenType = sqliteKeywordCode(z, i);
          334  +      *tokenType = sqliteKeywordCode((char*)z, i);
   335    335         return i;
   336    336       }
   337    337     }
   338    338     *tokenType = TK_ILLEGAL;
   339    339     return 1;
   340    340   }
   341    341   

Changes to src/vdbe.c.

    26     26   ** type to the other occurs as necessary.
    27     27   ** 
    28     28   ** Most of the code in this file is taken up by the sqliteVdbeExec()
    29     29   ** function which does the work of interpreting a VDBE program.
    30     30   ** But other routines are also provided to help in building up
    31     31   ** a program instruction by instruction.
    32     32   **
    33         -** $Id: vdbe.c,v 1.86 2001/10/18 12:34:48 drh Exp $
           33  +** $Id: vdbe.c,v 1.87 2001/10/19 16:44:57 drh Exp $
    34     34   */
    35     35   #include "sqliteInt.h"
    36     36   #include <ctype.h>
    37     37   
    38     38   /*
    39     39   ** SQL is translated into a sequence of instructions to be
    40     40   ** executed by a virtual machine.  Each instruction is an instance
................................................................................
   198    198     int nLineAlloc;     /* Number of spaces allocated for zLine */
   199    199     int nMem;           /* Number of memory locations currently allocated */
   200    200     Mem *aMem;          /* The memory locations */
   201    201     Agg agg;            /* Aggregate information */
   202    202     int nSet;           /* Number of sets allocated */
   203    203     Set *aSet;          /* An array of sets */
   204    204     int nFetch;         /* Number of OP_Fetch instructions executed */
          205  +  int nCallback;      /* Number of callbacks invoked so far */
   205    206   };
   206    207   
   207    208   /*
   208    209   ** Create a new virtual database engine.
   209    210   */
   210    211   Vdbe *sqliteVdbeCreate(sqlite *db){
   211    212     Vdbe *p;
................................................................................
   807    808     "SortMakeRec",       "SortMakeKey",       "Sort",              "SortNext",
   808    809     "SortKey",           "SortCallback",      "SortClose",         "FileOpen",
   809    810     "FileRead",          "FileColumn",        "FileClose",         "AggReset",
   810    811     "AggFocus",          "AggIncr",           "AggNext",           "AggSet",
   811    812     "AggGet",            "SetInsert",         "SetFound",          "SetNotFound",
   812    813     "SetClear",          "MakeRecord",        "MakeKey",           "MakeIdxKey",
   813    814     "Goto",              "If",                "Halt",              "ColumnCount",
   814         -  "ColumnName",        "Callback",          "Integer",           "String",
   815         -  "Null",              "Pop",               "Dup",               "Pull",
   816         -  "Add",               "AddImm",            "Subtract",          "Multiply",
   817         -  "Divide",            "Remainder",         "BitAnd",            "BitOr",
   818         -  "BitNot",            "ShiftLeft",         "ShiftRight",        "AbsValue",
   819         -  "Precision",         "Min",               "Max",               "Like",
   820         -  "Glob",              "Eq",                "Ne",                "Lt",
   821         -  "Le",                "Gt",                "Ge",                "IsNull",
   822         -  "NotNull",           "Negative",          "And",               "Or",
   823         -  "Not",               "Concat",            "Noop",              "Strlen",
   824         -  "Substr",          
          815  +  "ColumnName",        "Callback",          "NullCallback",      "Integer",
          816  +  "String",            "Null",              "Pop",               "Dup",
          817  +  "Pull",              "Add",               "AddImm",            "Subtract",
          818  +  "Multiply",          "Divide",            "Remainder",         "BitAnd",
          819  +  "BitOr",             "BitNot",            "ShiftLeft",         "ShiftRight",
          820  +  "AbsValue",          "Precision",         "Min",               "Max",
          821  +  "Like",              "Glob",              "Eq",                "Ne",
          822  +  "Lt",                "Le",                "Gt",                "Ge",
          823  +  "IsNull",            "NotNull",           "Negative",          "And",
          824  +  "Or",                "Not",               "Concat",            "Noop",
          825  +  "Strlen",            "Substr",          
   825    826   };
   826    827   
   827    828   /*
   828    829   ** Given the name of an opcode, return its number.  Return 0 if
   829    830   ** there is no match.
   830    831   **
   831    832   ** This routine is used for testing and debugging.
................................................................................
  1190   1191   ** array passed as the 4th parameter to the callback.  No checking
  1191   1192   ** is done.  If this value is wrong, a coredump can result.
  1192   1193   */
  1193   1194   case OP_ColumnCount: {
  1194   1195     p->azColName = sqliteRealloc(p->azColName, (pOp->p1+1)*sizeof(char*));
  1195   1196     if( p->azColName==0 ) goto no_mem;
  1196   1197     p->azColName[pOp->p1] = 0;
         1198  +  p->nCallback = 0;
  1197   1199     break;
  1198   1200   }
  1199   1201   
  1200   1202   /* Opcode: ColumnName P1 * P3
  1201   1203   **
  1202   1204   ** P3 becomes the P1-th column name (first is 0).  An array of pointers
  1203   1205   ** to all column names is passed as the 4th parameter to the callback.
  1204   1206   ** The ColumnCount opcode must be executed first to allocate space to
  1205   1207   ** hold the column names.  Failure to do this will likely result in
  1206   1208   ** a coredump.
  1207   1209   */
  1208   1210   case OP_ColumnName: {
  1209   1211     p->azColName[pOp->p1] = pOp->p3 ? pOp->p3 : "";
         1212  +  p->nCallback = 0;
  1210   1213     break;
  1211   1214   }
  1212   1215   
  1213   1216   /* Opcode: Callback P1 * *
  1214   1217   **
  1215   1218   ** Pop P1 values off the stack and form them into an array.  Then
  1216   1219   ** invoke the callback function using the newly formed array as the
................................................................................
  1227   1230       }
  1228   1231     }
  1229   1232     zStack[p->tos+1] = 0;
  1230   1233     if( xCallback!=0 ){
  1231   1234       if( xCallback(pArg, pOp->p1, &zStack[i], p->azColName)!=0 ){
  1232   1235         rc = SQLITE_ABORT;
  1233   1236       }
         1237  +    p->nCallback++;
  1234   1238     }
  1235   1239     PopStack(p, pOp->p1);
  1236   1240     break;
  1237   1241   }
         1242  +
         1243  +/* Opcode: NullCallback P1 * *
         1244  +**
         1245  +** Invoke the callback function once with the 2nd argument (the
         1246  +** number of columns) equal to P1 and with the 4th argument (the
         1247  +** names of the columns) set according to prior OP_ColumnName and
         1248  +** OP_ColumnCount instructions.  This is all like the regular
         1249  +** OP_Callback or OP_SortCallback opcodes.  But the 3rd argument
         1250  +** which normally contains a pointer to an array of pointers to
         1251  +** data is NULL.
         1252  +**
         1253  +** The callback is only invoked if there have been no prior calls
         1254  +** to OP_Callback or OP_SortCallback.
         1255  +**
         1256  +** This opcode is used to report the number and names of columns
         1257  +** in cases where the result set is empty.
         1258  +*/
         1259  +case OP_NullCallback: {
         1260  +  if( xCallback!=0 && p->nCallback==0 ){
         1261  +    if( xCallback(pArg, pOp->p1, 0, p->azColName)!=0 ){
         1262  +      rc = SQLITE_ABORT;
         1263  +    }
         1264  +    p->nCallback++;
         1265  +  }
         1266  +  break;
         1267  +}
  1238   1268   
  1239   1269   /* Opcode: Concat P1 P2 P3
  1240   1270   **
  1241   1271   ** Look at the first P1 elements of the stack.  Append them all 
  1242   1272   ** together with the lowest element first.  Use P3 as a separator.  
  1243   1273   ** Put the result on the top of the stack.  The original P1 elements
  1244   1274   ** are popped from the stack if P2==0 and retained if P2==1.
................................................................................
  3372   3402   case OP_SortCallback: {
  3373   3403     int i = p->tos;
  3374   3404     VERIFY( if( i<0 ) goto not_enough_stack; )
  3375   3405     if( xCallback!=0 ){
  3376   3406       if( xCallback(pArg, pOp->p1, (char**)zStack[i], p->azColName) ){
  3377   3407         rc = SQLITE_ABORT;
  3378   3408       }
         3409  +    p->nCallback++;
  3379   3410     }
  3380   3411     POPSTACK;
  3381   3412     break;
  3382   3413   }
  3383   3414   
  3384   3415   /* Opcode: SortClose P1 * *
  3385   3416   **

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.29 2001/10/13 02:59:09 drh Exp $
           18  +** $Id: vdbe.h,v 1.30 2001/10/19 16:44:57 drh 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
................................................................................
   151    151   #define OP_Goto               69
   152    152   #define OP_If                 70
   153    153   #define OP_Halt               71
   154    154   
   155    155   #define OP_ColumnCount        72
   156    156   #define OP_ColumnName         73
   157    157   #define OP_Callback           74
          158  +#define OP_NullCallback       75
          159  +
          160  +#define OP_Integer            76
          161  +#define OP_String             77
          162  +#define OP_Null               78
          163  +#define OP_Pop                79
          164  +#define OP_Dup                80
          165  +#define OP_Pull               81
   158    166   
   159         -#define OP_Integer            75
   160         -#define OP_String             76
   161         -#define OP_Null               77
   162         -#define OP_Pop                78
   163         -#define OP_Dup                79
   164         -#define OP_Pull               80
          167  +#define OP_Add                82
          168  +#define OP_AddImm             83
          169  +#define OP_Subtract           84
          170  +#define OP_Multiply           85
          171  +#define OP_Divide             86
          172  +#define OP_Remainder          87
          173  +#define OP_BitAnd             88
          174  +#define OP_BitOr              89
          175  +#define OP_BitNot             90
          176  +#define OP_ShiftLeft          91
          177  +#define OP_ShiftRight         92
          178  +#define OP_AbsValue           93
          179  +#define OP_Precision          94
          180  +#define OP_Min                95
          181  +#define OP_Max                96
          182  +#define OP_Like               97
          183  +#define OP_Glob               98
          184  +#define OP_Eq                 99
          185  +#define OP_Ne                100
          186  +#define OP_Lt                101
          187  +#define OP_Le                102
          188  +#define OP_Gt                103
          189  +#define OP_Ge                104
          190  +#define OP_IsNull            105
          191  +#define OP_NotNull           106
          192  +#define OP_Negative          107
          193  +#define OP_And               108
          194  +#define OP_Or                109
          195  +#define OP_Not               110
          196  +#define OP_Concat            111
          197  +#define OP_Noop              112
   165    198   
   166         -#define OP_Add                81
   167         -#define OP_AddImm             82
   168         -#define OP_Subtract           83
   169         -#define OP_Multiply           84
   170         -#define OP_Divide             85
   171         -#define OP_Remainder          86
   172         -#define OP_BitAnd             87
   173         -#define OP_BitOr              88
   174         -#define OP_BitNot             89
   175         -#define OP_ShiftLeft          90
   176         -#define OP_ShiftRight         91
   177         -#define OP_AbsValue           92
   178         -#define OP_Precision          93
   179         -#define OP_Min                94
   180         -#define OP_Max                95
   181         -#define OP_Like               96
   182         -#define OP_Glob               97
   183         -#define OP_Eq                 98
   184         -#define OP_Ne                 99
   185         -#define OP_Lt                100
   186         -#define OP_Le                101
   187         -#define OP_Gt                102
   188         -#define OP_Ge                103
   189         -#define OP_IsNull            104
   190         -#define OP_NotNull           105
   191         -#define OP_Negative          106
   192         -#define OP_And               107
   193         -#define OP_Or                108
   194         -#define OP_Not               109
   195         -#define OP_Concat            110
   196         -#define OP_Noop              111
          199  +#define OP_Strlen            113
          200  +#define OP_Substr            114
   197    201   
   198         -#define OP_Strlen            112
   199         -#define OP_Substr            113
   200         -
   201         -#define OP_MAX               113
          202  +#define OP_MAX               114
   202    203   
   203    204   /*
   204    205   ** Prototypes for the VDBE interface.  See comments on the implementation
   205    206   ** for a description of what each of these routines does.
   206    207   */
   207    208   Vdbe *sqliteVdbeCreate(sqlite*);
   208    209   void sqliteVdbeCreateCallback(Vdbe*, int*);

Changes to test/select1.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the SELECT statement.
    13     13   #
    14         -# $Id: select1.test,v 1.13 2001/10/18 12:34:48 drh Exp $
           14  +# $Id: select1.test,v 1.14 2001/10/19 16:44:58 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Try to select on a non-existant table.
    20     20   #
    21     21   do_test select1-1.1 {
................................................................................
   410    410   do_test select1-8.5 {
   411    411     execsql {
   412    412       SELECT min(1,2,3), -max(1,2,3)
   413    413       FROM test1 ORDER BY f1
   414    414     }
   415    415   } {1 -3 1 -3}
   416    416   
          417  +
          418  +# Check the behavior when the result set is empty
          419  +#
          420  +do_test select1-9.1 {
          421  +  catch {unset r}
          422  +  set r(*) {}
          423  +  db eval {SELECT * FROM test1 WHERE f1<0} r {}
          424  +  set r(*)
          425  +} {}
          426  +do_test select1-9.2 {
          427  +  execsql {PRAGMA empty_result_callbacks=on}
          428  +  set r(*) {}
          429  +  db eval {SELECT * FROM test1 WHERE f1<0} r {}
          430  +  set r(*)
          431  +} {f1 f2}
          432  +do_test select1-9.3 {
          433  +  set r(*) {}
          434  +  db eval {SELECT * FROM test1 WHERE f1<(select count(*) from test2)} r {}
          435  +  set r(*)
          436  +} {f1 f2}
          437  +do_test select1-9.4 {
          438  +  set r(*) {}
          439  +  db eval {SELECT * FROM test1 ORDER BY f1} r {}
          440  +  set r(*)
          441  +} {f1 f2}
          442  +do_test select1-9.5 {
          443  +  set r(*) {}
          444  +  db eval {SELECT * FROM test1 WHERE f1<0 ORDER BY f1} r {}
          445  +  set r(*)
          446  +} {f1 f2}
          447  +unset r
          448  +
   417    449   finish_test

Changes to www/c_interface.tcl.

     1      1   #
     2      2   # Run this Tcl script to generate the sqlite.html file.
     3      3   #
     4         -set rcsid {$Id: c_interface.tcl,v 1.17 2001/10/12 17:30:05 drh Exp $}
            4  +set rcsid {$Id: c_interface.tcl,v 1.18 2001/10/19 16:44:58 drh Exp $}
     5      5   
     6      6   puts {<html>
     7      7   <head>
     8      8     <title>The C language interface to the SQLite library</title>
     9      9   </head>
    10     10   <body bgcolor=white>
    11     11   <h1 align=center>
................................................................................
    16     16   </p>"
    17     17   
    18     18   puts {
    19     19   <p>The SQLite library is designed to be very easy to use from
    20     20   a C or C++ program.  This document gives an overview of the C/C++
    21     21   programming interface.</p>
    22     22   
    23         -<h2>The API</h2>
           23  +<h2>The Core API</h2>
    24     24   
    25     25   <p>The interface to the SQLite library consists of three core functions,
    26     26   one opaque data structure, and some constants used as return values.
    27     27   The core interface is as follows:</p>
    28     28   
    29     29   <blockquote><pre>
    30     30   typedef struct sqlite sqlite;
           31  +#define SQLITE_OK           0   /* Successful result */
    31     32   
    32     33   sqlite *sqlite_open(const char *dbname, int mode, char **errmsg);
    33     34   
    34     35   void sqlite_close(sqlite*);
    35     36   
    36     37   int sqlite_exec(
    37     38     sqlite*,
    38     39     char *sql,
    39     40     int (*)(void*,int,char**,char**),
    40     41     void*,
    41     42     char **errmsg
    42     43   );
    43         -
    44         -#define SQLITE_OK           0   /* Successful result */
    45         -#define SQLITE_ERROR        1   /* SQL error or missing database */
    46         -#define SQLITE_INTERNAL     2   /* An internal logic error in SQLite */
    47         -#define SQLITE_PERM         3   /* Access permission denied */
    48         -#define SQLITE_ABORT        4   /* Callback routine requested an abort */
    49         -#define SQLITE_BUSY         5   /* The database file is locked */
    50         -#define SQLITE_LOCKED       6   /* A table in the database is locked */
    51         -#define SQLITE_NOMEM        7   /* A malloc() failed */
    52         -#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
    53         -#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite_interrupt() */
    54         -#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
    55         -#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
    56         -#define SQLITE_NOTFOUND    12   /* (Internal Only) Table or record not found */
    57         -#define SQLITE_FULL        13   /* Insertion failed because database is full */
    58         -#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
    59         -#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
    60         -#define SQLITE_EMPTY       16   /* (Internal Only) Database table is empty */
    61         -#define SQLITE_SCHEMA      17   /* The database schema changed */
    62         -#define SQLITE_TOOBIG      18   /* Too much data for one row of a table */
    63         -#define SQLITE_CONSTRAINT  19   /* Abort due to contraint violation */
    64     44   </pre></blockquote>
    65     45   
    66         -<p>Only the three core routines shown above are required to use
    67         -SQLite.  But there are many other functions that provide 
    68         -useful interfaces.  These extended routines are as follows:
    69         -</p>
    70         -
    71         -<blockquote><pre>
    72         -int sqlite_get_table(
    73         -  sqlite*,
    74         -  char *sql,
    75         -  char ***result,
    76         -  int *nrow,
    77         -  int *ncolumn,
    78         -  char **errmsg
    79         -);
    80         -
    81         -void sqlite_free_table(char**);
    82         -
    83         -void sqlite_interrupt(sqlite*);
    84         -
    85         -int sqlite_complete(const char *sql);
    86         -
    87         -void sqlite_busy_handler(sqlite*, int (*)(void*,const char*,int), void*);
    88         -
    89         -void sqlite_busy_timeout(sqlite*, int ms);
    90         -
    91         -const char sqlite_version[];
    92         -
    93         -const char sqlite_encoding[];
    94         -
    95         -int sqlite_exec_printf(
    96         -  sqlite*,
    97         -  char *sql,
    98         -  int (*)(void*,int,char**,char**),
    99         -  void*,
   100         -  char **errmsg,
   101         -  ...
   102         -);
   103         -
   104         -int sqlite_exec_vprintf(
   105         -  sqlite*,
   106         -  char *sql,
   107         -  int (*)(void*,int,char**,char**),
   108         -  void*,
   109         -  char **errmsg,
   110         -  va_list
   111         -);
   112         -
   113         -int sqlite_get_table_printf(
   114         -  sqlite*,
   115         -  char *sql,
   116         -  char ***result,
   117         -  int *nrow,
   118         -  int *ncolumn,
   119         -  char **errmsg,
   120         -  ...
   121         -);
   122         -
   123         -int sqlite_get_table_vprintf(
   124         -  sqlite*,
   125         -  char *sql,
   126         -  char ***result,
   127         -  int *nrow,
   128         -  int *ncolumn,
   129         -  char **errmsg,
   130         -  va_list
   131         -);
   132         -
   133         -</pre></blockquote>
   134         -
   135         -<p>All of the above definitions are included in the "sqlite.h"
   136         -header file that comes in the source tree.</p>
   137         -
           46  +<p>
           47  +The above is all you really need to know in order to use SQLite
           48  +in your C or C++ programs.  There are other convenience functions
           49  +available (and described below) but we will begin by describing
           50  +the core functions shown above.
           51  +</p>
   138     52   <h2>Opening a database</h2>
   139     53   
   140     54   <p>Use the <b>sqlite_open()</b> function to open an existing SQLite
   141     55   database or to create a new SQLite database.  The first argument
   142     56   is the database name.  The second argument is intended to signal
   143     57   whether the database is going to be used for reading and writing
   144     58   or just for reading.  But in the current implementation, the
................................................................................
   220    134   argv[i][0] == 0
   221    135   </pre></blockquote>
   222    136   <p>But if the i-th parameter is NULL we will get:</p>
   223    137   <blockquote><pre>
   224    138   argv[i] == 0
   225    139   </pre></blockquote>
   226    140   <p>The names of the columns are contained in the fourth argument.</p>
          141  +
          142  +<p>If the EMPTY_RESULT_CALLBACKS pragma is set to ON and the result of
          143  +a query is an empty set, then the callback is invoked once with the
          144  +third parameter (argv) set to 0.  In other words
          145  +<blockquote><pre>
          146  +argv == 0
          147  +</pre></blockquote>
          148  +The second parameter (argc)
          149  +and the fourth parameter (columnNames) are still valid
          150  +and can be used to determine the number and names of the result
          151  +columns if there had been a result.
          152  +The default behavior is not to invoke the callback at all if the
          153  +result set is empty.</p>
   227    154   
   228    155   <p>The callback function should normally return 0.  If the callback
   229    156   function returns non-zero, the query is immediately aborted and 
   230    157   <b>sqlite_exec()</b> will return SQLITE_ABORT.</p>
   231    158   
   232         -<p>The <b>sqlite_exec()</b> function returns an integer to indicate
   233         -success or failure of the operation.  The following are possible
   234         -return values:</p>
          159  +<h2>Error Codes</h2>
          160  +
          161  +<p>
          162  +The <b>sqlite_exec()</b> function normally returns SQLITE_OK.  But
          163  +if something goes wrong it can return a different value to indicate
          164  +the type of error.  Here is a complete list of the return codes:
          165  +</p>
          166  +
          167  +<blockquote><pre>
          168  +#define SQLITE_OK           0   /* Successful result */
          169  +#define SQLITE_ERROR        1   /* SQL error or missing database */
          170  +#define SQLITE_INTERNAL     2   /* An internal logic error in SQLite */
          171  +#define SQLITE_PERM         3   /* Access permission denied */
          172  +#define SQLITE_ABORT        4   /* Callback routine requested an abort */
          173  +#define SQLITE_BUSY         5   /* The database file is locked */
          174  +#define SQLITE_LOCKED       6   /* A table in the database is locked */
          175  +#define SQLITE_NOMEM        7   /* A malloc() failed */
          176  +#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
          177  +#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite_interrupt() */
          178  +#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
          179  +#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
          180  +#define SQLITE_NOTFOUND    12   /* (Internal Only) Table or record not found */
          181  +#define SQLITE_FULL        13   /* Insertion failed because database is full */
          182  +#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
          183  +#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
          184  +#define SQLITE_EMPTY       16   /* (Internal Only) Database table is empty */
          185  +#define SQLITE_SCHEMA      17   /* The database schema changed */
          186  +#define SQLITE_TOOBIG      18   /* Too much data for one row of a table */
          187  +#define SQLITE_CONSTRAINT  19   /* Abort due to contraint violation */
          188  +</pre></blockquote>
          189  +
          190  +<p>
          191  +The meanings of these various return values are as follows:
          192  +</p>
   235    193   
   236    194   <blockquote>
   237    195   <dl>
   238    196   <dt>SQLITE_OK</dt>
   239    197   <dd><p>This value is returned if everything worked and there were no errors.
   240    198   </p></dd>
   241    199   <dt>SQLITE_INTERNAL</dt>
................................................................................
   328    286   <dt>SQLITE_CONSTRAINT</dt>
   329    287   <dd><p>This constant is returned if the SQL statement would have violated
   330    288   a database constraint.
   331    289   </p></dd>
   332    290   </dl>
   333    291   </blockquote>
   334    292   
          293  +<h2>The Extended API</h2>
          294  +
          295  +<p>Only the three core routines shown above are required to use
          296  +SQLite.  But there are many other functions that provide 
          297  +useful interfaces.  These extended routines are as follows:
          298  +</p>
          299  +
          300  +<blockquote><pre>
          301  +int sqlite_get_table(
          302  +  sqlite*,
          303  +  char *sql,
          304  +  char ***result,
          305  +  int *nrow,
          306  +  int *ncolumn,
          307  +  char **errmsg
          308  +);
          309  +
          310  +void sqlite_free_table(char**);
          311  +
          312  +void sqlite_interrupt(sqlite*);
          313  +
          314  +int sqlite_complete(const char *sql);
          315  +
          316  +void sqlite_busy_handler(sqlite*, int (*)(void*,const char*,int), void*);
          317  +
          318  +void sqlite_busy_timeout(sqlite*, int ms);
          319  +
          320  +const char sqlite_version[];
          321  +
          322  +const char sqlite_encoding[];
          323  +
          324  +int sqlite_exec_printf(
          325  +  sqlite*,
          326  +  char *sql,
          327  +  int (*)(void*,int,char**,char**),
          328  +  void*,
          329  +  char **errmsg,
          330  +  ...
          331  +);
          332  +
          333  +int sqlite_exec_vprintf(
          334  +  sqlite*,
          335  +  char *sql,
          336  +  int (*)(void*,int,char**,char**),
          337  +  void*,
          338  +  char **errmsg,
          339  +  va_list
          340  +);
          341  +
          342  +int sqlite_get_table_printf(
          343  +  sqlite*,
          344  +  char *sql,
          345  +  char ***result,
          346  +  int *nrow,
          347  +  int *ncolumn,
          348  +  char **errmsg,
          349  +  ...
          350  +);
          351  +
          352  +int sqlite_get_table_vprintf(
          353  +  sqlite*,
          354  +  char *sql,
          355  +  char ***result,
          356  +  int *nrow,
          357  +  int *ncolumn,
          358  +  char **errmsg,
          359  +  va_list
          360  +);
          361  +
          362  +</pre></blockquote>
          363  +
          364  +<p>All of the above definitions are included in the "sqlite.h"
          365  +header file that comes in the source tree.</p>
          366  +
   335    367   <h2>Querying without using a callback function</h2>
   336    368   
   337    369   <p>The <b>sqlite_get_table()</b> function is a wrapper around
   338    370   <b>sqlite_exec()</b> that collects all the information from successive
   339    371   callbacks and write it into memory obtained from malloc().  This
   340    372   is a convenience function that allows the application to get the
   341    373   entire result of a database query with a single function call.</p>
................................................................................
   370    402   result[6] = "D. Richard Hipp"<br>
   371    403   result[7] = "drh"<br>
   372    404   result[8] = "zadok"
   373    405   </blockquote>
   374    406   
   375    407   <p>Notice that the "host" value for the "dummy" record is NULL so
   376    408   the result[] array contains a NULL pointer at that slot.</p>
          409  +
          410  +<p>If the result set of a query is empty, then by default
          411  +<b>sqlite_get_table()</b> will set nrow to 0 and leave its
          412  +result parameter is set to NULL.  But if the EMPTY_RESULT_CALLBACKS
          413  +pragma is ON then the result parameter is initialized to the names
          414  +of the columns only.  For example, consider this query which has
          415  +an empty result set:</p>
          416  +
          417  +<blockquote>
          418  +SELECT employee_name, login, host FROM users WHERE employee_name IS NULL;
          419  +</blockquote>
          420  +
          421  +<p>
          422  +The default behavior gives this results:
          423  +</p>
          424  +
          425  +<blockquote>
          426  +nrow = 0<br>
          427  +ncolumn = 0<br>
          428  +result = 0<br>
          429  +</blockquote>
          430  +
          431  +<p>
          432  +But if the EMPTY_RESULT_CALLBACKS pragma is ON, then the following
          433  +is returned:
          434  +</p>
          435  +
          436  +<blockquote>
          437  +nrow = 0<br>
          438  +ncolumn = 3<br>
          439  +result[0] = "employee_name"<br>
          440  +result[1] = "login"<br>
          441  +result[2] = "host"<br>
          442  +</blockquote>
   377    443   
   378    444   <p>Memory to hold the information returned by <b>sqlite_get_table()</b>
   379    445   is obtained from malloc().  But the calling function should not try
   380    446   to free this information directly.  Instead, pass the complete table
   381         -to <b>sqlite_free_table()</b> when the table is no longer needed.</p>
          447  +to <b>sqlite_free_table()</b> when the table is no longer needed.
          448  +It is safe to call <b>sqlite_free_table()</b> will a NULL pointer such
          449  +as would be returned if the result set is empty.</p>
   382    450   
   383    451   <p>The <b>sqlite_get_table()</b> routine returns the same integer
   384    452   result code as <b>sqlite_exec()</b>.</p>
   385    453   
   386    454   <h2>Interrupting an SQLite operation</h2>
   387    455   
   388    456   <p>The <b>sqlite_interrupt()</b> function can be called from a

Changes to www/changes.tcl.

    13     13   
    14     14   
    15     15   proc chng {date desc} {
    16     16     puts "<DT><B>$date</B></DT>"
    17     17     puts "<DD><P><UL>$desc</UL></P></DD>"
    18     18   }
    19     19   
    20         -chng {2001 Oct ?? (2.0.6)} {
           20  +chng {2001 Oct 19 (2.0.6)} {
           21  +<li>Added the EMPTY_RESULT_CALLBACKS pragma</li>
    21     22   <li>Support for UTF-8 and ISO8859 characters in column and table names.</li>
    22     23   <li>Bug fix: Compute correct table names with the FULL_COLUMN_NAMES pragma
    23     24       is turned on.</li>
    24     25   }
    25     26   
    26     27   chng {2001 Oct 14 (2.0.5)} {
    27     28   <li>Added the COUNT_CHANGES pragma.</li>

Changes to www/lang.tcl.

     1      1   #
     2      2   # Run this Tcl script to generate the sqlite.html file.
     3      3   #
     4         -set rcsid {$Id: lang.tcl,v 1.13 2001/10/15 00:44:36 drh Exp $}
            4  +set rcsid {$Id: lang.tcl,v 1.14 2001/10/19 16:44:58 drh Exp $}
     5      5   
     6      6   puts {<html>
     7      7   <head>
     8      8     <title>Query Language Understood By SQLite</title>
     9      9   </head>
    10     10   <body bgcolor=white>
    11     11   <h1 align=center>
................................................................................
   633    633   
   634    634   <li><p><b>PRAGMA count_changes = ON;
   635    635          <br>PRAGMA count_changes = OFF;</b></p>
   636    636       <p>When on, the COUNT_CHANGES pragma causes the callback function to
   637    637       be invoked once for each DELETE, INSERT, or UPDATE operation.  The
   638    638       argument is the number of rows that were changed.</p>
   639    639   
          640  +<li><p><b>PRAGMA empty_result_callbacks = ON;
          641  +       <br>PRAGMA empty_result_callbacks = OFF;</b></p>
          642  +    <p>When on, the EMPTY_RESULT_CALLBACKS pragma causes the callback
          643  +    function to be invoked once for each query that has an empty result
          644  +    set.  The third "<b>argv</b>" parameter to the callback is set to NULL
          645  +    because there is no data to report.  But the second "<b>argc</b>" and
          646  +    fourth "<b>columnNames</b>" parameters are valid and can be used to
          647  +    determine the number and names of the columns that would have been in
          648  +    the result set had the set not been empty.</p>
          649  +
   640    650   <li><p><b>PRAGMA full_column_names = ON;
   641    651          <br>PRAGMA full_column_names = OFF;</b></p>
   642    652       <p>The column names reported in an SQLite callback are normally just
   643    653       the name of the column itself, except for joins when "TABLE.COLUMN"
   644    654       is used.  But when full_column_names is turned on, column names are
   645    655       always reported as "TABLE.COLUMN" even for simple queries.</p></li>
   646    656