示例#1
0
        //Checks if output metadata columns match ogrlayer source columns
        public override bool isMetadataValid()
        {
            //get default output
            IDTSOutput100 output = null;

            for (int i = 0; i < ComponentMetaData.OutputCollection.Count; i++)
            {
                if (!ComponentMetaData.OutputCollection[i].IsErrorOut)
                {
                    output = ComponentMetaData.OutputCollection[i];
                }
            }

            //get ogrlayer and layer definition
            Layer OGRLayer;
            bool  isSQLLayer = (!(ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value == null || ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value.ToString() == string.Empty));

            if (isSQLLayer)
            {
                OGRLayer = getSQLLayer();
            }
            else
            {
                OGRLayer = getLayer();
            }

            FeatureDefn OGRFeatureDef = OGRLayer.GetLayerDefn();

            // Get Geometry column name
            string geomtryColumn = (OGRLayer.GetGeometryColumn() != "") ? OGRLayer.GetGeometryColumn() : "GEOMETRY";

            // Begin checks
            bool isValid = true;

            if (OGRFeatureDef.GetFieldCount() + 1 == output.OutputColumnCollection.Count)
            {
                int i = 0;
                do
                {
                    //check if ogr field exists by name
                    IDTSOutputColumn100 col = output.OutputColumnCollection[i];
                    int OGRFieldIndex       = OGRFeatureDef.GetFieldIndex(col.Name);
                    if (OGRFieldIndex == -1)
                    {
                        //set isValid false if not geom column
                        if ((col.Name != geomtryColumn) ||
                            (col.DataType != DataType.DT_IMAGE) ||
                            ((string)ComponentMetaData.CustomPropertyCollection["Geometry Column"].Value != geomtryColumn))
                        {
                            isValid = false;
                        }
                    }
                    else
                    {
                        //is isVaild to false if field types don't match
                        FieldDefn OGRFieldDef  = OGRFeatureDef.GetFieldDefn(OGRFieldIndex);
                        FieldType OGRFieldType = OGRFieldDef.GetFieldType();
                        if ((col.DataType != this.OGRTypeToBufferType(OGRFieldType)) &&
                            (!(OGRFieldType == FieldType.OFTString && col.DataType == DataType.DT_NTEXT)))    // special case where lenth not provided by OFTString
                        {
                            isValid = false;
                        }
                    }
                    i++;
                } while (isValid && i < output.OutputColumnCollection.Count);
            }
            else
            {
                isValid = false;
            }

            //Manualy call release on OGR layer sql result set if needed
            if (isSQLLayer)
            {
                this.OGRDataSource.ReleaseResultSet(OGRLayer);
            }
            return(isValid);
        }
示例#2
0
        public override void ReinitializeMetaData()
        {
            base.ReinitializeMetaData();

            //get default output
            IDTSOutput100 defaultOutput = null;

            this.GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex);
            foreach (IDTSOutput100 output in ComponentMetaData.OutputCollection)
            {
                if (output.ID != errorOutputID)
                {
                    defaultOutput = output;
                }
            }

            if (this.isConnected)
            {
                defaultOutput.OutputColumnCollection.RemoveAll();
                defaultOutput.ExternalMetadataColumnCollection.RemoveAll();

                //get ogrlayer and layer definition
                Layer OGRLayer;
                bool  isSQLLayer = (!(ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value == null || ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value.ToString() == string.Empty));
                if (isSQLLayer)
                {
                    OGRLayer = getSQLLayer();
                }
                else
                {
                    OGRLayer = getLayer();
                }
                FeatureDefn OGRFeatureDef = OGRLayer.GetLayerDefn();

                //for each field in ogrlayer add output column and external metadata
                int i = 0;
                while (i < OGRFeatureDef.GetFieldCount())
                {
                    //map OGR field type to SSIS data type
                    FieldDefn OGRFieldDef    = OGRFeatureDef.GetFieldDefn(i);
                    DataType  BufferDataType = this.OGRTypeToBufferType(OGRFieldDef.GetFieldType());
                    int       length         = 0;
                    int       precision      = OGRFieldDef.GetWidth();
                    int       scale          = OGRFieldDef.GetPrecision();
                    int       codepage       = 1252;

                    switch (BufferDataType)
                    {
                    case DataType.DT_WSTR:
                        length    = precision;
                        codepage  = 0;
                        precision = 0;
                        scale     = 0;
                        //check for length == 0
                        if (length == 0)
                        {
                            //BufferDataType = DataType.DT_NTEXT;
                            length = 4000;
                        }
                        break;

                    default:
                        length    = 0;
                        precision = 0;
                        codepage  = 0;
                        scale     = 0;
                        break;
                    }

                    //create column metadata
                    IDTSOutputColumn100 col = defaultOutput.OutputColumnCollection.New();
                    col.Name = OGRFieldDef.GetName();
                    col.ErrorRowDisposition      = DTSRowDisposition.RD_FailComponent;
                    col.TruncationRowDisposition = DTSRowDisposition.RD_FailComponent;
                    col.SetDataTypeProperties(BufferDataType, length, precision, scale, codepage);

                    //create external metadata
                    IDTSExternalMetadataColumn100 ecol = defaultOutput.ExternalMetadataColumnCollection.New();
                    ecol.Name      = col.Name;
                    ecol.DataType  = col.DataType;
                    ecol.Precision = col.Precision;
                    ecol.Length    = col.Length;
                    ecol.Scale     = col.Scale;
                    ecol.CodePage  = col.CodePage;

                    col.ExternalMetadataColumnID = ecol.ID;

                    i++;
                }

                //get geometry column
                string geomtryColumn = (OGRLayer.GetGeometryColumn() != "") ? OGRLayer.GetGeometryColumn() : "GEOMETRY";

                //add geom output column
                IDTSOutputColumn100 geomCol = defaultOutput.OutputColumnCollection.New();
                geomCol.Name = geomtryColumn;
                geomCol.ErrorRowDisposition      = DTSRowDisposition.RD_FailComponent;
                geomCol.TruncationRowDisposition = DTSRowDisposition.RD_FailComponent;
                geomCol.SetDataTypeProperties(DataType.DT_IMAGE, 0, 0, 0, 0);

                //add geom external metadata
                IDTSExternalMetadataColumn100 egeomCol = defaultOutput.ExternalMetadataColumnCollection.New();
                egeomCol.Name      = geomCol.Name;
                egeomCol.DataType  = geomCol.DataType;
                egeomCol.Precision = geomCol.Precision;
                egeomCol.Length    = geomCol.Length;
                egeomCol.Scale     = geomCol.Scale;
                egeomCol.CodePage  = geomCol.CodePage;

                //map column metadata to external column metadata
                geomCol.ExternalMetadataColumnID = egeomCol.ID;

                //set geometry column custom property
                ComponentMetaData.CustomPropertyCollection["Geometry Column"].Value = geomtryColumn;

                if (isSQLLayer)
                {
                    this.OGRDataSource.ReleaseResultSet(OGRLayer);
                }
            }
        }