ikptr ik_sqlite3_uri_int64 (ikptr s_filename, ikptr s_param_name, ikptr s_default, ikpcb * pcb) { #ifdef HAVE_SQLITE3_URI_INT64 const char * filename = IK_CHARP_FROM_BYTEVECTOR_OR_POINTER_OR_FALSE(s_filename); const char * param_name = IK_CHARP_FROM_BYTEVECTOR_OR_POINTER_OR_FALSE(s_param_name); sqlite3_int64 def = ik_integer_to_sint64(s_default); sqlite3_int64 rv; rv = sqlite3_uri_int64(filename, param_name, def); return ika_integer_from_sint64(pcb, rv); #else feature_failure(__func__); #endif }
/* ** This is the xOpen method used for the "multiplex" VFS. ** ** Most of the work is done by the underlying original VFS. This method ** simply links the new file into the appropriate multiplex group if it is a ** file that needs to be tracked. */ static int multiplexOpen( sqlite3_vfs *pVfs, /* The multiplex VFS */ const char *zName, /* Name of file to be opened */ sqlite3_file *pConn, /* Fill in this file descriptor */ int flags, /* Flags to control the opening */ int *pOutFlags /* Flags showing results of opening */ ){ int rc = SQLITE_OK; /* Result code */ multiplexConn *pMultiplexOpen; /* The new multiplex file descriptor */ multiplexGroup *pGroup = 0; /* Corresponding multiplexGroup object */ sqlite3_file *pSubOpen = 0; /* Real file descriptor */ sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs; /* Real VFS */ int nName = 0; int sz = 0; char *zToFree = 0; UNUSED_PARAMETER(pVfs); memset(pConn, 0, pVfs->szOsFile); assert( zName || (flags & SQLITE_OPEN_DELETEONCLOSE) ); /* We need to create a group structure and manage ** access to this group of files. */ multiplexEnter(); pMultiplexOpen = (multiplexConn*)pConn; if( rc==SQLITE_OK ){ /* allocate space for group */ nName = zName ? multiplexStrlen30(zName) : 0; sz = sizeof(multiplexGroup) /* multiplexGroup */ + nName + 1; /* zName */ pGroup = sqlite3_malloc64( sz ); if( pGroup==0 ){ rc = SQLITE_NOMEM; } } if( rc==SQLITE_OK ){ const char *zUri = (flags & SQLITE_OPEN_URI) ? zName : 0; /* assign pointers to extra space allocated */ memset(pGroup, 0, sz); pMultiplexOpen->pGroup = pGroup; pGroup->bEnabled = (unsigned char)-1; pGroup->bTruncate = sqlite3_uri_boolean(zUri, "truncate", (flags & SQLITE_OPEN_MAIN_DB)==0); pGroup->szChunk = (int)sqlite3_uri_int64(zUri, "chunksize", SQLITE_MULTIPLEX_CHUNK_SIZE); pGroup->szChunk = (pGroup->szChunk+0xffff)&~0xffff; if( zName ){ char *p = (char *)&pGroup[1]; pGroup->zName = p; memcpy(pGroup->zName, zName, nName+1); pGroup->nName = nName; } if( pGroup->bEnabled ){ /* Make sure that the chunksize is such that the pending byte does not ** falls at the end of a chunk. A region of up to 64K following ** the pending byte is never written, so if the pending byte occurs ** near the end of a chunk, that chunk will be too small. */ #ifndef SQLITE_OMIT_WSD extern int sqlite3PendingByte; #else int sqlite3PendingByte = 0x40000000; #endif while( (sqlite3PendingByte % pGroup->szChunk)>=(pGroup->szChunk-65536) ){ pGroup->szChunk += 65536; } } pGroup->flags = flags; rc = multiplexSubFilename(pGroup, 1); if( rc==SQLITE_OK ){ pSubOpen = multiplexSubOpen(pGroup, 0, &rc, pOutFlags, 0); if( pSubOpen==0 && rc==SQLITE_OK ) rc = SQLITE_CANTOPEN; } if( rc==SQLITE_OK ){ sqlite3_int64 sz64; rc = pSubOpen->pMethods->xFileSize(pSubOpen, &sz64); if( rc==SQLITE_OK && zName ){ int bExists; if( flags & SQLITE_OPEN_MASTER_JOURNAL ){ pGroup->bEnabled = 0; }else if( sz64==0 ){ if( flags & SQLITE_OPEN_MAIN_JOURNAL ){ /* If opening a main journal file and the first chunk is zero ** bytes in size, delete any subsequent chunks from the ** file-system. */ int iChunk = 1; do { rc = pOrigVfs->xAccess(pOrigVfs, pGroup->aReal[iChunk].z, SQLITE_ACCESS_EXISTS, &bExists ); if( rc==SQLITE_OK && bExists ){ rc = pOrigVfs->xDelete(pOrigVfs, pGroup->aReal[iChunk].z, 0); if( rc==SQLITE_OK ){ rc = multiplexSubFilename(pGroup, ++iChunk); } } }while( rc==SQLITE_OK && bExists ); } }else{ /* If the first overflow file exists and if the size of the main file ** is different from the chunk size, that means the chunk size is set ** set incorrectly. So fix it. ** ** Or, if the first overflow file does not exist and the main file is ** larger than the chunk size, that means the chunk size is too small. ** But we have no way of determining the intended chunk size, so ** just disable the multiplexor all togethre. */ rc = pOrigVfs->xAccess(pOrigVfs, pGroup->aReal[1].z, SQLITE_ACCESS_EXISTS, &bExists); bExists = multiplexSubSize(pGroup, 1, &rc)>0; if( rc==SQLITE_OK && bExists && sz64==(sz64&0xffff0000) && sz64>0 && sz64!=pGroup->szChunk ){ pGroup->szChunk = (int)sz64; }else if( rc==SQLITE_OK && !bExists && sz64>pGroup->szChunk ){ pGroup->bEnabled = 0; } } } } if( rc==SQLITE_OK ){ if( pSubOpen->pMethods->iVersion==1 ){ pMultiplexOpen->base.pMethods = &gMultiplex.sIoMethodsV1; }else{ pMultiplexOpen->base.pMethods = &gMultiplex.sIoMethodsV2; } /* place this group at the head of our list */ pGroup->pNext = gMultiplex.pGroups; if( gMultiplex.pGroups ) gMultiplex.pGroups->pPrev = pGroup; gMultiplex.pGroups = pGroup; }else{ multiplexFreeComponents(pGroup); sqlite3_free(pGroup); } } multiplexLeave(); sqlite3_free(zToFree); return rc; }
DLL_FUNCTION(int64_t*) BU_SQLite_URI_LongLong(const char* zFilename, const char* zParam, int64_t* bDefault) { #pragma comment(linker, "/EXPORT:BU_SQLite_URI_LongLong=_BU_SQLite_URI_LongLong@12") return new int64_t(sqlite3_uri_int64(zFilename, zParam, *bDefault)); }