Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pragma Settings for SQLite #5024

Closed
shlatchz opened this issue Apr 9, 2016 · 10 comments
Closed

Pragma Settings for SQLite #5024

shlatchz opened this issue Apr 9, 2016 · 10 comments
Assignees

Comments

@shlatchz
Copy link

shlatchz commented Apr 9, 2016

The following code

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    var connectionStringBuilder = new SqliteConnectionStringBuilder() { DataSource = Constants.DataDBPath  };
    var connectionString = connectionStringBuilder.ToString();
    var connection = new SQLiteConnection() { ConnectionString = connectionString };
    optionsBuilder.UseSqlite(connection);
}

cannot receive pragma settings such as journalmode or syncmode.
How can I apply the pragma settings to the db?

I tried:

using (var context = new DataDBContext())
{
    var connection = context.Database.GetDbConnection();
    connection.Open();
    var command = connection.CreateCommand();
    command.CommandText = "PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF; PRAGMA count_changes=OFF; PRAGMA temp_store=OFF; PRAGMA page_size=65536; PRAGMA cache_size=-16777216;";
    command.ExecuteNonQuery();
}

but it didn't help.

@ErikEJ
Copy link
Contributor

ErikEJ commented Apr 10, 2016

You need to do it in the same context as where you are doing the EF data access

@shlatchz
Copy link
Author

Can you please elaborate?
Are you saying that I have to do it each time I modify the DB?

@rowanmiller
Copy link
Contributor

@natemcmaster can you confirm?

@rowanmiller
Copy link
Contributor

@natemcmaster ping 😄

@rowanmiller rowanmiller modified the milestones: 1.0.1, 1.0.0 May 11, 2016
@natemcmaster
Copy link
Contributor

@shlatchz if you want to issue custom pragma statements, you need to do this every time you open a connection. Changing values via pragma statements do not persist across calls to sqlite_open_v2. At the moment, we don't have API in Microsoft.Data.Sqlite.SqlConnection to support executing something arbitrary (such as issuing pragma statements) everytime a connection opens.

Moving up a layer in the stack. EntityFramework Core has a class that wraps SqliteConnection. This wrapper handles opening/closing SqliteConnection and has its own logic for issuing pragma statements when connections open. See Microsoft.EntityFrameworkCore.Storage.Internal.SqliteRelationalConnection. EF lets you pass an connection object instead of a connection string if you want to manage the lifecycle of opening/closing a connection yourself. UseSqlite(DbConnection connection).

@natemcmaster natemcmaster removed this from the 1.0.1 milestone May 11, 2016
@natemcmaster
Copy link
Contributor

Remarking for triage: what is the work here? Add API to Microsoft.Data.Sqlite or EF?

@natemcmaster natemcmaster removed the pri0 label May 11, 2016
@rowanmiller
Copy link
Contributor

@natemcmaster this is mostly to investigate and work out what we should do. It seems like we may want a way to easily configure pragma settings when you setup the context to target SQLite. Or it may be a more general "connection preamble" feature. It's in the 1.0.1 milestone to look at post-RTM though

@rowanmiller rowanmiller added this to the 1.0.1 milestone May 12, 2016
@natemcmaster
Copy link
Contributor

I have this given this some consideration and prototyped some designs today. My current thinking leads me to believe we should consider this a duplicate of the lifecycle hooks feature (#626). Most designs I came up with end up working essentially like a general connection preamble feature. This general feature has bigger implications than just SQLite pragmas, so we should probably gather for some design work on this first.

@rowanmiller
Copy link
Contributor

Closing this issue as the idea of connection preamble is being tracked as part of the bigger Lifecycle Hooks feature (#626).

@rowanmiller
Copy link
Contributor

BTW just to make it explicit - we are not closing this because we aren't planning to implement it. We very much agree this is super useful, it's just already tracked as part of #626.

gfs added a commit to microsoft/AttackSurfaceAnalyzer that referenced this issue Mar 11, 2020
Fix pragmas to apply everytime a connection is opened per dotnet/efcore#5024
gfs added a commit to microsoft/AttackSurfaceAnalyzer that referenced this issue Mar 30, 2020
* Fix first run bug.

* Remove unneeded .ToArray()

* Delete SqliteFilename

* Fix Roslyn Warnings

* Update DatabaseManager.cs

* Update InsertTestsWithIntermittentTransactions.cs

* Allow journal mode configuration

Fix pragmas to apply everytime a connection is opened per dotnet/efcore#5024

* Use a settings object for passing database settings.

Add a few more settings (pragma passthroughs).

* Add CommitTests

* Rename files.

* Move/Rename files.

Adds Query Tests

* Update QueryTests.cs

Documentation

* Make Synchronous a string so the values are more obvious

* Code Cleanup

* Add LiteDbManager placeholder.

* Add prelim litedb support (for benchmarking).

* Progress towards LiteDb Benchmark

* Small fixes

* Update LiteDbManager.cs

* Add System.Data.Sqlite implementation of DB manager

* Add nullable checks.

* Nullable fixes

* More nullable fixes

* Nullable Fixes pt. 1

Mostly finished with lib.

* Finish nullable work in lib

Aside from the experimental litedb work.

* More nullable fixes.

* More nullable work.

Re-adds SystemSQLite support.

* Fixes for SystemSQLite support

* Finish nullable work

* clean up GetCollectModified

* Add LiteDb Query Tests

* Move System.Data.SQLite and LiteDB code into the benchmarks

Removes those dependencies from the main library and cli.

* Fix null reference exceptions

* Remove old default arguments

We now use null

* Add a GetAllMissing function

* Update BaseCompare to use GetAllMissing

* Fix constructors so Objects are properly deserializable.

* Add new GetAllMissing2 function

This is a hybrid between the two approaches.

* Adds crypto tests

* Pull get missing query out out function

* Update FileSystemCollector.cs

* Update csproj files to improve assembly names

* Update csproj and pipelines

* Fix pipelines

* Rename tests file.

* Update to use SHA512

* Nullable work.

* Fix build.

* Help the pipeline find the tests properly

* Update Strings.cs

* Update Strings.cs

* Update AsaLibTests.cs

* Update pr-validation.yml

Now properly fail when tests fail but still report test results.

* Add BatchSize for writenext

* Update SqlConnectionHolder.cs

* Update SqlConnectionHolder.cs

* Update batching

* fix race condition

* Update InsertTestsWithoutTransactions.cs

* Fix batch size default and max batch size.

* Fix comobjectcollector

* Fix registry collector.

* Centralize code for translating sid to names

Only attempt to do so when it could possibly succeed, this reduces number of exceptions dramatically.

* Update AsaLibTests.cs

* Update AsaLibTests.cs

* Fix registry objects to distinguish which view they were gathered from.

* Gather Com Objects in Both Views
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
@ajcvickers ajcvickers removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-unknown labels Oct 18, 2022
@ajcvickers ajcvickers removed this from the 1.1.0 milestone Oct 18, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants