0

Running C#, .NET 4.5 - I am attempting to write a byte[] to an Oracle 11g database using the devart driver for Oracle (NuGet pkg: dotConnect.Express.for.Oracle, version: 8.4.201).

In a special case, I am experiencing that my buffer offset is ignored and I am a bit unsure if I am missing something really obvious or if I have found a bug in the driver. The case goes as follows:

DDL:

CREATE TABLE MYTABLE (MYID NUMBER(12), MYDATA BLOB);

My NUnit test looks as follows:

[Test]
public void BlobQuestionTest()
{
    var buffer = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQ");
    // Insert record with empty blob
    using (var con = new OracleConnection(Config.ConnectionString))
    {
        con.Open();
        const string sql = "INSERT INTO MYTABLE (MYID, MYDATA) VALUES (:MyId, :MyData)";
        var cmd = new OracleCommand(sql, con);
        cmd.Parameters.Add("MyId", 42);
        var lob = new OracleLob(con, OracleDbType.Blob);
        cmd.Parameters.Add("MyData", lob);
        var affectedRows = cmd.ExecuteNonQuery();
        Assert.AreEqual(1, affectedRows); // Passes
        con.Commit();
    }
    // Later on, lock the row and update the record with the blob data
    using (var con = new OracleConnection(Config.ConnectionString))
    {
        con.Open();
        const string sql = "SELECT MYDATA FROM MYTABLE WHERE MYID = :MyId FOR UPDATE";
        var cmd = new OracleCommand(sql, con);
        cmd.Parameters.Add("MyId", 42);
        var reader = cmd.ExecuteReader();
        reader.Read();
        var lob = reader.GetOracleLob(0);
        Assert.AreEqual(0, lob.Length); // Passes
        lob.Write(buffer, offset: 4, count: 4);
        var actual = Encoding.UTF8.GetString((byte[])lob.Value, index: 0, count: 4);
        Assert.AreEqual("EFGH", actual); // <--- Fails (actual: ABCD) - why??
        con.Commit();
    }
}

As you can see from the comments, the last Assert fails because the offset of 4 appears to have been ignored but I have no idea why?

I have tracked down that if I change my insert statement to: INSERT INTO MYTABLE (MYID) VALUES (:MyId) and don't add the empty blob as parameter to the INSERT statement, then the offset is respected when I write to the blob stream, and the assert Assert.AreEqual("EFGH", actual); passes.

So yeah, I have tried searching for a good explanation on this, but as far as I can tell, the devart documentation does not cover this.

Lasse Christiansen
  • 10,205
  • 7
  • 50
  • 79

1 Answers1

0

We have fixed the bug with ignoring the offset parameter of the OracleLob.Write method in the OCI mode. We will post here when the corresponding build of dotConnect for Oracle is available for download.

UPDATE:

New build of dotConnect for Oracle 8.4.215 is available for download! It can be downloaded from http://www.devart.com/dotconnect/oracle/download.html (trial version) or from Registered Users' Area (for users with valid subscription only). For more information, please refer to http://forums.devart.com/viewtopic.php?t=30078

The new nuget package for dotConnect Express for Oracle 8.4.215 is also released. https://www.nuget.org/packages/dotConnect.Express.for.Oracle/8.4.215

Devart
  • 119,203
  • 23
  • 166
  • 186