Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 725
MaYaN Avatar asked Jul 21 '14 14:07

MaYaN


People also ask

What does Pragma do in SQLite?

SQLite PRAGMA command is a special command to be used to control various environmental variables and state flags within the SQLite environment. A PRAGMA value can be read and it can also be set based on the requirements.

What is Pragma Integrity_check?

PRAGMA integrity_check behaves like a SELECT query that returns results in a single row. To read the results with sqlite3_exec , you need to use a callback. Please note that PRAGMA integrity_check is not guaranteed to find all errors, so you can use it only to check for broken databases, not for healthy databases.

What is Pragma table info?

The table_info pragma is used to query information about a specific table. The result set will contain one row for each column in the table.

What is Pragma command?

The pragma command is specific to SQLite and is not compatible with any other SQL database engine. Specific pragma statements may be removed and others added in future releases of SQLite. There is no guarantee of backwards compatibility. No error messages are generated if an unknown pragma is issued.


1 Answers

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");
like image 192
mythz Avatar answered Sep 22 '22 14:09

mythz