Search code examples
c#sqliteormlite-servicestack

How can I read the PRAGMA from SQLite using ServiceStack OrmLite?


I am writing a custom PRAGMA to my SQLite db file using the below code:

using (var db = GetNewConnection())
{
    var version = "1234";
    var query = string.Format("PRAGMA user_version={0}", version);

    db.ExecuteSql(query);
}

Which successfully writes the PRAGMA to the file and I can check that using SQLite Expert or LINQPad by executing:

PRAGMA user_version

But how can I read the value of PRAGMA from the DB file using OrmLite v3.9.71?

I have tried the below but it fails to parse the SQL as it can't find a "FROM":

db.Select<object>("PRAGMA user_version");

I have also tried the below, none of them work:

db.Select<dynamic>("PRAGMA user_version");
db.Select<string>("PRAGMA user_version");
db.Select<int>("PRAGMA user_version");

Any ideas?


Solution

  • db.Select<T> is for retrieving a List of rows.

    db.Single<T> is to retrieve a single row whilst

    db.Scalar<T> is to retrieve a single column value.

    So to retrieve a single integer value you can use:

    db.Scalar<int>("PRAGMA user_version");