Skip to content

Commit

Permalink
Microsoft.Data.Sqlite: Revert to using string overload of sqlite3_pre…
Browse files Browse the repository at this point in the history
…pare (#25510)

This reverts commit 063a2bd.
  • Loading branch information
bricelam authored Aug 13, 2021
1 parent eb9a2b8 commit 5d9ae8d
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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 @@ -471,19 +470,15 @@ 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 start = 0;
var tail = _commandText;
do
{
timer.Start();

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

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

SqliteException.ThrowExceptionForRC(rc, _connection.Handle);

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

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

_prepared = true;
}
Expand Down

0 comments on commit 5d9ae8d

Please sign in to comment.