Beispiel #1
0
 public static DataConnection CreateDataConnection(
     string connectionString,
     SqlServerVersion version   = SqlServerVersion.v2008,
     SqlServerProvider provider = SqlServerProvider.SystemDataSqlClient)
 {
     return(new DataConnection(GetDataProvider(version, provider), connectionString));
 }
Beispiel #2
0
        private static DataConnection CreateDataConnection(string connectionString, SqlServerVersion sqlServerVersion)
        {
            var sqlServerDataProvider = (SqlServerDataProvider)SqlServerTools.GetDataProvider(sqlServerVersion, SqlServerProvider.MicrosoftDataSqlClient);

            DatabaseContext.CreateMappings(sqlServerDataProvider.MappingSchema);
            return(new DataConnection(sqlServerDataProvider, new SqlConnection(connectionString)));
        }
Beispiel #3
0
        public static void Script(string[] target, Database db
                                  , string output, bool progress, SqlServerVersion sql_version
                                  , bool do_version)//.Version100)
        {
            if (null == db)
            {
                throw new ScripterException("Invalid Database");
            }

            _do_version = do_version;

            Scripter         scripter = new Scripter(db.Parent);
            ScriptingOptions op       = new ScriptingOptions
            {
                AllowSystemObjects = false
                ,
                WithDependencies    = false
                , ClusteredIndexes  = true
                , Indexes           = true
                , DriAllConstraints = true

                                      //,

                                      //, DriAll = true
                , TargetServerVersion = sql_version
            };

            System.Console.WriteLine("Target Version {0}", op.TargetServerVersion);

            scripter.Options = op;

            Script(target, db, scripter, output, progress);
        }
Beispiel #4
0
 public static DataConnection CreateDataConnection(
     IDbTransaction transaction,
     SqlServerVersion version   = SqlServerVersion.v2008,
     SqlServerProvider provider = SqlServerProvider.SystemDataSqlClient)
 {
     return(new DataConnection(GetDataProvider(version, provider), transaction));
 }
Beispiel #5
0
        public static bool SupportsVersion(TSqlPlatforms platform, SqlServerVersion version)
        {
            switch (version)
            {
            case SqlServerVersion.Sql90:
                return((platform & TSqlPlatforms.Sql90) == TSqlPlatforms.Sql90);

            case SqlServerVersion.Sql100:
                return((platform & TSqlPlatforms.Sql100) == TSqlPlatforms.Sql100);

            case SqlServerVersion.Sql110:
                return((platform & TSqlPlatforms.Sql110) == TSqlPlatforms.Sql110);

            case SqlServerVersion.Sql120:
                return((platform & TSqlPlatforms.Sql120) == TSqlPlatforms.Sql120);

            case SqlServerVersion.Sql130:
                return((platform & TSqlPlatforms.Sql130) == TSqlPlatforms.Sql130);

            case SqlServerVersion.Sql140:
                return((platform & TSqlPlatforms.Sql140) == TSqlPlatforms.Sql140);

            case SqlServerVersion.SqlAzure:
                return((platform & TSqlPlatforms.SqlAzure) == TSqlPlatforms.SqlAzure);

            default:
                return(false);
            }
        }
Beispiel #6
0
        protected virtual IDataProvider CreateSqlServerProvider(SqlServerVersion version, string connectionString)
        {
            if (!string.IsNullOrEmpty(connectionString))
            {
                return(DataConnection.GetDataProvider("System.Data.SqlClient", connectionString));
            }

            string providerName;

            switch (version)
            {
            case SqlServerVersion.v2000:
                providerName = ProviderName.SqlServer2000;
                break;

            case SqlServerVersion.v2005:
                providerName = ProviderName.SqlServer2005;
                break;

            case SqlServerVersion.v2008:
                providerName = ProviderName.SqlServer2008;
                break;

            case SqlServerVersion.v2012:
                providerName = ProviderName.SqlServer2012;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new SqlServerDataProvider(providerName, version));
        }
