4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** Code for testing the virtual table interfaces. This code
13 ** is not included in the SQLite library. It is used for automated
14 ** testing of the SQLite library.
16 ** The FS virtual table is created as follows:
18 ** CREATE VIRTUAL TABLE tbl USING fs(idx);
20 ** where idx is the name of a table in the db with 2 columns. The virtual
21 ** table also has two columns - file path and file contents.
23 ** The first column of table idx must be an IPK, and the second contains file
24 ** paths. For example:
26 ** CREATE TABLE idx(id INTEGER PRIMARY KEY, path TEXT);
27 ** INSERT INTO idx VALUES(4, '/etc/passwd');
29 ** Adding the row to the idx table automatically creates a row in the
30 ** virtual table with rowid=4, path=/etc/passwd and a text field that
31 ** contains data read from file /etc/passwd on disk.
33 *************************************************************************
34 ** Virtual table module "fsdir"
36 ** This module is designed to be used as a read-only eponymous virtual table.
37 ** Its schema is as follows:
39 ** CREATE TABLE fsdir(dir TEXT, name TEXT);
41 ** When queried, a WHERE term of the form "dir = $dir" must be provided. The
42 ** virtual table then appears to have one row for each entry in file-system
43 ** directory $dir. Column dir contains a copy of $dir, and column "name"
44 ** contains the name of the directory entry.
46 ** If the specified $dir cannot be opened or is not a directory, it is not
47 ** an error. The virtual table appears to be empty in this case.
49 *************************************************************************
50 ** Virtual table module "fstree"
52 ** This module is also a read-only eponymous virtual table with the
55 ** CREATE TABLE fstree(path TEXT, size INT, data BLOB);
57 ** Running a "SELECT * FROM fstree" query on this table returns the entire
58 ** contents of the file-system, starting at "/". To restrict the search
59 ** space, the virtual table supports LIKE and GLOB constraints on the
60 ** 'path' column. For example:
62 ** SELECT * FROM fstree WHERE path LIKE '/home/dan/sqlite/%'
64 #include "sqliteInt.h"
65 #if defined(INCLUDE_SQLITE_TCL_H)
66 # include "sqlite_tcl.h"
73 #include <sys/types.h>
77 #if SQLITE_OS_UNIX || defined(__MINGW_H)
81 # define DIRENT dirent
86 # if !defined(__MINGW_H)
87 # include "test_windirent.h"
90 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
94 #ifndef SQLITE_OMIT_VIRTUALTABLE
96 typedef struct fs_vtab fs_vtab
;
97 typedef struct fs_cursor fs_cursor
;
100 ** A fs virtual-table object
105 char *zDb
; /* Name of db containing zTbl */
106 char *zTbl
; /* Name of docid->file map table */
109 /* A fs cursor object */
111 sqlite3_vtab_cursor base
;
118 /*************************************************************************
119 ** Start of fsdir implementation.
121 typedef struct FsdirVtab FsdirVtab
;
122 typedef struct FsdirCsr FsdirCsr
;
128 sqlite3_vtab_cursor base
;
129 char *zDir
; /* Buffer containing directory scanned */
130 DIR *pDir
; /* Open directory */
131 sqlite3_int64 iRowid
;
132 struct DIRENT entry
; /* Current entry */
136 ** This function is the implementation of both the xConnect and xCreate
137 ** methods of the fsdir virtual table.
139 ** The argv[] array contains the following:
141 ** argv[0] -> module name ("fs")
142 ** argv[1] -> database name
143 ** argv[2] -> table name
144 ** argv[...] -> other module argument fields.
146 static int fsdirConnect(
149 int argc
, const char *const*argv
,
150 sqlite3_vtab
**ppVtab
,
156 *pzErr
= sqlite3_mprintf("wrong number of arguments");
160 pTab
= (FsdirVtab
*)sqlite3_malloc(sizeof(FsdirVtab
));
161 if( !pTab
) return SQLITE_NOMEM
;
162 memset(pTab
, 0, sizeof(FsdirVtab
));
164 *ppVtab
= &pTab
->base
;
165 sqlite3_declare_vtab(db
, "CREATE TABLE xyz(dir, name);");
171 ** xDestroy/xDisconnect implementation.
173 static int fsdirDisconnect(sqlite3_vtab
*pVtab
){
179 ** xBestIndex implementation. The only constraint supported is:
183 static int fsdirBestIndex(sqlite3_vtab
*tab
, sqlite3_index_info
*pIdxInfo
){
186 pIdxInfo
->estimatedCost
= 1000000000.0;
188 for(ii
=0; ii
<pIdxInfo
->nConstraint
; ii
++){
189 struct sqlite3_index_constraint
const *p
= &pIdxInfo
->aConstraint
[ii
];
190 if( p
->iColumn
==0 && p
->usable
&& p
->op
==SQLITE_INDEX_CONSTRAINT_EQ
){
191 struct sqlite3_index_constraint_usage
*pUsage
;
192 pUsage
= &pIdxInfo
->aConstraintUsage
[ii
];
194 pUsage
->argvIndex
= 1;
195 pIdxInfo
->idxNum
= 1;
196 pIdxInfo
->estimatedCost
= 1.0;
205 ** xOpen implementation.
207 ** Open a new fsdir cursor.
209 static int fsdirOpen(sqlite3_vtab
*pVTab
, sqlite3_vtab_cursor
**ppCursor
){
211 /* Allocate an extra 256 bytes because it is undefined how big dirent.d_name
212 ** is and we need enough space. Linux provides plenty already, but
213 ** Solaris only provides one byte. */
214 pCur
= (FsdirCsr
*)sqlite3_malloc(sizeof(FsdirCsr
)+256);
215 if( pCur
==0 ) return SQLITE_NOMEM
;
216 memset(pCur
, 0, sizeof(FsdirCsr
));
217 *ppCursor
= &pCur
->base
;
222 ** Close a fsdir cursor.
224 static int fsdirClose(sqlite3_vtab_cursor
*cur
){
225 FsdirCsr
*pCur
= (FsdirCsr
*)cur
;
226 if( pCur
->pDir
) closedir(pCur
->pDir
);
227 sqlite3_free(pCur
->zDir
);
233 ** Skip the cursor to the next entry.
235 static int fsdirNext(sqlite3_vtab_cursor
*cur
){
236 FsdirCsr
*pCsr
= (FsdirCsr
*)cur
;
239 struct DIRENT
*pRes
= 0;
240 #if defined(__MINGW_H)
241 pRes
= readdir(pCsr
->pDir
);
243 memcpy(&pCsr
->entry
, pRes
, sizeof(struct DIRENT
));
246 readdir_r(pCsr
->pDir
, &pCsr
->entry
, &pRes
);
249 closedir(pCsr
->pDir
);
259 ** xFilter method implementation.
261 static int fsdirFilter(
262 sqlite3_vtab_cursor
*pVtabCursor
,
263 int idxNum
, const char *idxStr
,
264 int argc
, sqlite3_value
**argv
266 FsdirCsr
*pCsr
= (FsdirCsr
*)pVtabCursor
;
271 if( idxNum
!=1 || argc
!=1 ){
276 sqlite3_free(pCsr
->zDir
);
278 closedir(pCsr
->pDir
);
282 zDir
= (const char*)sqlite3_value_text(argv
[0]);
283 nDir
= sqlite3_value_bytes(argv
[0]);
284 pCsr
->zDir
= sqlite3_malloc(nDir
+1);
285 if( pCsr
->zDir
==0 ) return SQLITE_NOMEM
;
286 memcpy(pCsr
->zDir
, zDir
, nDir
+1);
288 pCsr
->pDir
= opendir(pCsr
->zDir
);
289 return fsdirNext(pVtabCursor
);
293 ** xEof method implementation.
295 static int fsdirEof(sqlite3_vtab_cursor
*cur
){
296 FsdirCsr
*pCsr
= (FsdirCsr
*)cur
;
297 return pCsr
->pDir
==0;
301 ** xColumn method implementation.
303 static int fsdirColumn(sqlite3_vtab_cursor
*cur
, sqlite3_context
*ctx
, int i
){
304 FsdirCsr
*pCsr
= (FsdirCsr
*)cur
;
307 sqlite3_result_text(ctx
, pCsr
->zDir
, -1, SQLITE_STATIC
);
311 sqlite3_result_text(ctx
, pCsr
->entry
.d_name
, -1, SQLITE_TRANSIENT
);
322 ** xRowid method implementation.
324 static int fsdirRowid(sqlite3_vtab_cursor
*cur
, sqlite_int64
*pRowid
){
325 FsdirCsr
*pCsr
= (FsdirCsr
*)cur
;
326 *pRowid
= pCsr
->iRowid
;
330 ** End of fsdir implementation.
331 *************************************************************************/
333 /*************************************************************************
334 ** Start of fstree implementation.
336 typedef struct FstreeVtab FstreeVtab
;
337 typedef struct FstreeCsr FstreeCsr
;
344 sqlite3_vtab_cursor base
;
345 sqlite3_stmt
*pStmt
; /* Statement to list paths */
346 int fd
; /* File descriptor open on current path */
350 ** This function is the implementation of both the xConnect and xCreate
351 ** methods of the fstree virtual table.
353 ** The argv[] array contains the following:
355 ** argv[0] -> module name ("fs")
356 ** argv[1] -> database name
357 ** argv[2] -> table name
358 ** argv[...] -> other module argument fields.
360 static int fstreeConnect(
363 int argc
, const char *const*argv
,
364 sqlite3_vtab
**ppVtab
,
370 *pzErr
= sqlite3_mprintf("wrong number of arguments");
374 pTab
= (FstreeVtab
*)sqlite3_malloc(sizeof(FstreeVtab
));
375 if( !pTab
) return SQLITE_NOMEM
;
376 memset(pTab
, 0, sizeof(FstreeVtab
));
379 *ppVtab
= &pTab
->base
;
380 sqlite3_declare_vtab(db
, "CREATE TABLE xyz(path, size, data);");
386 ** xDestroy/xDisconnect implementation.
388 static int fstreeDisconnect(sqlite3_vtab
*pVtab
){
394 ** xBestIndex implementation. The only constraint supported is:
398 static int fstreeBestIndex(sqlite3_vtab
*tab
, sqlite3_index_info
*pIdxInfo
){
401 for(ii
=0; ii
<pIdxInfo
->nConstraint
; ii
++){
402 struct sqlite3_index_constraint
const *p
= &pIdxInfo
->aConstraint
[ii
];
403 if( p
->iColumn
==0 && p
->usable
&& (
404 p
->op
==SQLITE_INDEX_CONSTRAINT_GLOB
405 || p
->op
==SQLITE_INDEX_CONSTRAINT_LIKE
406 || p
->op
==SQLITE_INDEX_CONSTRAINT_EQ
408 struct sqlite3_index_constraint_usage
*pUsage
;
409 pUsage
= &pIdxInfo
->aConstraintUsage
[ii
];
410 pIdxInfo
->idxNum
= p
->op
;
411 pUsage
->argvIndex
= 1;
412 pIdxInfo
->estimatedCost
= 100000.0;
417 pIdxInfo
->estimatedCost
= 1000000000.0;
422 ** xOpen implementation.
424 ** Open a new fstree cursor.
426 static int fstreeOpen(sqlite3_vtab
*pVTab
, sqlite3_vtab_cursor
**ppCursor
){
428 pCur
= (FstreeCsr
*)sqlite3_malloc(sizeof(FstreeCsr
));
429 if( pCur
==0 ) return SQLITE_NOMEM
;
430 memset(pCur
, 0, sizeof(FstreeCsr
));
432 *ppCursor
= &pCur
->base
;
436 static void fstreeCloseFd(FstreeCsr
*pCsr
){
444 ** Close a fstree cursor.
446 static int fstreeClose(sqlite3_vtab_cursor
*cur
){
447 FstreeCsr
*pCsr
= (FstreeCsr
*)cur
;
448 sqlite3_finalize(pCsr
->pStmt
);
455 ** Skip the cursor to the next entry.
457 static int fstreeNext(sqlite3_vtab_cursor
*cur
){
458 FstreeCsr
*pCsr
= (FstreeCsr
*)cur
;
462 rc
= sqlite3_step(pCsr
->pStmt
);
463 if( rc
!=SQLITE_ROW
){
464 rc
= sqlite3_finalize(pCsr
->pStmt
);
468 pCsr
->fd
= open((const char*)sqlite3_column_text(pCsr
->pStmt
, 0), O_RDONLY
);
475 ** xFilter method implementation.
477 static int fstreeFilter(
478 sqlite3_vtab_cursor
*pVtabCursor
,
479 int idxNum
, const char *idxStr
,
480 int argc
, sqlite3_value
**argv
482 FstreeCsr
*pCsr
= (FstreeCsr
*)pVtabCursor
;
483 FstreeVtab
*pTab
= (FstreeVtab
*)(pCsr
->base
.pVtab
);
487 " SELECT CASE WHEN dir=?2 THEN ?3 ELSE dir END || '/' || name "
488 " FROM fsdir WHERE dir=?1 AND name NOT LIKE '.%'"
490 " SELECT dir || '/' || name FROM r, fsdir WHERE dir=d AND name NOT LIKE '.%'"
491 ") SELECT d FROM r;";
499 char aWild
[2] = { '\0', '\0' };
502 const char *zDrive
= windirent_getenv("fstreeDrive");
504 zDrive
= windirent_getenv("SystemDrive");
506 zRoot
= sqlite3_mprintf("%s%c", zDrive
, '/');
507 nRoot
= sqlite3Strlen30(zRoot
);
508 zPrefix
= sqlite3_mprintf("%s", zDrive
);
509 nPrefix
= sqlite3Strlen30(zPrefix
);
521 sqlite3_finalize(pCsr
->pStmt
);
523 rc
= sqlite3_prepare_v2(pTab
->db
, zSql
, -1, &pCsr
->pStmt
, 0);
524 if( rc
!=SQLITE_OK
) return rc
;
527 const char *zQuery
= (const char*)sqlite3_value_text(argv
[0]);
529 case SQLITE_INDEX_CONSTRAINT_GLOB
:
533 case SQLITE_INDEX_CONSTRAINT_LIKE
:
539 if( sqlite3_strnicmp(zQuery
, zPrefix
, nPrefix
)==0 ){
541 for(i
=nPrefix
; zQuery
[i
]; i
++){
542 if( zQuery
[i
]==aWild
[0] || zQuery
[i
]==aWild
[1] ) break;
543 if( zQuery
[i
]=='/' ) nDir
= i
;
548 if( nDir
==0 ) nDir
= 1;
550 sqlite3_bind_text(pCsr
->pStmt
, 1, zDir
, nDir
, SQLITE_TRANSIENT
);
551 sqlite3_bind_text(pCsr
->pStmt
, 2, zRoot
, nRoot
, SQLITE_TRANSIENT
);
552 sqlite3_bind_text(pCsr
->pStmt
, 3, zPrefix
, nPrefix
, SQLITE_TRANSIENT
);
555 sqlite3_free(zPrefix
);
559 return fstreeNext(pVtabCursor
);
563 ** xEof method implementation.
565 static int fstreeEof(sqlite3_vtab_cursor
*cur
){
566 FstreeCsr
*pCsr
= (FstreeCsr
*)cur
;
567 return pCsr
->pStmt
==0;
571 ** xColumn method implementation.
573 static int fstreeColumn(sqlite3_vtab_cursor
*cur
, sqlite3_context
*ctx
, int i
){
574 FstreeCsr
*pCsr
= (FstreeCsr
*)cur
;
575 if( i
==0 ){ /* path */
576 sqlite3_result_value(ctx
, sqlite3_column_value(pCsr
->pStmt
, 0));
579 fstat(pCsr
->fd
, &sBuf
);
581 if( S_ISREG(sBuf
.st_mode
) ){
583 sqlite3_result_int64(ctx
, sBuf
.st_size
);
586 char *aBuf
= sqlite3_malloc(sBuf
.st_mode
+1);
587 if( !aBuf
) return SQLITE_NOMEM
;
588 nRead
= read(pCsr
->fd
, aBuf
, sBuf
.st_mode
);
589 if( nRead
!=sBuf
.st_mode
){
592 sqlite3_result_blob(ctx
, aBuf
, nRead
, SQLITE_TRANSIENT
);
602 ** xRowid method implementation.
604 static int fstreeRowid(sqlite3_vtab_cursor
*cur
, sqlite_int64
*pRowid
){
609 ** End of fstree implementation.
610 *************************************************************************/
616 ** This function is the implementation of both the xConnect and xCreate
617 ** methods of the fs virtual table.
619 ** The argv[] array contains the following:
621 ** argv[0] -> module name ("fs")
622 ** argv[1] -> database name
623 ** argv[2] -> table name
624 ** argv[...] -> other module argument fields.
626 static int fsConnect(
629 int argc
, const char *const*argv
,
630 sqlite3_vtab
**ppVtab
,
636 const char *zDb
= argv
[1];
639 *pzErr
= sqlite3_mprintf("wrong number of arguments");
644 nByte
= sizeof(fs_vtab
) + (int)strlen(zTbl
) + 1 + (int)strlen(zDb
) + 1;
645 pVtab
= (fs_vtab
*)sqlite3MallocZero( nByte
);
646 if( !pVtab
) return SQLITE_NOMEM
;
648 pVtab
->zTbl
= (char *)&pVtab
[1];
649 pVtab
->zDb
= &pVtab
->zTbl
[strlen(zTbl
)+1];
651 memcpy(pVtab
->zTbl
, zTbl
, strlen(zTbl
));
652 memcpy(pVtab
->zDb
, zDb
, strlen(zDb
));
653 *ppVtab
= &pVtab
->base
;
654 sqlite3_declare_vtab(db
, "CREATE TABLE x(path TEXT, data TEXT)");
658 /* Note that for this virtual table, the xCreate and xConnect
659 ** methods are identical. */
661 static int fsDisconnect(sqlite3_vtab
*pVtab
){
665 /* The xDisconnect and xDestroy methods are also the same */
668 ** Open a new fs cursor.
670 static int fsOpen(sqlite3_vtab
*pVTab
, sqlite3_vtab_cursor
**ppCursor
){
672 pCur
= sqlite3MallocZero(sizeof(fs_cursor
));
673 *ppCursor
= &pCur
->base
;
678 ** Close a fs cursor.
680 static int fsClose(sqlite3_vtab_cursor
*cur
){
681 fs_cursor
*pCur
= (fs_cursor
*)cur
;
682 sqlite3_finalize(pCur
->pStmt
);
683 sqlite3_free(pCur
->zBuf
);
688 static int fsNext(sqlite3_vtab_cursor
*cur
){
689 fs_cursor
*pCur
= (fs_cursor
*)cur
;
692 rc
= sqlite3_step(pCur
->pStmt
);
693 if( rc
==SQLITE_ROW
|| rc
==SQLITE_DONE
) rc
= SQLITE_OK
;
699 sqlite3_vtab_cursor
*pVtabCursor
,
700 int idxNum
, const char *idxStr
,
701 int argc
, sqlite3_value
**argv
704 fs_cursor
*pCur
= (fs_cursor
*)pVtabCursor
;
705 fs_vtab
*p
= (fs_vtab
*)(pVtabCursor
->pVtab
);
707 assert( (idxNum
==0 && argc
==0) || (idxNum
==1 && argc
==1) );
709 char *zStmt
= sqlite3_mprintf(
710 "SELECT * FROM %Q.%Q WHERE rowid=?", p
->zDb
, p
->zTbl
);
711 if( !zStmt
) return SQLITE_NOMEM
;
712 rc
= sqlite3_prepare_v2(p
->db
, zStmt
, -1, &pCur
->pStmt
, 0);
715 sqlite3_bind_value(pCur
->pStmt
, 1, argv
[0]);
718 char *zStmt
= sqlite3_mprintf("SELECT * FROM %Q.%Q", p
->zDb
, p
->zTbl
);
719 if( !zStmt
) return SQLITE_NOMEM
;
720 rc
= sqlite3_prepare_v2(p
->db
, zStmt
, -1, &pCur
->pStmt
, 0);
725 rc
= fsNext(pVtabCursor
);
730 static int fsColumn(sqlite3_vtab_cursor
*cur
, sqlite3_context
*ctx
, int i
){
731 fs_cursor
*pCur
= (fs_cursor
*)cur
;
733 assert( i
==0 || i
==1 || i
==2 );
735 sqlite3_result_value(ctx
, sqlite3_column_value(pCur
->pStmt
, 0));
737 const char *zFile
= (const char *)sqlite3_column_text(pCur
->pStmt
, 1);
742 fd
= open(zFile
, O_RDONLY
);
743 if( fd
<0 ) return SQLITE_IOERR
;
746 if( sbuf
.st_size
>=pCur
->nAlloc
){
747 int nNew
= sbuf
.st_size
*2;
749 if( nNew
<1024 ) nNew
= 1024;
751 zNew
= sqlite3Realloc(pCur
->zBuf
, nNew
);
760 n
= (int)read(fd
, pCur
->zBuf
, sbuf
.st_size
);
762 if( n
!=sbuf
.st_size
) return SQLITE_ERROR
;
763 pCur
->nBuf
= sbuf
.st_size
;
764 pCur
->zBuf
[pCur
->nBuf
] = '\0';
766 sqlite3_result_text(ctx
, pCur
->zBuf
, -1, SQLITE_TRANSIENT
);
771 static int fsRowid(sqlite3_vtab_cursor
*cur
, sqlite_int64
*pRowid
){
772 fs_cursor
*pCur
= (fs_cursor
*)cur
;
773 *pRowid
= sqlite3_column_int64(pCur
->pStmt
, 0);
777 static int fsEof(sqlite3_vtab_cursor
*cur
){
778 fs_cursor
*pCur
= (fs_cursor
*)cur
;
779 return (sqlite3_data_count(pCur
->pStmt
)==0);
782 static int fsBestIndex(sqlite3_vtab
*tab
, sqlite3_index_info
*pIdxInfo
){
785 for(ii
=0; ii
<pIdxInfo
->nConstraint
; ii
++){
786 struct sqlite3_index_constraint
const *pCons
= &pIdxInfo
->aConstraint
[ii
];
787 if( pCons
->iColumn
<0 && pCons
->usable
788 && pCons
->op
==SQLITE_INDEX_CONSTRAINT_EQ
){
789 struct sqlite3_index_constraint_usage
*pUsage
;
790 pUsage
= &pIdxInfo
->aConstraintUsage
[ii
];
792 pUsage
->argvIndex
= 1;
793 pIdxInfo
->idxNum
= 1;
794 pIdxInfo
->estimatedCost
= 1.0;
803 ** A virtual table module that provides read-only access to a
804 ** Tcl global variable namespace.
806 static sqlite3_module fsModule
= {
813 fsOpen
, /* xOpen - open a cursor */
814 fsClose
, /* xClose - close a cursor */
815 fsFilter
, /* xFilter - configure scan constraints */
816 fsNext
, /* xNext - advance a cursor */
817 fsEof
, /* xEof - check for end of scan */
818 fsColumn
, /* xColumn - read data */
819 fsRowid
, /* xRowid - read data */
829 static sqlite3_module fsdirModule
= {
831 fsdirConnect
, /* xCreate */
832 fsdirConnect
, /* xConnect */
833 fsdirBestIndex
, /* xBestIndex */
834 fsdirDisconnect
, /* xDisconnect */
835 fsdirDisconnect
, /* xDestroy */
836 fsdirOpen
, /* xOpen - open a cursor */
837 fsdirClose
, /* xClose - close a cursor */
838 fsdirFilter
, /* xFilter - configure scan constraints */
839 fsdirNext
, /* xNext - advance a cursor */
840 fsdirEof
, /* xEof - check for end of scan */
841 fsdirColumn
, /* xColumn - read data */
842 fsdirRowid
, /* xRowid - read data */
852 static sqlite3_module fstreeModule
= {
854 fstreeConnect
, /* xCreate */
855 fstreeConnect
, /* xConnect */
856 fstreeBestIndex
, /* xBestIndex */
857 fstreeDisconnect
, /* xDisconnect */
858 fstreeDisconnect
, /* xDestroy */
859 fstreeOpen
, /* xOpen - open a cursor */
860 fstreeClose
, /* xClose - close a cursor */
861 fstreeFilter
, /* xFilter - configure scan constraints */
862 fstreeNext
, /* xNext - advance a cursor */
863 fstreeEof
, /* xEof - check for end of scan */
864 fstreeColumn
, /* xColumn - read data */
865 fstreeRowid
, /* xRowid - read data */
876 ** Decode a pointer to an sqlite3 object.
878 extern int getDbPointer(Tcl_Interp
*interp
, const char *zA
, sqlite3
**ppDb
);
881 ** Register the echo virtual table module.
883 static int SQLITE_TCLAPI
register_fs_module(
884 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
885 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
886 int objc
, /* Number of arguments */
887 Tcl_Obj
*CONST objv
[] /* Command arguments */
891 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
894 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
895 #ifndef SQLITE_OMIT_VIRTUALTABLE
896 sqlite3_create_module(db
, "fs", &fsModule
, (void *)interp
);
897 sqlite3_create_module(db
, "fsdir", &fsdirModule
, 0);
898 sqlite3_create_module(db
, "fstree", &fstreeModule
, 0);
907 ** Register commands with the TCL interpreter.
909 int Sqlitetestfs_Init(Tcl_Interp
*interp
){
910 #ifndef SQLITE_OMIT_VIRTUALTABLE
913 Tcl_ObjCmdProc
*xProc
;
916 { "register_fs_module", register_fs_module
, 0 },
919 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
920 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
921 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);