Greetings,
I can create and open wxSQLite3 databases in Linux, but not in Windows. I get error 14 whenever I try to open the database. I have read that SQLite3 requires sqlite3_temp_directory to be set before opening a database on Windows. If this is the case, how do I set this variable with wxSQLite3?
Compiling in c++ with wxWidgets-2.9.4 and wxSQLite3-3.0.3 on Xubuntu 12.04 LTS, using MinGW.
Thanks.
Paul
wxSQLite3 MSW temp directory Topic is solved
Re: wxSQLite3 MSW temp directory
Code: Select all
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
Make sure path and filename are correct and that you have write privileges in the directory if you're creating a new file. Also, filenames under Linux are case sensitive.
Use the source, Luke!
Re: wxSQLite3 MSW temp directory
Thanks. It already works fine in Linux, it is in Windows that I have the problem.
My question was related to
However, the temp directory must already be handled by wxSQLite3 or not needed, as I discovered that rather than trying to create the database in the program's 'C:\Program Files\Vendor\Program' folder, but used the directory returned by wxStandardPaths::Get().GetUserDataDir() and created that directory. Then, it worked fine.
My question was related to
http://www.sqlite.org/c3ref/temp_directory.html.Note to Windows Runtime users: The temporary directory must be set prior to calling sqlite3_open or sqlite3_open_v2. Otherwise, various features that require the use of temporary files may fail.
However, the temp directory must already be handled by wxSQLite3 or not needed, as I discovered that rather than trying to create the database in the program's 'C:\Program Files\Vendor\Program' folder, but used the directory returned by wxStandardPaths::Get().GetUserDataDir() and created that directory. Then, it worked fine.
Re: wxSQLite3 MSW temp directory
On Linux platforms SQLite itself tries to determine a suitable temporary directory. No such mechanism is implemented for Windows platforms.paulcrown wrote:Thanks. It already works fine in Linux, it is in Windows that I have the problem.
For SQlite versions below 3.7.14 the temporary directory could be set using a PRAGMA statement - no need for a specific method in wxSQLite3 to do this. However, starting with SQLite 3.7.14 the PRAGMA is deprecated and should not be used any longer. Instead there is now a Windows specific SQLite API function to set the temporary directory.paulcrown wrote:My question was related tohttp://www.sqlite.org/c3ref/temp_directory.html.Note to Windows Runtime users: The temporary directory must be set prior to calling sqlite3_open or sqlite3_open_v2. Otherwise, various features that require the use of temporary files may fail.
I have to admit that this change did not catch my attention. I will add a method to wxSQLite3 for this purpose.
SQLite tries to create database files and temporary files in the current working directory - a subdirectory of "Program Files" for a regularly installed Windows application if you didn't set the working directory explicitly. If an existing database file is opened, journal files and other temporary files will be created in the directory in which the database file resides. This of course requires that the directory where the database resides has to be writable. This is usually not the case for the directory "Program Files" and its subdirectories on newer Windows versions, unless you take care of setting the access rights in the installer of your application.paulcrown wrote:However, the temp directory must already be handled by wxSQLite3 or not needed, as I discovered that rather than trying to create the database in the program's 'C:\Program Files\Vendor\Program' folder, but used the directory returned by wxStandardPaths::Get().GetUserDataDir() and created that directory. Then, it worked fine.
No special action has to be taken, if the database file is created in a directory with write access. However, I will add a method for setting the temporary directory in wxSQLite3 - as mentioned above -, although this does not solve the issue when you try to create a database in a write protected directory.
Regards,
Ulrich
Re: wxSQLite3 MSW temp directory
Thanks utelle.
I look forward to your update that allows the temp directory to be set in Windows, however, forcing me to think about using a directory other than Program Files was actually a good thing. I have changed my code to use wxStandardPaths::Get().GetUserDataDir() on Linux as well as Windows, and all is working fine now.
In case you aren't told often enough, your work on wxSQLite3 is greatly appreciated.
Paul
I look forward to your update that allows the temp directory to be set in Windows, however, forcing me to think about using a directory other than Program Files was actually a good thing. I have changed my code to use wxStandardPaths::Get().GetUserDataDir() on Linux as well as Windows, and all is working fine now.
In case you aren't told often enough, your work on wxSQLite3 is greatly appreciated.
Paul
Re: wxSQLite3 MSW temp directory
I'm a bit uncertain how to implement this method. SQLite provides a function to set the temporary directory only on Windows platforms, but not for any other platform. wxSQLite3 is cross platform, that is, if I implement a method for setting the temporary directory developers might expect that this will work cross platform, too. However, it will function only on Windows platforms. Should the method return a boolean to signal whether the temporary directory could be set? Or should it throw an exception? Or should it silently do nothing on Unix/Linux like platforms?paulcrown wrote:I look forward to your update that allows the temp directory to be set in Windows,
(Yes, there is a global static SQLite variable sqlite3_temp_directory, however, I really don't like the idea to tamper directly with global variables.)
Although SQLite provides a function for setting the data directory on Windows, too, the SQLite documentation states that this was introduced solely for WinRT where no other mechanism exists to set the data directory. However, I think I'm not going to implement a method for this within wxSQLite3. If absolute paths are used to specify the file name and location of the database this should work on any platform without requiring to explicitly set the SQLite data directory.paulcrown wrote:however, forcing me to think about using a directory other than Program Files was actually a good thing. I have changed my code to use wxStandardPaths::Get().GetUserDataDir() on Linux as well as Windows, and all is working fine now.
Thanks. I'm always glad to hear that.paulcrown wrote:In case you aren't told often enough, your work on wxSQLite3 is greatly appreciated.
Regards,
Ulrich
Re: wxSQLite3 MSW temp directory
I personally am used to using libraries that provide a feature that is only applicable to a specific OS. If is important, I build-in a set of #ifdef macros on how to handle such feature depending on the OS. What I would like, and is not always the case, is for the function to return false when it is on a non-applicable OS. Some functions do as you suggest and remain silent on Linux; I would prefer they return false. This forces me to look up and see that it isn't ok for that OS, or more often, is dealt with in the same manner as a normal failure. I wouldn't want it to throw an exception.utelle wrote:Should the method return a boolean to signal whether the temporary directory could be set? Or should it throw an exception? Or should it silently do nothing on Unix/Linux like platforms?
I agree, that I don't think wxSQLite needs to worry about setting a data directory; it can either be set within the wxWidgets, or in my case use wxStandardPaths to create an absolute path that can be passed to wxSQLite. My comment from before was in regards to teaching myself that I shouldn't have saving the database in ExecutablePath irregardless. It makes much more sense for me to store databases in a data directory which wxStandardPaths already designates appropriately for each OS: in Windows 7 it provides "C:\users\MyName\AppData\Roaming\mydatadir", while in Linux it provides me with "/home/myuser/.mydatadir".utelle wrote:Although SQLite provides a function for setting the data directory on Windows, too, the SQLite documentation states that this was introduced solely for WinRT where no other mechanism exists to set the data directory. However, I think I'm not going to implement a method for this within wxSQLite3.
Paul
Re: wxSQLite3 MSW temp directory
Thanks for your comments. I'll implement the method to return a boolean and not to throw an exception. For non-Windows platforms it will always return false. Probably within a week or so (after testing on Windows and Linux) the new wxSQLite3 version will be available.paulcrown wrote:I personally am used to using libraries that provide a feature that is only applicable to a specific OS. If is important, I build-in a set of #ifdef macros on how to handle such feature depending on the OS. What I would like, and is not always the case, is for the function to return false when it is on a non-applicable OS. Some functions do as you suggest and remain silent on Linux; I would prefer they return false. This forces me to look up and see that it isn't ok for that OS, or more often, is dealt with in the same manner as a normal failure. I wouldn't want it to throw an exception.
Edit [2013-09-09]: wxSQLite3 3.0.5 (including the new static method wxSQLite3Database::SetTemporaryDirectory) is available for download.
Regards,
Ulrich