Beispiel #7
0
        /// <summary>
        /// Creates an <see cref="IDataProvider" /> that uses Microsoft.Data.SqlClient internally.
        /// </summary>
        /// <param name="sqlServerVersion">The SQL Server version of the target database (optional). Defaults to <see cref="SqlServerVersion.v2017" />.</param>
        /// <param name="createMappings">
        /// The delegate that manipulates the mapping schema of the data provider (optional). Alternatively, you could use the Linq2Db attributes to configure
        /// your model classes, but we strongly recommend that you use the Linq2Db <see cref="FluentMappingBuilder" /> to specify how model classes are mapped.
        /// </param>
        public static IDataProvider CreateSqlServerDataProvider(SqlServerVersion sqlServerVersion = SqlServerVersion.v2017, Action <MappingSchema>?createMappings = null)
        {
            var dataProvider = SqlServerTools.GetDataProvider(sqlServerVersion, SqlServerProvider.MicrosoftDataSqlClient);

            createMappings?.Invoke(dataProvider.MappingSchema);
            return(dataProvider);
        }
Beispiel #8
0
        public SqlConnector(string connectionString, Schema schema, DynamicQueryManager dqm, SqlServerVersion version)
            : base(schema, dqm)
        {
            this.connectionString = connectionString;
            this.ParameterBuilder = new SqlParameterBuilder();

            this.Version = version;
            if (version >= SqlServerVersion.SqlServer2008 && schema != null)
            {
                var s = schema.Settings;

                if (!s.TypeValues.ContainsKey(typeof(TimeSpan)))
                {
                    schema.Settings.TypeValues.Add(typeof(TimeSpan), SqlDbType.Time);
                }

                if (!s.UdtSqlName.ContainsKey(typeof(SqlHierarchyId)))
                {
                    s.UdtSqlName.Add(typeof(SqlHierarchyId), "HierarchyId");
                }

                if (!s.UdtSqlName.ContainsKey(typeof(SqlGeography)))
                {
                    s.UdtSqlName.Add(typeof(SqlGeography), "Geography");
                }

                if (!s.UdtSqlName.ContainsKey(typeof(SqlGeometry)))
                {
                    s.UdtSqlName.Add(typeof(SqlGeometry), "Geometry");
                }
            }
        }
Beispiel #9
0
 public RuleTest(IList <Tuple <string, string> > testScripts, TSqlModelOptions databaseOptions, SqlServerVersion sqlVersion)
 {
     _trash          = new DisposableList();
     TestScripts     = testScripts;
     DatabaseOptions = databaseOptions ?? new TSqlModelOptions();
     SqlVersion      = sqlVersion;
 }
Beispiel #10
0
        public static TSqlParser BuildNew(SqlServerVersion version, bool quoted)
        {
            switch (version)
            {
            case SqlServerVersion.Sql90:
                return(new TSql90Parser(quoted));

            case SqlServerVersion.Sql100:
                return(new TSql100Parser(quoted));

            case SqlServerVersion.Sql110:
                return(new TSql110Parser(quoted));

            case SqlServerVersion.Sql120:
                return(new TSql120Parser(quoted));

            case SqlServerVersion.Sql130:
                return(new TSql130Parser(quoted));

            case SqlServerVersion.Sql140:
                return(new TSql130Parser(quoted));

            case SqlServerVersion.Sql150:
                return(new TSql130Parser(quoted));

            default:
                throw new ArgumentOutOfRangeException(nameof(version), version, null);
            }
        }
Beispiel #11
0
        public static SqlServerVersion[] GetSqlServerVersions()
        {
            var values = Enum.GetValues(typeof(SqlServerVersion));

            SqlServerVersion[] array = new SqlServerVersion[values.Length];
            values.CopyTo(array, 0);
            return(array);
        }
