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

Commit 169807a

Browse files
committed
Add new SqlServer2008Dialect.Provider for SQLServer 2008 specific behavior
1 parent b6ec56b commit 169807a

File tree

9 files changed

+65
-15
lines changed

9 files changed

+65
-15
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ServiceStack.OrmLite.SqlServer
6+
{
7+
public class SqlServer2008OrmLiteDialectProvider : SqlServerOrmLiteDialectProvider
8+
{
9+
public new static SqlServer2008OrmLiteDialectProvider Instance = new SqlServer2008OrmLiteDialectProvider();
10+
11+
public override string SqlConcat(IEnumerable<object> args)
12+
{
13+
var sb = new StringBuilder();
14+
foreach (var arg in args)
15+
{
16+
if (sb.Length > 0)
17+
sb.Append(" + ");
18+
19+
var argType = arg.GetType();
20+
if (argType.IsNumericType() || argType == typeof(bool) || argType == typeof(DateTime) || argType == typeof(TimeSpan))
21+
{
22+
sb.AppendFormat("'{0}'", arg);
23+
}
24+
else if (arg is string s && s.StartsWith("'") || arg is PartialSqlString p)
25+
{
26+
sb.Append(arg);
27+
}
28+
else
29+
{
30+
sb.Append($"CAST({arg} AS VARCHAR(MAX))");
31+
}
32+
}
33+
34+
return sb.ToString();
35+
}
36+
}
37+
}

src/ServiceStack.OrmLite.SqlServer/SqlServerDialect.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ public static class SqlServerDialect
77
public static IOrmLiteDialectProvider Provider => SqlServerOrmLiteDialectProvider.Instance;
88
}
99

10+
public static class SqlServer2008Dialect
11+
{
12+
public static IOrmLiteDialectProvider Provider => SqlServer2008OrmLiteDialectProvider.Instance;
13+
}
14+
1015
public static class SqlServer2012Dialect
1116
{
1217
public static IOrmLiteDialectProvider Provider => SqlServer2012OrmLiteDialectProvider.Instance;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void Can_select_limit_on_Table_with_References()
8383
if (Dialect == Dialect.MySql)
8484
return; //= This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
8585

86-
if (Dialect == Dialect.SqlServer)
86+
if ((Dialect & Dialect.AnySqlServer) == Dialect)
8787
return; // generates Windowing function "... WHERE CustomerId IN (SELECT * FROM ...)"
8888
// when should generate "... WHERE CustomerId IN (SELECT Id FROM ...)"
8989
// both on .NET and .NET Core
@@ -132,7 +132,7 @@ public async Task Can_select_limit_on_Table_with_References_Async()
132132
if (Dialect == Dialect.MySql)
133133
return; //= This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
134134

135-
if (Dialect == Dialect.SqlServer)
135+
if ((Dialect & Dialect.AnySqlServer) == Dialect)
136136
return; // generates Windowing function "... WHERE CustomerId IN (SELECT * FROM ...)"
137137
// when should generate "... WHERE CustomerId IN (SELECT Id FROM ...)"
138138
// both on .NET and .NET Core

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ public void Can_select_limit_on_Table_with_References()
612612
if (Dialect == Dialect.MySql) return;
613613

614614
//Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
615-
if (Dialect == Dialect.SqlServer) return;
615+
if ((Dialect & Dialect.AnySqlServer) == Dialect)
616+
return;
616617

617618
using (var db = OpenDbConnection())
618619
{

tests/ServiceStack.OrmLite.Tests/LoadReferencesJoinTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ public void Can_load_references_with_OrderBy_and_Paging()
712712
//This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
713713
if (Dialect == Dialect.MySql)
714714
return;
715-
if (Dialect == Dialect.SqlServer) //Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
715+
if ((Dialect & Dialect.AnySqlServer) == Dialect) //Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
716716
return;
717717

718718
db.DropTable<ParentSelf>();

tests/ServiceStack.OrmLite.Tests/MaxDataTypeTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ public class MaxDataTypeTests : OrmLiteTestBase
1111
public void Can_insert_and_select_max_values()
1212
{
1313
//OrmLiteConfig.ThrowOnError = true;
14+
var isSqlServer = (Dialect & Dialect.AnySqlServer) == Dialect;
1415

1516
var model = new ModelWithFieldsOfDifferentTypes
1617
{
1718
Int = int.MaxValue,
1819
Long = long.MaxValue,
1920
Double = double.MaxValue,
20-
Decimal = Dialect != Dialect.SqlServer && Dialect != Dialect.SqlServer2012 && Dialect != Dialect.Sqlite
21+
Decimal = !isSqlServer && Dialect != Dialect.Sqlite
2122
? Decimal.MaxValue
2223
: long.MaxValue,
2324
DateTime = Dialect != Dialect.MySql

tests/ServiceStack.OrmLite.Tests/OrmLiteSaveTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void Save_populates_AutoIncrementId()
3434
public void Can_disable_AutoIncrement_field()
3535
{
3636
//Can't insert in identity column
37-
if (Dialect == Dialect.SqlServer || Dialect == Dialect.SqlServer2012)
37+
if ((Dialect & Dialect.AnySqlServer) == Dialect)
3838
return;
3939

4040
using (var db = OpenDbConnection())

tests/ServiceStack.OrmLite.Tests/OrmLiteTestBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ private OrmLiteConnectionFactory Init()
135135
return dbFactory;
136136
case Dialect.SqlServer:
137137
return Init(Config.SqlServerBuildDb, SqlServerDialect.Provider);
138+
case Dialect.SqlServer2008:
139+
return Init(Config.SqlServerBuildDb, SqlServer2008Dialect.Provider);
138140
case Dialect.SqlServer2012:
139141
return Init(Config.SqlServerBuildDb, SqlServer2012Dialect.Provider);
140142
case Dialect.MySql:

tests/ServiceStack.OrmLite.Tests/TestHelpers.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Data;
34

45
namespace ServiceStack.OrmLite.Tests
56
{
7+
[Flags]
68
public enum Dialect
79
{
8-
Sqlite,
9-
SqlServer,
10-
SqlServer2012,
11-
PostgreSql,
12-
MySql,
13-
SqlServerMdf,
14-
Oracle,
15-
Firebird,
16-
VistaDb,
10+
Sqlite = 1,
11+
SqlServer = 2,
12+
SqlServer2008 = 4,
13+
SqlServer2012 = 8,
14+
PostgreSql = 16,
15+
MySql = 32,
16+
SqlServerMdf = 64,
17+
Oracle = 128,
18+
Firebird = 256,
19+
VistaDb = 512,
20+
AnySqlServer = SqlServer | SqlServer2008 | SqlServer2012 | SqlServerMdf,
1721
}
1822

1923
public static class TestHelpers

0 commit comments

Comments
 (0)