diff options
author | drh <drh@noemail.net> | 2018-11-16 13:06:30 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-11-16 13:06:30 +0000 |
commit | eabbf37fae9416e0680cdd4068314be3d45ca7be (patch) | |
tree | 3bc2566581bb4f8233488d00d08b49141cd685db /ext/misc/fileio.c | |
parent | cbfaa076d70dd0ec0110bcc24c32e2ae11d633e0 (diff) | |
download | sqlite-eabbf37fae9416e0680cdd4068314be3d45ca7be.tar.gz sqlite-eabbf37fae9416e0680cdd4068314be3d45ca7be.zip |
Fix comments and make magic numbers into #defines in the fsdir
implementation.
FossilOrigin-Name: c537c9c3630ca979bdccab977275bfc11cce33ea54adb71a4bd4f46c85f65c6f
Diffstat (limited to 'ext/misc/fileio.c')
-rw-r--r-- | ext/misc/fileio.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c index 12d20084f..47f474b6b 100644 --- a/ext/misc/fileio.c +++ b/ext/misc/fileio.c @@ -106,7 +106,18 @@ SQLITE_EXTENSION_INIT1 #include <errno.h> +/* +** Structure of the fsdir() table-valued function +*/ + /* 0 1 2 3 4 5 */ #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)" +#define FSDIR_COLUMN_NAME 0 /* Name of the file */ +#define FSDIR_COLUMN_MODE 1 /* Access mode */ +#define FSDIR_COLUMN_MTIME 2 /* Last modification time */ +#define FSDIR_COLUMN_DATA 3 /* File content */ +#define FSDIR_COLUMN_PATH 4 /* Path to top of search */ +#define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */ + /* ** Set the result stored by context ctx to a blob containing the @@ -695,20 +706,20 @@ static int fsdirColumn( ){ fsdir_cursor *pCur = (fsdir_cursor*)cur; switch( i ){ - case 0: { /* name */ + case FSDIR_COLUMN_NAME: { sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT); break; } - case 1: /* mode */ + case FSDIR_COLUMN_MODE: sqlite3_result_int64(ctx, pCur->sStat.st_mode); break; - case 2: /* mtime */ + case FSDIR_COLUMN_MTIME: sqlite3_result_int64(ctx, pCur->sStat.st_mtime); break; - case 3: { /* data */ + case FSDIR_COLUMN_DATA: { mode_t m = pCur->sStat.st_mode; if( S_ISDIR(m) ){ sqlite3_result_null(ctx); @@ -738,6 +749,12 @@ static int fsdirColumn( readFileContents(ctx, pCur->zPath); } } + case FSDIR_COLUMN_PATH: + default: { + /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters. + ** always return their values as NULL */ + break; + } } return SQLITE_OK; } @@ -764,6 +781,9 @@ static int fsdirEof(sqlite3_vtab_cursor *cur){ /* ** xFilter callback. +** +** idxNum==1 PATH parameter only +** idxNum==2 Both PATH and DIR supplied */ static int fsdirFilter( sqlite3_vtab_cursor *cur, @@ -816,20 +836,18 @@ static int fsdirFilter( ** In this implementation idxNum is used to represent the ** query plan. idxStr is unused. ** -** The query plan is represented by bits in idxNum: +** The query plan is represented by values of idxNum: ** -** (1) start = $value -- constraint exists -** (2) stop = $value -- constraint exists -** (4) step = $value -- constraint exists -** (8) output in descending order +** (1) The path value is supplied by argv[0] +** (2) Path is in argv[0] and dir is in argv[1] */ static int fsdirBestIndex( sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo ){ int i; /* Loop over constraints */ - int idx4 = -1; - int idx5 = -1; + int idx4 = -1; /* Index in pIdxInfo->aConstraint of PATH= */ + int idx5 = -1; /* Index in pIdxInfo->aConstraint of DIR= */ const struct sqlite3_index_constraint *pConstraint; (void)tab; |