Beispiel #12
0
        public SqlServerDataProvider(string name, SqlServerVersion version)
            : base(name, (MappingSchema)null)
        {
            Version = version;

            if (version == SqlServerVersion.v2000)
            {
                SqlProviderFlags.AcceptsTakeAsParameter   = false;
                SqlProviderFlags.IsSkipSupported          = false;
                SqlProviderFlags.IsCountSubQuerySupported = false;
            }
            else
            {
                SqlProviderFlags.IsApplyJoinSupported = true;
                SqlProviderFlags.TakeHintsSupported   = TakeHints.Percent | TakeHints.WithTies;
                SqlProviderFlags.IsCommonTableExpressionsSupported = version >= SqlServerVersion.v2008;
            }

            SetCharField("char", (r, i) => r.GetString(i).TrimEnd(' '));
            SetCharField("nchar", (r, i) => r.GetString(i).TrimEnd(' '));
            SetCharFieldToType <char>("char", (r, i) => DataTools.GetChar(r, i));
            SetCharFieldToType <char>("nchar", (r, i) => DataTools.GetChar(r, i));

            if (!Configuration.AvoidSpecificDataProviderAPI)
            {
                SetProviderField <SqlDataReader, SqlBinary, SqlBinary>((r, i) => r.GetSqlBinary(i));
                SetProviderField <SqlDataReader, SqlBoolean, SqlBoolean>((r, i) => r.GetSqlBoolean(i));
                SetProviderField <SqlDataReader, SqlByte, SqlByte>((r, i) => r.GetSqlByte(i));
                SetProviderField <SqlDataReader, SqlDateTime, SqlDateTime>((r, i) => r.GetSqlDateTime(i));
                SetProviderField <SqlDataReader, SqlDecimal, SqlDecimal>((r, i) => r.GetSqlDecimal(i));
                SetProviderField <SqlDataReader, SqlDouble, SqlDouble>((r, i) => r.GetSqlDouble(i));
                SetProviderField <SqlDataReader, SqlGuid, SqlGuid>((r, i) => r.GetSqlGuid(i));
                SetProviderField <SqlDataReader, SqlInt16, SqlInt16>((r, i) => r.GetSqlInt16(i));
                SetProviderField <SqlDataReader, SqlInt32, SqlInt32>((r, i) => r.GetSqlInt32(i));
                SetProviderField <SqlDataReader, SqlInt64, SqlInt64>((r, i) => r.GetSqlInt64(i));
                SetProviderField <SqlDataReader, SqlMoney, SqlMoney>((r, i) => r.GetSqlMoney(i));
                SetProviderField <SqlDataReader, SqlSingle, SqlSingle>((r, i) => r.GetSqlSingle(i));
                SetProviderField <SqlDataReader, SqlString, SqlString>((r, i) => r.GetSqlString(i));
                SetProviderField <SqlDataReader, SqlXml, SqlXml>((r, i) => r.GetSqlXml(i));

                SetProviderField <SqlDataReader, DateTimeOffset>((r, i) => r.GetDateTimeOffset(i));
                SetProviderField <SqlDataReader, TimeSpan>      ((r, i) => r.GetTimeSpan(i));
            }
            else
            {
                SetProviderField <IDataReader, SqlString, SqlString>((r, i) => r.GetString(i));
            }

            _sqlServer2000SqlOptimizer = new SqlServer2000SqlOptimizer(SqlProviderFlags);
            _sqlServer2005SqlOptimizer = new SqlServer2005SqlOptimizer(SqlProviderFlags);
            _sqlServer2008SqlOptimizer = new SqlServerSqlOptimizer(SqlProviderFlags);
            _sqlServer2012SqlOptimizer = new SqlServer2012SqlOptimizer(SqlProviderFlags);

            SetField <IDataReader, decimal>((r, i) => r.GetDecimal(i));
            SetField <IDataReader, decimal>("money", (r, i) => SqlServerTools.DataReaderGetMoney(r, i));
            SetField <IDataReader, decimal>("smallmoney", (r, i) => SqlServerTools.DataReaderGetMoney(r, i));
            SetField <IDataReader, decimal>("decimal", (r, i) => SqlServerTools.DataReaderGetDecimal(r, i));
        }
