2013-07-02 32 views
2

我有一个使用SQLite数据库的Windows Phone 8应用程序。要访问数据库,我用安迪·威格利的WinRT的包装(sourceWindows Phone 8上的SQLite性能非常差

我的数据库很简单,只有一张桌子: 地点:整数主键“字段索引”,VARCHAR“字段1”,VARCHAR“字段2”, varchar“Field3”,varchar“Field4”,varchar“Field5”,varchar“Field6”,int“CategoryID”

我也对“FieldIndex”和“CategoryID”都有索引。

表中共有4000个条目,数据库大小为900 kB。我也压缩了数据库(真空)。数据库作为应用程序内容(=安装文件夹=只读)部署到手机中。我只在查询中使用数据库。我的数据访问代码如下所示:

using (var db = new SQLiteWinRTPhone.Database(Package.Current.InstalledLocation, @"Model\db.sqlite")) 
{ 
    await db.OpenAsync(SQLiteWinRTPhone.SqliteOpenMode.OpenRead); 
    await db.ExecuteStatementAsync("PRAGMA journal_mode = MEMORY"); 
    await db.ExecuteStatementAsync("PRAGMA temp_store = 2;"); 

    using (var stmt = await db.PrepareStatementAsync("SELECT * FROM Locations;")) 
    { 
     int i = 0; 
     while (await stmt.StepAsync()) 
     { 
      // There is nothing happening here 
      // Just for testing. In my real code, I iterate on all rows and store them in a object. I wanted isolate the issue here. 
      i++; 
     } 
    } 
    MessageBox.Show("We read " + i.toString() + " records."); 
} 

此刻,上述语句需要20秒才能完成。从我的角度来看,这是不可接受的。我试图分析我的应用程序,热路径在本地代码库(大部分与ConcRT相关)。 WinRT包装被编译为“发布”,我不明白为什么性能如此糟糕。

目标:我想要读取所有行并将它们存储在一个对象中,以便绑定到我的视图,搜索等等。

任何想法,我可以做些什么来使我的数据库查询有点可以接受(< 5秒)?

+0

'SELECT COUNT(0)Location'? – spender

+0

@spender SELECT COUNT(0)FROM Locations; - > 4000 – Jasper

+0

我认为spender意味着使用'SELECT COUNT(0)FROM Location'并获取该查询的返回值,而不是查询表中的所有内容,然后只计算返回的行。 – Tory

回答

0

我不知道你的代码有什么问题。 您也可以尝试使用另一个包装器,例如c#-sqlite + sqlite-net ORM。 https://github.com/peterhuene/sqlite-net-wp8我已经将它用于我的项目,并且性能非常好。