Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UWP: Crash in .NET native release builds when consuming winsqlite3.dll #375

Open
rigdern opened this issue Jan 12, 2018 · 0 comments
Open

Comments

@rigdern
Copy link

rigdern commented Jan 12, 2018

Two changes need to be made to all of the DllImports for "winsqlite3":

  1. Calling convention has to be switched from Cdecl to StdCall
  2. ExactSpelling has to be set to true

For example:

[DllImport("winsqlite3", EntryPoint = "sqlite3_open", CallingConvention = CallingConvention.Cdecl)]

should be:

[DllImport("winsqlite3", EntryPoint = "sqlite3_open", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]

rigdern pushed a commit to rigdern/react-native-sqlite-storage that referenced this issue Jun 24, 2018
The UWP implementation is very similar to the iOS implementation. There are some differences. Most of them are because I didn't have time to port certain features and I haven't needed them. Here's the list of differences:
  - Reading and writing blobs isn't supported.
  - I didn't port the sqlcipher stuff.
  - I didn't port the custom regex SQL function so REGEXP may not be supported.
  - `attach` isn't supported.
  - Some `open` options aren't supported:
    - dblocation. I wasn't sure how to map it to UWP. Also, the Android implementations don't seem to support this.
    - key (related to sqlcipher)
  - Differences with `delete`:
    - The dblocation option isn't supported
    - Closes the DB if it's open. This felt like the right thing to do.

All of the code in the SQLite.Net-PCL directory is from https://github.com/oysteinkrog/SQLite.Net-PCL. It provides a thin wrapper around the C SQLite APIs which enables them to be called from C#. A couple of tweaks were made to the code to fix these bugs:
  - oysteinkrog/SQLite.Net-PCL#374
  - oysteinkrog/SQLite.Net-PCL#375

This implementation requires at least the Windows 10 Anniversary Update. This is because it relies on the version of SQLite that is built into Windows 10 and this was introduced in the Anniversary Update. You can learn more at https://blogs.windows.com/buildingapps/2017/02/06/using-sqlite-databases-uwp-apps/.

With a little work, this module could be updated to support earlier versions of Windows 10. Here's how:
  - When constructing `SQLiteApiWinRT`, pass `false` for the `useWinSqlite` parameter.
  - Install the "SQLite for Universal Windows Platform" extension which will bring a version of SQLite into your app: https://marketplace.visualstudio.com/items?itemName=SQLiteDevelopmentTeam.SQLiteforUniversalWindowsPlatform

TODO:
  - backgroundExecuteSqlBatch
  - executeSql
  - backgroundExecuteSql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant