Example #1
0
        protected override void ReadMetadata(string providerManifestToken, DbProviderServices providerServices, DbDataReader reader)
        {
            base.ReadMetadata(providerManifestToken, providerServices, reader);

            var fieldCount        = FieldCount;
            var hasSpatialColumns = false;
            DbSpatialDataReader spatialDataReader = null;

            if (fieldCount > 0)
            {
                // FieldCount == 0 indicates NullDataReader
                spatialDataReader = providerServices.GetSpatialDataReader(reader, providerManifestToken);
            }

            if (spatialDataReader != null)
            {
                _geographyColumns = new bool[fieldCount];
                _geometryColumns  = new bool[fieldCount];

                for (var i = 0; i < fieldCount; i++)
                {
                    _geographyColumns[i] = spatialDataReader.IsGeographyColumn(i);
                    _geometryColumns[i]  = spatialDataReader.IsGeometryColumn(i);
                    hasSpatialColumns    = hasSpatialColumns || _geographyColumns[i] || _geometryColumns[i];
                    Debug.Assert(!_geographyColumns[i] || !_geometryColumns[i]);
                }
            }

            _spatialDataReader = hasSpatialColumns ? spatialDataReader : null;
        }
Example #2
0
        protected override void ReadMetadata(
            string providerManifestToken,
            DbProviderServices providerServices,
            DbDataReader reader)
        {
            base.ReadMetadata(providerManifestToken, providerServices, reader);
            int  fieldCount = this.FieldCount;
            bool flag       = false;
            DbSpatialDataReader spatialDataReader = (DbSpatialDataReader)null;

            if (fieldCount > 0)
            {
                spatialDataReader = providerServices.GetSpatialDataReader(reader, providerManifestToken);
            }
            if (spatialDataReader != null)
            {
                this._geographyColumns = new bool[fieldCount];
                this._geometryColumns  = new bool[fieldCount];
                for (int ordinal = 0; ordinal < fieldCount; ++ordinal)
                {
                    this._geographyColumns[ordinal] = spatialDataReader.IsGeographyColumn(ordinal);
                    this._geometryColumns[ordinal]  = spatialDataReader.IsGeometryColumn(ordinal);
                    flag = flag || this._geographyColumns[ordinal] || this._geometryColumns[ordinal];
                }
            }
            this._spatialDataReader = flag ? spatialDataReader : (DbSpatialDataReader)null;
        }
        private static ReaderMetadata ReadMetadata(string providerManifestToken, DbProviderServices providerSerivces, DbDataReader reader)
        {
            var fieldCount        = reader.FieldCount;
            var hasSpatialColumns = false;
            DbSpatialDataReader spatialDataReader = null;

            bool[] geographyColumns = null;
            bool[] geometryColumns  = null;
            try
            {
                spatialDataReader = providerSerivces.GetSpatialDataReader(reader, providerManifestToken);
                geographyColumns  = new bool[fieldCount];
                geometryColumns   = new bool[fieldCount];
            }
            catch (ProviderIncompatibleException)
            {
            }

            var dataTypeNames = new string[fieldCount];
            var columnTypes   = new Type[fieldCount];
            var columnNames   = new string[fieldCount];

            for (var i = 0; i < fieldCount; i++)
            {
                dataTypeNames[i] = reader.GetDataTypeName(i);
                columnTypes[i]   = reader.GetFieldType(i);
                columnNames[i]   = reader.GetName(i);
                if (spatialDataReader != null)
                {
                    geographyColumns[i] = spatialDataReader.IsGeographyColumn(i);
                    geometryColumns[i]  = spatialDataReader.IsGeometryColumn(i);
                    hasSpatialColumns   = hasSpatialColumns || geographyColumns[i] || geometryColumns[i];
                    Debug.Assert(!geographyColumns[i] || !geometryColumns[i]);
                }
            }

            return(new ReaderMetadata(
                       fieldCount, dataTypeNames, columnTypes, columnNames, hasSpatialColumns, spatialDataReader, geographyColumns, geometryColumns));
        }