你是否注意到在头文件
sqlite3.h
中还有一个额外的文档来源?此外,Google代码搜索是你的好朋友。
不要太担心遗漏的内容,这就是测试套件的作用。从方法名称、文档和示例实现中猜测每个方法的目的,进行初步实现,然后在目标平台上运行测试;迭代直至测试通过。根据你引用的接口文档的粗略阅读,以下是一些猜测:
int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
int flags, int *pOutFlags);
int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
这些是您平常使用的文件管理功能。您会注意到,xOpen()
返回一个结构体sqlite3_file
,它具有自己的指针方法用于读取和写入。
void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
void (*xDlClose)(sqlite3_vfs*, void*);
这些是用于共享库的(请参阅Linux上的dlopen()手册)。在嵌入式环境中,您可能可以将其保持未实现状态(尝试将其设置为NULL)。
int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
如果你的操作系统标准库没有提供随机数生成器,那么你可能需要实现一个。我建议使用线性反馈移位寄存器,它既小巧又好用。
int (*xSleep)(sqlite3_vfs*, int microseconds);
int (*xCurrentTime)(sqlite3_vfs*, double*);
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
这些是时间管理功能,可以与您的操作系统连接起来。
int (*xGetLastError)(sqlite3_vfs*, int, char *);
您可以始终返回0来避免错误。请参见os_unix.c中的unixGetLastError(感谢Google代码搜索!)
祝好运!
fopen
和它的朋友们不能用于sqlite,因为它没有锁定机制,语义尤其是与数据何时到达永久存储相关的方面还没有被确定下来,这些都是sqlite需要的。 - zwol