Example #1
0
        IDataProvider IDataProviderFactory.GetDataProvider(IEnumerable <NamedValue> attributes)
        {
            var provider     = SqlServerProvider.SystemDataSqlClient;
            var version      = attributes.FirstOrDefault(_ => _.Name == "version");
            var assemblyName = attributes.FirstOrDefault(_ => _.Name == "assemblyName")?.Value;

            if (assemblyName == SqlServerProviderAdapter.MicrosoftAssemblyName)
            {
                provider = SqlServerProvider.MicrosoftDataSqlClient;
            }

            if (version != null)
            {
                switch (version.Value)
                {
                case "2000": return(SqlServerTools.GetDataProvider(SqlServerVersion.v2000, provider));

                case "2005": return(SqlServerTools.GetDataProvider(SqlServerVersion.v2005, provider));

                case "2012": return(SqlServerTools.GetDataProvider(SqlServerVersion.v2012, provider));

                case "2014": return(SqlServerTools.GetDataProvider(SqlServerVersion.v2012, provider));

                case "2017": return(SqlServerTools.GetDataProvider(SqlServerVersion.v2017, provider));
                }
            }

            return(SqlServerTools.GetDataProvider(SqlServerVersion.v2008, provider));
        }
		protected override string? GetDbType(GetSchemaOptions options, string? columnType, DataTypeInfo? dataType, long? length, int? precision, int? scale, string? udtCatalog, string? udtSchema, string? udtName)
		{
			// database name for udt not supported by sql server
			if (udtName != null)
				return (udtSchema != null ? SqlServerTools.QuoteIdentifier(udtSchema) + '.' : null) + SqlServerTools.QuoteIdentifier(udtName);

			return base.GetDbType(options, columnType, dataType, length, precision, scale, udtCatalog, udtSchema, udtName);
		}
Example #3
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));
        }
        protected override string GetDbType(string columnType, DataTypeInfo dataType, long?length, int?prec, int?scale, string udtCatalog, string udtSchema, string udtName)
        {
            // database name for udt not supported by sql server
            if (udtName != null)
            {
                return((udtSchema != null ? SqlServerTools.QuoteIdentifier(udtSchema) + '.' : null) + SqlServerTools.QuoteIdentifier(udtName));
            }

            return(base.GetDbType(columnType, dataType, length, prec, scale, udtCatalog, udtSchema, udtName));
        }
Example #5
0
        public override object Convert(object value, ConvertType convertType)
        {
            switch (convertType)
            {
            case ConvertType.NameToQueryParameter:
            case ConvertType.NameToCommandParameter:
            case ConvertType.NameToSprocParameter:
                return("@" + value);

            case ConvertType.NameToQueryField:
            case ConvertType.NameToQueryFieldAlias:
            case ConvertType.NameToQueryTableAlias:
            {
                var name = value.ToString();

                if (name.Length > 0 && name[0] == '[')
                {
                    return(value);
                }

                return(SqlServerTools.QuoteIdentifier(name));
            }

            case ConvertType.NameToDatabase:
            case ConvertType.NameToSchema:
            case ConvertType.NameToQueryTable:
                if (value != null)
                {
                    var name = value.ToString();

                    if (name.Length > 0 && name[0] == '[')
                    {
                        return(value);
                    }

//						if (name.IndexOf('.') > 0)
//							value = string.Join("].[", name.Split('.'));

                    return(SqlServerTools.QuoteIdentifier(name));
                }

                break;

            case ConvertType.SprocParameterToName:
                if (value != null)
                {
                    var str = value.ToString();
                    return(str.Length > 0 && str[0] == '@'? str.Substring(1): str);
                }
                break;
            }

            return(value);
        }
Example #6
0
        public override StringBuilder Convert(StringBuilder sb, string value, ConvertType convertType)
        {
            switch (convertType)
            {
            case ConvertType.NameToQueryParameter:
            case ConvertType.NameToCommandParameter:
            case ConvertType.NameToSprocParameter:
                return(sb.Append('@').Append(value));

            case ConvertType.NameToQueryField:
            case ConvertType.NameToQueryFieldAlias:
            case ConvertType.NameToQueryTableAlias:
                if (value.Length > 0 && value[0] == '[')
                {
                    return(sb.Append(value));
                }

                if (value == "$action")
                {
                    return(sb.Append(value));
                }

                return(SqlServerTools.QuoteIdentifier(sb, value));

            case ConvertType.NameToServer:
            case ConvertType.NameToDatabase:
            case ConvertType.NameToSchema:
            case ConvertType.NameToQueryTable:
            case ConvertType.NameToProcedure:
                if (value.Length > 0 && value[0] == '[')
                {
                    return(sb.Append(value));
                }

                return(SqlServerTools.QuoteIdentifier(sb, value));

            case ConvertType.SprocParameterToName:
                return(value.Length > 0 && value[0] == '@'
                                                ? sb.Append(value.Substring(1))
                                                : sb.Append(value));
            }

            return(sb.Append(value));
        }
