sprintf(&z[j],"%03d",n);
sprintf(&z[j],"%03d",n+1);
static void strftimeFunc(sqlite_func *context, int argc, const char **argv){  DateTime x;  int n, i, j;  char *z;  const char *zFmt = argv[0];  char zBuf[100];  if( argv[0]==0 || isDate(argc-1, argv+1, &x) ) return;  for(i=0, n=1; zFmt[i]; i++, n++){    if( zFmt[i]=='%' ){      switch( zFmt[i+1] ){        case 'd':        case 'H':        case 'm':        case 'M':        case 'S':        case 'W':          n++;          /* fall thru */        case 'w':        case '%':          break;        case 'f':          n += 8;          break;        case 'j':          n += 3;          break;        case 'Y':          n += 8;          break;        case 's':        case 'J':          n += 50;          break;        default:          return;  /* ERROR.  return a NULL */      }      i++;    }  }  if( n<sizeof(zBuf) ){    z = zBuf;  }else{    z = sqliteMalloc( n );    if( z==0 ) return;  }  computeJD(&x);  computeYMD_HMS(&x);  for(i=j=0; zFmt[i]; i++){    if( zFmt[i]!='%' ){      z[j++] = zFmt[i];    }else{      i++;      switch( zFmt[i] ){        case 'd':  sprintf(&z[j],"%02d",x.D); j+=2; break;        case 'f': {          int s = x.s;          int ms = (x.s - s)*1000.0;          sprintf(&z[j],"%02d.%03d",s,ms);          j += strlen(&z[j]);          break;        }        case 'H':  sprintf(&z[j],"%02d",x.h); j+=2; break;        case 'W': /* Fall thru */        case 'j': {          int n;          DateTime y = x;          y.validJD = 0;          y.M = 1;          y.D = 1;          computeJD(&y);          n = x.rJD - y.rJD + 1;          if( zFmt[i]=='W' ){            sprintf(&z[j],"%02d",(n+6)/7);            j += 2;          }else{            sprintf(&z[j],"%03d",n);            j += 3;          }          break;        }        case 'J':  sprintf(&z[j],"%.16g",x.rJD); j+=strlen(&z[j]); break;        case 'm':  sprintf(&z[j],"%02d",x.M); j+=2; break;        case 'M':  sprintf(&z[j],"%02d",x.m); j+=2; break;        case 's': {          sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0 + 0.5));          j += strlen(&z[j]);          break;        }        case 'S':  sprintf(&z[j],"%02d",(int)(x.s+0.5)); j+=2; break;        case 'w':  z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;        case 'Y':  sprintf(&z[j],"%04d",x.Y); j+=strlen(&z[j]); break;        case '%':  z[j++] = '%'; break;      }    }  }  z[j] = 0;  sqlite_set_result_string(context, z, -1);  if( z!=zBuf ){    sqliteFree(z);  }}