1 /* 2 ** 2016-09-07 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 ** 13 ** This file implements an in-memory VFS. A database is held as a contiguous 14 ** block of memory. 15 ** 16 ** This file also implements interface sqlite3_serialize() and 17 ** sqlite3_deserialize(). 18 */ 19 #include "sqliteInt.h" 20 #ifdef SQLITE_ENABLE_DESERIALIZE 21 22 /* 23 ** Forward declaration of objects used by this utility 24 */ 25 typedef struct sqlite3_vfs MemVfs; 26 typedef struct MemFile MemFile; 27 28 /* Access to a lower-level VFS that (might) implement dynamic loading, 29 ** access to randomness, etc. 30 */ 31 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData)) 32 33 /* An open file */ 34 struct MemFile { 35 sqlite3_file base; /* IO methods */ 36 sqlite3_int64 sz; /* Size of the file */ 37 sqlite3_int64 szAlloc; /* Space allocated to aData */ 38 sqlite3_int64 szMax; /* Maximum allowed size of the file */ 39 unsigned char *aData; /* content of the file */ 40 int nMmap; /* Number of memory mapped pages */ 41 unsigned mFlags; /* Flags */ 42 int eLock; /* Most recent lock against this file */ 43 }; 44 45 /* The default maximum size of an in-memory database */ 46 #ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE 47 # define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824 48 #endif 49 50 /* 51 ** Methods for MemFile 52 */ 53 static int memdbClose(sqlite3_file*); 54 static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 55 static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst); 56 static int memdbTruncate(sqlite3_file*, sqlite3_int64 size); 57 static int memdbSync(sqlite3_file*, int flags); 58 static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize); 59 static int memdbLock(sqlite3_file*, int); 60 /* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */ 61 static int memdbFileControl(sqlite3_file*, int op, void *pArg); 62 /* static int memdbSectorSize(sqlite3_file*); // not used */ 63 static int memdbDeviceCharacteristics(sqlite3_file*); 64 static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); 65 static int memdbUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p); 66 67 /* 68 ** Methods for MemVfs 69 */ 70 static int memdbOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); 71 /* static int memdbDelete(sqlite3_vfs*, const char *zName, int syncDir); */ 72 static int memdbAccess(sqlite3_vfs*, const char *zName, int flags, int *); 73 static int memdbFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut); 74 static void *memdbDlOpen(sqlite3_vfs*, const char *zFilename); 75 static void memdbDlError(sqlite3_vfs*, int nByte, char *zErrMsg); 76 static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void); 77 static void memdbDlClose(sqlite3_vfs*, void*); 78 static int memdbRandomness(sqlite3_vfs*, int nByte, char *zOut); 79 static int memdbSleep(sqlite3_vfs*, int microseconds); 80 /* static int memdbCurrentTime(sqlite3_vfs*, double*); */ 81 static int memdbGetLastError(sqlite3_vfs*, int, char *); 82 static int memdbCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*); 83 84 static sqlite3_vfs memdb_vfs = { 85 2, /* iVersion */ 86 0, /* szOsFile (set when registered) */ 87 1024, /* mxPathname */ 88 0, /* pNext */ 89 "memdb", /* zName */ 90 0, /* pAppData (set when registered) */ 91 memdbOpen, /* xOpen */ 92 0, /* memdbDelete, */ /* xDelete */ 93 memdbAccess, /* xAccess */ 94 memdbFullPathname, /* xFullPathname */ 95 memdbDlOpen, /* xDlOpen */ 96 memdbDlError, /* xDlError */ 97 memdbDlSym, /* xDlSym */ 98 memdbDlClose, /* xDlClose */ 99 memdbRandomness, /* xRandomness */ 100 memdbSleep, /* xSleep */ 101 0, /* memdbCurrentTime, */ /* xCurrentTime */ 102 memdbGetLastError, /* xGetLastError */ 103 memdbCurrentTimeInt64 /* xCurrentTimeInt64 */ 104 }; 105 106 static const sqlite3_io_methods memdb_io_methods = { 107 3, /* iVersion */ 108 memdbClose, /* xClose */ 109 memdbRead, /* xRead */ 110 memdbWrite, /* xWrite */ 111 memdbTruncate, /* xTruncate */ 112 memdbSync, /* xSync */ 113 memdbFileSize, /* xFileSize */ 114 memdbLock, /* xLock */ 115 memdbLock, /* xUnlock - same as xLock in this case */ 116 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */ 117 memdbFileControl, /* xFileControl */ 118 0, /* memdbSectorSize,*/ /* xSectorSize */ 119 memdbDeviceCharacteristics, /* xDeviceCharacteristics */ 120 0, /* xShmMap */ 121 0, /* xShmLock */ 122 0, /* xShmBarrier */ 123 0, /* xShmUnmap */ 124 memdbFetch, /* xFetch */ 125 memdbUnfetch /* xUnfetch */ 126 }; 127 128 129 130 /* 131 ** Close an memdb-file. 132 ** 133 ** The pData pointer is owned by the application, so there is nothing 134 ** to free. 135 */ 136 static int memdbClose(sqlite3_file *pFile){ 137 MemFile *p = (MemFile *)pFile; 138 if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ) sqlite3_free(p->aData); 139 return SQLITE_OK; 140 } 141 142 /* 143 ** Read data from an memdb-file. 144 */ 145 static int memdbRead( 146 sqlite3_file *pFile, 147 void *zBuf, 148 int iAmt, 149 sqlite_int64 iOfst 150 ){ 151 MemFile *p = (MemFile *)pFile; 152 if( iOfst+iAmt>p->sz ){ 153 memset(zBuf, 0, iAmt); 154 if( iOfst<p->sz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst); 155 return SQLITE_IOERR_SHORT_READ; 156 } 157 memcpy(zBuf, p->aData+iOfst, iAmt); 158 return SQLITE_OK; 159 } 160 161 /* 162 ** Try to enlarge the memory allocation to hold at least sz bytes 163 */ 164 static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){ 165 unsigned char *pNew; 166 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){ 167 return SQLITE_FULL; 168 } 169 if( newSz>p->szMax ){ 170 return SQLITE_FULL; 171 } 172 newSz *= 2; 173 if( newSz>p->szMax ) newSz = p->szMax; 174 pNew = sqlite3_realloc64(p->aData, newSz); 175 if( pNew==0 ) return SQLITE_NOMEM; 176 p->aData = pNew; 177 p->szAlloc = newSz; 178 return SQLITE_OK; 179 } 180 181 /* 182 ** Write data to an memdb-file. 183 */ 184 static int memdbWrite( 185 sqlite3_file *pFile, 186 const void *z, 187 int iAmt, 188 sqlite_int64 iOfst 189 ){ 190 MemFile *p = (MemFile *)pFile; 191 if( p->mFlags & SQLITE_DESERIALIZE_READONLY ) return SQLITE_READONLY; 192 if( iOfst+iAmt>p->sz ){ 193 int rc; 194 if( iOfst+iAmt>p->szAlloc 195 && (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK 196 ){ 197 return rc; 198 } 199 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz); 200 p->sz = iOfst+iAmt; 201 } 202 memcpy(p->aData+iOfst, z, iAmt); 203 return SQLITE_OK; 204 } 205 206 /* 207 ** Truncate an memdb-file. 208 ** 209 ** In rollback mode (which is always the case for memdb, as it does not 210 ** support WAL mode) the truncate() method is only used to reduce 211 ** the size of a file, never to increase the size. 212 */ 213 static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ 214 MemFile *p = (MemFile *)pFile; 215 if( NEVER(size>p->sz) ) return SQLITE_FULL; 216 p->sz = size; 217 return SQLITE_OK; 218 } 219 220 /* 221 ** Sync an memdb-file. 222 */ 223 static int memdbSync(sqlite3_file *pFile, int flags){ 224 return SQLITE_OK; 225 } 226 227 /* 228 ** Return the current file-size of an memdb-file. 229 */ 230 static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ 231 MemFile *p = (MemFile *)pFile; 232 *pSize = p->sz; 233 return SQLITE_OK; 234 } 235 236 /* 237 ** Lock an memdb-file. 238 */ 239 static int memdbLock(sqlite3_file *pFile, int eLock){ 240 MemFile *p = (MemFile *)pFile; 241 p->eLock = eLock; 242 return SQLITE_OK; 243 } 244 245 #if 0 /* Never used because memdbAccess() always returns false */ 246 /* 247 ** Check if another file-handle holds a RESERVED lock on an memdb-file. 248 */ 249 static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){ 250 *pResOut = 0; 251 return SQLITE_OK; 252 } 253 #endif 254 255 /* 256 ** File control method. For custom operations on an memdb-file. 257 */ 258 static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){ 259 MemFile *p = (MemFile *)pFile; 260 int rc = SQLITE_NOTFOUND; 261 if( op==SQLITE_FCNTL_VFSNAME ){ 262 *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz); 263 rc = SQLITE_OK; 264 } 265 if( op==SQLITE_FCNTL_SIZE_LIMIT ){ 266 sqlite3_int64 iLimit = *(sqlite3_int64*)pArg; 267 if( iLimit<p->sz ){ 268 if( iLimit<0 ){ 269 iLimit = p->szMax; 270 }else{ 271 iLimit = p->sz; 272 } 273 } 274 p->szMax = iLimit; 275 *(sqlite3_int64*)pArg = iLimit; 276 rc = SQLITE_OK; 277 } 278 return rc; 279 } 280 281 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */ 282 /* 283 ** Return the sector-size in bytes for an memdb-file. 284 */ 285 static int memdbSectorSize(sqlite3_file *pFile){ 286 return 1024; 287 } 288 #endif 289 290 /* 291 ** Return the device characteristic flags supported by an memdb-file. 292 */ 293 static int memdbDeviceCharacteristics(sqlite3_file *pFile){ 294 return SQLITE_IOCAP_ATOMIC | 295 SQLITE_IOCAP_POWERSAFE_OVERWRITE | 296 SQLITE_IOCAP_SAFE_APPEND | 297 SQLITE_IOCAP_SEQUENTIAL; 298 } 299 300 /* Fetch a page of a memory-mapped file */ 301 static int memdbFetch( 302 sqlite3_file *pFile, 303 sqlite3_int64 iOfst, 304 int iAmt, 305 void **pp 306 ){ 307 MemFile *p = (MemFile *)pFile; 308 p->nMmap++; 309 *pp = (void*)(p->aData + iOfst); 310 return SQLITE_OK; 311 } 312 313 /* Release a memory-mapped page */ 314 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){ 315 MemFile *p = (MemFile *)pFile; 316 p->nMmap--; 317 return SQLITE_OK; 318 } 319 320 /* 321 ** Open an mem file handle. 322 */ 323 static int memdbOpen( 324 sqlite3_vfs *pVfs, 325 const char *zName, 326 sqlite3_file *pFile, 327 int flags, 328 int *pOutFlags 329 ){ 330 MemFile *p = (MemFile*)pFile; 331 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ 332 return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags); 333 } 334 memset(p, 0, sizeof(*p)); 335 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; 336 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ 337 *pOutFlags = flags | SQLITE_OPEN_MEMORY; 338 p->base.pMethods = &memdb_io_methods; 339 p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE; 340 return SQLITE_OK; 341 } 342 343 #if 0 /* Only used to delete rollback journals, master journals, and WAL 344 ** files, none of which exist in memdb. So this routine is never used */ 345 /* 346 ** Delete the file located at zPath. If the dirSync argument is true, 347 ** ensure the file-system modifications are synced to disk before 348 ** returning. 349 */ 350 static int memdbDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ 351 return SQLITE_IOERR_DELETE; 352 } 353 #endif 354 355 /* 356 ** Test for access permissions. Return true if the requested permission 357 ** is available, or false otherwise. 358 ** 359 ** With memdb, no files ever exist on disk. So always return false. 360 */ 361 static int memdbAccess( 362 sqlite3_vfs *pVfs, 363 const char *zPath, 364 int flags, 365 int *pResOut 366 ){ 367 *pResOut = 0; 368 return SQLITE_OK; 369 } 370 371 /* 372 ** Populate buffer zOut with the full canonical pathname corresponding 373 ** to the pathname in zPath. zOut is guaranteed to point to a buffer 374 ** of at least (INST_MAX_PATHNAME+1) bytes. 375 */ 376 static int memdbFullPathname( 377 sqlite3_vfs *pVfs, 378 const char *zPath, 379 int nOut, 380 char *zOut 381 ){ 382 sqlite3_snprintf(nOut, zOut, "%s", zPath); 383 return SQLITE_OK; 384 } 385 386 /* 387 ** Open the dynamic library located at zPath and return a handle. 388 */ 389 static void *memdbDlOpen(sqlite3_vfs *pVfs, const char *zPath){ 390 return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath); 391 } 392 393 /* 394 ** Populate the buffer zErrMsg (size nByte bytes) with a human readable 395 ** utf-8 string describing the most recent error encountered associated 396 ** with dynamic libraries. 397 */ 398 static void memdbDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ 399 ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg); 400 } 401 402 /* 403 ** Return a pointer to the symbol zSymbol in the dynamic library pHandle. 404 */ 405 static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){ 406 return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym); 407 } 408 409 /* 410 ** Close the dynamic library handle pHandle. 411 */ 412 static void memdbDlClose(sqlite3_vfs *pVfs, void *pHandle){ 413 ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle); 414 } 415 416 /* 417 ** Populate the buffer pointed to by zBufOut with nByte bytes of 418 ** random data. 419 */ 420 static int memdbRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ 421 return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut); 422 } 423 424 /* 425 ** Sleep for nMicro microseconds. Return the number of microseconds 426 ** actually slept. 427 */ 428 static int memdbSleep(sqlite3_vfs *pVfs, int nMicro){ 429 return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro); 430 } 431 432 #if 0 /* Never used. Modern cores only call xCurrentTimeInt64() */ 433 /* 434 ** Return the current time as a Julian Day number in *pTimeOut. 435 */ 436 static int memdbCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ 437 return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut); 438 } 439 #endif 440 441 static int memdbGetLastError(sqlite3_vfs *pVfs, int a, char *b){ 442 return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b); 443 } 444 static int memdbCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){ 445 return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p); 446 } 447 448 /* 449 ** Translate a database connection pointer and schema name into a 450 ** MemFile pointer. 451 */ 452 static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){ 453 MemFile *p = 0; 454 int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p); 455 if( rc ) return 0; 456 if( p->base.pMethods!=&memdb_io_methods ) return 0; 457 return p; 458 } 459 460 /* 461 ** Return the serialization of a database 462 */ 463 unsigned char *sqlite3_serialize( 464 sqlite3 *db, /* The database connection */ 465 const char *zSchema, /* Which database within the connection */ 466 sqlite3_int64 *piSize, /* Write size here, if not NULL */ 467 unsigned int mFlags /* Maybe SQLITE_SERIALIZE_NOCOPY */ 468 ){ 469 MemFile *p; 470 int iDb; 471 Btree *pBt; 472 sqlite3_int64 sz; 473 int szPage = 0; 474 sqlite3_stmt *pStmt = 0; 475 unsigned char *pOut; 476 char *zSql; 477 int rc; 478 479 #ifdef SQLITE_ENABLE_API_ARMOR 480 if( !sqlite3SafetyCheckOk(db) ){ 481 (void)SQLITE_MISUSE_BKPT; 482 return 0; 483 } 484 #endif 485 486 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; 487 p = memdbFromDbSchema(db, zSchema); 488 iDb = sqlite3FindDbName(db, zSchema); 489 if( piSize ) *piSize = -1; 490 if( iDb<0 ) return 0; 491 if( p ){ 492 if( piSize ) *piSize = p->sz; 493 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ 494 pOut = p->aData; 495 }else{ 496 pOut = sqlite3_malloc64( p->sz ); 497 if( pOut ) memcpy(pOut, p->aData, p->sz); 498 } 499 return pOut; 500 } 501 pBt = db->aDb[iDb].pBt; 502 if( pBt==0 ) return 0; 503 szPage = sqlite3BtreeGetPageSize(pBt); 504 zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema); 505 rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM; 506 sqlite3_free(zSql); 507 if( rc ) return 0; 508 rc = sqlite3_step(pStmt); 509 if( rc!=SQLITE_ROW ){ 510 pOut = 0; 511 }else{ 512 sz = sqlite3_column_int64(pStmt, 0)*szPage; 513 if( piSize ) *piSize = sz; 514 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ 515 pOut = 0; 516 }else{ 517 pOut = sqlite3_malloc64( sz ); 518 if( pOut ){ 519 int nPage = sqlite3_column_int(pStmt, 0); 520 Pager *pPager = sqlite3BtreePager(pBt); 521 int pgno; 522 for(pgno=1; pgno<=nPage; pgno++){ 523 DbPage *pPage = 0; 524 unsigned char *pTo = pOut + szPage*(sqlite3_int64)(pgno-1); 525 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0); 526 if( rc==SQLITE_OK ){ 527 memcpy(pTo, sqlite3PagerGetData(pPage), szPage); 528 }else{ 529 memset(pTo, 0, szPage); 530 } 531 sqlite3PagerUnref(pPage); 532 } 533 } 534 } 535 } 536 sqlite3_finalize(pStmt); 537 return pOut; 538 } 539 540 /* Convert zSchema to a MemDB and initialize its content. 541 */ 542 int sqlite3_deserialize( 543 sqlite3 *db, /* The database connection */ 544 const char *zSchema, /* Which DB to reopen with the deserialization */ 545 unsigned char *pData, /* The serialized database content */ 546 sqlite3_int64 szDb, /* Number bytes in the deserialization */ 547 sqlite3_int64 szBuf, /* Total size of buffer pData[] */ 548 unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ 549 ){ 550 MemFile *p; 551 char *zSql; 552 sqlite3_stmt *pStmt = 0; 553 int rc; 554 int iDb; 555 556 #ifdef SQLITE_ENABLE_API_ARMOR 557 if( !sqlite3SafetyCheckOk(db) ){ 558 return SQLITE_MISUSE_BKPT; 559 } 560 if( szDb<0 ) return SQLITE_MISUSE_BKPT; 561 if( szBuf<0 ) return SQLITE_MISUSE_BKPT; 562 #endif 563 564 sqlite3_mutex_enter(db->mutex); 565 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; 566 iDb = sqlite3FindDbName(db, zSchema); 567 if( iDb<0 ){ 568 rc = SQLITE_ERROR; 569 goto end_deserialize; 570 } 571 zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema); 572 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); 573 sqlite3_free(zSql); 574 if( rc ) goto end_deserialize; 575 db->init.iDb = (u8)iDb; 576 db->init.reopenMemdb = 1; 577 rc = sqlite3_step(pStmt); 578 db->init.reopenMemdb = 0; 579 if( rc!=SQLITE_DONE ){ 580 rc = SQLITE_ERROR; 581 goto end_deserialize; 582 } 583 p = memdbFromDbSchema(db, zSchema); 584 if( p==0 ){ 585 rc = SQLITE_ERROR; 586 }else{ 587 p->aData = pData; 588 p->sz = szDb; 589 p->szAlloc = szBuf; 590 p->szMax = szBuf; 591 if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){ 592 p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE; 593 } 594 p->mFlags = mFlags; 595 rc = SQLITE_OK; 596 } 597 598 end_deserialize: 599 sqlite3_finalize(pStmt); 600 sqlite3_mutex_leave(db->mutex); 601 return rc; 602 } 603 604 /* 605 ** This routine is called when the extension is loaded. 606 ** Register the new VFS. 607 */ 608 int sqlite3MemdbInit(void){ 609 sqlite3_vfs *pLower = sqlite3_vfs_find(0); 610 int sz = pLower->szOsFile; 611 memdb_vfs.pAppData = pLower; 612 /* In all known configurations of SQLite, the size of a default 613 ** sqlite3_file is greater than the size of a memdb sqlite3_file. 614 ** Should that ever change, remove the following NEVER() */ 615 if( NEVER(sz<sizeof(MemFile)) ) sz = sizeof(MemFile); 616 memdb_vfs.szOsFile = sz; 617 return sqlite3_vfs_register(&memdb_vfs, 0); 618 } 619 #endif /* SQLITE_ENABLE_DESERIALIZE */ 620