예제 #1
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));
        }
예제 #2
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));

            switch (version)
            {
            case SqlServerVersion.v2000:
                _sqlOptimizer = new SqlServer2000SqlOptimizer(SqlProviderFlags);
                break;

            case SqlServerVersion.v2005:
                _sqlOptimizer = new SqlServer2005SqlOptimizer(SqlProviderFlags);
                break;

            default:
            case SqlServerVersion.v2008:
                _sqlOptimizer = new SqlServer2008SqlOptimizer(SqlProviderFlags);
                break;

            case SqlServerVersion.v2012:
                _sqlOptimizer = new SqlServer2012SqlOptimizer(SqlProviderFlags);
                break;

            case SqlServerVersion.v2017:
                _sqlOptimizer = new SqlServer2017SqlOptimizer(SqlProviderFlags);
                break;
            }

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