- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
int main(int argc,char **argv){
int rc
sqlite3 *db;
rc = sqlite3_open(argv[1], &db);
printf("rc = %d\n", rc);
if(rc){
printf("Not Valid Database\n");
sqlite3_close(db);
exit(1);
}
如果我使用 ./test exsisting_database.sqlite3
运行它,它会按预期返回 0
。但是使用 ./test not_exsisting_database.sqlite3
它仍然返回 0
并创建文件 not_exsisting_database.sqlite3
最佳答案
从此处找到的有关打开数据库的 SQLite 文档: https://sqlite.org/c3ref/open.html
The sqlite3_open_v2() interface works like sqlite3_open() except thatit accepts two additional parameters for additional control over thenew database connection. The flags parameter to sqlite3_open_v2() cantake one of the following three values, optionally combined with theSQLITE_OPEN_NOMUTEX, SQLITE_OPEN_FULLMUTEX, SQLITE_OPEN_SHAREDCACHE,SQLITE_OPEN_PRIVATECACHE, and/or SQLITE_OPEN_URI flags:
SQLITE_OPEN_READONLY The database is opened in read-only mode. If thedatabase does not already exist, an error is returned.
SQLITE_OPEN_READWRITE The database is opened for reading and writingif possible, or reading only if the file is write protected by theoperating system. In either case the database must already exist,otherwise an error is returned.
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE The database is opened forreading and writing, and is created if it does not already exist.This is the behavior that is always used for sqlite3_open() and sqlite3_open16().
所以你需要使用不带 SQLITE_OPEN_CREATE 标志的 sqlite3_open_v2() 而不是 sqlite3_open()
关于c - 如果尝试打开不存在的文件,sqlite3_open 不会返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46073011/
主屏幕启动后,通知打开事件上的 OneSignal 会触发,然后导航到所需的屏幕。我想检测应用程序是否在主屏幕呈现之前按下通知启动,以便我可以直接导航到第二个屏幕并避免不必要地调用 api。 "rea
我的一位同事在对图像进行分类时在 python 服务中遇到错误。下面是错误跟踪日志 File "nsfw.py", line 7, in score = classifier.get_score(
我的一位同事在对图像进行分类时在 python 服务中遇到错误。下面是错误跟踪日志 File "nsfw.py", line 7, in score = classifier.get_score(
我正在尝试使用代号 1 运行连续测试。 第一个测试打开模拟器并访问 sqlite 数据库并返回 true 并关闭该模拟器。下一个测试打开另一个模拟器并运行该测试,但这个模拟器不访问数据库,所以我假设为
我是一名优秀的程序员,十分优秀!