55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using System;
|
|
using GZTW.Profile;
|
|
using System.Text.RegularExpressions;
|
|
namespace GZTW.Data
|
|
{
|
|
/// <summary>
|
|
/// A factory for returning database objects
|
|
/// </summary>
|
|
public sealed class GZTWDatabaseFactory
|
|
{
|
|
private GZTWDatabaseFactory()
|
|
{
|
|
}
|
|
|
|
public static GZTWDatabase CreateDatabase(AyaNovaConnectionSettings a)
|
|
{
|
|
//instantiate and return database depending upon connection setting type
|
|
switch(a.DBType)
|
|
{
|
|
case AyaNovaConnectionSettings.DataBaseType.MSSQL:
|
|
{
|
|
GZTW.Data.Sql.SqlDatabase q= new GZTW.Data.Sql.SqlDatabase();
|
|
q.ConnectionString=a.DataBaseConnectionStringUnTokenized;
|
|
return q;
|
|
}
|
|
|
|
case AyaNovaConnectionSettings.DataBaseType.FireBird:
|
|
{
|
|
|
|
GZTW.Data.FireBird.FireBirdDatabase q= new GZTW.Data.FireBird.FireBirdDatabase();
|
|
//case 1391 - make sure a user= statement is present if embedded
|
|
string sConnect = a.DataBaseConnectionStringUnTokenized;
|
|
if (a.SingleUserConnection)
|
|
{
|
|
Regex regex = new Regex("User\\s*=", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
|
|
if (!regex.IsMatch(sConnect))
|
|
sConnect = sConnect + "User=SYSDBA;";
|
|
}
|
|
|
|
//case 1721 - make sure Charset=UNICODE_FSS; is specified
|
|
if (!sConnect.Contains("Charset"))
|
|
sConnect = sConnect + "Charset=UNICODE_FSS;";
|
|
|
|
q.ConnectionString = sConnect;
|
|
return q;
|
|
}
|
|
|
|
|
|
}
|
|
throw new ApplicationException("GZTWDatabaseFactory: Unable to instantiate provider specific database object from settings in config file\r\nDataBaseType is not set, in-valid or config file is missing or unreadable");
|
|
|
|
}
|
|
}
|
|
}
|