Skip to content

Commit f28225c

Browse files
committed
[sqliteds] Initialize kSqlite3Vfs in a forward-compatible way
1 parent 029fa9a commit f28225c

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

tree/dataframe/src/RSqliteDS.cxx

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ int VfsRdOnlyDeviceCharacteristics(sqlite3_file * /*pFile*/)
162162
}
163163

164164
////////////////////////////////////////////////////////////////////////////
165-
/// Set the function pointers of the custom VFS implementation
165+
/// Set the function pointers of the custom VFS I/O operations in a
166+
/// forward-compatible way
166167
static sqlite3_io_methods GetSqlite3IoMethods()
167168
{
168169
// The C style initialization is compatible with version 1 and later versions of the struct.
@@ -293,33 +294,33 @@ int VfsRdOnlyCurrentTime(sqlite3_vfs *vfs, double *prNow)
293294
return rc;
294295
}
295296

297+
////////////////////////////////////////////////////////////////////////////
298+
/// Set the function pointers of the VFS implementation in a
299+
/// forward-compatible way
300+
static sqlite3_vfs GetSqlite3Vfs()
301+
{
302+
// The C style initialization is compatible with version 1 and later versions of the struct.
303+
// Version 1 was introduced with sqlite 3.5, version 2 with sqlite 3.7, version 3 with sqlite 3.7.6
304+
sqlite3_vfs vfs;
305+
memset(&vfs, 0, sizeof(vfs));
306+
vfs.iVersion = 1;
307+
vfs.szOsFile = sizeof(VfsRootFile);
308+
vfs.mxPathname = 2000;
309+
vfs.zName = gSQliteVfsName;
310+
vfs.xOpen = VfsRdOnlyOpen;
311+
vfs.xDelete = VfsRdOnlyDelete;
312+
vfs.xAccess = VfsRdOnlyAccess;
313+
vfs.xFullPathname = VfsRdOnlyFullPathname;
314+
vfs.xRandomness = VfsRdOnlyRandomness;
315+
vfs.xSleep = VfsRdOnlySleep;
316+
vfs.xCurrentTime = VfsRdOnlyCurrentTime;
317+
vfs.xGetLastError = VfsRdOnlyGetLastError;
318+
return vfs;
319+
}
320+
296321
////////////////////////////////////////////////////////////////////////////
297322
/// A global struct of function pointers and details on the VfsRootFile class that together constitue a VFS module
298-
static struct sqlite3_vfs kSqlite3Vfs = {
299-
1, // version of the struct
300-
sizeof(VfsRootFile),
301-
2000, // maximum URL length
302-
nullptr, // pNext, maintained by sqlite
303-
gSQliteVfsName,
304-
nullptr, // pAppData
305-
VfsRdOnlyOpen,
306-
VfsRdOnlyDelete,
307-
VfsRdOnlyAccess,
308-
VfsRdOnlyFullPathname,
309-
nullptr, // xDlOpen
310-
nullptr, // xDlError
311-
nullptr, // xDlSym
312-
nullptr, // xDlClose
313-
VfsRdOnlyRandomness,
314-
VfsRdOnlySleep,
315-
VfsRdOnlyCurrentTime,
316-
VfsRdOnlyGetLastError,
317-
VfsRdOnlyCurrentTimeInt64,
318-
// Version 3 and later callbacks
319-
nullptr, // xSetSystemCall
320-
nullptr, // xGetSystemCall
321-
nullptr, // xNextSystemCall
322-
};
323+
static struct sqlite3_vfs kSqlite3Vfs = GetSqlite3Vfs();
323324

324325
static bool RegisterSqliteVfs()
325326
{

0 commit comments

Comments
 (0)