Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function sqlite3_open_v2 filepath

Tags:

c++

sqlite

qt

I have a problem with sqlite3_open_v2 function. OS is 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'm quite sure it's not utf-8 codding problem, cause first function works fine and i tried to change codding in project properties. Maybe problem is with filepath in first arg. Absolute paths didn't work too.

Anyone had any idea and exmple of using this function?

like image 714
adm Avatar asked May 27 '12 17:05

adm


2 Answers

Thanks for answers.

Problem was with last parameter. It must be 0 or NULL instead of ""

That's all, thanks anyway

like image 133
adm Avatar answered Sep 21 '22 17:09

adm


This is probably because the file does not exist in the working directory. I would add some code to print the path of the current working directory just before calling sqlite3_open_v2 to be sure.

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

In order to allow the creation of 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 have a look at the documentation for more information: http://www.sqlite.org/c3ref/open.html

like image 29
Didier Spezia Avatar answered Sep 23 '22 17:09

Didier Spezia