Example #7
0
        IDataProvider IDataProviderFactory.GetDataProvider(IEnumerable <NamedValue> attributes)
        {
            var provider     = SqlServerProvider.SystemDataSqlClient;
            var version      = attributes.FirstOrDefault(_ => _.Name == "version");
            var assemblyName = attributes.FirstOrDefault(_ => _.Name == "assemblyName")?.Value;

            if (assemblyName == SqlServerProviderAdapter.MicrosoftAssemblyName)
            {
                provider = SqlServerProvider.MicrosoftDataSqlClient;
            }

            return(version?.Value switch
            {
                "2000" => SqlServerTools.GetDataProvider(SqlServerVersion.v2000, provider),
                "2005" => SqlServerTools.GetDataProvider(SqlServerVersion.v2005, provider),
                "2012" => SqlServerTools.GetDataProvider(SqlServerVersion.v2012, provider),
                "2014" => SqlServerTools.GetDataProvider(SqlServerVersion.v2012, provider),
                "2017" => SqlServerTools.GetDataProvider(SqlServerVersion.v2017, provider),
                _ => SqlServerTools.GetDataProvider(SqlServerVersion.v2008, provider),
            });
Example #8
0
        public SqlServerDataProvider(string name, SqlServerVersion version, SqlServerProvider provider)
            : base(
                name,
                MappingSchemaInstance.Get(version),
                SqlServerProviderAdapter.GetInstance(provider))
        {
            Version  = version;
            Provider = provider;

            SqlProviderFlags.IsDistinctOrderBySupported       = false;
            SqlProviderFlags.IsSubQueryOrderBySupported       = false;
            SqlProviderFlags.IsDistinctSetOperationsSupported = true;
            SqlProviderFlags.IsCountDistinctSupported         = true;
            SqlProviderFlags.IsUpdateFromSupported            = true;

            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));

            _sqlOptimizer = version switch
            {
                SqlServerVersion.v2000 => new SqlServer2000SqlOptimizer(SqlProviderFlags),
                SqlServerVersion.v2005 => new SqlServer2005SqlOptimizer(SqlProviderFlags),
                SqlServerVersion.v2012 => new SqlServer2012SqlOptimizer(SqlProviderFlags),
                SqlServerVersion.v2017 => new SqlServer2017SqlOptimizer(SqlProviderFlags),
                _ => new SqlServer2008SqlOptimizer(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));

            // missing:
            // GetSqlBytes
            // GetSqlChars
            SetProviderField <SqlBinary, SqlBinary>(SqlTypes.GetSqlBinaryReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlBoolean, SqlBoolean>(SqlTypes.GetSqlBooleanReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlByte, SqlByte>(SqlTypes.GetSqlByteReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlDateTime, SqlDateTime>(SqlTypes.GetSqlDateTimeReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlDecimal, SqlDecimal>(SqlTypes.GetSqlDecimalReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlDouble, SqlDouble>(SqlTypes.GetSqlDoubleReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlGuid, SqlGuid>(SqlTypes.GetSqlGuidReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlInt16, SqlInt16>(SqlTypes.GetSqlInt16ReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlInt32, SqlInt32>(SqlTypes.GetSqlInt32ReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlInt64, SqlInt64>(SqlTypes.GetSqlInt64ReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlMoney, SqlMoney>(SqlTypes.GetSqlMoneyReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlSingle, SqlSingle>(SqlTypes.GetSqlSingleReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlString, SqlString>(SqlTypes.GetSqlStringReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <SqlXml, SqlXml>(Adapter.GetSqlXmlReaderMethod, dataReaderType: Adapter.DataReaderType);

            SetProviderField <DateTimeOffset>(Adapter.GetDateTimeOffsetReaderMethod, dataReaderType: Adapter.DataReaderType);
            SetProviderField <TimeSpan>      (Adapter.GetTimeSpanReaderMethod, dataReaderType: Adapter.DataReaderType);

            // non-specific fallback
            SetProviderField <IDataReader, SqlString, SqlString>((r, i) => r.GetString(i));

            SqlServerTypes.Configure(this);
        }