Sqlite3_open_v2 function file path

I have a problem with sqlite3_open_v2 function. OS - Windows developing in Qt Creator.

sqlite3_open("database.db", &db); // works fine

but

sqlite3_open_v2("database.db", &db, SQLITE_OPEN_READWRITE, ""); // don't work

I am sure that this is not a utf-8 codding problem, because the first function works fine, and I tried to change the encoding in the project properties. Perhaps the problem is with the file path in the first argument. Absolute paths didn't work either.

Has anyone had any idea and used this feature?

+4
source share
2 answers

This is probably due to the fact that the file does not exist in the working directory. I would add some code to print the path to the current working directory immediately before calling sqlite3_open_v2.

One difference between sqlite3_open and sqlite3_open_v2 with SQLITE_OPEN_READWRITE is the first, which will create an empty database when the file is not found, and the second is not.

To create a database with sqlite3_open_v2, you should use:

 sqlite3_open_v2("database.db", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL ); 

Be sure to check out the documentation for more information: http://www.sqlite.org/c3ref/open.html

+4
source

Thanks for answers.

The problem was the last parameter. It must be 0 or NULL instead of ""

All thanks anyway

+4
source

Source: https://habr.com/ru/post/1414614/


All Articles