コード例 #1
0
        public IDataProvider GetDataProvider(IEnumerable <NamedValue> attributes)
        {
            var versionText = attributes.FirstOrDefault(_ => _.Name == "version");

            var version = versionText.Value switch
            {
                var x when x.StartsWith("7.3.") || x == "7.3" || x == "7_3" => DB2iSeriesVersion.V7_3,
                var x when x.StartsWith("7.2.") || x == "7.2" || x == "7_2" => DB2iSeriesVersion.V7_2,
                _ => DB2iSeriesVersion.V7_1
            };

            var providerType = attributes.FirstOrDefault(_ => _.Name == "assemblyName")?.Value switch
            {
#if NETFRAMEWORK
                DB2iSeriesAccessClientProviderAdapter.AssemblyName => DB2iSeriesProviderType.AccessClient,
#endif
                DB2.DB2ProviderAdapter.AssemblyName => DB2iSeriesProviderType.DB2,
                OleDbProviderAdapter.AssemblyName => DB2iSeriesProviderType.OleDb,
                OdbcProviderAdapter.AssemblyName => DB2iSeriesProviderType.Odbc,
                null => DB2iSeriesProviderOptions.Defaults.ProviderType,
                var x => throw ExceptionHelper.InvalidAssemblyName(x)
            };

            var mapGuidAsString = attributes.Any(x => x.Name == Constants.ProviderFlags.MapGuidAsString);

            return(DB2iSeriesTools.GetDataProvider(version, providerType, new DB2iSeriesMappingOptions(mapGuidAsString)));
        }
    }
}
コード例 #2
0
        protected override BulkCopyRowsCopied MultipleRowsCopy <T>(DataConnection dataConnection, BulkCopyOptions options, IEnumerable <T> source)
        {
            if ((options.MaxBatchSize ?? int.MaxValue) > MAX_ALLOWABLE_BATCH_SIZE)
            {
                options.MaxBatchSize = MAX_ALLOWABLE_BATCH_SIZE;
            }

            return(MultipleRowsCopy2(dataConnection, options, source, " FROM " + DB2iSeriesTools.iSeriesDummyTableName(dataConnection)));
        }
コード例 #3
0
        public DB2iSeriesDataProvider AutoDetectDataProvider(string connectionString)
        {
            try
            {
                var providerType = GetProviderType(connectionString);
                var minLevel     = GetServerMinLevel(connectionString, providerType);

                return(DB2iSeriesTools.GetDataProvider(minLevel, providerType, new DB2iSeriesMappingOptions(mapGuidAsString)));
            }
            catch (Exception e)
            {
                throw ExceptionHelper.ConnectionStringParsingFailure(e);
            }
        }
コード例 #4
0
        private ServerVersion GetServerVersion(string connectionString, DB2iSeriesProviderType providerType)
        {
            using (var conn = (DbConnection)DB2iSeriesTools.GetDataProvider(DB2iSeriesVersion.V7_1, providerType, DB2iSeriesMappingOptions.Default).CreateConnection(connectionString))
            {
                conn.Open();

                var serverVersionParts = conn.ServerVersion.Substring(0, 5).Split('.');
                var major = int.Parse(serverVersionParts.First());
                var minor = int.Parse(serverVersionParts.Last());

                var patchLevel = GetMaxPatchLevel(conn, major, minor);

                return(new ServerVersion(major, minor, patchLevel));
            }
        }
コード例 #5
0
        protected override void BuildSelectClause(SelectQuery selectQuery)
        {
            if (selectQuery.HasUnion)
            {
                // need to set any column aliases as the same as the top level one
                var topquery = selectQuery;

                while (topquery.ParentSelect != null && topquery.ParentSelect.HasUnion)
                {
                    topquery = topquery.ParentSelect;
                }
                var alia = selectQuery.Select.Columns.Select(c => c.Alias).ToArray();

                selectQuery.Unions.ForEach((u) =>
                {
                    int colNo = 0;
                    u.SelectQuery.Select.Columns
                    .ForEach(c =>
                    {
                        c.Alias = alia[colNo];
                        colNo++;
                    });
                });
            }

            if (selectQuery.From.Tables.Count == 0)
            {
                AppendIndent().AppendLine("SELECT");
                BuildColumns(selectQuery);
                AppendIndent().AppendLine($"FROM {DB2iSeriesTools.iSeriesDummyTableName()} FETCH FIRST 1 ROW ONLY");
            }
            else
            {
                base.BuildSelectClause(selectQuery);
            }
        }
