protected SqliteSqlDatabaseContext(DataAccessModel model, SqliteSqlDatabaseContextInfo contextInfo, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager)
			: base(model, new SqliteSqlDialect(), sqlDataTypeProvider, sqlQueryFormatterManager, Path.GetFileNameWithoutExtension(contextInfo.FileName), contextInfo)
		{
			this.FileName = contextInfo.FileName;
			this.IsSharedCacheConnection = IsSharedConnectionRegex.IsMatch(this.FileName);
			this.IsInMemoryConnection = IsMemoryConnectionRegex.IsMatch(this.FileName);
		}
Exemplo n.º 2
0
        private MySqlSqlDatabaseContext(DataAccessModel model, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, MySqlSqlDatabaseContextInfo contextInfo)
            : base(model, MySqlSqlDialect.Default, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo.DatabaseName, contextInfo)
        {
            this.ServerName = contextInfo.ServerName;
            this.Username = contextInfo.UserName;
            this.Password = contextInfo.Password;

            this.ConnectionString = String.Format("Server={0}; Database={1}; Uid={2}; Pwd={3}; Pooling={4}; AutoEnlist=false; charset=utf8; Convert Zero Datetime={5}; Allow Zero Datetime={6};", this.ServerName, this.DatabaseName, this.Username, this.Password, contextInfo.PoolConnections, contextInfo.ConvertZeroDateTime ? "true" : "false", contextInfo.AllowConvertZeroDateTime ? "true" : "false");
            this.ServerConnectionString = Regex.Replace(this.ConnectionString, @"Database\s*\=[^;$]+[;$]", "");

            this.SchemaManager = new MySqlSqlDatabaseSchemaManager(this);
        }
Exemplo n.º 3
0
		protected SqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, string databaseName, SqlDatabaseContextInfo contextInfo)
		{
			this.DatabaseName = databaseName;
			this.DataAccessModel = model; 
			this.CommandTimeout = contextInfo.CommandTimeout == null ? null : (TimeSpan?)TimeSpan.FromSeconds(contextInfo.CommandTimeout.Value);
			var categories = contextInfo.Categories ?? "";
			this.ContextCategories = categories.Trim().Length == 0 ? new string[0] : categories.Split(',').Select(c => c.Trim()).ToArray();
			this.SqlDialect = sqlDialect;
			this.SqlDataTypeProvider = sqlDataTypeProvider;
			this.SqlQueryFormatterManager = sqlQueryFormatterManager;
			this.SchemaName = EnvironmentSubstitutor.Substitute(contextInfo.SchemaName);
			this.TableNamePrefix = EnvironmentSubstitutor.Substitute(contextInfo.TableNamePrefix);
		}
