This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 9 files changed +65
-15
lines changed
src/ServiceStack.OrmLite.SqlServer
tests/ServiceStack.OrmLite.Tests Expand file tree Collapse file tree 9 files changed +65
-15
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ public static class SqlServerDialect
7
7
public static IOrmLiteDialectProvider Provider => SqlServerOrmLiteDialectProvider . Instance ;
8
8
}
9
9
10
+ public static class SqlServer2008Dialect
11
+ {
12
+ public static IOrmLiteDialectProvider Provider => SqlServer2008OrmLiteDialectProvider . Instance ;
13
+ }
14
+
10
15
public static class SqlServer2012Dialect
11
16
{
12
17
public static IOrmLiteDialectProvider Provider => SqlServer2012OrmLiteDialectProvider . Instance ;
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ public void Can_select_limit_on_Table_with_References()
83
83
if ( Dialect == Dialect . MySql )
84
84
return ; //= This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
85
85
86
- if ( Dialect == Dialect . SqlServer )
86
+ if ( ( Dialect & Dialect . AnySqlServer ) == Dialect )
87
87
return ; // generates Windowing function "... WHERE CustomerId IN (SELECT * FROM ...)"
88
88
// when should generate "... WHERE CustomerId IN (SELECT Id FROM ...)"
89
89
// both on .NET and .NET Core
@@ -132,7 +132,7 @@ public async Task Can_select_limit_on_Table_with_References_Async()
132
132
if ( Dialect == Dialect . MySql )
133
133
return ; //= This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
134
134
135
- if ( Dialect == Dialect . SqlServer )
135
+ if ( ( Dialect & Dialect . AnySqlServer ) == Dialect )
136
136
return ; // generates Windowing function "... WHERE CustomerId IN (SELECT * FROM ...)"
137
137
// when should generate "... WHERE CustomerId IN (SELECT Id FROM ...)"
138
138
// both on .NET and .NET Core
Original file line number Diff line number Diff line change @@ -612,7 +612,8 @@ public void Can_select_limit_on_Table_with_References()
612
612
if ( Dialect == Dialect . MySql ) return ;
613
613
614
614
//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 ;
616
617
617
618
using ( var db = OpenDbConnection ( ) )
618
619
{
Original file line number Diff line number Diff line change @@ -712,7 +712,7 @@ public void Can_load_references_with_OrderBy_and_Paging()
712
712
//This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
713
713
if ( Dialect == Dialect . MySql )
714
714
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.
716
716
return ;
717
717
718
718
db . DropTable < ParentSelf > ( ) ;
Original file line number Diff line number Diff line change @@ -11,13 +11,14 @@ public class MaxDataTypeTests : OrmLiteTestBase
11
11
public void Can_insert_and_select_max_values ( )
12
12
{
13
13
//OrmLiteConfig.ThrowOnError = true;
14
+ var isSqlServer = ( Dialect & Dialect . AnySqlServer ) == Dialect ;
14
15
15
16
var model = new ModelWithFieldsOfDifferentTypes
16
17
{
17
18
Int = int . MaxValue ,
18
19
Long = long . MaxValue ,
19
20
Double = double . MaxValue ,
20
- Decimal = Dialect != Dialect . SqlServer && Dialect != Dialect . SqlServer2012 && Dialect != Dialect . Sqlite
21
+ Decimal = ! isSqlServer && Dialect != Dialect . Sqlite
21
22
? Decimal . MaxValue
22
23
: long . MaxValue ,
23
24
DateTime = Dialect != Dialect . MySql
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public void Save_populates_AutoIncrementId()
34
34
public void Can_disable_AutoIncrement_field ( )
35
35
{
36
36
//Can't insert in identity column
37
- if ( Dialect == Dialect . SqlServer || Dialect == Dialect . SqlServer2012 )
37
+ if ( ( Dialect & Dialect . AnySqlServer ) == Dialect )
38
38
return ;
39
39
40
40
using ( var db = OpenDbConnection ( ) )
Original file line number Diff line number Diff line change @@ -135,6 +135,8 @@ private OrmLiteConnectionFactory Init()
135
135
return dbFactory ;
136
136
case Dialect . SqlServer :
137
137
return Init ( Config . SqlServerBuildDb , SqlServerDialect . Provider ) ;
138
+ case Dialect . SqlServer2008 :
139
+ return Init ( Config . SqlServerBuildDb , SqlServer2008Dialect . Provider ) ;
138
140
case Dialect . SqlServer2012 :
139
141
return Init ( Config . SqlServerBuildDb , SqlServer2012Dialect . Provider ) ;
140
142
case Dialect . MySql :
Original file line number Diff line number Diff line change
1
+ using System ;
1
2
using System . Collections . Generic ;
2
3
using System . Data ;
3
4
4
5
namespace ServiceStack . OrmLite . Tests
5
6
{
7
+ [ Flags ]
6
8
public enum Dialect
7
9
{
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 ,
17
21
}
18
22
19
23
public static class TestHelpers
You can’t perform that action at this time.
0 commit comments