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

Commit bdd204b

Browse files
committed
Make a few tests work on Oracle
1 parent a06a4fa commit bdd204b

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

tests/ServiceStack.OrmLite.Tests/EnumTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void CanQueryByEnumValue_using_select_with_string()
6969
db.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
7070

7171
var target = db.Select<TypeWithEnum>(
72-
"EnumValue".SqlColumn() + " = @value", new { value = SomeEnum.Value1 });
72+
"EnumValue".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = SomeEnum.Value1 });
7373

7474
Assert.AreEqual(2, target.Count());
7575
}
@@ -252,7 +252,7 @@ public void CanQueryByEnumValue_using_select_with_string_enum_flags()
252252
db.Save(new TypeWithFlagsEnum { Id = 3, Flags = FlagsEnum.FlagTwo });
253253

254254
var target = db.Select<TypeWithFlagsEnum>(
255-
"Flags".SqlColumn() + " = @value", new { value = FlagsEnum.FlagOne });
255+
"Flags".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = FlagsEnum.FlagOne });
256256
db.GetLastSql().Print();
257257
Assert.That(target.Count, Is.EqualTo(2));
258258
}
@@ -269,7 +269,7 @@ public void CanQueryByEnumValue_using_select_with_string_EnumAsInt()
269269
db.Save(new TypeWithEnumAsInt { Id = 3, EnumValue = SomeEnumAsInt.Value2 });
270270

271271
var target = db.Select<TypeWithEnumAsInt>(
272-
"EnumValue".SqlColumn() + " = @value", new { value = SomeEnumAsInt.Value1 });
272+
"EnumValue".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = SomeEnumAsInt.Value1 });
273273
db.GetLastSql().Print();
274274
Assert.That(target.Count, Is.EqualTo(2));
275275
}
@@ -336,7 +336,7 @@ public void Can_save_Enum_as_Integers()
336336
db.Insert(new TypeWithTreatEnumAsInt { Id = 2, EnumValue = SomeEnumTreatAsInt.Value2 });
337337

338338
var row = db.Single<TypeWithTreatEnumAsInt>(
339-
"EnumValue".SqlColumn() + " = @value", new { value = "2" });
339+
"EnumValue".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = "2" });
340340

341341
Assert.That(row.Id, Is.EqualTo(2));
342342
}

tests/ServiceStack.OrmLite.Tests/Expression/SqlExpressionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ public void Can_select_RowCount_with_db_params()
421421

422422
var table = typeof(LetterFrequency).Name.SqlTable();
423423

424-
rowCount = db.RowCount("SELECT * FROM {0} WHERE Letter = @p1".Fmt(table), new { p1 = "B" });
424+
rowCount = db.RowCount("SELECT * FROM {0} WHERE Letter = @p1".PreNormalizeSql(db).Fmt(table), new { p1 = "B" });
425425
Assert.That(rowCount, Is.EqualTo(4));
426426

427-
rowCount = db.RowCount("SELECT * FROM {0} WHERE Letter = @p1".Fmt(table),
427+
rowCount = db.RowCount("SELECT * FROM {0} WHERE Letter = @p1".PreNormalizeSql(db).Fmt(table),
428428
new[] { db.CreateParam("p1", "B") });
429429
Assert.That(rowCount, Is.EqualTo(4));
430430
}

tests/ServiceStack.OrmLite.Tests/ShippersExample.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ public void Shippers_UseCase()
9797
var trainsAreUs = db.Single<Shipper>(q => q.ShipperTypeId == trainsType.Id);
9898
Assert.That(trainsAreUs.CompanyName, Is.EqualTo("Trains R Us"));
9999

100-
trainsAreUs = db.Single<Shipper>("ShipperTypeId".SqlColumn() + " = @Id", new { trainsType.Id });
100+
trainsAreUs = db.Single<Shipper>("ShipperTypeId".SqlColumn() + " = @Id".PreNormalizeSql(db), new { trainsType.Id });
101101
Assert.That(trainsAreUs.CompanyName, Is.EqualTo("Trains R Us"));
102102

