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

1

6

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?

Indulgent answered 21/7, 2014 at 14:36 Comment(0)
K
7

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");
Keloid answered 21/7, 2014 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.