forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOracle8iDialectFixture.cs
152 lines (127 loc) · 8.29 KB
/
Oracle8iDialectFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.SqlCommand;
using NHibernate.Util;
using NUnit.Framework;
namespace NHibernate.Test.DialectTest
{
[TestFixture]
public class Oracle8iDialectFixture
{
#region Limit only
[Test]
public void GetLimitStringWithTableStartingWithSelectKeyword()
{
var dialect = new Oracle8iDialect();
var sqlString=new SqlString(@"select selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" as column3_2_ from ""SelectLimit"" selectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( select selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" as column3_2_ from ""SelectLimit"" selectlimi0_ ) where rownum <=1");
var limited=dialect.GetLimitString(sqlString, null, new SqlString("1"));
Assert.AreEqual(limited, expected);
}
[Test]
public void GetLimitStringWithTableNotStartingWithSelectKeyword()
{
var dialect = new Oracle8iDialect();
var sqlString = new SqlString(@"select eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" as column3_2_ from ""ESelectLimit"" eselectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( select eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" as column3_2_ from ""ESelectLimit"" eselectlimi0_ ) where rownum <=1");
var limited = dialect.GetLimitString(sqlString, null, new SqlString("1"));
Assert.AreEqual(limited, expected);
}
[Test]
public void GetLimitStringWithTableStartingWithSelectKeywordAndDifferentCasing()
{
var dialect = new Oracle8iDialect();
var sqlString = new SqlString(@"sElEct selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" As column3_2_ fRom ""SelectLimit"" selectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( sElEct selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" As column3_2_ fRom ""SelectLimit"" selectlimi0_ ) where rownum <=1");
var limited = dialect.GetLimitString(sqlString, null, new SqlString("1"));
Assert.AreEqual(limited, expected);
}
[Test]
public void GetLimitStringWithTableNotStartingWithSelectKeywordAndDifferentCasing()
{
var dialect = new Oracle8iDialect();
var sqlString = new SqlString(@"sElEct eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" As column3_2_ fRom ""ESelectLimit"" eselectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( sElEct eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" As column3_2_ fRom ""ESelectLimit"" eselectlimi0_ ) where rownum <=1");
var limited = dialect.GetLimitString(sqlString, null, new SqlString("1"));
Assert.AreEqual(limited, expected);
}
#endregion
#region Offset And List
[Test]
public void GetLimitStringWithOffsetAndLimitAndTableStartingWithSelectKeyword()
{
var dialect = new Oracle8iDialect();
var sqlString = new SqlString(@"select selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" as column3_2_ from ""SelectLimit"" selectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( select row_.*, rownum rownum_ from ( select selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" as column3_2_ from ""SelectLimit"" selectlimi0_ ) row_ where rownum <=1) where rownum_ >1");
var limited = dialect.GetLimitString(sqlString, new SqlString("1"), new SqlString("1"));
Assert.AreEqual(limited, expected);
}
[Test]
public void GetLimitStringWithOffsetAndLimitAndTableNotStartingWithSelectKeyword()
{
var dialect = new Oracle8iDialect();
var sqlString = new SqlString(@"select eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" as column3_2_ from ""ESelectLimit"" eselectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( select row_.*, rownum rownum_ from ( select eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" as column3_2_ from ""ESelectLimit"" eselectlimi0_ ) row_ where rownum <=1) where rownum_ >1");
var limited = dialect.GetLimitString(sqlString, new SqlString("1"), new SqlString("1"));
Assert.AreEqual(limited, expected);
}
[Test]
public void GetLimitStringWithOffsetAndLimitAndTableStartingWithSelectKeywordAndDifferentCasing()
{
var dialect = new Oracle8iDialect();
var sqlString = new SqlString(@"sElEct selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" As column3_2_ fRom ""SelectLimit"" selectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( select row_.*, rownum rownum_ from ( sElEct selectlimi0_.""Id"" as column1_2_,selectlimi0_.""FirstName"" as column2_2_,selectlimi0_.""LastName"" As column3_2_ fRom ""SelectLimit"" selectlimi0_ ) row_ where rownum <=1) where rownum_ >1");
var limited = dialect.GetLimitString(sqlString, new SqlString("1"), new SqlString("1"));
Assert.AreEqual(limited, expected);
}
[Test]
public void GetLimitStringWithOffsetAndLimitAndTableNotStartingWithSelectKeywordAndDifferentCasing()
{
var dialect = new Oracle8iDialect();
var sqlString = new SqlString(@"sElEct eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" As column3_2_ fRom ""ESelectLimit"" eselectlimi0_");
var expected = new SqlString(@"select column1_2_,column2_2_,column3_2_ from ( select row_.*, rownum rownum_ from ( sElEct eselectlimi0_.""Id"" as column1_2_,eselectlimi0_.""FirstName"" as column2_2_,eselectlimi0_.""LastName"" As column3_2_ fRom ""ESelectLimit"" eselectlimi0_ ) row_ where rownum <=1) where rownum_ >1");
var limited = dialect.GetLimitString(sqlString, new SqlString("1"), new SqlString("1"));
Assert.AreEqual(limited, expected);
}
#endregion
#region Types
[Test]
public void CheckUnicode()
{
var dialect = new Oracle8iDialect();
var cfg = TestConfigurationHelper.GetDefaultConfiguration();
dialect.Configure(cfg.Properties);
var useNPrefixedTypesForUnicode = PropertiesHelper.GetBoolean(Environment.OracleUseNPrefixedTypesForUnicode, cfg.Properties, false);
Assert.That(dialect.UseNPrefixedTypesForUnicode, Is.EqualTo(useNPrefixedTypesForUnicode),
$"Unexpected value for {nameof(Oracle8iDialect)}.{nameof(Oracle8iDialect.UseNPrefixedTypesForUnicode)} after configuration");
var unicodeStringType = dialect.GetTypeName(NHibernateUtil.String.SqlType);
Assert.That(unicodeStringType, (useNPrefixedTypesForUnicode ? Does.StartWith("N") : Does.Not.StartWith("N")).IgnoreCase,
"Unexpected type name for an Unicode string");
}
[Test]
public void CheckUnicodeNoPrefix()
{
var dialect = new Oracle8iDialect();
var cfg = TestConfigurationHelper.GetDefaultConfiguration();
cfg.SetProperty(Environment.OracleUseNPrefixedTypesForUnicode, "false");
dialect.Configure(cfg.Properties);
Assert.That(dialect.UseNPrefixedTypesForUnicode, Is.False,
$"Unexpected value for {nameof(Oracle8iDialect)}.{nameof(Oracle8iDialect.UseNPrefixedTypesForUnicode)} after configuration");
var unicodeStringType = dialect.GetTypeName(NHibernateUtil.String.SqlType);
Assert.That(unicodeStringType, Does.Not.StartWith("N").IgnoreCase, "Unexpected type name for an Unicode string");
}
[Test]
public void CheckUnicodeWithPrefix()
{
var dialect = new Oracle8iDialect();
var cfg = TestConfigurationHelper.GetDefaultConfiguration();
cfg.SetProperty(Environment.OracleUseNPrefixedTypesForUnicode, "true");
dialect.Configure(cfg.Properties);
Assert.That(dialect.UseNPrefixedTypesForUnicode, Is.True,
$"Unexpected value for {nameof(Oracle8iDialect)}.{nameof(Oracle8iDialect.UseNPrefixedTypesForUnicode)} after configuration");
var unicodeStringType = dialect.GetTypeName(NHibernateUtil.String.SqlType);
Assert.That(unicodeStringType, Does.StartWith("N").IgnoreCase, "Unexpected type name for an Unicode string");
}
#endregion
}
}