diff --git a/README.md b/README.md index 197c2324..ac828552 100644 --- a/README.md +++ b/README.md @@ -282,7 +282,7 @@ Add `PackageProviders().Append(winrt::SQLitePlugin::ReactPackageProvider());` be Refer to this guide for more details: https://microsoft.github.io/react-native-windows/docs/next/native-modules-using -## Setting up your project to import a pre-populated SQLite database from application for iOS +## Pre-populated SQLite database (iOS) #### Step 1 - Create 'www' folder. @@ -327,6 +327,15 @@ Modify you openDatabase call in your application adding createFromLocation param ``` For Android, the www directory is always relative to the assets directory for the app: src/main/assets +## Pre-populated SQLite database (Windows) +Almost identical to iOS, but we'll be using Visual Studio + +1. Put your database in `windows\\www` +2. Open `windows\.sln` with Visual Studio +3. Right-click `\Assets` in the Solution Explorer +4. `Add -> Existing Item` and select your database +5. Finally, set `Content` to `True` in File Properties (right side of Visual Studio, by default) + Enjoy! ## Opening a database diff --git a/platforms/windows/SQLitePlugin/SQLitePlugin.cpp b/platforms/windows/SQLitePlugin/SQLitePlugin.cpp index 2693a0ea..45414b88 100644 --- a/platforms/windows/SQLitePlugin/SQLitePlugin.cpp +++ b/platforms/windows/SQLitePlugin/SQLitePlugin.cpp @@ -307,13 +307,18 @@ namespace SQLitePlugin { try { - CopyDbAsync(assetFile, to_hstring(*dbFileName)).GetResults(); + CopyDbAsync(assetFile, to_hstring(*dbFileName)).get(); } catch (hresult_error const& ex) { - // CopyDbAsync throws when the file already exists. - onFailure("Unable to copy asset file: " + winrt::to_string(ex.message())); - return; + if (ex.code() == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) + { + // Ignore, CopyDbAsync throws when the file already exists. + } else + { + onFailure("Unable to copy asset file: " + winrt::to_string(ex.message())); + return; + } } } } @@ -554,4 +559,4 @@ namespace SQLitePlugin { return ApplicationData::Current().LocalFolder().Path() + L"\\" + dbFileName; } -} +} \ No newline at end of file