コード例 #6
0
        protected override void OnConnectionTypeCreated(Type connectionType)
        {
            DB2iSeriesTypes.ConnectionType = connectionType;

            dynamic ass = connectionType.Assembly;

            DB2iSeriesTypes.BigInt.Type         = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2BigInt", true);
            DB2iSeriesTypes.Binary.Type         = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Binary", true);
            DB2iSeriesTypes.Blob.Type           = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Blob", true);
            DB2iSeriesTypes.Char.Type           = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Char", true);
            DB2iSeriesTypes.CharBitData.Type    = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2CharBitData", true);
            DB2iSeriesTypes.Clob.Type           = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Clob", true);
            DB2iSeriesTypes.Date.Type           = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Date", true);
            DB2iSeriesTypes.DataLink.Type       = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2DataLink", true);
            DB2iSeriesTypes.DbClob.Type         = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2DbClob", true);
            DB2iSeriesTypes.DecFloat16.Type     = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2DecFloat16", true);
            DB2iSeriesTypes.DecFloat34.Type     = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2DecFloat34", true);
            DB2iSeriesTypes.Decimal.Type        = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Decimal", true);
            DB2iSeriesTypes.Double.Type         = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Double", true);
            DB2iSeriesTypes.Graphic.Type        = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Graphic", true);
            DB2iSeriesTypes.Integer.Type        = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Integer", true);
            DB2iSeriesTypes.Numeric.Type        = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Numeric", true);
            DB2iSeriesTypes.Real.Type           = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Real", true);
            DB2iSeriesTypes.RowId.Type          = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Rowid", true);
            DB2iSeriesTypes.SmallInt.Type       = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2SmallInt", true);
            DB2iSeriesTypes.Time.Type           = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Time", true);
            DB2iSeriesTypes.TimeStamp.Type      = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2TimeStamp", true);
            DB2iSeriesTypes.VarBinary.Type      = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2VarBinary", true);
            DB2iSeriesTypes.VarChar.Type        = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2VarChar", true);
            DB2iSeriesTypes.VarCharBitData.Type = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2VarCharBitData", true);
            DB2iSeriesTypes.VarGraphic.Type     = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2VarGraphic", true);
            DB2iSeriesTypes.Xml.Type            = ass.GetType(DB2iSeriesTools.AssemblyName + ".iDB2Xml", true);

            SetProviderField(DB2iSeriesTypes.BigInt, typeof(long), "GetiDB2BigInt");
            SetProviderField(DB2iSeriesTypes.Binary, typeof(byte[]), "GetiDB2Binary");
            SetProviderField(DB2iSeriesTypes.Blob, typeof(byte[]), "GetiDB2Blob");
            SetProviderField(DB2iSeriesTypes.Char, typeof(string), "GetiDB2Char");
            SetProviderField(DB2iSeriesTypes.CharBitData, typeof(byte[]), "GetiDB2CharBitData");
            SetProviderField(DB2iSeriesTypes.Clob, typeof(string), "GetiDB2Clob");
            SetProviderField(DB2iSeriesTypes.DataLink, typeof(string), "GetiDB2DataLink");
            SetProviderField(DB2iSeriesTypes.Date, typeof(System.DateTime), "GetiDB2Date");
            SetProviderField(DB2iSeriesTypes.DbClob, typeof(string), "GetiDB2DbClob");
            SetProviderField(DB2iSeriesTypes.DecFloat16, typeof(decimal), "GetiDB2DecFloat16");
            SetProviderField(DB2iSeriesTypes.DecFloat34, typeof(decimal), "GetiDB2DecFloat34");
            SetProviderField(DB2iSeriesTypes.Decimal, typeof(decimal), "GetiDB2Decimal");
            SetProviderField(DB2iSeriesTypes.Double, typeof(double), "GetiDB2Double");
            SetProviderField(DB2iSeriesTypes.Graphic, typeof(string), "GetiDB2Graphic");
            SetProviderField(DB2iSeriesTypes.Integer, typeof(int), "GetiDB2Integer");
            SetProviderField(DB2iSeriesTypes.Numeric, typeof(decimal), "GetiDB2Numeric");
            SetProviderField(DB2iSeriesTypes.Real, typeof(float), "GetiDB2Real");
            SetProviderField(DB2iSeriesTypes.RowId, typeof(byte[]), "GetiDB2RowId");
            SetProviderField(DB2iSeriesTypes.SmallInt, typeof(short), "GetiDB2SmallInt");
            SetProviderField(DB2iSeriesTypes.Time, typeof(System.DateTime), "GetiDB2Time");
            SetProviderField(DB2iSeriesTypes.TimeStamp, typeof(System.DateTime), "GetiDB2TimeStamp");
            SetProviderField(DB2iSeriesTypes.VarBinary, typeof(byte[]), "GetiDB2VarBinary");
            SetProviderField(DB2iSeriesTypes.VarChar, typeof(string), "GetiDB2VarChar");
            SetProviderField(DB2iSeriesTypes.VarCharBitData, typeof(byte[]), "GetiDB2VarCharBitData");
            SetProviderField(DB2iSeriesTypes.VarGraphic, typeof(string), "GetiDB2VarGraphic");
            SetProviderField(DB2iSeriesTypes.Xml, typeof(string), "GetiDB2Xml");

            MappingSchema.AddScalarType(DB2iSeriesTypes.BigInt, GetNullValue(DB2iSeriesTypes.BigInt), true, DataType.Int64);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Binary, GetNullValue(DB2iSeriesTypes.Binary), true, DataType.Binary);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Blob, GetNullValue(DB2iSeriesTypes.Blob), true, DataType.Blob);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Char, GetNullValue(DB2iSeriesTypes.Char), true, DataType.Char);
            MappingSchema.AddScalarType(DB2iSeriesTypes.CharBitData, GetNullValue(DB2iSeriesTypes.CharBitData), true, DataType.Binary);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Clob, GetNullValue(DB2iSeriesTypes.Clob), true, DataType.NText);
            MappingSchema.AddScalarType(DB2iSeriesTypes.DataLink, GetNullValue(DB2iSeriesTypes.DataLink), true, DataType.NText);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Date, GetNullValue(DB2iSeriesTypes.Date), true, DataType.Date);
            MappingSchema.AddScalarType(DB2iSeriesTypes.DbClob, GetNullValue(DB2iSeriesTypes.DbClob), true, DataType.NText);
            MappingSchema.AddScalarType(DB2iSeriesTypes.DecFloat16, GetNullValue(DB2iSeriesTypes.DecFloat16), true, DataType.Decimal);
            MappingSchema.AddScalarType(DB2iSeriesTypes.DecFloat34, GetNullValue(DB2iSeriesTypes.DecFloat34), true, DataType.Decimal);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Decimal, GetNullValue(DB2iSeriesTypes.Decimal), true, DataType.Decimal);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Double, GetNullValue(DB2iSeriesTypes.Double), true, DataType.Double);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Graphic, GetNullValue(DB2iSeriesTypes.Graphic), true, DataType.NText);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Integer, GetNullValue(DB2iSeriesTypes.Integer), true, DataType.Int32);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Numeric, GetNullValue(DB2iSeriesTypes.Numeric), true, DataType.Decimal);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Real, GetNullValue(DB2iSeriesTypes.Real), true, DataType.Single);
            MappingSchema.AddScalarType(DB2iSeriesTypes.RowId, GetNullValue(DB2iSeriesTypes.RowId), true, DataType.VarBinary);
            MappingSchema.AddScalarType(DB2iSeriesTypes.SmallInt, GetNullValue(DB2iSeriesTypes.SmallInt), true, DataType.Int16);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Time, GetNullValue(DB2iSeriesTypes.Time), true, DataType.Time);
            MappingSchema.AddScalarType(DB2iSeriesTypes.TimeStamp, GetNullValue(DB2iSeriesTypes.TimeStamp), true, DataType.DateTime2);
            MappingSchema.AddScalarType(DB2iSeriesTypes.VarBinary, GetNullValue(DB2iSeriesTypes.VarBinary), true, DataType.VarBinary);
            MappingSchema.AddScalarType(DB2iSeriesTypes.VarChar, GetNullValue(DB2iSeriesTypes.VarChar), true, DataType.VarChar);
            MappingSchema.AddScalarType(DB2iSeriesTypes.VarCharBitData, GetNullValue(DB2iSeriesTypes.VarCharBitData), true, DataType.VarBinary);
            MappingSchema.AddScalarType(DB2iSeriesTypes.VarGraphic, GetNullValue(DB2iSeriesTypes.VarGraphic), true, DataType.NText);
            MappingSchema.AddScalarType(DB2iSeriesTypes.Xml, GetNullValue(DB2iSeriesTypes.Xml), true, DataType.Xml);
            _setBlob = GetSetParameter(connectionType, "iDB2Parameter", "iDB2DbType", "iDB2DbType", "iDB2Blob");
            if (DataConnection.TraceSwitch.TraceInfo)
            {
                DataConnection.WriteTraceLine(DataReaderType.AssemblyEx().FullName, DataConnection.TraceSwitch.DisplayName);
            }
            DB2iSeriesTools.Initialized();
        }
