Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 883f252

Browse files
committed
Make updating blobs work for Oracle and SQLite.
Updating blobs was failing because the data was written converted to a base64 string and read as binary.
1 parent dc659ba commit 883f252

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/ServiceStack.OrmLite.Oracle/OracleOrmLiteDialectProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ public override string GetQuotedValue(object value, Type fieldType)
278278
: enumValue;
279279
}
280280

281+
if (fieldType == typeof(byte[]))
282+
{
283+
return "hextoraw('" + BitConverter.ToString((byte[])value).Replace("-", "") + "')";
284+
}
285+
281286
return base.GetQuotedValue(value, fieldType);
282287
}
283288

src/ServiceStack.OrmLite.Sqlite/SqliteOrmLiteDialectProviderBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ public override string GetQuotedValue(object value, Type fieldType)
220220
return base.GetQuotedValue(dateTimeOffsetValue.ToString("o"), typeof (string));
221221
}
222222

223+
if (fieldType == typeof(byte[]))
224+
{
225+
return "x'" + BitConverter.ToString((byte[])value).Replace("-", "") + "'";
226+
}
227+
223228
return base.GetQuotedValue(value, fieldType);
224229
}
225230

tests/ServiceStack.OrmLite.Tests/OrmLiteUpdateTests.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using NUnit.Framework;
66
using ServiceStack.Common.Tests.Models;
7+
using ServiceStack.DataAnnotations;
78
using ServiceStack.OrmLite.Tests.Shared;
89
using ServiceStack.Text;
910

@@ -159,5 +160,49 @@ public void Can_UpdateOnly_multiple_columns()
159160
Assert.That(person.FirstName, Is.EqualTo("JJ"));
160161
Assert.That(person.Age, Is.EqualTo(12));
161162
}
163+
164+
[Test]
165+
public void Can_Update_Only_Blobs()
166+
{
167+
db.DropAndCreateTable<SomeBlobs>();
168+
169+
db.Insert(new SomeBlobs {FirstName = "Bro", LastName = "Last"});
170+
db.Insert(new SomeBlobs { FirstName = "Sis", LastName = "Last" });
171+
172+
var existing = db.Select<SomeBlobs>(p => p.FirstName == "Bro").First();
173+
174+
const string blob1String = "This is going into Blob1";
175+
var blob1Array = blob1String.ToArray();
176+
var blob1Bytes = blob1Array.Length * 2;
177+
existing.Blob1 = new byte[blob1Bytes];
178+
Buffer.BlockCopy(blob1Array, 0, existing.Blob1, 0, blob1Bytes);
179+
180+
const string blob2String = "And this is going into Blob2";
181+
var blob2Array = blob2String.ToArray();
182+
var blob2Bytes = blob2Array.Length * 2;
183+
existing.Blob2 = new byte[blob2Bytes];
184+
Buffer.BlockCopy(blob2Array, 0, existing.Blob2, 0, blob2Bytes);
185+
186+
db.UpdateOnly(existing, p => new {p.Blob1, p.Blob2, p.FirstName}, r => r.LastName == "Last" && r.FirstName == "Bro");
187+
188+
var verify = db.Select<SomeBlobs>(p => p.FirstName == "Bro").First();
189+
190+
var verifyBlob1 = new char[verify.Blob1.Length / 2];
191+
Buffer.BlockCopy(verify.Blob1, 0, verifyBlob1, 0, verify.Blob1.Length);
192+
193+
Assert.That(existing.Blob1, Is.EquivalentTo(verify.Blob1));
194+
Assert.That(existing.Blob2, Is.EquivalentTo(verify.Blob2));
195+
}
196+
}
197+
198+
[CompositeIndex("FirstName", "LastName")]
199+
public class SomeBlobs
200+
{
201+
[AutoIncrement]
202+
public int Id { get; set; }
203+
public string FirstName { get; set; }
204+
public string LastName { get; set; }
205+
public byte[] Blob1 { get; set; }
206+
public byte[] Blob2 { get; set; }
162207
}
163-
}
208+
}

0 commit comments

Comments
 (0)