+-

我希望能够检查给定的SQLite数据库是否打开.我怎样才能在C/C++中做到这一点?我查看了SQLite C/C++ API,并没有看到为此目的明显的东西.
最佳答案
正如WhozCraig首次提到的,您需要检查sqlite3_open的返回值.如果返回代码是SQLITE_OK,则数据库已打开.您可能还需要检查指针参数是否未设置为null.
这个函数的接口是documented.
Here是一个邮件列表帖子,其中有人解释了为什么没有isOpen函数.
顺便说一句,强烈建议使用RAII创建DatabaseHandle类.这样,你的程序一定会在完成后用sqlite3对象调用sqlite3_close.从sqlite3_open的文档:
Whether or not an error occurs when it is opened, resources associated
with the database connection handle should be released by passing it
to sqlite3_close() when it is no longer required.
点击查看更多相关文章
转载注明原文:如何检查SQLite数据库是否在C/C++中打开 - 乐贴网