-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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.Core issue with multiple Blob colums #32770
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,30 @@ | |
|
||
namespace Microsoft.Data.Sqlite | ||
{ | ||
|
||
internal class SqliteDataRecord : SqliteValueReader, IDisposable | ||
{ | ||
internal class RowIdInfo | ||
{ | ||
public int Ordinal { get; set; } | ||
public string TableName { get; set; } | ||
|
||
public RowIdInfo(int ordinal, string tableName) | ||
{ | ||
Ordinal = ordinal; | ||
TableName = tableName; | ||
} | ||
} | ||
|
||
private readonly SqliteConnection _connection; | ||
private readonly Action<int> _addChanges; | ||
private byte[][]? _blobCache; | ||
private int?[]? _typeCache; | ||
private Dictionary<string, int>? _columnNameOrdinalCache; | ||
private string[]? _columnNameCache; | ||
private bool _stepped; | ||
private int? _rowidOrdinal; | ||
readonly Dictionary<string, RowIdInfo> RowIds = new Dictionary<string, RowIdInfo>(); | ||
|
||
private bool _alreadyThrown; | ||
private bool _alreadyAddedChanges; | ||
|
||
|
@@ -310,11 +324,11 @@ public virtual Stream GetStream(int ordinal) | |
var blobDatabaseName = sqlite3_column_database_name(Handle, ordinal).utf8_to_string(); | ||
var blobTableName = sqlite3_column_table_name(Handle, ordinal).utf8_to_string(); | ||
|
||
if (!_rowidOrdinal.HasValue) | ||
RowIdInfo? rowIdForOrdinal = null; | ||
string rowidkey = $"{blobDatabaseName}_{blobTableName}"; | ||
if (!RowIds.TryGetValue(rowidkey, out rowIdForOrdinal)) | ||
{ | ||
_rowidOrdinal = -1; | ||
var pkColumns = -1L; | ||
|
||
for (var i = 0; i < FieldCount; i++) | ||
{ | ||
if (i == ordinal) | ||
|
@@ -337,7 +351,8 @@ public virtual Stream GetStream(int ordinal) | |
var columnName = sqlite3_column_origin_name(Handle, i).utf8_to_string(); | ||
if (columnName == "rowid") | ||
{ | ||
_rowidOrdinal = i; | ||
rowIdForOrdinal = new RowIdInfo(i, tableName); | ||
RowIds.Add(rowidkey, rowIdForOrdinal); | ||
break; | ||
} | ||
|
||
|
@@ -368,22 +383,23 @@ public virtual Stream GetStream(int ordinal) | |
|
||
if (pkColumns == 1L) | ||
{ | ||
_rowidOrdinal = i; | ||
rowIdForOrdinal = new RowIdInfo(i, tableName); | ||
RowIds.Add(rowidkey, rowIdForOrdinal); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
Debug.Assert(_rowidOrdinal.HasValue); | ||
//Debug.Assert(rowIdForOrdinal!=null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-add Assert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Puppy error, sorry. Commented for initial checks and later committed. Not intentional. Sorry again! |
||
} | ||
|
||
if (_rowidOrdinal.Value < 0) | ||
if (rowIdForOrdinal == null) | ||
{ | ||
return new MemoryStream(GetCachedBlob(ordinal), false); | ||
} | ||
|
||
var blobColumnName = sqlite3_column_origin_name(Handle, ordinal).utf8_to_string(); | ||
var rowid = GetInt64(_rowidOrdinal.Value); | ||
var rowid = GetInt64(rowIdForOrdinal.Ordinal); | ||
|
||
return new SqliteBlob(_connection, blobDatabaseName, blobTableName, blobColumnName, rowid, readOnly: true); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use a value tuple for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was only for readability