Update SQLite.cs "not an error" bug #81
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When SQLite3.Step() returns an error, the error message is retrieved using SQLite3.GetErrmsg() after Finalize() or
Reset() is called. However, these cleanup functions clear SQLite's error state, causing GetErrmsg() to return "not an
error" instead of the actual error message.
Related issue: praeclarum/sqlite-net#1041
Fix 1: SQLiteCommand.ExecuteNonQuery()
Before (line ~3066):
public int ExecuteNonQuery ()
{
if (_conn.Trace) {
_conn.Tracer?.Invoke ("Executing: " + this);
}
}
After:
public int ExecuteNonQuery ()
{
if (_conn.Trace) {
_conn.Tracer?.Invoke ("Executing: " + this);
}
}
Fix 2: PreparedSqlLiteInsertCommand.ExecuteNonQuery()
Before (line ~3740):
public int ExecuteNonQuery (object[] source)
{
if (Initialized && Statement == NullStatement) {
throw new ObjectDisposedException (nameof (PreparedSqlLiteInsertCommand));
}
Connection.DateTimeStringFormat, Connection.StoreTimeSpanAsTicks);
}
}
r = SQLite3.Step (Statement);
SQLite3.ExtendedResult.ConstraintNotNull) {
SQLite3.Reset (Statement); // ← Reset BEFORE GetErrmsg
throw NotNullConstraintViolationException.New (r, SQLite3.GetErrmsg (Connection.Handle)); // ← Too late!
}
else {
SQLite3.Reset (Statement); // ← Reset BEFORE GetErrmsg
throw SQLiteException.New (r, SQLite3.GetErrmsg (Connection.Handle)); // ← Too late!
}
}
After:
public int ExecuteNonQuery (object[] source)
{
if (Initialized && Statement == NullStatement) {
throw new ObjectDisposedException (nameof (PreparedSqlLiteInsertCommand));
}
Connection.DateTimeStringFormat, Connection.StoreTimeSpanAsTicks);
}
}
}
Notes