如何通过SQLiteAsyncConnection执行原始SQLite查询

Che*_*eng 3 c# sqlite windows-8

我指的是http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspxhttp://wp.qmatteoq. COM /使用-sqlite的-在你的窗户-8 Metro风格的应用程序/

据我所知,sqlite-net对外键没有很好的支持.因此,我没有创建一个映射到表的类,而是使用以下方式创建表.

    public static readonly String PROFILE_TABLE_CREATE = "create table if not exists " 
            + PROFILE_TABLE_NAME + "(" 
            + COLUMN_PROFILE_ID + " integer primary key autoincrement, "
            + COLUMN_TIMESTAMP + " integer not null, "
            + COLUMN_PROFILE_NAME + " text not null, "
            + COLUMN_AGE + " integer not null, "
            + COLUMN_GENDER + " integer not null"
            + ");";

    private async void CreateDatabase()
    {
        SQLiteAsyncConnection conn = new SQLiteAsyncConnection(DATABASE_NAME);
        await conn.ExecuteAsync(PROFILE_TABLE_CREATE);
    }
Run Code Online (Sandbox Code Playgroud)

现在,我想执行查询.例如,特定表中有多少行?

我可以执行sqlite table windows 8 appQueryAsync中的读取列名称.但是,我没有要映射到表的类.

在Java中,我可以执行原始查询,如下所示:

    String sql =  "select count(*) from " + tableName + " where " + HistorySQLiteOpenHelper.COLUMN_FK_TIMESTAMP + " = " + profileTimestamp;
    Cursor cursor = database.rawQuery(sql, null);
Run Code Online (Sandbox Code Playgroud)

我怎么能在C#Windows Store App中这样做?

chu*_*e x 7

要获得单个值,如计数,您将使用ExecuteScalarAsync:

SQLiteAsyncConnection conn = new SQLiteAsyncConnection(DATABASE_NAME);
int profileCount = await conn.ExecuteScalarAsync<int>("select count(*) from " + PROFILE_TABLE);
Run Code Online (Sandbox Code Playgroud)