Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: e92fd56138a5007dbc4875ac9fc0a68a022064ff [file] [log] [blame]
dan0a7a9152010-04-07 07:57:381/*
2** 2010 April 7
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
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.
10**
11*************************************************************************
12**
drha12b6fa2011-05-23 18:37:4213** This file implements an example of a simple VFS implementation that
14** omits complex features often not required or not possible on embedded
15** platforms. Code is included to buffer writes to the journal file,
16** which can be a significant performance improvement on some embedded
17** platforms.
dan0a7a9152010-04-07 07:57:3818**
dan0a7a9152010-04-07 07:57:3819** OVERVIEW
20**
21** The code in this file implements a minimal SQLite VFS that can be
22** used on Linux and other posix-like operating systems. The following
23** system calls are used:
24**
25** File-system: access(), unlink(), getcwd()
26** File IO: open(), read(), write(), fsync(), close(), fstat()
27** Other: sleep(), usleep(), time()
28**
29** The following VFS features are omitted:
30**
31** 1. File locking. The user must ensure that there is at most one
32** connection to each database when using this VFS. Multiple
33** connections to a single shared-cache count as a single connection
34** for the purposes of the previous statement.
35**
36** 2. The loading of dynamic extensions (shared libraries).
37**
38** 3. Temporary files. The user must configure SQLite to use in-memory
39** temp files when using this VFS. The easiest way to do this is to
40** compile with:
41**
42** -DSQLITE_TEMP_STORE=3
43**
44** 4. File truncation. As of version 3.6.24, SQLite may run without
45** a working xTruncate() call, providing the user does not configure
46** SQLite to use "journal_mode=truncate", or use both
47** "journal_mode=persist" and ATTACHed databases.
48**
49** It is assumed that the system uses UNIX-like path-names. Specifically,
50** that '/' characters are used to separate path components and that
51** a path-name is a relative path unless it begins with a '/'. And that
52** no UTF-8 encoded paths are greater than 512 bytes in length.
53**
54** JOURNAL WRITE-BUFFERING
55**
56** To commit a transaction to the database, SQLite first writes rollback
57** information into the journal file. This usually consists of 4 steps:
58**
59** 1. The rollback information is sequentially written into the journal
60** file, starting at the start of the file.
61** 2. The journal file is synced to disk.
62** 3. A modification is made to the first few bytes of the journal file.
63** 4. The journal file is synced to disk again.
64**
65** Most of the data is written in step 1 using a series of calls to the
66** VFS xWrite() method. The buffers passed to the xWrite() calls are of
67** various sizes. For example, as of version 3.6.24, when committing a
68** transaction that modifies 3 pages of a database file that uses 4096
69** byte pages residing on a media with 512 byte sectors, SQLite makes
70** eleven calls to the xWrite() method to create the rollback journal,
71** as follows:
72**
73** Write offset | Bytes written
74** ----------------------------
75** 0 512
76** 512 4
77** 516 4096
78** 4612 4
79** 4616 4
80** 4620 4096
81** 8716 4
82** 8720 4
83** 8724 4096
84** 12820 4
85** ++++++++++++SYNC+++++++++++
86** 0 12
87** ++++++++++++SYNC+++++++++++
88**
89** On many operating systems, this is an efficient way to write to a file.
90** However, on some embedded systems that do not cache writes in OS
91** buffers it is much more efficient to write data in blocks that are
92** an integer multiple of the sector-size in size and aligned at the
93** start of a sector.
94**
95** To work around this, the code in this file allocates a fixed size
96** buffer of SQLITE_DEMOVFS_BUFFERSZ using sqlite3_malloc() whenever a
97** journal file is opened. It uses the buffer to coalesce sequential
98** writes into aligned SQLITE_DEMOVFS_BUFFERSZ blocks. When SQLite
99** invokes the xSync() method to sync the contents of the file to disk,
100** all accumulated data is written out, even if it does not constitute
101** a complete block. This means the actual IO to create the rollback
102** journal for the example transaction above is this:
103**
104** Write offset | Bytes written
105** ----------------------------
106** 0 8192
107** 8192 4632
108** ++++++++++++SYNC+++++++++++
109** 0 12
110** ++++++++++++SYNC+++++++++++
111**
112** Much more efficient if the underlying OS is not caching write
113** operations.
114*/
115
shaneh3a2d29f2011-04-04 21:48:01116#if !defined(SQLITE_TEST) || SQLITE_OS_UNIX
dan0a7a9152010-04-07 07:57:38117
drh883ad042015-02-19 00:29:11118#include "sqlite3.h"
dan0a7a9152010-04-07 07:57:38119
120#include <assert.h>
121#include <string.h>
122#include <sys/types.h>
123#include <sys/stat.h>
124#include <sys/file.h>
125#include <sys/param.h>
126#include <unistd.h>
127#include <time.h>
danfc6a6212010-08-17 05:55:35128#include <errno.h>
drh134ec492011-05-05 13:53:46129#include <fcntl.h>
dan0a7a9152010-04-07 07:57:38130
131/*
132** Size of the write buffer used by journal files in bytes.
133*/
134#ifndef SQLITE_DEMOVFS_BUFFERSZ
135# define SQLITE_DEMOVFS_BUFFERSZ 8192
136#endif
137
138/*
danfc6a6212010-08-17 05:55:35139** The maximum pathname length supported by this VFS.
140*/
141#define MAXPATHNAME 512
142
143/*
dan0a7a9152010-04-07 07:57:38144** When using this VFS, the sqlite3_file* handles that SQLite uses are
145** actually pointers to instances of type DemoFile.
146*/
147typedef struct DemoFile DemoFile;
148struct DemoFile {
149 sqlite3_file base; /* Base class. Must be first. */
150 int fd; /* File descriptor */
151
152 char *aBuffer; /* Pointer to malloc'd buffer */
153 int nBuffer; /* Valid bytes of data in zBuffer */
154 sqlite3_int64 iBufferOfst; /* Offset in file of zBuffer[0] */
155};
156
157/*
158** Write directly to the file passed as the first argument. Even if the
159** file has a write-buffer (DemoFile.aBuffer), ignore it.
160*/
161static int demoDirectWrite(
162 DemoFile *p, /* File handle */
163 const void *zBuf, /* Buffer containing data to write */
164 int iAmt, /* Size of data to write in bytes */
165 sqlite_int64 iOfst /* File offset to write to */
166){
167 off_t ofst; /* Return value from lseek() */
168 size_t nWrite; /* Return value from write() */
169
170 ofst = lseek(p->fd, iOfst, SEEK_SET);
171 if( ofst!=iOfst ){
172 return SQLITE_IOERR_WRITE;
173 }
174
175 nWrite = write(p->fd, zBuf, iAmt);
176 if( nWrite!=iAmt ){
177 return SQLITE_IOERR_WRITE;
178 }
179
180 return SQLITE_OK;
181}
182
183/*
184** Flush the contents of the DemoFile.aBuffer buffer to disk. This is a
185** no-op if this particular file does not have a buffer (i.e. it is not
186** a journal file) or if the buffer is currently empty.
187*/
188static int demoFlushBuffer(DemoFile *p){
189 int rc = SQLITE_OK;
190 if( p->nBuffer ){
191 rc = demoDirectWrite(p, p->aBuffer, p->nBuffer, p->iBufferOfst);
192 p->nBuffer = 0;
193 }
194 return rc;
195}
196
197/*
198** Close a file.
199*/
200static int demoClose(sqlite3_file *pFile){
201 int rc;
202 DemoFile *p = (DemoFile*)pFile;
203 rc = demoFlushBuffer(p);
204 sqlite3_free(p->aBuffer);
205 close(p->fd);
206 return rc;
207}
208
209/*
210** Read data from a file.
211*/
212static int demoRead(
213 sqlite3_file *pFile,
214 void *zBuf,
215 int iAmt,
216 sqlite_int64 iOfst
217){
218 DemoFile *p = (DemoFile*)pFile;
219 off_t ofst; /* Return value from lseek() */
220 int nRead; /* Return value from read() */
221 int rc; /* Return code from demoFlushBuffer() */
222
223 /* Flush any data in the write buffer to disk in case this operation
224 ** is trying to read data the file-region currently cached in the buffer.
225 ** It would be possible to detect this case and possibly save an
226 ** unnecessary write here, but in practice SQLite will rarely read from
227 ** a journal file when there is data cached in the write-buffer.
228 */
229 rc = demoFlushBuffer(p);
230 if( rc!=SQLITE_OK ){
231 return rc;
232 }
233
234 ofst = lseek(p->fd, iOfst, SEEK_SET);
235 if( ofst!=iOfst ){
236 return SQLITE_IOERR_READ;
237 }
238 nRead = read(p->fd, zBuf, iAmt);
239
240 if( nRead==iAmt ){
241 return SQLITE_OK;
242 }else if( nRead>=0 ){
dane3664dc2019-06-15 15:32:37243 if( nRead<iAmt ){
244 memset(&((char*)zBuf)[nRead], 0, iAmt-nRead);
245 }
dan0a7a9152010-04-07 07:57:38246 return SQLITE_IOERR_SHORT_READ;
247 }
248
249 return SQLITE_IOERR_READ;
250}
251
252/*
253** Write data to a crash-file.
254*/
255static int demoWrite(
256 sqlite3_file *pFile,
257 const void *zBuf,
258 int iAmt,
259 sqlite_int64 iOfst
260){
261 DemoFile *p = (DemoFile*)pFile;
262
263 if( p->aBuffer ){
264 char *z = (char *)zBuf; /* Pointer to remaining data to write */
265 int n = iAmt; /* Number of bytes at z */
266 sqlite3_int64 i = iOfst; /* File offset to write to */
267
268 while( n>0 ){
269 int nCopy; /* Number of bytes to copy into buffer */
270
271 /* If the buffer is full, or if this data is not being written directly
272 ** following the data already buffered, flush the buffer. Flushing
273 ** the buffer is a no-op if it is empty.
274 */
275 if( p->nBuffer==SQLITE_DEMOVFS_BUFFERSZ || p->iBufferOfst+p->nBuffer!=i ){
276 int rc = demoFlushBuffer(p);
277 if( rc!=SQLITE_OK ){
278 return rc;
279 }
280 }
281 assert( p->nBuffer==0 || p->iBufferOfst+p->nBuffer==i );
282 p->iBufferOfst = i - p->nBuffer;
283
284 /* Copy as much data as possible into the buffer. */
285 nCopy = SQLITE_DEMOVFS_BUFFERSZ - p->nBuffer;
286 if( nCopy>n ){
287 nCopy = n;
288 }
289 memcpy(&p->aBuffer[p->nBuffer], z, nCopy);
290 p->nBuffer += nCopy;
291
292 n -= nCopy;
293 i += nCopy;
294 z += nCopy;
295 }
296 }else{
297 return demoDirectWrite(p, zBuf, iAmt, iOfst);
298 }
299
300 return SQLITE_OK;
301}
302
303/*
304** Truncate a file. This is a no-op for this VFS (see header comments at
305** the top of the file).
306*/
307static int demoTruncate(sqlite3_file *pFile, sqlite_int64 size){
308#if 0
309 if( ftruncate(((DemoFile *)pFile)->fd, size) ) return SQLITE_IOERR_TRUNCATE;
310#endif
311 return SQLITE_OK;
312}
313
314/*
315** Sync the contents of the file to the persistent media.
316*/
317static int demoSync(sqlite3_file *pFile, int flags){
318 DemoFile *p = (DemoFile*)pFile;
319 int rc;
320
321 rc = demoFlushBuffer(p);
322 if( rc!=SQLITE_OK ){
323 return rc;
324 }
325
326 rc = fsync(p->fd);
327 return (rc==0 ? SQLITE_OK : SQLITE_IOERR_FSYNC);
328}
329
330/*
331** Write the size of the file in bytes to *pSize.
332*/
333static int demoFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
334 DemoFile *p = (DemoFile*)pFile;
335 int rc; /* Return code from fstat() call */
336 struct stat sStat; /* Output of fstat() call */
337
338 /* Flush the contents of the buffer to disk. As with the flush in the
339 ** demoRead() method, it would be possible to avoid this and save a write
340 ** here and there. But in practice this comes up so infrequently it is
341 ** not worth the trouble.
342 */
343 rc = demoFlushBuffer(p);
344 if( rc!=SQLITE_OK ){
345 return rc;
346 }
347
348 rc = fstat(p->fd, &sStat);
349 if( rc!=0 ) return SQLITE_IOERR_FSTAT;
350 *pSize = sStat.st_size;
351 return SQLITE_OK;
352}
353
354/*
355** Locking functions. The xLock() and xUnlock() methods are both no-ops.
356** The xCheckReservedLock() always indicates that no other process holds
357** a reserved lock on the database file. This ensures that if a hot-journal
358** file is found in the file-system it is rolled back.
359*/
360static int demoLock(sqlite3_file *pFile, int eLock){
361 return SQLITE_OK;
362}
363static int demoUnlock(sqlite3_file *pFile, int eLock){
364 return SQLITE_OK;
365}
366static int demoCheckReservedLock(sqlite3_file *pFile, int *pResOut){
367 *pResOut = 0;
368 return SQLITE_OK;
369}
370
371/*
372** No xFileControl() verbs are implemented by this VFS.
373*/
374static int demoFileControl(sqlite3_file *pFile, int op, void *pArg){
dane3664dc2019-06-15 15:32:37375 return SQLITE_NOTFOUND;
dan0a7a9152010-04-07 07:57:38376}
377
378/*
379** The xSectorSize() and xDeviceCharacteristics() methods. These two
380** may return special values allowing SQLite to optimize file-system
381** access to some extent. But it is also safe to simply return 0.
382*/
383static int demoSectorSize(sqlite3_file *pFile){
384 return 0;
385}
386static int demoDeviceCharacteristics(sqlite3_file *pFile){
387 return 0;
388}
389
390/*
391** Open a file handle.
392*/
393static int demoOpen(
394 sqlite3_vfs *pVfs, /* VFS */
395 const char *zName, /* File to open, or 0 for a temp file */
396 sqlite3_file *pFile, /* Pointer to DemoFile struct to populate */
397 int flags, /* Input SQLITE_OPEN_XXX flags */
398 int *pOutFlags /* Output SQLITE_OPEN_XXX flags (or NULL) */
399){
400 static const sqlite3_io_methods demoio = {
401 1, /* iVersion */
402 demoClose, /* xClose */
403 demoRead, /* xRead */
404 demoWrite, /* xWrite */
405 demoTruncate, /* xTruncate */
406 demoSync, /* xSync */
407 demoFileSize, /* xFileSize */
408 demoLock, /* xLock */
409 demoUnlock, /* xUnlock */
410 demoCheckReservedLock, /* xCheckReservedLock */
411 demoFileControl, /* xFileControl */
412 demoSectorSize, /* xSectorSize */
413 demoDeviceCharacteristics /* xDeviceCharacteristics */
414 };
415
416 DemoFile *p = (DemoFile*)pFile; /* Populate this structure */
417 int oflags = 0; /* flags to pass to open() call */
418 char *aBuf = 0;
419
420 if( zName==0 ){
421 return SQLITE_IOERR;
422 }
423
424 if( flags&SQLITE_OPEN_MAIN_JOURNAL ){
425 aBuf = (char *)sqlite3_malloc(SQLITE_DEMOVFS_BUFFERSZ);
426 if( !aBuf ){
427 return SQLITE_NOMEM;
428 }
429 }
430
431 if( flags&SQLITE_OPEN_EXCLUSIVE ) oflags |= O_EXCL;
432 if( flags&SQLITE_OPEN_CREATE ) oflags |= O_CREAT;
433 if( flags&SQLITE_OPEN_READONLY ) oflags |= O_RDONLY;
434 if( flags&SQLITE_OPEN_READWRITE ) oflags |= O_RDWR;
435
436 memset(p, 0, sizeof(DemoFile));
437 p->fd = open(zName, oflags, 0600);
438 if( p->fd<0 ){
439 sqlite3_free(aBuf);
440 return SQLITE_CANTOPEN;
441 }
442 p->aBuffer = aBuf;
443
444 if( pOutFlags ){
445 *pOutFlags = flags;
446 }
447 p->base.pMethods = &demoio;
448 return SQLITE_OK;
449}
450
451/*
452** Delete the file identified by argument zPath. If the dirSync parameter
453** is non-zero, then ensure the file-system modification to delete the
454** file has been synced to disk before returning.
455*/
456static int demoDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
danfc6a6212010-08-17 05:55:35457 int rc; /* Return code */
458
dan0a7a9152010-04-07 07:57:38459 rc = unlink(zPath);
danfc6a6212010-08-17 05:55:35460 if( rc!=0 && errno==ENOENT ) return SQLITE_OK;
461
dan0a7a9152010-04-07 07:57:38462 if( rc==0 && dirSync ){
463 int dfd; /* File descriptor open on directory */
drhcb577162022-09-30 14:35:18464 char *zSlash;
danfc6a6212010-08-17 05:55:35465 char zDir[MAXPATHNAME+1]; /* Name of directory containing file zPath */
dan0a7a9152010-04-07 07:57:38466
467 /* Figure out the directory name from the path of the file deleted. */
danfc6a6212010-08-17 05:55:35468 sqlite3_snprintf(MAXPATHNAME, zDir, "%s", zPath);
469 zDir[MAXPATHNAME] = '\0';
drh2d3261f2022-09-30 20:53:36470 zSlash = strrchr(zDir,'/');
drhcb577162022-09-30 14:35:18471 if( zSlash ){
472 /* Open a file-descriptor on the directory. Sync. Close. */
473 zSlash[0] = 0;
474 dfd = open(zDir, O_RDONLY, 0);
475 if( dfd<0 ){
476 rc = -1;
477 }else{
478 rc = fsync(dfd);
479 close(dfd);
480 }
dan0a7a9152010-04-07 07:57:38481 }
482 }
483 return (rc==0 ? SQLITE_OK : SQLITE_IOERR_DELETE);
484}
485
drh9d6caca2010-04-08 11:35:18486#ifndef F_OK
487# define F_OK 0
488#endif
489#ifndef R_OK
490# define R_OK 4
491#endif
492#ifndef W_OK
493# define W_OK 2
494#endif
495
dan0a7a9152010-04-07 07:57:38496/*
497** Query the file-system to see if the named file exists, is readable or
498** is both readable and writable.
499*/
500static int demoAccess(
501 sqlite3_vfs *pVfs,
502 const char *zPath,
503 int flags,
504 int *pResOut
505){
506 int rc; /* access() return code */
507 int eAccess = F_OK; /* Second argument to access() */
508
509 assert( flags==SQLITE_ACCESS_EXISTS /* access(zPath, F_OK) */
510 || flags==SQLITE_ACCESS_READ /* access(zPath, R_OK) */
511 || flags==SQLITE_ACCESS_READWRITE /* access(zPath, R_OK|W_OK) */
512 );
513
dan0a7a9152010-04-07 07:57:38514 if( flags==SQLITE_ACCESS_READWRITE ) eAccess = R_OK|W_OK;
515 if( flags==SQLITE_ACCESS_READ ) eAccess = R_OK;
516
517 rc = access(zPath, eAccess);
518 *pResOut = (rc==0);
519 return SQLITE_OK;
520}
521
522/*
523** Argument zPath points to a nul-terminated string containing a file path.
524** If zPath is an absolute path, then it is copied as is into the output
525** buffer. Otherwise, if it is a relative path, then the equivalent full
526** path is written to the output buffer.
527**
528** This function assumes that paths are UNIX style. Specifically, that:
529**
530** 1. Path components are separated by a '/'. and
531** 2. Full paths begin with a '/' character.
532*/
533static int demoFullPathname(
534 sqlite3_vfs *pVfs, /* VFS */
535 const char *zPath, /* Input path (possibly a relative path) */
536 int nPathOut, /* Size of output buffer in bytes */
537 char *zPathOut /* Pointer to output buffer */
538){
danfc6a6212010-08-17 05:55:35539 char zDir[MAXPATHNAME+1];
dan0a7a9152010-04-07 07:57:38540 if( zPath[0]=='/' ){
541 zDir[0] = '\0';
542 }else{
drhd3f49642013-08-06 18:35:31543 if( getcwd(zDir, sizeof(zDir))==0 ) return SQLITE_IOERR;
dan0a7a9152010-04-07 07:57:38544 }
danfc6a6212010-08-17 05:55:35545 zDir[MAXPATHNAME] = '\0';
dan0a7a9152010-04-07 07:57:38546
547 sqlite3_snprintf(nPathOut, zPathOut, "%s/%s", zDir, zPath);
548 zPathOut[nPathOut-1] = '\0';
549
550 return SQLITE_OK;
551}
552
553/*
554** The following four VFS methods:
555**
556** xDlOpen
557** xDlError
558** xDlSym
559** xDlClose
560**
561** are supposed to implement the functionality needed by SQLite to load
562** extensions compiled as shared objects. This simple VFS does not support
563** this functionality, so the following functions are no-ops.
564*/
565static void *demoDlOpen(sqlite3_vfs *pVfs, const char *zPath){
566 return 0;
567}
568static void demoDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
569 sqlite3_snprintf(nByte, zErrMsg, "Loadable extensions are not supported");
570 zErrMsg[nByte-1] = '\0';
571}
572static void (*demoDlSym(sqlite3_vfs *pVfs, void *pH, const char *z))(void){
573 return 0;
574}
575static void demoDlClose(sqlite3_vfs *pVfs, void *pHandle){
576 return;
577}
578
579/*
580** Parameter zByte points to a buffer nByte bytes in size. Populate this
581** buffer with pseudo-random data.
582*/
583static int demoRandomness(sqlite3_vfs *pVfs, int nByte, char *zByte){
584 return SQLITE_OK;
585}
586
587/*
588** Sleep for at least nMicro microseconds. Return the (approximate) number
589** of microseconds slept for.
590*/
591static int demoSleep(sqlite3_vfs *pVfs, int nMicro){
592 sleep(nMicro / 1000000);
593 usleep(nMicro % 1000000);
594 return nMicro;
595}
596
597/*
598** Set *pTime to the current UTC time expressed as a Julian day. Return
599** SQLITE_OK if successful, or an error code otherwise.
600**
601** http://en.wikipedia.org/wiki/Julian_day
602**
603** This implementation is not very good. The current time is rounded to
604** an integer number of seconds. Also, assuming time_t is a signed 32-bit
605** value, it will stop working some time in the year 2038 AD (the so-called
606** "year 2038" problem that afflicts systems that store time this way).
607*/
608static int demoCurrentTime(sqlite3_vfs *pVfs, double *pTime){
609 time_t t = time(0);
610 *pTime = t/86400.0 + 2440587.5;
611 return SQLITE_OK;
612}
613
614/*
615** This function returns a pointer to the VFS implemented in this file.
616** To make the VFS available to SQLite:
617**
618** sqlite3_vfs_register(sqlite3_demovfs(), 0);
619*/
620sqlite3_vfs *sqlite3_demovfs(void){
621 static sqlite3_vfs demovfs = {
622 1, /* iVersion */
623 sizeof(DemoFile), /* szOsFile */
danfc6a6212010-08-17 05:55:35624 MAXPATHNAME, /* mxPathname */
dan0a7a9152010-04-07 07:57:38625 0, /* pNext */
626 "demo", /* zName */
627 0, /* pAppData */
628 demoOpen, /* xOpen */
629 demoDelete, /* xDelete */
630 demoAccess, /* xAccess */
631 demoFullPathname, /* xFullPathname */
632 demoDlOpen, /* xDlOpen */
633 demoDlError, /* xDlError */
634 demoDlSym, /* xDlSym */
635 demoDlClose, /* xDlClose */
636 demoRandomness, /* xRandomness */
637 demoSleep, /* xSleep */
drhf2424c52010-04-26 00:04:55638 demoCurrentTime, /* xCurrentTime */
dan0a7a9152010-04-07 07:57:38639 };
640 return &demovfs;
641}
642
shaneh3a2d29f2011-04-04 21:48:01643#endif /* !defined(SQLITE_TEST) || SQLITE_OS_UNIX */
dan0a7a9152010-04-07 07:57:38644
645
646#ifdef SQLITE_TEST
647
drh064b6812024-07-30 15:49:02648#include "tclsqlite.h"
dan0a7a9152010-04-07 07:57:38649
shaneh3a2d29f2011-04-04 21:48:01650#if SQLITE_OS_UNIX
mistachkin7617e4a2016-07-28 17:11:20651static int SQLITE_TCLAPI register_demovfs(
dan0a7a9152010-04-07 07:57:38652 ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
653 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
654 int objc, /* Number of arguments */
655 Tcl_Obj *CONST objv[] /* Command arguments */
656){
657 sqlite3_vfs_register(sqlite3_demovfs(), 1);
658 return TCL_OK;
659}
mistachkin7617e4a2016-07-28 17:11:20660static int SQLITE_TCLAPI unregister_demovfs(
dan0a7a9152010-04-07 07:57:38661 ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
662 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
663 int objc, /* Number of arguments */
664 Tcl_Obj *CONST objv[] /* Command arguments */
665){
666 sqlite3_vfs_unregister(sqlite3_demovfs());
667 return TCL_OK;
668}
669
670/*
671** Register commands with the TCL interpreter.
672*/
673int Sqlitetest_demovfs_Init(Tcl_Interp *interp){
674 Tcl_CreateObjCommand(interp, "register_demovfs", register_demovfs, 0, 0);
675 Tcl_CreateObjCommand(interp, "unregister_demovfs", unregister_demovfs, 0, 0);
676 return TCL_OK;
677}
678
679#else
680int Sqlitetest_demovfs_Init(Tcl_Interp *interp){ return TCL_OK; }
681#endif
682
683#endif /* SQLITE_TEST */