コード例 #7
0
 protected override IDbConnection CreateConnectionInternal(string connectionString)
 {
     NamingConvention = DB2iSeriesTools.GetDB2iSeriesNamingConvention(connectionString);
     return(base.CreateConnectionInternal(connectionString));
 }
コード例 #8
0
 protected override void BuildInsertOrUpdateQuery(SqlInsertOrUpdateStatement insertOrUpdate) =>
 BuildInsertOrUpdateQueryAsMerge(insertOrUpdate, $"FROM {DB2iSeriesTools.iSeriesDummyTableName()} FETCH FIRST 1 ROW ONLY");
コード例 #9
0
 protected override void BuildCommand(SqlStatement selectQuery, int commandNumber) =>
 StringBuilder.AppendLine($"SELECT {DB2iSeriesTools.IdentityColumnSql} FROM {DB2iSeriesTools.iSeriesDummyTableName()}");
コード例 #10
0
        protected override List <TableInfo> GetTables(DataConnection dataConnection)
        {
            var sql = $@"
				  Select 
					CAST(CURRENT_SERVER AS VARCHAR(128)) AS Catalog_Name
				  , Table_Schema
				  , Table_Name
				  , Table_Text
				  , Table_Type
				  , System_Table_Schema
				  From {dataConnection.GetTableName("QSYS2", "SYSTABLES")}
				  Where Table_Type In('L', 'P', 'T', 'V')
				  And System_Table_Schema in ('{GetLibList(dataConnection)}')	
				  Order By System_Table_Schema, System_Table_Name
				 "                ;

            var defaultSchema = dataConnection.Execute <string>("select current_schema from " + DB2iSeriesTools.iSeriesDummyTableName(dataConnection));
            Func <IDataReader, TableInfo> drf = (IDataReader dr) => new TableInfo
            {
                CatalogName     = dr["Catalog_Name"].ToString().TrimEnd(),
                Description     = dr["Table_Text"].ToString().TrimEnd(),
                IsDefaultSchema = dr["System_Table_Schema"].ToString().TrimEnd() == defaultSchema,
                IsView          = new[] { "L", "V" }.Contains <string>(dr["Table_Type"].ToString()),
                SchemaName      = dr["Table_Schema"].ToString().TrimEnd(),
                TableID         = dataConnection.Connection.Database + "." + dr["Table_Schema"].ToString().TrimEnd() + "." + dr["Table_Name"].ToString().TrimEnd(),
                TableName       = dr["Table_Name"].ToString().TrimEnd()
            };
            var _list = dataConnection.Query(drf, sql).ToList();

            return(_list);
        }
