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

fix: #27138, stream with 64-bit PK #27187

Merged
2 commits merged into from
Jan 14, 2022
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
2 changes: 1 addition & 1 deletion src/Microsoft.Data.Sqlite.Core/SqliteDataRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public virtual Stream GetStream(int ordinal)
}

var blobColumnName = sqlite3_column_origin_name(Handle, ordinal).utf8_to_string();
var rowid = GetInt32(_rowidOrdinal.Value);
var rowid = GetInt64(_rowidOrdinal.Value);

return new SqliteBlob(_connection, blobDatabaseName, blobTableName, blobColumnName, rowid, readOnly: true);
}
Expand Down
28 changes: 28 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteDataReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,34 @@ public void GetStream_Blob_works(string createTableCmd, string selectCmd)
}
}

[Fact]
public void GetStream_Blob_works_when_long_pk()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();

connection.ExecuteNonQuery(
"CREATE TABLE DataTable (Id INTEGER PRIMARY KEY, Data BLOB);" +
$"INSERT INTO DataTable VALUES (2147483648, X'01020304');");

var selectCommand = connection.CreateCommand();
selectCommand.CommandText = $"SELECT Id, Data FROM DataTable WHERE Id = 2147483648";
using (var reader = selectCommand.ExecuteReader())
{
Assert.True(reader.Read());
using (var sourceStream = reader.GetStream(1))
{
Assert.IsType<SqliteBlob>(sourceStream);
var buffer = new byte[4];
var bytesRead = sourceStream.Read(buffer, 0, 4);
Assert.Equal(4, bytesRead);
Assert.Equal(new byte[] { 0x01, 0x02, 0x03, 0x04 }, buffer);
}
}
}
}

[Fact]
public void GetStream_works_when_composite_pk()
{
Expand Down