Skip to content

Commit 0545b45

Browse files
Add teamcity build for SQL Anywhere
1 parent 4e88f69 commit 0545b45

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

lib/teamcity/SapSQLAnywhere/SQLAnywhere_installation.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Installation steps for SAP SQL Anywhere 17 for NH TeamCity:
33
Please make sure you comply with it's license.
44

55
2. Run the installer
6-
3. Create the test database with default options
7-
4. Run Interactive SQL and connect to the test database
8-
5. Run the query
9-
set option ansi_update_constraints = 'Off'
10-
Otherwise some tests will fail.
11-
12-
5. Ensure the MSDTC Windows service is enabled. All transaction scope tests, even
6+
3. Ensure the MSDTC Windows service is enabled. All transaction scope tests, even
137
those normally not distributed, use it with SAP SQL Anywhere 17
148

9+
The NHibernate.TestDatabaseSetup should normally do on its own the following operations:
10+
1. Create the test database with default options
11+
2. Run the query
12+
set option ansi_update_constraints = 'Off'
13+
(Otherwise some tests will fail.)
14+

src/NHibernate.TestDatabaseSetup/TestDatabaseSetup.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
using System.Data.Odbc;
44
using System.Data.SqlClient;
55
#if NETFX
6+
using System.Data.Common;
67
using System.Data.SqlServerCe;
78
using System.Data.SQLite;
9+
using System.Diagnostics;
810
#endif
911
using System.IO;
1012
using FirebirdSql.Data.FirebirdClient;
@@ -30,7 +32,8 @@ public class DatabaseSetup
3032
{"NHibernate.Driver.OdbcDriver", SetupSqlServerOdbc},
3133
#if NETFX
3234
{"NHibernate.Driver.SQLite20Driver", SetupSQLite},
33-
{"NHibernate.Driver.SqlServerCeDriver", SetupSqlServerCe}
35+
{"NHibernate.Driver.SqlServerCeDriver", SetupSqlServerCe},
36+
{"NHibernate.Driver.SapSQLAnywhere17Driver", SetupSqlAnywhere},
3437
#endif
3538
};
3639

@@ -241,6 +244,57 @@ private static void SetupOracle(Cfg.Configuration cfg)
241244
// }
242245
//}
243246
}
247+
248+
#if NETFX
249+
private static void SetupSqlAnywhere(Cfg.Configuration cfg)
250+
{
251+
var connStr = cfg.Properties[Cfg.Environment.ConnectionString];
252+
253+
var factory = DbProviderFactories.GetFactory("Sap.Data.SQLAnywhere");
254+
var connBuilder = factory.CreateConnectionStringBuilder();
255+
connBuilder.ConnectionString = connStr;
256+
var filename = (string) connBuilder["DBF"];
257+
258+
RunProcess("dbstop", $"-c \"UID=nhibernate;PWD=nhibernate;DBN=nhibernate\" -d", false);
259+
RunProcess("dberase", $"-y {filename}", false);
260+
// -dba: login,pwd
261+
RunProcess("dbinit", $"-dba nhibernate,nhibernate {filename}", true);
262+
263+
using (var conn = factory.CreateConnection())
264+
{
265+
conn.ConnectionString = connStr;
266+
conn.Open();
267+
using (var cmd = conn.CreateCommand())
268+
{
269+
cmd.CommandText = "set option ansi_update_constraints = 'Off'";
270+
cmd.ExecuteNonQuery();
271+
}
272+
}
273+
}
274+
275+
private static void RunProcess(string processName, string arguments, bool checkSuccess)
276+
{
277+
using (var process = new Process())
278+
{
279+
process.StartInfo.FileName = processName;
280+
process.StartInfo.Arguments = arguments;
281+
process.StartInfo.CreateNoWindow = true;
282+
process.StartInfo.UseShellExecute = false;
283+
process.StartInfo.RedirectStandardOutput = true;
284+
process.StartInfo.RedirectStandardError = true;
285+
process.Start();
286+
Console.WriteLine($"{processName} output:");
287+
Console.Write(process.StandardOutput.ReadToEnd());
288+
Console.WriteLine();
289+
Console.WriteLine($"{processName} error output:");
290+
Console.Write(process.StandardError.ReadToEnd());
291+
Console.WriteLine();
292+
process.WaitForExit();
293+
if (checkSuccess && process.ExitCode != 0)
294+
throw new InvalidOperationException($"{processName} has failed");
295+
}
296+
}
297+
#endif
244298
}
245299
}
246300

teamcity.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@
210210
<property name="nhibernate.connection.connection_string" value="Data Source=localhost;Database=nhibernate;User ID=nhibernate;Password=nhibernate;Protocol=memory;Old Guids=True;" />
211211
</target>
212212

213+
<target name="setup-teamcity-sqlanywhere">
214+
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SapSQLAnywhere17Driver" />
215+
<property name="nhibernate.dialect" value="NHibernate.Dialect.SapSQLAnywhere17Dialect" />
216+
<property name="nhibernate.connection.connection_string" value="UID=nhibernate;PWD=nhibernate;ServerName=nhibernate;DBN=nhibernate;DBF=sqlAnywhere.db;Enlist=false;" />
217+
</target>
218+
213219
<script language="C#" prefix="testResult">
214220
<references>
215221
<include name="System.dll" />

0 commit comments

Comments
 (0)