Skip to content

Fix Pre-Populated database for Windows #550

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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\<ProjectName>\www`
2. Open `windows\<ProjectName>.sln` with Visual Studio
3. Right-click `<ProjectName>\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
Expand Down
15 changes: 10 additions & 5 deletions platforms/windows/SQLitePlugin/SQLitePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -554,4 +559,4 @@ namespace SQLitePlugin
{
return ApplicationData::Current().LocalFolder().Path() + L"\\" + dbFileName;
}
}
}