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

SQLite: Revert multi-threading change #25541

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Data.Sqlite.Properties;
Expand Down Expand Up @@ -470,15 +471,19 @@ private IEnumerable<sqlite3_stmt> PrepareAndEnumerateStatements(Stopwatch timer)
{
DisposePreparedStatements(disposing: false);

var byteCount = Encoding.UTF8.GetByteCount(_commandText);
var sql = new byte[byteCount + 1];
Encoding.UTF8.GetBytes(_commandText, 0, _commandText.Length, sql, 0);

int rc;
sqlite3_stmt stmt;
var tail = _commandText;
var start = 0;
do
{
timer.Start();

string nextTail;
while (IsBusy(rc = sqlite3_prepare_v2(_connection!.Handle, tail, out stmt, out nextTail)))
ReadOnlySpan<byte> tail;
while (IsBusy(rc = sqlite3_prepare_v2(_connection!.Handle, sql.AsSpan(start), out stmt, out tail)))
{
if (CommandTimeout != 0
&& timer.ElapsedMilliseconds >= CommandTimeout * 1000L)
Expand All @@ -490,14 +495,14 @@ private IEnumerable<sqlite3_stmt> PrepareAndEnumerateStatements(Stopwatch timer)
}

timer.Stop();
tail = nextTail;
start = sql.Length - tail.Length;

SqliteException.ThrowExceptionForRC(rc, _connection.Handle);

// Statement was empty, white space, or a comment
if (stmt.IsInvalid)
{
if (tail.Length != 0)
if (start < byteCount)
{
continue;
}
Expand All @@ -509,7 +514,7 @@ private IEnumerable<sqlite3_stmt> PrepareAndEnumerateStatements(Stopwatch timer)

yield return stmt;
}
while (tail.Length != 0);
while (start < byteCount);

_prepared = true;
}
Expand Down
5 changes: 0 additions & 5 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnectionInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public SqliteConnectionInternal(SqliteConnectionStringBuilder connectionOptions,
var filename = connectionOptions.DataSource;
var flags = 0;

if (sqlite3_threadsafe() != 0)
{
flags |= SQLITE_OPEN_NOMUTEX;
}

if (filename.StartsWith("file:", StringComparison.OrdinalIgnoreCase))
{
flags |= SQLITE_OPEN_URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private enum Keywords
private bool? _foreignKeys;
private bool _recursiveTriggers;
private int _defaultTimeout = 30;
private bool _pooling;
private bool _pooling = true;

static SqliteConnectionStringBuilder()
{
Expand Down Expand Up @@ -462,7 +462,7 @@ private void Reset(Keywords index)
return;

case Keywords.Pooling:
_pooling = false;
_pooling = true;
Copy link
Contributor Author

@bricelam bricelam Aug 16, 2021

Choose a reason for hiding this comment

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

I'd like to try this in RC1 to get feedback on the feature. If there are any significant drawbacks, we can revert to false before GA.

return;

default:
Expand Down