コード例 #11
0
        protected override List <ProcedureInfo> GetProcedures(DataConnection dataConnection)
        {
            var sql = $@"
		  Select
			CAST(CURRENT_SERVER AS VARCHAR(128)) AS Catalog_Name
		  , Function_Type
		  , Routine_Definition
		  , Routine_Name
		  , Routine_Schema
		  , Routine_Type
		  , Specific_Name
		  , Specific_Schema
		  From {dataConnection.GetTableName("QSYS2", "SYSROUTINES")}
		  Where Specific_Schema in('{GetLibList(dataConnection)}')
		  Order By Specific_Schema, Specific_Name
		  "        ;

            //And {GetSchemaFilter("col.TBCREATOR")}
            var defaultSchema = dataConnection.Execute <string>("select current_schema from " + DB2iSeriesTools.iSeriesDummyTableName(dataConnection));

            ProcedureInfo drf(IDataReader dr)
            {
                return(new ProcedureInfo
                {
                    CatalogName = Convert.ToString(dr["Catalog_Name"]).TrimEnd(),
                    IsDefaultSchema = Convert.ToString(dr["Routine_Schema"]).TrimEnd() == defaultSchema,
                    IsFunction = Convert.ToString(dr["Routine_Type"]) == "FUNCTION",
                    IsTableFunction = Convert.ToString(dr["Function_Type"]) == "T",
                    ProcedureDefinition = Convert.ToString(dr["Routine_Definition"]).TrimEnd(),
                    ProcedureID = dataConnection.Connection.Database + "." + Convert.ToString(dr["Specific_Schema"]).TrimEnd() + "." + Convert.ToString(dr["Specific_Name"]).TrimEnd(),
                    ProcedureName = Convert.ToString(dr["Routine_Name"]).TrimEnd(),
                    SchemaName = Convert.ToString(dr["Routine_Schema"]).TrimEnd()
                });
            }

            var list = dataConnection.Query(drf, sql).ToList();

            return(list);
        }
コード例 #12
0
 protected override void BuildCommand(int commandNumber)
 {
     StringBuilder.AppendLine(string.Format("SELECT {0} FROM {1}", DB2iSeriesTools.IdentityColumnSql, DB2iSeriesTools.iSeriesDummyTableName()));
 }
コード例 #13
0
 protected override void BuildInsertOrUpdateQuery()
 {
     BuildInsertOrUpdateQueryAsMerge(string.Format("FROM {0} FETCH FIRST 1 ROW ONLY", DB2iSeriesTools.iSeriesDummyTableName()));
 }