/ Check-in [c537c9c3]
Login

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

Overview
Comment:Fix comments and make magic numbers into #defines in the fsdir implementation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c537c9c3630ca979bdccab977275bfc11cce33ea54adb71a4bd4f46c85f65c6f
User & Date: drh 2018-11-16 13:06:30
Context
2018-11-16
13:56
Enhance the xBestIndex interface of virtual table so that if the xBestIndex method returns SQLITE_CONSTRAINT then that particular combination of constraints is considered unusable and does not participate further in query planning. check-in: 684013ce user: drh tags: trunk
13:06
Fix comments and make magic numbers into #defines in the fsdir implementation. check-in: c537c9c3 user: drh tags: trunk
08:36
Fix a problem with virtual table "fsdir" and some join queries. check-in: 7fffcee0 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/fileio.c.

   102    102   #  define mkdir(path,mode) _mkdir(path)
   103    103   #  define lstat(path,buf) stat(path,buf)
   104    104   #endif
   105    105   #include <time.h>
   106    106   #include <errno.h>
   107    107   
   108    108   
          109  +/*
          110  +** Structure of the fsdir() table-valued function
          111  +*/
          112  +                 /*    0    1    2     3    4           5             */
   109    113   #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
          114  +#define FSDIR_COLUMN_NAME     0     /* Name of the file */
          115  +#define FSDIR_COLUMN_MODE     1     /* Access mode */
          116  +#define FSDIR_COLUMN_MTIME    2     /* Last modification time */
          117  +#define FSDIR_COLUMN_DATA     3     /* File content */
          118  +#define FSDIR_COLUMN_PATH     4     /* Path to top of search */
          119  +#define FSDIR_COLUMN_DIR      5     /* Path is relative to this directory */
          120  +
   110    121   
   111    122   /*
   112    123   ** Set the result stored by context ctx to a blob containing the 
   113    124   ** contents of file zName.
   114    125   */
   115    126   static void readFileContents(sqlite3_context *ctx, const char *zName){
   116    127     FILE *in;
................................................................................
   691    702   static int fsdirColumn(
   692    703     sqlite3_vtab_cursor *cur,   /* The cursor */
   693    704     sqlite3_context *ctx,       /* First argument to sqlite3_result_...() */
   694    705     int i                       /* Which column to return */
   695    706   ){
   696    707     fsdir_cursor *pCur = (fsdir_cursor*)cur;
   697    708     switch( i ){
   698         -    case 0: { /* name */
          709  +    case FSDIR_COLUMN_NAME: {
   699    710         sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
   700    711         break;
   701    712       }
   702    713   
   703         -    case 1: /* mode */
          714  +    case FSDIR_COLUMN_MODE:
   704    715         sqlite3_result_int64(ctx, pCur->sStat.st_mode);
   705    716         break;
   706    717   
   707         -    case 2: /* mtime */
          718  +    case FSDIR_COLUMN_MTIME:
   708    719         sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
   709    720         break;
   710    721   
   711         -    case 3: { /* data */
          722  +    case FSDIR_COLUMN_DATA: {
   712    723         mode_t m = pCur->sStat.st_mode;
   713    724         if( S_ISDIR(m) ){
   714    725           sqlite3_result_null(ctx);
   715    726   #if !defined(_WIN32) && !defined(WIN32)
   716    727         }else if( S_ISLNK(m) ){
   717    728           char aStatic[64];
   718    729           char *aBuf = aStatic;
................................................................................
   734    745           sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
   735    746           if( aBuf!=aStatic ) sqlite3_free(aBuf);
   736    747   #endif
   737    748         }else{
   738    749           readFileContents(ctx, pCur->zPath);
   739    750         }
   740    751       }
          752  +    case FSDIR_COLUMN_PATH:
          753  +    default: {
          754  +      /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
          755  +      ** always return their values as NULL */
          756  +      break;
          757  +    }
   741    758     }
   742    759     return SQLITE_OK;
   743    760   }
   744    761   
   745    762   /*
   746    763   ** Return the rowid for the current row. In this implementation, the
   747    764   ** first row returned is assigned rowid value 1, and each subsequent
................................................................................
   760    777   static int fsdirEof(sqlite3_vtab_cursor *cur){
   761    778     fsdir_cursor *pCur = (fsdir_cursor*)cur;
   762    779     return (pCur->zPath==0);
   763    780   }
   764    781   
   765    782   /*
   766    783   ** xFilter callback.
          784  +**
          785  +** idxNum==1   PATH parameter only
          786  +** idxNum==2   Both PATH and DIR supplied
   767    787   */
   768    788   static int fsdirFilter(
   769    789     sqlite3_vtab_cursor *cur, 
   770    790     int idxNum, const char *idxStr,
   771    791     int argc, sqlite3_value **argv
   772    792   ){
   773    793     const char *zDir = 0;
................................................................................
   812    832   ** that uses the generate_series virtual table.  This routine needs to create
   813    833   ** a query plan for each invocation and compute an estimated cost for that
   814    834   ** plan.
   815    835   **
   816    836   ** In this implementation idxNum is used to represent the
   817    837   ** query plan.  idxStr is unused.
   818    838   **
   819         -** The query plan is represented by bits in idxNum:
          839  +** The query plan is represented by values of idxNum:
   820    840   **
   821         -**  (1)  start = $value  -- constraint exists
   822         -**  (2)  stop = $value   -- constraint exists
   823         -**  (4)  step = $value   -- constraint exists
   824         -**  (8)  output in descending order
          841  +**  (1)  The path value is supplied by argv[0]
          842  +**  (2)  Path is in argv[0] and dir is in argv[1]
   825    843   */
   826    844   static int fsdirBestIndex(
   827    845     sqlite3_vtab *tab,
   828    846     sqlite3_index_info *pIdxInfo
   829    847   ){
   830    848     int i;                 /* Loop over constraints */
   831         -  int idx4 = -1;
   832         -  int idx5 = -1;
          849  +  int idx4 = -1;         /* Index in pIdxInfo->aConstraint of PATH= */
          850  +  int idx5 = -1;         /* Index in pIdxInfo->aConstraint of DIR= */
   833    851     const struct sqlite3_index_constraint *pConstraint;
   834    852   
   835    853     (void)tab;
   836    854     pConstraint = pIdxInfo->aConstraint;
   837    855     for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
   838    856       if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
   839    857       if( pConstraint->iColumn==4 && pConstraint->usable ) idx4 = i;