Page 1 of 1
Howto read PRAGMA user_version?
Posted: Wed 02 Dec 2015 05:35
by bairog
Hello.
Are there any classes for reading PRAGMA database properties while using Entity Framework Code-First approach (I'm especially interested in
user_version)?
And howto read user_version of a given SQLite database file (for example \\NETWORK SHARE\test.db) in situation when I don't use DbContext?
Thank you.
Re: Howto read PRAGMA user_version?
Posted: Thu 03 Dec 2015 08:59
by Shalex
There are no Entity Framework specific classes for working with user_version pragma. Either create a new ADO.NET connection or access an existing one within a context (var connection = ((IObjectContextAdapter)myDbContext).ObjectContext.Connection;) and execute PRAGMA statements via SQLiteCommand.
Re: Howto read PRAGMA user_version?
Posted: Tue 13 Jun 2017 13:19
by bairog
Hello again.
I use the following code to read
user_version:
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreQuery<long>("PRAGMA user_version").FirstOrDefault()
and following code to change
user_version:
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreCommand("PRAGMA user_version=XX")
It works perfect for one database.
But when I use one main database and several attached (with different
user_version value) - how can I read them all (using
.ToList() instead of
.FirstOrDefault() returns list with only one element for me)?
And change each one separately?
Thank you in advance.
Re: Howto read PRAGMA user_version?
Posted: Fri 16 Jun 2017 17:44
by Shalex
Here is an SQLite documenation:
https://sqlite.org/pragma.html#pragma_user_version.
Please specify the exact PRAGMA command you are using to return a result set of user_version values for all (main and attached) databases.
Re: Howto read PRAGMA user_version?
Posted: Mon 19 Jun 2017 12:38
by bairog
Thank you.
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreQuery<long>("PRAGMA main.user_version").FirstOrDefault();
and
Code: Select all
((IObjectContextAdapter)myDbContext).ObjectContext.ExecuteStoreQuery<long>("PRAGMA AttachedDatabaseName1.user_version").FirstOrDefault();
works perfectly.