How can I read PRAGMA from SQLite using ServiceStack OrmLite?

I am writing a custom PRAGMA in my SQL db file using the code below:

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

Which successfully writes PRAGMA to a file, and I can verify that using SQLite Expert or LINQPad it does:

 PRAGMA user_version 

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

I tried the following, but it couldnโ€™t parse SQL because it could not find "FROM":

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

I also tried the following: none of them work:

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

Any ideas?

+6
source share
1 answer

db.Select<T> is for getting a list of strings.

db.Single<T> - extract one line, while

db.Scalar<T> - get one column value.

So, to get a single integer value, you can use:

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

Source: https://habr.com/ru/post/972588/


All Articles