5

I am trying to develop a WinRT DLL which uses SQLite to write database. But it seems like some win32 APIs in SQLite source code are not supported by metro, such as, LoadLibraryW, GetTempPathA.

Is there any way to compile SQLite source code or use SQLite with WinRT DLL?

3
  • possible duplicate of Using SQLite with WinRT
    – dalle
    Oct 14, 2011 at 6:54
  • @dalle: It seems that, although the titles are similar, the problems described are quite different. Oct 14, 2011 at 6:56
  • @BjörnPollex: True, the questions and described problems differs a bit, but it the answer is still the same. Some Win32 functions are not permitted when compiling using WinRT, such as LoadLibraryW, GetTempPathA, CreateFileA, CreateFileW, DeleteFileA and so on. The hardest one to port is probably LoadLibraryW.
    – dalle
    Oct 14, 2011 at 7:22

6 Answers 6

2

Well you could always link sqlite3 statically and define new functions for accessing files etc via sqlite3_vfs.

2

In VS2012 there is an extension now called SQLite for Windows Runtime. You can download and install this via Visual Studio (requires a restart of the IDE). Then, go to your WinRT project, Add a Reference, under "Windows" choose "Extensions" and you should see it.

enter image description here

1

There's a winrt branch of SQLite now that only uses supported API. On top of that, we implemented SQLite3-WinRT, a WinRT component that allows using SQLite in any of the WinRT languages.

0
  1. rename sqlite3.c to sqlite3.cpp
  2. replace LoadLibrary with LoadPackagedLibrary
  3. Fix lots of syntax errors.
3
  • Why rename? You can link c and c++ modules together. In fact, that is how I incorporate SQLite myself... Nov 17, 2011 at 10:16
  • 1
    My VS11 on W8 Consumer Preview says you can't ("cannot compile C files with /ZW (Metro) option").
    – Cygon
    Mar 4, 2012 at 10:07
  • You can create an win32 static lib project, then you can use the .lib in metro style app project. Pls wait for the next SQlite release, because the SQLite branch of WinRT has been merged to trunk. sqlite.org/src/timeline?r=winrt
    – linyehui
    Jun 14, 2012 at 8:50
0

From the SQLite site

SQLite version 3.7.13 adds support for WinRT and metro style applications for Microsoft Windows 8. The 3.7.13 release is coming sooner than is usual after the previous release in order to get this new capability into the hands of developers. To use SQLite in a metro style application, compile with the -DSQLITE_OS_WINRT flag. Because of the increased application security and safety requirements of WinRT, all database filenames should be full pathnames. Note that SQLite is not capable of accessing databases outside the installation directory and application data directory. This restriction is another security and safety feature of WinRT. Apart from these restrictions, SQLite should work exactly the same on WinRT as it does on every other system.

Tim Heuer provides a walk-through of building a metro app using SQLite on his blog

0

Let me add some remarks on using sqlite/winrt that may save you some headaches:

  1. Winrt allows you to write only to specific folder (c:\users\<user>\My documents\<app>). You have to put your DB here. (Trivial in managed environment.)

  2. Time from time Sqlite uses temp files. (Complex queries that need transient indices, vacuum etc.) These files also must be created in the app folder, but sqlite won't do this unless you set it with temp_store_directory pragma. If you don't do this, you may get random user bug reports.

  3. Note that above pragma is officially deprecated. Ignore this. Native coders might be tempted to use global variable sqlite3_temp_directory instead (encouraged way), but the current binary release (dll) does not publish this variable. (You can do it yourself, but then change sqlite sources and use _declspec(dllexport) attribute; def file does not work.)

  4. Don't rely too much on sqlite file operations. The implementation is not particularly good. For example testing of write access will succeed even if you don't have write permissions.

Apart from this there seem to be no problems with winrt. More advanced users might supply their own (better) winrt driver. It is not too difficult...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.