Exemplo n.º 4
0
        protected PostgresSqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, PostgresSqlDatabaseContextInfo contextInfo)
            : base(model, sqlDialect, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo.DatabaseName, contextInfo)
        {
            this.Host = contextInfo.ServerName;
            this.UserId = contextInfo.UserId;
            this.Password = contextInfo.Password;
            this.Port = contextInfo.Port;
            this.CommandTimeout = TimeSpan.FromSeconds(contextInfo.CommandTimeout);

            this.ConnectionString = String.Format("Host={0};User Id={1};Password={2};Database={3};Port={4};Pooling={5};MinPoolSize={6};MaxPoolSize={7};Enlist=false;Timeout={8};CommandTimeout={9}", contextInfo.ServerName, contextInfo.UserId, contextInfo.Password, contextInfo.DatabaseName, contextInfo.Port, contextInfo.Pooling, contextInfo.MinPoolSize, contextInfo.MaxPoolSize, contextInfo.ConnectionTimeout, contextInfo.CommandTimeout);
            this.ServerConnectionString = Regex.Replace(this.ConnectionString, @"Database\s*\=[^;]+[;$]", "Database=postgres;");

            this.SchemaManager = new PostgresSharedSqlDatabaseSchemaManager(this);
        }
		protected PostgresSqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, PostgresSqlDatabaseContextInfo contextInfo)
			: base(model, sqlDialect, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo.DatabaseName, contextInfo)
		{
			this.SupportsPreparedTransactions = contextInfo.EnablePreparedTransactions;

			this.Host = contextInfo.ServerName;
			this.UserId = contextInfo.UserId;
			this.Password = contextInfo.Password;
			this.Port = contextInfo.Port;
			
			var connectionStringBuilder = new NpgsqlConnectionStringBuilder
			{
				Host = contextInfo.ServerName,
				Username = contextInfo.UserId,
				Password = contextInfo.Password,
				Port = contextInfo.Port,
				Pooling = contextInfo.Pooling,
				Enlist = false,
				MinPoolSize = contextInfo.MinPoolSize,
				MaxPoolSize = contextInfo.MaxPoolSize,
				KeepAlive = contextInfo.KeepAlive,
				ConnectionIdleLifetime = contextInfo.ConnectionIdleLifetime,
				ConvertInfinityDateTime = contextInfo.ConvertInfinityDateTime
			};

			if (contextInfo.Timeout != null)
			{
				connectionStringBuilder.Timeout = contextInfo.Timeout.Value;
			}

			if (contextInfo.ConnectionTimeout.HasValue)
			{
				connectionStringBuilder.Timeout = contextInfo.ConnectionTimeout.Value;
			}
			
			if (contextInfo.ConnectionCommandTimeout.HasValue)
			{
				connectionStringBuilder.CommandTimeout = contextInfo.ConnectionCommandTimeout.Value;
			}

			connectionStringBuilder.Database = contextInfo.DatabaseName;

			this.ConnectionString = connectionStringBuilder.ToString();

			connectionStringBuilder.Database = "postgres";

			this.ServerConnectionString = connectionStringBuilder.ToString();

			this.SchemaManager = new PostgresSqlDatabaseSchemaManager(this);
		}
        public SqliteMonoSqlDatabaseContext(DataAccessModel model, SqliteSqlDatabaseContextInfo contextInfo, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager)
            : base(model, contextInfo, sqlDataTypeProvider, sqlQueryFormatterManager)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder
            {
                Enlist = false,
                DataSource = contextInfo.FileName
            };

            connectionStringBuilder.Add("foreign keys", 1);

            this.ConnectionString = connectionStringBuilder.ConnectionString;
            this.ServerConnectionString = this.ConnectionString;

            this.SchemaManager = new SqliteMonoSqlDatabaseSchemaManager(this);
        }
        protected PostgresDotConnectSqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, PostgresDotConnectSqlDatabaseContextInfo contextInfo)
            : base(model, sqlDialect, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo.DatabaseName, contextInfo)
        {
            if (!string.IsNullOrEmpty(contextInfo.ConnectionString))
            {
                this.ConnectionString = contextInfo.ConnectionString;
                this.ServerConnectionString = Regex.Replace(this.ConnectionString, @"Database\s*\=[^;$]+[;$]", "");
            }
            else
            {
                this.Host = contextInfo.ServerName;
                this.UserId = contextInfo.UserId;
                this.Password = contextInfo.Password;
                this.Port = contextInfo.Port;

                var connectionStringBuilder = new PgSqlConnectionStringBuilder
                {
                    Host = contextInfo.ServerName,
                    UserId = contextInfo.UserId,
                    Password = contextInfo.Password,
                    Port = contextInfo.Port,
                    Pooling = contextInfo.Pooling,
                    Enlist = false,
                    Charset = "UTF8",
                    Unicode = true,
                    MaxPoolSize = contextInfo.MaxPoolSize,
                    UnpreparedExecute = contextInfo.UnpreparedExecute
                };

                if (contextInfo.ConnectionTimeout != null)
                {
                    connectionStringBuilder.ConnectionTimeout = contextInfo.ConnectionTimeout.Value;
                }

                if (contextInfo.ConnectionCommandTimeout != null)
                {
                    connectionStringBuilder.DefaultCommandTimeout = contextInfo.ConnectionCommandTimeout.Value;
                }

                this.ServerConnectionString = connectionStringBuilder.ConnectionString;
                connectionStringBuilder.Database = contextInfo.DatabaseName;
                this.ConnectionString = connectionStringBuilder.ConnectionString;
            }

            this.SchemaManager = new PostgresSqlDatabaseSchemaManager(this);
        }
Exemplo n.º 8
0
        protected PostgresSqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, PostgresSqlDatabaseContextInfo contextInfo)
            : base(model, sqlDialect, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo.DatabaseName, contextInfo)
        {
            this.Host = contextInfo.ServerName;
            this.UserId = contextInfo.UserId;
            this.Password = contextInfo.Password;
            this.Port = contextInfo.Port;

            var connectionStringBuilder = new NpgsqlConnectionStringBuilder
            {
                Host = contextInfo.ServerName,
                Username = contextInfo.UserId,
                Password = contextInfo.Password,
                Port = contextInfo.Port,
                Pooling = contextInfo.Pooling,
                Enlist = false,
                BackendTimeouts = contextInfo.BackendTimeouts,
                MinPoolSize = contextInfo.MinPoolSize,
                MaxPoolSize = contextInfo.MaxPoolSize
            };

            if (contextInfo.ConnectionTimeout.HasValue)
            {
                connectionStringBuilder.Timeout = contextInfo.ConnectionTimeout.Value;
            }

            if (contextInfo.ConnectionCommandTimeout.HasValue)
            {
                connectionStringBuilder.CommandTimeout = contextInfo.ConnectionCommandTimeout.Value;
            }

            connectionStringBuilder.Database = contextInfo.DatabaseName;

            this.ConnectionString = connectionStringBuilder.ToString();

            connectionStringBuilder.Database = "postgres";

            this.ServerConnectionString = connectionStringBuilder.ToString();

            this.SchemaManager = new PostgresSqlDatabaseSchemaManager(this);
        }
        public SqliteOfficialsSqlDatabaseContext(DataAccessModel model, SqliteSqlDatabaseContextInfo contextInfo, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager)
            : base(model, contextInfo, sqlDataTypeProvider, sqlQueryFormatterManager)
        {
            Version version;
            var versionString = SQLiteConnection.SQLiteVersion;

            if (Version.TryParse(versionString, out version))
            {
                if (version < new Version(3, 7, 7))
                {
                    bool isInMemory;
                    var uri = contextInfo.FileName;

                    Logger.WarnFormat("Sqlite version {0} does not support URIs", versionString);

                    uri = ConvertNewStyleUriToOldStyleUri(uri, out isInMemory);

                    this.IsInMemoryConnection = isInMemory;
                    this.IsSharedCacheConnection = false;
                    this.FileName = uri;
                }
            }
            else
            {
                Logger.WarnFormat("Cannot parse sqlite version: {0}", versionString);
            }

            var connectionStringBuilder = new SQLiteConnectionStringBuilder();

            connectionStringBuilder.FullUri = this.FileName;
            connectionStringBuilder.Enlist = false;
            connectionStringBuilder.ForeignKeys = true;

            this.ConnectionString = connectionStringBuilder.ConnectionString;
            this.ServerConnectionString = this.ConnectionString;

            this.SchemaManager = new SqliteOfficialSqlDatabaseSchemaManager(this);
        }
