13# define PATH_MAX FILENAME_MAX
17struct Vfs : sqlite3_vfs {
19 sqlite3_io_methods ioMethods;
22struct File : sqlite3_file {
23 class QtFile :
public QFile {
27 , removeOnClose(removeOnClose)
42int xClose(sqlite3_file *sfile)
44 auto file =
static_cast<File *
>(sfile);
46 file->pFile =
nullptr;
50int xRead(sqlite3_file *sfile,
void *
ptr,
int iAmt, sqlite3_int64 iOfst)
52 auto file =
static_cast<File *
>(sfile);
54 return SQLITE_IOERR_READ;
56 auto sz =
file->pFile->
read(
static_cast<char *
>(
ptr), iAmt);
58 memset(
static_cast<char *
>(
ptr) + sz, 0,
size_t(iAmt - sz));
59 return SQLITE_IOERR_SHORT_READ;
64int xWrite(sqlite3_file *sfile,
const void *
data,
int iAmt, sqlite3_int64 iOfst)
66 auto file =
static_cast<File *
>(sfile);
68 return SQLITE_IOERR_SEEK;
69 return file->pFile->
write(
reinterpret_cast<const char*
>(
data), iAmt) == iAmt ? SQLITE_OK : SQLITE_IOERR_WRITE;
72int xTruncate(sqlite3_file *sfile, sqlite3_int64
size)
74 auto file =
static_cast<File *
>(sfile);
75 return file->pFile->
resize(
size) ? SQLITE_OK : SQLITE_IOERR_TRUNCATE;
78int xSync(sqlite3_file *sfile,
int )
80 static_cast<File *
>(sfile)->pFile->flush();
84int xFileSize(sqlite3_file *sfile, sqlite3_int64 *pSize)
86 auto file =
static_cast<File *
>(sfile);
93int xLock(sqlite3_file *,
int) {
return SQLITE_OK; }
95int xUnlock(sqlite3_file *,
int) {
return SQLITE_OK; }
97int xCheckReservedLock(sqlite3_file *,
int *pResOut)
103int xFileControl(sqlite3_file *,
int,
void *) {
return SQLITE_NOTFOUND; }
105int xSectorSize(sqlite3_file *)
110int xDeviceCharacteristics(sqlite3_file *)
115int xOpen(sqlite3_vfs *svfs, sqlite3_filename zName, sqlite3_file *sfile,
116 int flags,
int *pOutFlags)
118 auto vfs =
static_cast<Vfs *
>(svfs);
119 auto file =
static_cast<File *
>(sfile);
120 memset(
file, 0,
sizeof(File));
122 if (!zName || (
flags & SQLITE_OPEN_MEMORY))
124 if ((
flags & SQLITE_OPEN_READONLY) &&
125 !(
flags & SQLITE_OPEN_READWRITE) &&
126 !(
flags & SQLITE_OPEN_CREATE) &&
127 !(
flags & SQLITE_OPEN_DELETEONCLOSE)) {
140 if ((
flags & SQLITE_OPEN_CREATE) && (
flags & SQLITE_OPEN_EXCLUSIVE))
143 if (
flags & SQLITE_OPEN_READWRITE)
147 file->pMethods = &vfs->ioMethods;
150 return SQLITE_CANTOPEN;
157int xDelete(sqlite3_vfs *,
const char *zName,
int)
162int xAccess(sqlite3_vfs *,
const char *zName,
int flags,
int *pResOut)
166 case SQLITE_ACCESS_EXISTS:
167 case SQLITE_ACCESS_READ:
176int xFullPathname(sqlite3_vfs *,
const char *zName,
int nOut,
char *zOut)
182 for (;zName[
i] &&
i < nOut; ++
i)
192int xRandomness(sqlite3_vfs *svfs,
int nByte,
char *zOut)
194 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
195 return vfs->xRandomness(vfs, nByte, zOut);
198int xSleep(sqlite3_vfs *svfs,
int microseconds)
200 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
201 return vfs->xSleep(vfs, microseconds);
204int xCurrentTime(sqlite3_vfs *svfs,
double *zOut)
206 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
207 return vfs->xCurrentTime(vfs, zOut);
210int xGetLastError(sqlite3_vfs *,
int,
char *)
215int xCurrentTimeInt64(sqlite3_vfs *svfs, sqlite3_int64 *zOut)
217 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
218 return vfs->xCurrentTimeInt64(vfs, zOut);
225 memset(&vfs, 0,
sizeof(Vfs));
227 vfs.szOsFile =
sizeof(File);
231 vfs.xDelete = &xDelete;
232 vfs.xAccess = &xAccess;
233 vfs.xFullPathname = &xFullPathname;
234 vfs.xRandomness = &xRandomness;
235 vfs.xSleep = &xSleep;
236 vfs.xCurrentTime = &xCurrentTime;
237 vfs.xGetLastError = &xGetLastError;
238 vfs.xCurrentTimeInt64 = &xCurrentTimeInt64;
239 vfs.pVfs = sqlite3_vfs_find(
nullptr);
240 vfs.ioMethods.iVersion = 1;
241 vfs.ioMethods.xClose = &xClose;
242 vfs.ioMethods.xRead = &xRead;
243 vfs.ioMethods.xWrite = &xWrite;
244 vfs.ioMethods.xTruncate = &xTruncate;
245 vfs.ioMethods.xSync = &xSync;
246 vfs.ioMethods.xFileSize = &xFileSize;
247 vfs.ioMethods.xLock = &xLock;
248 vfs.ioMethods.xUnlock = &xUnlock;
249 vfs.ioMethods.xCheckReservedLock = &xCheckReservedLock;
250 vfs.ioMethods.xFileControl = &xFileControl;
251 vfs.ioMethods.xSectorSize = &xSectorSize;
252 vfs.ioMethods.xDeviceCharacteristics = &xDeviceCharacteristics;
254 sqlite3_vfs_register(&vfs, 0);
bool seek(qint64 offset) override
For random-access devices, this function sets the current position to pos, returning true on success,...
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool remove()
Removes the file specified by fileName().
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
qint64 size() const override
\reimp
bool resize(qint64 sz) override
\reimp
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static ControlElement< T > * ptr(QWidget *widget)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
settings remove("monkey")