103103

104104
Assert.That(db.Select<Shipper>(q => q.CompanyName == "Trains R Us" || q.Phone == "555-UNICORNS"), Has.Count.EqualTo(2));
105-
Assert.That(db.Select<Shipper>("CompanyName".SqlColumn() + " = @company OR Phone = @phone",
105+
Assert.That(db.Select<Shipper>("CompanyName".SqlColumn() + " = @company OR Phone = @phone".PreNormalizeSql(db),
106106
new { company = "Trains R Us", phone = "555-UNICORNS" }), Has.Count.EqualTo(2));
107107

108108
Assert.That(db.Select<Shipper>(q => q.ShipperTypeId == planesType.Id), Has.Count.EqualTo(2));
109-
Assert.That(db.Select<Shipper>("ShipperTypeId".SqlColumn() + " = @Id", new { planesType.Id }), Has.Count.EqualTo(2));
109+
Assert.That(db.Select<Shipper>("ShipperTypeId".SqlColumn() + " = @Id".PreNormalizeSql(db), new { planesType.Id }), Has.Count.EqualTo(2));
110110

111111
//Lets update a record
112112
trainsAreUs.Phone = "666-TRAINS";
@@ -126,7 +126,7 @@ public void Shippers_UseCase()
126126
var partialColumns = db.Select<SubsetOfShipper>(db.From<Shipper>().Where(q => q.ShipperTypeId == planesType.Id));
127127
Assert.That(partialColumns, Has.Count.EqualTo(2));
128128

129-
partialColumns = db.Select<SubsetOfShipper>(typeof(Shipper), "ShipperTypeId".SqlColumn() + " = @Id", new { planesType.Id });
129+
partialColumns = db.Select<SubsetOfShipper>(typeof(Shipper), "ShipperTypeId".SqlColumn() + " = @Id".PreNormalizeSql(db), new { planesType.Id });
130130
Assert.That(partialColumns, Has.Count.EqualTo(2));
131131

132132
//Select into another POCO class that matches sql

tests/ServiceStack.OrmLite.Tests/TestHelpers.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Data;
2+
13
namespace ServiceStack.OrmLite.Tests
24
{
35
public enum Dialect
@@ -25,5 +27,13 @@ public static string NormalizeSql(this string sql)
2527
.Replace("\n", " ")
2628
.TrimEnd();
2729
}
30+
31+
public static string PreNormalizeSql(this string sql, IDbConnection db)
32+
{
33+
var paramString = db.GetDialectProvider().ParamString;
34+
if (paramString.Equals("@"))
35+
return sql;
36+
return sql.Replace("@", paramString);
37+
}
2838
}
2939
}

tests/ServiceStack.OrmLite.Tests/UseCase/SimpleUseCase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void Simple_CRUD_example()
2929
db.Insert(new User { Id = 2, Name = "B", CreatedDate = DateTime.Now });
3030
db.Insert(new User { Id = 3, Name = "B", CreatedDate = DateTime.Now });
3131

32-
var rowsB = db.Select<User>("Name = @name", new { name = "B" });
32+
var rowsB = db.Select<User>("Name = @name".PreNormalizeSql(db), new { name = "B" });
3333

3434
Assert.That(rowsB, Has.Count.EqualTo(2));
3535

@@ -38,7 +38,7 @@ public void Simple_CRUD_example()
3838

3939
rowsB.ForEach(x => db.Delete(x));
4040

41-
rowsB = db.Select<User>("Name = @name", new { name = "B" });
41+
rowsB = db.Select<User>("Name = @name".PreNormalizeSql(db), new { name = "B" });
4242
Assert.That(rowsB, Has.Count.EqualTo(0));
4343

4444
var rowsLeft = db.Select<User>();

0 commit comments

Comments
 (0)