【问题标题】:How to use an existing sqlite database on windows phone 8 with cordova如何在带有cordova的windows phone 8上使用现有的sqlite数据库
【发布时间】:2014-03-18 15:07:40
【问题描述】:

我正在使用cordova 3.0 构建一个混合应用程序。我使用插件将我的数据存储在 sqlite 数据库中。在 android 和 ios 上,我有一些脚本,它们将数据库复制到应用程序的“文档”文件夹中,我可以在其中读取/写入该预填充的数据库。现在我想在 windows phone 8 上存档。

我找到了一个教程: http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/

但这与科尔多瓦无关。

这是我的代码的样子:

namespace com.example.hello
{
   public partial class MainPage : PhoneApplicationPage
   {
    // Constructor
    public MainPage()
    {
        InitializeComponent();

        this.CordovaView.Loaded += CordovaView_Loaded;
    }

    private async void CordovaView_Loaded(object sender, RoutedEventArgs e)
    {
        await CopyDatabase();
        this.CordovaView.Loaded -= CordovaView_Loaded;
    }

    private async Task CopyDatabase()
    {
        bool isDatabaseExisting = false;

        try
        {
            StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("my.db");
            isDatabaseExisting = true;
        }
        catch
        {
            isDatabaseExisting = false;
        }

        if (!isDatabaseExisting)
        {
            StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("my.db");
            await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
        }
    }
}
}

但我总是得到一个异常“System.IO.FileNotFoundException”。但是 .db 文件仍然在正确的位置。如果我使用 sn-p 显示“ApplicationData.Current.LocalFolder”中的所有文件,我的 sqlite 填充仍然存在。

我也有截图的要点https://gist.github.com/pille72/9615840

【问题讨论】:

标签: c# sqlite cordova windows-phone-8 cordova-3


【解决方案1】:

将构建操作从 Resource 更改为 Content

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多