void *pArg = aAggs[i].argType==2 ? (void*)(-1) : db;
void *pArg; switch( aAggs[i].argType ){ case 0:  pArg = 0;           break; case 1:  pArg = db;          break; case 2:  pArg = (void*)(-1); break; }
void sqliteRegisterBuiltinFunctions(sqlite *db){  static struct {     char *zName;     signed char nArg;     signed char dataType;     u8 argType;               /* 0: none.  1: db  2: (-1) */     void (*xFunc)(sqlite_func*,int,const char**);  } aFuncs[] = {    { "min",       -1, SQLITE_ARGS,    0, minmaxFunc },    { "min",        0, 0,              0, 0          },    { "max",       -1, SQLITE_ARGS,    2, minmaxFunc },    { "max",        0, 0,              2, 0          },    { "typeof",     1, SQLITE_TEXT,    0, typeofFunc },    { "length",     1, SQLITE_NUMERIC, 0, lengthFunc },    { "substr",     3, SQLITE_TEXT,    0, substrFunc },    { "abs",        1, SQLITE_NUMERIC, 0, absFunc    },    { "round",      1, SQLITE_NUMERIC, 0, roundFunc  },    { "round",      2, SQLITE_NUMERIC, 0, roundFunc  },    { "upper",      1, SQLITE_TEXT,    0, upperFunc  },    { "lower",      1, SQLITE_TEXT,    0, lowerFunc  },    { "coalesce",  -1, SQLITE_ARGS,    0, ifnullFunc },    { "coalesce",   0, 0,              0, 0          },    { "coalesce",   1, 0,              0, 0          },    { "ifnull",     2, SQLITE_ARGS,    0, ifnullFunc },    { "random",    -1, SQLITE_NUMERIC, 0, randomFunc },    { "like",       2, SQLITE_NUMERIC, 0, likeFunc   },    { "glob",       2, SQLITE_NUMERIC, 0, globFunc   },    { "nullif",     2, SQLITE_ARGS,    0, nullifFunc },    { "sqlite_version",0,SQLITE_TEXT,  0, versionFunc},    { "quote",      1, SQLITE_ARGS,    0, quoteFunc  },    { "last_insert_rowid", 0, SQLITE_NUMERIC, 1, last_insert_rowid },    { "change_count",      0, SQLITE_NUMERIC, 1, change_count      },    { "last_statement_change_count",                           0, SQLITE_NUMERIC, 1, last_statement_change_count },#ifdef SQLITE_SOUNDEX    { "soundex",    1, SQLITE_TEXT,    0, soundexFunc},#endif#ifdef SQLITE_TEST    { "randstr",    2, SQLITE_TEXT,    0, randStr    },#endif  };  static struct {    char *zName;    signed char nArg;    signed char dataType;    u8 argType;    void (*xStep)(sqlite_func*,int,const char**);    void (*xFinalize)(sqlite_func*);  } aAggs[] = {    { "min",    1, 0,              0, minmaxStep,   minMaxFinalize },    { "max",    1, 0,              2, minmaxStep,   minMaxFinalize },    { "sum",    1, SQLITE_NUMERIC, 0, sumStep,      sumFinalize    },    { "avg",    1, SQLITE_NUMERIC, 0, sumStep,      avgFinalize    },    { "count",  0, SQLITE_NUMERIC, 0, countStep,    countFinalize  },    { "count",  1, SQLITE_NUMERIC, 0, countStep,    countFinalize  },#if 0    { "stddev", 1, SQLITE_NUMERIC, 0, stdDevStep,   stdDevFinalize },#endif  };  static const char *azTypeFuncs[] = { "min", "max", "typeof" };  int i;  for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){    void *pArg = aFuncs[i].argType==2 ? (void*)(-1) : db;    sqlite_create_function(db, aFuncs[i].zName,           aFuncs[i].nArg, aFuncs[i].xFunc, pArg);    if( aFuncs[i].xFunc ){      sqlite_function_type(db, aFuncs[i].zName, aFuncs[i].dataType);    }  }  for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){    void *pArg = aAggs[i].argType==2 ? (void*)(-1) : db;    sqlite_create_aggregate(db, aAggs[i].zName,           aAggs[i].nArg, aAggs[i].xStep, aAggs[i].xFinalize, pArg);    sqlite_function_type(db, aAggs[i].zName, aAggs[i].dataType);  }  for(i=0; i<sizeof(azTypeFuncs)/sizeof(azTypeFuncs[0]); i++){    int n = strlen(azTypeFuncs[i]);    FuncDef *p = sqliteHashFind(&db->aFunc, azTypeFuncs[i], n);    while( p ){      p->includeTypes = 1;      p = p->pNext;    }  }  sqliteRegisterDateTimeFunctions(db);}