13# define PATH_MAX FILENAME_MAX
15#if SQLITE_VERSION_NUMBER < 3040000
20struct Vfs : sqlite3_vfs {
22 sqlite3_io_methods ioMethods;
25struct File : sqlite3_file {
26 class QtFile :
public QFile {
30 , removeOnClose(removeOnClose)
45int xClose(sqlite3_file *sfile)
47 auto file =
static_cast<File *
>(sfile);
49 file->pFile =
nullptr;
53int xRead(sqlite3_file *sfile,
void *
ptr,
int iAmt, sqlite3_int64 iOfst)
55 auto file =
static_cast<File *
>(sfile);
57 return SQLITE_IOERR_READ;
59 auto sz =
file->pFile->
read(
static_cast<char *
>(
ptr), iAmt);
61 memset(
static_cast<char *
>(
ptr) + sz, 0,
size_t(iAmt - sz));
62 return SQLITE_IOERR_SHORT_READ;
67int xWrite(sqlite3_file *sfile,
const void *
data,
int iAmt, sqlite3_int64 iOfst)
69 auto file =
static_cast<File *
>(sfile);
71 return SQLITE_IOERR_SEEK;
72 return file->pFile->
write(
reinterpret_cast<const char*
>(
data), iAmt) == iAmt ? SQLITE_OK : SQLITE_IOERR_WRITE;
75int xTruncate(sqlite3_file *sfile, sqlite3_int64
size)
77 auto file =
static_cast<File *
>(sfile);
78 return file->pFile->
resize(
size) ? SQLITE_OK : SQLITE_IOERR_TRUNCATE;
81int xSync(sqlite3_file *sfile,
int )
83 static_cast<File *
>(sfile)->pFile->flush();
87int xFileSize(sqlite3_file *sfile, sqlite3_int64 *pSize)
89 auto file =
static_cast<File *
>(sfile);
96int xLock(sqlite3_file *,
int) {
return SQLITE_OK; }
98int xUnlock(sqlite3_file *,
int) {
return SQLITE_OK; }
100int xCheckReservedLock(sqlite3_file *,
int *pResOut)
106int xFileControl(sqlite3_file *,
int,
void *) {
return SQLITE_NOTFOUND; }
108int xSectorSize(sqlite3_file *)
113int xDeviceCharacteristics(sqlite3_file *)
119 int flags,
int *pOutFlags)
121 auto vfs =
static_cast<Vfs *
>(svfs);
122 auto file =
static_cast<File *
>(sfile);
123 memset(
file, 0,
sizeof(File));
125 if (!zName || (
flags & SQLITE_OPEN_MEMORY))
127 if ((
flags & SQLITE_OPEN_READONLY) &&
128 !(
flags & SQLITE_OPEN_READWRITE) &&
129 !(
flags & SQLITE_OPEN_CREATE) &&
130 !(
flags & SQLITE_OPEN_DELETEONCLOSE)) {
143 if ((
flags & SQLITE_OPEN_CREATE) && (
flags & SQLITE_OPEN_EXCLUSIVE))
146 if (
flags & SQLITE_OPEN_READWRITE)
150 file->pMethods = &vfs->ioMethods;
153 return SQLITE_CANTOPEN;
160int xDelete(sqlite3_vfs *,
const char *zName,
int)
165int xAccess(sqlite3_vfs *,
const char *zName,
int flags,
int *pResOut)
169 case SQLITE_ACCESS_EXISTS:
170 case SQLITE_ACCESS_READ:
179int xFullPathname(sqlite3_vfs *,
const char *zName,
int nOut,
char *zOut)
185 for (;zName[
i] &&
i < nOut; ++
i)
195int xRandomness(sqlite3_vfs *svfs,
int nByte,
char *zOut)
197 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
198 return vfs->xRandomness(vfs, nByte, zOut);
201int xSleep(sqlite3_vfs *svfs,
int microseconds)
203 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
204 return vfs->xSleep(vfs, microseconds);
207int xCurrentTime(sqlite3_vfs *svfs,
double *zOut)
209 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
210 return vfs->xCurrentTime(vfs, zOut);
213int xGetLastError(sqlite3_vfs *,
int,
char *)
218int xCurrentTimeInt64(sqlite3_vfs *svfs, sqlite3_int64 *zOut)
220 auto vfs =
static_cast<Vfs *
>(svfs)->pVfs;
221 return vfs->xCurrentTimeInt64(vfs, zOut);
228 memset(&vfs, 0,
sizeof(Vfs));
230 vfs.szOsFile =
sizeof(
File);
234 vfs.xDelete = &xDelete;
235 vfs.xAccess = &xAccess;
236 vfs.xFullPathname = &xFullPathname;
237 vfs.xRandomness = &xRandomness;
238 vfs.xSleep = &xSleep;
239 vfs.xCurrentTime = &xCurrentTime;
240 vfs.xGetLastError = &xGetLastError;
241 vfs.xCurrentTimeInt64 = &xCurrentTimeInt64;
242 vfs.pVfs = sqlite3_vfs_find(
nullptr);
243 vfs.ioMethods.iVersion = 1;
244 vfs.ioMethods.xClose = &xClose;
245 vfs.ioMethods.xRead = &xRead;
246 vfs.ioMethods.xWrite = &xWrite;
247 vfs.ioMethods.xTruncate = &xTruncate;
248 vfs.ioMethods.xSync = &xSync;
249 vfs.ioMethods.xFileSize = &xFileSize;
250 vfs.ioMethods.xLock = &xLock;
251 vfs.ioMethods.xUnlock = &xUnlock;
252 vfs.ioMethods.xCheckReservedLock = &xCheckReservedLock;
253 vfs.ioMethods.xFileControl = &xFileControl;
254 vfs.ioMethods.xSectorSize = &xSectorSize;
255 vfs.ioMethods.xDeviceCharacteristics = &xDeviceCharacteristics;
257 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,...
QFILE_MAYBE_NODISCARD 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
const char * sqlite3_filename
decltype(openFileForWriting({})) File
settings remove("monkey")