public DefaultSqlQueryFormatterManager(SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterConstructorMethod constructorMethod)
     : base(sqlDialect)
 {
     this.SqlDialect = sqlDialect;
     this.SqlDataTypeProvider = sqlDataTypeProvider;
     this.ConstructorMethod = constructorMethod;
 }
		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);
		}
        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);
        }
		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);
		}
		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);
		}
        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);
        }
        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);
        }
        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);
        }
 public SqlServerSqlQueryFormatter(SqlQueryFormatterOptions options, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider)
     : base(options, sqlDialect, sqlDataTypeProvider)
 {
 }
Exemple #12
0
 public DefaultSqlQueryFormatterManager(SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, Type sqlFormatterType)
     : this(sqlDialect, sqlDataTypeProvider, CreateConstructorMethodFromType(sqlFormatterType))
 {
 }
		public PostgresSqlDataDefinitionExpressionBuilder(SqlDatabaseContext sqlDatabaseContext, SqlDataTypeProvider sqlDataTypeProvider, SqlDialect sqlDialect)
		{
			this.SqlDatabaseContext = sqlDatabaseContext;
			this.SqlDataTypeProvider = sqlDataTypeProvider;
			this.SqlDialect = sqlDialect;
		}
Exemple #14
0
 public DefaultTimeSpanSqlDataType(SqlDataTypeProvider sqlDataTypeProvider, ConstraintDefaultsConfiguration constraintDefaultsConfiguration, Type type)
     : base(constraintDefaultsConfiguration, type)
 {
     this.sqlDataTypeProvider = sqlDataTypeProvider;
 }
