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?
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.
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.
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.
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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With