FOpen* 的 SQLite VFS 实施指南

发布于 2024-09-12 04:29:09 字数 627 浏览 3 评论 0原文

我即将使用 FOpen、FRead、FWrite、FSeek 和 FClose 为 Netburner 嵌入式设备(非 Windows)实现自定义 VFS(虚拟文件系统)。我很惊讶我找不到可用的 VFS 的 FOpen* 版本。这将使它更容易移植到嵌入式设备。

我在这里找到了一些有关为 SQLite 创建 VFS 的信息 http://sqlite.org/c3ref/vfs.html 但信息非常详细,我对实施还有很多其他问题。

我在 Win、OS2、Linux 的 SQLite 源代码中有一些示例 VFS,但它们没有很多注释,只有源代码。

我可以使用上面链接中提供的信息和示例来创建我的自定义 VFS,但我确信如果我这样做的话我会错过一些东西。

我的问题是:

  • 是否还有我缺少的有关 SQLite VFS 的更多文档?也许是实施指南?
  • 是否有可用的 SQLite VFS 的 Fopen 版本?
  • 创建自定义 SQLite VFS 后,是否有单元测试代码可用于测试它?
  • 您想分享的建议、评论、实施 SQLite VFS 的经验。

I am about to implement a custom VFS (virtual file system) for a Netburner embedded device (non windows) using FOpen, FRead, FWrite, FSeek, and FClose. I was surprised that i could not find a FOpen* version of the VFS available. It would make it a lot more portable to embedded devices.

I found some information on creating the VFS for SQLite here
http://sqlite.org/c3ref/vfs.html
but the information is very detailed and I have lots of other questions about the implementation.

I have some example VFS in the SQLite source code for Win, OS2, Linux but they don't have a lot of comments, only source code.

I could use the information provided in the link above and the examples to create my custom VFS but i'm sure that I would miss something if I did it that way.

My questions are:

  • Is there any more documentation about the SQLite VFS that I am missing? Maybe an implementation guide?
  • Is there an Fopen version of the SQLite VFS that is available?
  • Is there a unit testing code available to test my custom SQLite VFS once I have created it?
  • Suggestions, comments, experiences with implementing SQLite VFS that you would like to share.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光礼记 2024-09-19 04:29:09

您是否注意到头文件 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 代码搜索!)祝您

好运!

Did you notice that there is an additional source of documentation in the header file sqlite3.h? Also, Google code search is your friend.

Don't worry too much about missing things, this is what the test suite is for. Take a guess at the purpose of every method from their name, the documentation and the example implementations; go for a first-draft implementation; run the tests on your target platform; iterate until the bar is green. From a cursory reading of the interface doc that you quoted, here are some educated guesses:

  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);

Those are your run-off-the-mill file management functions. You'll notice that xOpen() in turn returns a structure sqlite3_file, that has pointer methods of its own for reading and writing.

  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*);

Those are for shared libraries (see the dlopen() man page on Linux). In an embedded environment, you probably can leave these unimplemented (try setting these to NULL).

  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);

You might have to implement a random number generator, if your OS' standard library doesn't provide one already. I suggest a linear feedback register, which is small yet good.

  int (*xSleep)(sqlite3_vfs*, int microseconds);
  int (*xCurrentTime)(sqlite3_vfs*, double*);
  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);

These are the time management functions, to hook up with your OS.

  int (*xGetLastError)(sqlite3_vfs*, int, char *);

You can get away by always returning 0 here :-) See unixGetLastError in os_unix.c (thanks Google Code Search!)

Good luck!

死开点丶别碍眼 2024-09-19 04:29:09

一种选择是使用基于内存的 VFS,然后在完成后将内存转储到文件。请参阅:http://article.gmane.org/gmane.comp.db .sqlite.general/46450 用于已经支持序列化/反序列化的基于内存的 VFS。

缺点是您必须手动写出文件才能使其保留。如果您的应用程序突然终止,对数据库的任何中间更改都将不会被持久化。

One option is to use a memory based VFS then simply dump the memory to file when you are done. See: http://article.gmane.org/gmane.comp.db.sqlite.general/46450 for a memory based VFS that already supports serialization/deserialization.

The disadvantage is that you must manually write the file out for it to persist. If your application suddenly dies any intermediate changes to the DB will not be persisted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文