Beispiel #13
0
 public DacCreator(string dacpacPath, List <Reference> references, SqlServerVersion version, TSqlModelOptions sqlModelOptions, string preDeploy, string postDeploy)
 {
     _outputPath       = dacpacPath;
     _references       = references;
     _version          = version;
     _options          = sqlModelOptions;
     _preDeployScript  = preDeploy;
     _postDeployScript = postDeploy;
 }
Beispiel #14
0
 public static MappingSchema Get(SqlServerVersion version)
 {
     return(version switch
     {
         SqlServerVersion.v2000 => SqlServer2000MappingSchema,
         SqlServerVersion.v2005 => SqlServer2005MappingSchema,
         SqlServerVersion.v2012 => SqlServer2012MappingSchema,
         SqlServerVersion.v2017 => SqlServer2017MappingSchema,
         _ => SqlServer2008MappingSchema,
     });
Beispiel #15
0
        public ModelWrapper(SqlServerVersion version, string directory, string refactorLog, string preScript, string postScript, List <DacReference> ssdtReferences)
        {
            _version     = version;
            _directory   = directory;
            _refactorLog = refactorLog;
            _preScript   = preScript;
            _postScript  = postScript;

            _model        = GetModel();
            _parser       = GetParser();
            ModelMessages = FillModel();
        }
Beispiel #16
0
        public ModelWrapper(SqlServerVersion version, string directory, string refactorLog, string preScript, string postScript)
        {
            _version     = version;
            _directory   = directory;
            _refactorLog = refactorLog;
            _preScript   = preScript;
            _postScript  = postScript;

            _model  = GetModel();
            _parser = GetParser();
            FillModel();
        }
Beispiel #17
0
 public DacCreator(Args args)
 {
     _outputPath = args.DacpacPath;
     _sourceFolder = args.SourcePath;
     _references = args.References;
     _version = args.SqlServerVersion;
     _options = args.SqlModelOptions;
     _preDeployScript = args.PreCompareScript;
     _postDeployScript = args.PostCompareScript;
     if(args.FixDeployScripts)
         ScriptFixer = new DdlScriptParser(_version);
 }
Beispiel #18
0
 public static MappingSchema Get(SqlServerVersion version)
 {
     return(version switch
     {
         SqlServerVersion.v2005 => new SqlServerMappingSchema.SqlServer2005MappingSchema(),
         SqlServerVersion.v2012 => new SqlServerMappingSchema.SqlServer2012MappingSchema(),
         SqlServerVersion.v2014 => new SqlServerMappingSchema.SqlServer2014MappingSchema(),
         SqlServerVersion.v2016 => new SqlServerMappingSchema.SqlServer2016MappingSchema(),
         SqlServerVersion.v2017 => new SqlServerMappingSchema.SqlServer2017MappingSchema(),
         SqlServerVersion.v2019 => new SqlServerMappingSchema.SqlServer2019MappingSchema(),
         _ => new SqlServerMappingSchema.SqlServer2008MappingSchema(),
     });
        public static IDataProvider GetDataProvider(SqlServerVersion version = SqlServerVersion.v2008)
        {
            switch (version)
            {
            case SqlServerVersion.v2000: return(_sqlServerDataProvider2000);

            case SqlServerVersion.v2005: return(_sqlServerDataProvider2005);

            case SqlServerVersion.v2012: return(_sqlServerDataProvider2012);
            }

            return(_sqlServerDataProvider2008);
        }
        public static DataConnection CreateDataConnection(IDbConnection connection, SqlServerVersion version = SqlServerVersion.v2008)
        {
            switch (version)
            {
            case SqlServerVersion.v2000: return(new DataConnection(_sqlServerDataProvider2000, connection));

            case SqlServerVersion.v2005: return(new DataConnection(_sqlServerDataProvider2005, connection));

            case SqlServerVersion.v2012: return(new DataConnection(_sqlServerDataProvider2012, connection));
            }

            return(new DataConnection(_sqlServerDataProvider2008, connection));
        }
        public static IServiceCollection AddDatabaseContext(this IServiceCollection services,
                                                            string connectionString,
                                                            SqlServerVersion sqlServerVersion = SqlServerVersion.v2017)
        {
            var sqlServerDataProvider = (SqlServerDataProvider)SqlServerTools.GetDataProvider(sqlServerVersion, SqlServerProvider.MicrosoftDataSqlClient);

            CreateMappings(sqlServerDataProvider.MappingSchema);
            return(services.AddSingleton(sqlServerDataProvider)
                   .AddTransient(c => new DataConnection(c.GetRequiredService <SqlServerDataProvider>(),
                                                         new SqlConnection(connectionString),
                                                         true))
                   .AddSingleton <Func <DataConnection> >(c => c.GetRequiredService <DataConnection>));
        }
Beispiel #22
0
        /// <summary>
        /// 重新整理SelectCommand。
        /// </summary>
        /// <param name="selectCommand"></param>
        /// <param name="sql"></param>
        public void FormatSelectCommand(ref SqlCommand selectCommand)
        {
            if (selectCommand == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(selectCommand.CommandText))
            {
                selectCommand.CommandText = string.Empty;
            }
            bool[] pagingArgsFlag = new bool[] { false, false, false };
            foreach (SqlParameter p in selectCommand.Parameters)
            {
                if (p.Value == null)
                {
                    p.Value = DBNull.Value;
                }
                if ("@PageIndex".Equals(p.ParameterName))
                {
                    pagingArgsFlag[0] = true;
                }
                if ("@DataCount".Equals(p.ParameterName))
                {
                    pagingArgsFlag[1] = true;
                }
                if ("@SortBy".Equals(p.ParameterName))
                {
                    pagingArgsFlag[2] = true;
                }
            }
            bool             pagingFlag = pagingArgsFlag[0] && pagingArgsFlag[1] && pagingArgsFlag[2];
            SqlServerVersion sv         = SqlServerVersion.SqlServer2005;

            if (selectCommand.CommandType == CommandType.Text && selectCommand.Connection != null && pagingFlag)
            {
                if (SqlServerSet.Instance.FXTConnectionString.Equals(selectCommand.Connection.ConnectionString))
                {
                    sv = SqlServerSet.Instance.FXTDataBaseVersion;
                }
                else if (SqlServerSet.Instance.TestConnectionString.Equals(selectCommand.Connection.ConnectionString))
                {
                    sv = SqlServerSet.Instance.TestDataBaseVersion;
                }
                selectCommand.CommandText = this.PagingDataView(selectCommand.CommandText
                                                                , sv
                                                                , Convert.ToInt32(selectCommand.Parameters["@PageIndex"].Value.ToString())
                                                                , Convert.ToInt32(selectCommand.Parameters["@DataCount"].Value.ToString())
                                                                , selectCommand.Parameters["@SortBy"].Value.ToString()
                                                                );
            }
        }
Beispiel #23
0
        /// <summary>
        /// 对Sql语句进行分页处理。
        /// </summary>
        /// <param name="dataView">待处理的Sql语句。</param>
        /// <param name="sqlServerVersion">SqlServer版本。</param>
        /// <param name="pageIndex">分页页码。</param>
        /// <param name="dataCount">每页显示数据数量。</param>
        /// <param name="sortBy">排序规则。</param>
        /// <param name="viewName">生成子视图名称。</param>
        /// <param name="rowIndexName">生成行标记序列名称。</param>
        /// <returns>处理后的分页语句。</returns>
        public string PagingDataView(string dataView, SqlServerVersion sqlServerVersion, int pageIndex, int dataCount, string sortBy, string viewName, string rowIndexName)
        {
            if (string.IsNullOrEmpty(dataView))
            {
                return(dataView);
            }
            if (pageIndex < 1)
            {
                pageIndex = 1;
            }
            if (dataCount < 1)
            {
                dataCount = 1;
            }
            if (string.IsNullOrEmpty(viewName))
            {
                viewName = string.Format("View_{0}", Guid.NewGuid().ToString().Replace("-", string.Empty));
            }
            if (string.IsNullOrEmpty(rowIndexName))
            {
                rowIndexName = string.Format("RowIndex_{0}", Guid.NewGuid().ToString().Replace("-", string.Empty));
            }
            switch (sqlServerVersion)
            {
            case SqlServerVersion.SqlServer2000:
            {
                return(string.Format("select top {3} * from ({0}) as {1}_A where id not in (select top {4} id from ({0}) as {1}_B order by {2}) order by {2};select Count(*) as Amount from ({0}) as {1}_C"
                                     , dataView
                                     , viewName
                                     , sortBy
                                     , dataCount
                                     , ((pageIndex - 1) * dataCount)
                                     ));
            }

            case SqlServerVersion.SqlServer2005:
            {
                return(string.Format("select * from (select Row_Number() over(order by {3}) as {2},* from ({0}) as {1}_A) as {1}_B where {2} between {4} and {5};select Count(*) as Amount from ({0}) as {1}_C"
                                     , dataView
                                     , viewName
                                     , rowIndexName
                                     , sortBy
                                     , ((pageIndex - 1) * dataCount + 1)
                                     , (pageIndex * dataCount)
                                     ));
            }

            default: goto case SqlServerVersion.SqlServer2005;
            }
        }
Beispiel #24
0
 public static IDataProvider GetDataProvider(
     SqlServerVersion version   = SqlServerVersion.v2008,
     SqlServerProvider provider = SqlServerProvider.SystemDataSqlClient)
 {
     return(provider switch
     {
         SqlServerProvider.SystemDataSqlClient => version switch
         {
             SqlServerVersion.v2000 => _sqlServerDataProvider2000sdc.Value,
             SqlServerVersion.v2005 => _sqlServerDataProvider2005sdc.Value,
             SqlServerVersion.v2012 => _sqlServerDataProvider2012sdc.Value,
             SqlServerVersion.v2017 => _sqlServerDataProvider2017sdc.Value,
             _ => _sqlServerDataProvider2008sdc.Value,
         },
Beispiel #25
0
 public DacCreator(Args args)
 {
     _outputPath       = args.DacpacPath;
     _sourceFolder     = args.SourcePath;
     _references       = args.References;
     _version          = args.SqlServerVersion;
     _options          = args.SqlModelOptions;
     _preDeployScript  = args.PreCompareScript;
     _postDeployScript = args.PostCompareScript;
     if (args.FixDeployScripts)
     {
         ScriptFixer = new DdlScriptParser(_version);
     }
 }
Beispiel #26
0
        public SqlServerDataProvider(string name, SqlServerVersion version)
            : base(name, null)
        {
            Version = version;

            if (version == SqlServerVersion.v2000)
            {
                SqlProviderFlags.AcceptsTakeAsParameter   = false;
                SqlProviderFlags.IsSkipSupported          = false;
                SqlProviderFlags.IsCountSubQuerySupported = false;
            }
            else
            {
                SqlProviderFlags.IsApplyJoinSupported = true;
            }

            SetCharField("char", (r, i) => r.GetString(i).TrimEnd());
            SetCharField("nchar", (r, i) => r.GetString(i).TrimEnd());

            if (!Configuration.AvoidSpecificDataProviderAPI)
            {
                SetProviderField <SqlDataReader, SqlBinary, SqlBinary>((r, i) => r.GetSqlBinary(i));
                SetProviderField <SqlDataReader, SqlBoolean, SqlBoolean>((r, i) => r.GetSqlBoolean(i));
                SetProviderField <SqlDataReader, SqlByte, SqlByte>((r, i) => r.GetSqlByte(i));
                SetProviderField <SqlDataReader, SqlDateTime, SqlDateTime>((r, i) => r.GetSqlDateTime(i));
                SetProviderField <SqlDataReader, SqlDecimal, SqlDecimal>((r, i) => r.GetSqlDecimal(i));
                SetProviderField <SqlDataReader, SqlDouble, SqlDouble>((r, i) => r.GetSqlDouble(i));
                SetProviderField <SqlDataReader, SqlGuid, SqlGuid>((r, i) => r.GetSqlGuid(i));
                SetProviderField <SqlDataReader, SqlInt16, SqlInt16>((r, i) => r.GetSqlInt16(i));
                SetProviderField <SqlDataReader, SqlInt32, SqlInt32>((r, i) => r.GetSqlInt32(i));
                SetProviderField <SqlDataReader, SqlInt64, SqlInt64>((r, i) => r.GetSqlInt64(i));
                SetProviderField <SqlDataReader, SqlMoney, SqlMoney>((r, i) => r.GetSqlMoney(i));
                SetProviderField <SqlDataReader, SqlSingle, SqlSingle>((r, i) => r.GetSqlSingle(i));
                SetProviderField <SqlDataReader, SqlString, SqlString>((r, i) => r.GetSqlString(i));
                SetProviderField <SqlDataReader, SqlXml, SqlXml>((r, i) => r.GetSqlXml(i));

                SetProviderField <SqlDataReader, DateTimeOffset>((r, i) => r.GetDateTimeOffset(i));
                SetProviderField <SqlDataReader, TimeSpan>      ((r, i) => r.GetTimeSpan(i));
            }
            else
            {
                SetProviderField <IDataReader, SqlString, SqlString>((r, i) => r.GetString(i));
            }

            _sqlOptimizer = new SqlServerSqlOptimizer(SqlProviderFlags);
            _sqlServer2000SqlOptimizer = new SqlServer2000SqlOptimizer(SqlProviderFlags);
            _sqlServer2005SqlOptimizer = new SqlServer2005SqlOptimizer(SqlProviderFlags);
        }
            public static MappingSchema Get(SqlServerVersion version)
            {
                switch (version)
                {
                case SqlServerVersion.v2000: return(SqlServer2000MappingSchema);

                case SqlServerVersion.v2005: return(SqlServer2005MappingSchema);

                default:
                case SqlServerVersion.v2008: return(SqlServer2008MappingSchema);

                case SqlServerVersion.v2012: return(SqlServer2012MappingSchema);

                case SqlServerVersion.v2017: return(SqlServer2017MappingSchema);
                }
            }
Beispiel #28
0
        public SqlConnector(string connectionString, Schema schema, SqlServerVersion version) : base(schema)
        {
            this.connectionString = connectionString;
            this.ParameterBuilder = new SqlParameterBuilder();

            this.Version = version;
            if (version >= SqlServerVersion.SqlServer2008 && schema != null)
            {
                var s = schema.Settings;

                if (!s.TypeValues.ContainsKey(typeof(TimeSpan)))
                {
                    schema.Settings.TypeValues.Add(typeof(TimeSpan), SqlDbType.Time);
                }
            }
        }
Beispiel #29
0
        private static int BuildDacpac(string name, string version, FileInfo output, SqlServerVersion sqlServerVersion, FileInfo[] input, FileInfo[] reference, string[] property)
        {
            // Set metadata for the package
            using var packageBuilder = new PackageBuilder();
            packageBuilder.SetMetadata(name, version);

            // Set properties on the model (if defined)
            if (property != null)
            {
                foreach (var propertyValue in property)
                {
                    string[] keyValuePair = propertyValue.Split('=', 2);
                    packageBuilder.SetProperty(keyValuePair[0], keyValuePair[1]);
                }
            }

            // Build the empty model for te targetted SQL Server version
            packageBuilder.UsingVersion(sqlServerVersion);

            // Add references to the model
            if (reference != null)
            {
                foreach (var referenceFile in reference)
                {
                    packageBuilder.AddReference(referenceFile);
                }
            }

            // Add input files
            if (input != null)
            {
                foreach (var inputFile in input)
                {
                    packageBuilder.AddInputFile(inputFile);
                }
            }

            // Validate the model
            if (!packageBuilder.ValidateModel())
            {
                return(1);
            }

            // Save the package to disk
            packageBuilder.SaveToDisk(output);
            return(0);
        }
        /// <summary>
        /// Creates a new baselined test. The input files and baseline file will be loaded from 
        /// the 
        /// </summary>
        public BaselinedRuleTest(
            TestContext testContext, 
            string testName, 
            TSqlModelOptions databaseOptions,
            SqlServerVersion sqlVersion)
            : base(new List<Tuple<string, string>>(), databaseOptions, sqlVersion)
        {
            ScriptsFolder = GetScriptsFolder(testName);
            Assert.IsTrue(Directory.Exists(ScriptsFolder), "Expected the test folder '{0}' to exist", ScriptsFolder);

            string outputDir = testContext.TestResultsDirectory;
            string outputFilename = String.Format("{0}-{1}.txt", testName, Output);
            OutputFilePath = Path.Combine(outputDir, testName, outputFilename);

            string baselineFilename = String.Format("{0}-{1}.txt", testName, Baseline);
            BaselineFilePath = Path.Combine(ScriptsFolder, baselineFilename);
        }
Beispiel #31
0
        /// <summary>
        /// Creates a new baselined test. The input files and baseline file will be loaded from
        /// the
        /// </summary>
        public BaselinedRuleTest(
            TestContext testContext,
            string testName,
            TSqlModelOptions databaseOptions,
            SqlServerVersion sqlVersion)
            : base(new List <Tuple <string, string> >(), databaseOptions, sqlVersion)
        {
            ScriptsFolder = GetScriptsFolder(testName);
            Assert.IsTrue(Directory.Exists(ScriptsFolder), "Expected the test folder '{0}' to exist", ScriptsFolder);

            string outputDir      = testContext.TestResultsDirectory;
            string outputFilename = String.Format("{0}-{1}.txt", testName, Output);

            OutputFilePath = Path.Combine(outputDir, testName, outputFilename);

            string baselineFilename = String.Format("{0}-{1}.txt", testName, Baseline);

            BaselineFilePath = Path.Combine(ScriptsFolder, baselineFilename);
        }
 private static void WriteInterfaceDeclaration(FormattedTextWriter writer, SqlServerVersion version, ModelTypeClass type, string interfaceName, Element element)
 {
     writer.WriteLine();
     writer.WriteLine($"public interface {interfaceName} : {DacUtilities.BaseModelInterfaceFullName}");
     using (writer.StartBlock())
     {
         foreach (ModelPropertyClass property in GetProperties(type))
         {
             if (!DacUtilities.SupportsVersion(property.SupportedPlatforms, version))
             {
                 continue;
             }
             bool   useGenericGetter;
             string typeName     = GetPropertyTypeName(property.DataType, out useGenericGetter);
             string propertyName = GetPropertyName(property, element);
             writer.WriteLine();
             writer.WriteLine($"{typeName} {propertyName} {{ get; }}");
         }
     }
 }
        public SqlConnector(string connectionString, Schema schema, DynamicQueryManager dqm, SqlServerVersion version)
            : base(schema, dqm)
        {
            this.connectionString = connectionString;
            this.ParameterBuilder = new SqlParameterBuilder();

            this.Version = version;
            if (version >= SqlServerVersion.SqlServer2008 && schema != null)
            {
                var s = schema.Settings;

                if (!s.TypeValues.ContainsKey(typeof(TimeSpan)))
                    schema.Settings.TypeValues.Add(typeof(TimeSpan), SqlDbType.Time);

                if (!s.UdtSqlName.ContainsKey(typeof(SqlHierarchyId)))
                    s.UdtSqlName.Add(typeof(SqlHierarchyId), "HierarchyId");

                if (!s.UdtSqlName.ContainsKey(typeof(SqlGeography)))
                    s.UdtSqlName.Add(typeof(SqlGeography), "Geography");

                if (!s.UdtSqlName.ContainsKey(typeof(SqlGeometry)))
                    s.UdtSqlName.Add(typeof(SqlGeometry), "Geometry");
            }
        }
 protected internal SqlServerVersionNotSupported(SqlServerVersion sqlVersion) 
     : base($"SQL Server {sqlVersion.GetHashCode()} is not supported from SqlTableDependency.")
 {
 }
Beispiel #35
0
 public DdlScriptParser(SqlServerVersion version)
 {
     _version = version;
 }