Exemple #15
0
        protected static SqlDataTypeProvider CreateSqlDataTypeProvider(DataAccessModel model, SqlDatabaseContextInfo contextInfo, Func <SqlDataTypeProvider> defaultProviderFactoryMethod)
        {
            SqlDataTypeProvider retval = null;

            if (contextInfo.SqlDataTypeProvider != null)
            {
                if (retval == null)
                {
                    var constructorInfo = contextInfo.SqlDataTypeProvider.GetConstructor(new[] { typeof(SqlDataTypeProvider) });

                    if (constructorInfo != null)
                    {
                        retval = (SqlDataTypeProvider)constructorInfo.Invoke(new object[] { defaultProviderFactoryMethod() });
                    }
                }

                if (retval == null)
                {
                    var constructorInfo = contextInfo.SqlDataTypeProvider.GetConstructors().OrderByDescending(c => c.GetParameters().Length).FirstOrDefault();

                    if (constructorInfo != null)
                    {
                        var context = new InjectionContext(model, contextInfo, defaultProviderFactoryMethod);
                        var args    = context.GetArguments(constructorInfo.GetParameters());

                        retval = (SqlDataTypeProvider)constructorInfo.Invoke(args);
                    }
                }
            }

            if (retval == null)
            {
                retval = defaultProviderFactoryMethod();
            }

            if (retval is DefaultSqlDataTypeProvider defaultSqlDataTypeProvider && contextInfo.SqlDataTypes?.Count > 0)
            {
                var sqlDataTypeContext = new InjectionContext(model, contextInfo, () => retval, c => c == "nullable" ? new Tuple <bool, object>(true, false) : new Tuple <bool, object>(false, false));

                foreach (var type in contextInfo.SqlDataTypes)
                {
                    var constructors = type.GetConstructors().OrderByDescending(c => c.GetParameters().Length).ToList();

                    for (var i = 0; i < constructors.Count; i++)
                    {
                        var constructorInfo = constructors[i];

                        var args = sqlDataTypeContext.GetArguments(constructorInfo.GetParameters());

                        try
                        {
                            var parameters = constructorInfo.GetParameters();

                            var index = parameters.IndexOfAny(c => c.Name == "nullable");

                            if (index >= 0)
                            {
                                args[index] = false;
                                var sqlDataType = (SqlDataType)constructorInfo.Invoke(args);
                                defaultSqlDataTypeProvider.DefineSqlDataType(sqlDataType);

                                args[index] = true;
                                sqlDataType = (SqlDataType)constructorInfo.Invoke(args);
                                defaultSqlDataTypeProvider.DefineSqlDataType(sqlDataType);
                            }
                            else
                            {
                                var sqlDataType = (SqlDataType)constructorInfo.Invoke(args);
                                defaultSqlDataTypeProvider.DefineSqlDataType(sqlDataType);
                            }

                            break;
                        }
                        catch (InvalidOperationException)
                        {
                            if (i == constructors.Count - 1)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
 private MySqlInsertIntoAutoIncrementAmmender(SqlDataTypeProvider sqlDataTypeProvider)
 {
 }
        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);
        }
 public PostgresSharedSqlQueryFormatter(SqlQueryFormatterOptions options, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, string schemaName)
     : base(options, sqlDialect, sqlDataTypeProvider)
 {
     this.schemaName = schemaName;
 }
 public DefaultSqlQueryFormatterManager(SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, Type sqlFormatterType)
     : this(sqlDialect, sqlDataTypeProvider, CreateConstructorMethodFromType(sqlFormatterType))
 {
 }
        public static Expression Ammend(Expression expression, SqlDataTypeProvider sqlDataTypeProvider)
        {
            var processor = new MySqlInsertIntoAutoIncrementAmmender(sqlDataTypeProvider);

            return processor.Visit(expression);
        }
 public DefaultTimeSpanSqlDataType(SqlDataTypeProvider sqlDataTypeProvider, ConstraintDefaults constraintDefaults, Type type)
     : base(constraintDefaults, type)
 {
     this.sqlDataTypeProvider = sqlDataTypeProvider;
 }
        public static Expression Amend(Expression expression, SqlDataTypeProvider sqlDataTypeProvider)
        {
            var processor = new PostgresDataDefinitionExpressionAmender(sqlDataTypeProvider);

            return processor.Visit(expression);
        }
 private PostgresDataDefinitionExpressionAmender(SqlDataTypeProvider sqlDataTypeProvider)
 {
     this.sqlDataTypeProvider = sqlDataTypeProvider;
 }
		public SqliteSqlQueryFormatter(SqlQueryFormatterOptions options, SqlDialect sqlDialect,  SqlDataTypeProvider sqlDataTypeProvider, TypeDescriptorProvider typeDescriptorProvider)
			: base(options, sqlDialect, sqlDataTypeProvider, typeDescriptorProvider)
		{
		}
		public PostgresSqlQueryFormatter(SqlQueryFormatterOptions options, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, TypeDescriptorProvider typeDescriptorProvider, string schemaName, bool convertEnumsToText)
			: base(options, sqlDialect, sqlDataTypeProvider, typeDescriptorProvider)
		{
			this.schemaName = schemaName;
			this.ConvertEnumsToText = convertEnumsToText;
		}
		public DefaultTimeSpanSqlDataType(SqlDataTypeProvider sqlDataTypeProvider, ConstraintDefaultsConfiguration constraintDefaultsConfiguration, Type type)
			: base(constraintDefaultsConfiguration, type)
		{
			this.sqlDataTypeProvider = sqlDataTypeProvider;
		}
 public DefaultTimeSpanSqlDataType(SqlDataTypeProvider sqlDataTypeProvider, ConstraintDefaults constraintDefaults, Type type)
     : base(constraintDefaults, type)
 {
     this.sqlDataTypeProvider = sqlDataTypeProvider;
 }
		public PostgresDotConnectSqlQueryFormatter(SqlQueryFormatterOptions options, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, TypeDescriptorProvider typeDescriptorProvider, string schemaName, bool convertEnumsToText)
			: base(options, sqlDialect, sqlDataTypeProvider, typeDescriptorProvider, schemaName, convertEnumsToText)
		{
		}
		public static Expression Build(SqlDataTypeProvider sqlDataTypeProvider, SqlDialect sqlDialect)
		{
			return null;
		}