Exemplo n.º 10
0
        protected SqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, string databaseName, SqlDatabaseContextInfo contextInfo)
        {
            this.DatabaseName    = databaseName;
            this.DataAccessModel = model;
            this.CommandTimeout  = contextInfo.CommandTimeout == null ? null : (TimeSpan?)TimeSpan.FromSeconds(contextInfo.CommandTimeout.Value);
            var categories = contextInfo.Categories ?? "";

            this.ContextCategories        = categories.Trim().Length == 0 ? new string[0] : categories.Split(',').Select(c => c.Trim()).ToArray();
            this.SqlDialect               = sqlDialect;
            this.SqlDataTypeProvider      = sqlDataTypeProvider;
            this.SqlQueryFormatterManager = sqlQueryFormatterManager;
            this.SchemaName               = EnvironmentSubstitutor.Substitute(contextInfo.SchemaName);
            this.TableNamePrefix          = EnvironmentSubstitutor.Substitute(contextInfo.TableNamePrefix);
        }
Exemplo n.º 11
0
        private SqlServerSqlDatabaseContext(DataAccessModel model, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, SqlServerSqlDatabaseContextInfo contextInfo)
            : base(model, SqlServerSqlDialect.Default, sqlDataTypeProvider, sqlQueryFormatterManager, GetDatabaseName(contextInfo).Trim(), contextInfo)
        {
            this.ServerName = contextInfo.ServerName;
            this.Username = contextInfo.UserName;
            this.Password = contextInfo.Password;
            this.Instance = contextInfo.Instance;
            this.DeleteDatabaseDropsTablesOnly = contextInfo.DeleteDatabaseDropsTablesOnly;

            if (!string.IsNullOrEmpty(contextInfo.ConnectionString))
            {
                var found = false;

                this.ConnectionString = contextInfo.ConnectionString;

                this.ConnectionString = Regex.Replace(this.ConnectionString, @"Enlist\s*=[^;$]+", c =>
                {
                    found = true;

                    return "Enlist=False";
                });

                if (!found)
                {
                    this.ConnectionString += ";Enlist=False;";
                }

                this.ServerConnectionString = ConnectionStringDatabaseNameRegex.Replace(this.ConnectionString, "Initial Catalog=master;");
            }
            else
            {
                var connectionStringBuilder = new SqlConnectionStringBuilder();

                var dataSource = this.ServerName;

                if (!string.IsNullOrEmpty(this.Instance))
                {
                    dataSource += @"\" + this.Instance;
                }

                if (string.IsNullOrEmpty(this.Username) || contextInfo.TrustedConnection)
                {
                    connectionStringBuilder.IntegratedSecurity = true;
                }
                else
                {
                    connectionStringBuilder.UserID = this.Username;
                    connectionStringBuilder.Password = this.Password;
                }

                connectionStringBuilder.Enlist = false;
                connectionStringBuilder.DataSource = dataSource;
                connectionStringBuilder.InitialCatalog = this.DatabaseName;
                connectionStringBuilder.Encrypt = contextInfo.Encrypt;

                if (contextInfo.ConnectionTimeout != null)
                {
                    connectionStringBuilder.ConnectTimeout = contextInfo.ConnectionTimeout.Value;
                }

                this.ConnectionString = connectionStringBuilder.ConnectionString;
                connectionStringBuilder.InitialCatalog = "master";
                this.ServerConnectionString = connectionStringBuilder.ConnectionString;
            }

            this.SchemaManager = new SqlServerSqlDatabaseSchemaManager(this);
        }