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

Microsoft.Data.Sqlite: Add deferred transactions #21212

Merged
2 commits merged into from
Aug 11, 2020

Conversation

AlexanderTaeschner
Copy link
Contributor

Adds BeginTransaction(bool deferred) to SqliteConnection.

Fixes #20786

Copy link
Contributor

@bricelam bricelam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs Outdated Show resolved Hide resolved
src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs Outdated Show resolved Hide resolved
@bricelam bricelam self-assigned this Jun 12, 2020
@bricelam
Copy link
Contributor

bricelam commented Jun 15, 2020

Hmm, test fails on SQLCipher with no such table: Data during connection1.ExecuteScalar

@AlexanderTaeschner
Copy link
Contributor Author

On my local build the test works fine for e_sqlcipher, so I'm not sure how to fix it.

@bricelam
Copy link
Contributor

It looks like it passed several times on the CI as well. I'll investigate

@microsoft-github-updates microsoft-github-updates bot changed the base branch from master to main July 23, 2020 04:35
@bricelam
Copy link
Contributor

(Rebased and squashed on top of main)

@bricelam
Copy link
Contributor

bricelam commented Aug 11, 2020

If it passes this time, I'm inclined to just merge this and deal with the test when/if it becomes flakey again.

@ghost
Copy link

ghost commented Aug 11, 2020

Hello @bricelam!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 9f9e239 into dotnet:main Aug 11, 2020
@bricelam
Copy link
Contributor

😒 The flakey test failed on winsqlite3 this time. I'm going to experiment a bit in #22129

@p-m-j
Copy link

p-m-j commented Mar 21, 2022

Would this not make more sense as the default behaviour? If it were it would then align more with the SQLite documentation.

https://www.sqlite.org/lang_transaction.html
2.2. DEFERRED, IMMEDIATE, and EXCLUSIVE transactions
Transactions can be DEFERRED, IMMEDIATE, or EXCLUSIVE. The default transaction behavior is DEFERRED.

https://www.sqlite.org/sharedcache.html#table_level_locking
2.1. Transaction Level Locking
SQLite connections can open two kinds of transactions, read and write transactions. This is not done explicitly, a transaction is implicitly a read-transaction until it first writes to a database table, at which point it becomes a write-transaction.

If this changed in a future version it might make more sense if the paramater naming was also inversed so bool deferred -> bool immediate

@bricelam
Copy link
Contributor

@p-m-j see my previous comments on the subject:

We tried to switch to deferred transactions by default in version 2.0, but several users started seeing deadlocks in their apps (aspnet/Microsoft.Data.Sqlite#474).

@p-m-j
Copy link

p-m-j commented Mar 22, 2022

@bricelam i guess someone will be upset no matter which default you choose.

How about a connection string flag to toggle the default behaviour?

@bricelam
Copy link
Contributor

Hmm... File an issue so we can discuss it as a team. I'm personally against it since you'd have to be very aware of the implications for every line of SQL you write, and any time you introduce concurrency in your app. Having to set it manually every time reminds you to think about everything that might go wrong. In other words, I think the connection string keyword would harm more people than it helped.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft.Data.Sqlite: Support deferred transactions
3 participants