Ejemplo n.º 1
0
        public RecordStateFactory(int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo, Expression gatherData, string[] propertyNames, TypeUsage[] typeUsages)
        {
            this.StateSlotNumber            = stateSlotNumber;
            this.ColumnCount                = columnCount;
            this.NestedRecordStateFactories = new System.Collections.ObjectModel.ReadOnlyCollection <RecordStateFactory>(nestedRecordStateFactories);
            this.DataRecordInfo             = dataRecordInfo;
            this.GatherData  = Translator.Compile <bool>(gatherData);
            this.Description = gatherData.ToString();
            this.ColumnNames = new System.Collections.ObjectModel.ReadOnlyCollection <string>(propertyNames);
            this.TypeUsages  = new System.Collections.ObjectModel.ReadOnlyCollection <TypeUsage>(typeUsages);

            this.FieldNameLookup = new FieldNameLookup(this.ColumnNames, -1);

            // pre-compute the nested objects from typeUsage, for performance
            bool[] isColumnNested = new bool[columnCount];

            for (int ordinal = 0; ordinal < columnCount; ordinal++)
            {
                switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                {
                case BuiltInTypeKind.EntityType:
                case BuiltInTypeKind.ComplexType:
                case BuiltInTypeKind.RowType:
                case BuiltInTypeKind.CollectionType:
                    isColumnNested[ordinal] = true;
                    this.HasNestedColumns   = true;
                    break;

                default:
                    isColumnNested[ordinal] = false;
                    break;
                }
            }
            this.IsColumnNested = new System.Collections.ObjectModel.ReadOnlyCollection <bool>(isColumnNested);
        }
Ejemplo n.º 2
0
		internal DbDataRecord (SchemaInfo[] schema, object[] values, FieldNameLookup lookup)
		{
			this.schema = schema;
			this.lookup = lookup;
			this.values = values;
			this.fieldCount = values.Length;
		}
 private void BuildSchemaInfo()
 {
     int fieldCount = this._reader.FieldCount;
     string[] columnNameArray = new string[fieldCount];
     for (int i = 0; i < fieldCount; i++)
     {
         columnNameArray[i] = this._reader.GetName(i);
     }
     ADP.BuildSchemaTableInfoTableNames(columnNameArray);
     SchemaInfo[] infoArray = new SchemaInfo[fieldCount];
     PropertyDescriptor[] properties = new PropertyDescriptor[this._reader.FieldCount];
     for (int j = 0; j < infoArray.Length; j++)
     {
         SchemaInfo info = new SchemaInfo {
             name = this._reader.GetName(j),
             type = this._reader.GetFieldType(j),
             typeName = this._reader.GetDataTypeName(j)
         };
         properties[j] = new DbColumnDescriptor(j, columnNameArray[j], info.type);
         infoArray[j] = info;
     }
     this._schemaInfo = infoArray;
     this._fieldNameLookup = new FieldNameLookup(this._reader, -1);
     this._descriptors = new PropertyDescriptorCollection(properties);
 }
Ejemplo n.º 4
0
 // copy all runtime data information
 internal DataRecordInternal(object[] values, PropertyDescriptorCollection descriptors, FieldNameLookup fieldNameLookup)
 {
     Debug.Assert(null != values, "invalid attempt to instantiate DataRecordInternal with null value[]");
     _values = values;
     _propertyDescriptors = descriptors;
     _fieldNameLookup = fieldNameLookup;
 }
 internal DataRecordInternal(SchemaInfo[] schemaInfo, object[] values, PropertyDescriptorCollection descriptors, FieldNameLookup fieldNameLookup)
 {
     this._schemaInfo = schemaInfo;
     this._values = values;
     this._propertyDescriptors = descriptors;
     this._fieldNameLookup = fieldNameLookup;
 }
Ejemplo n.º 6
0
 public override int GetOrdinal(string name)
 {
     if (this._fieldNameLookup == null)
     {
         this._fieldNameLookup = new FieldNameLookup((IDataRecord)this);
     }
     return(this._fieldNameLookup.GetOrdinal(name));
 }
        private FieldNameLookup _fieldNameLookup; // MDAC 69015

        // copy all runtime data information
        internal DataRecordInternal(SchemaInfo[] schemaInfo, object[] values, PropertyDescriptorCollection descriptors, FieldNameLookup fieldNameLookup) {
            Debug.Assert(null != schemaInfo, "invalid attempt to instantiate DataRecordInternal with null schema information");
            Debug.Assert(null != values, "invalid attempt to instantiate DataRecordInternal with null value[]");
            _schemaInfo = schemaInfo;
            _values = values;
            _propertyDescriptors = descriptors;
            _fieldNameLookup = fieldNameLookup;
        }
Ejemplo n.º 8
0
		public DbEnumerator (IDataReader reader, bool closeReader)
		{
			this.reader = reader;
			this.closeReader = closeReader;
			this.lookup = new FieldNameLookup ();
			this.fieldCount = reader.FieldCount;
			LoadSchema ();
		}
Ejemplo n.º 9
0
 /// <summary>
 /// </summary>
 public override int GetOrdinal(string name)
 {
     if (null == _fieldNameLookup)
     {
         _fieldNameLookup = new FieldNameLookup(this, -1);
     }
     return(_fieldNameLookup.GetOrdinal(name));
 }
 public override int GetOrdinal(string name)
 {
     this.EnsureCanGetMetaData("GetOrdinal");
     if (this._fieldNameLookup == null)
     {
         this._fieldNameLookup = new FieldNameLookup(this, -1);
     }
     return(this._fieldNameLookup.GetOrdinal(name));
 }
Ejemplo n.º 11
0
        public T Get <T>(string name, T defaultValue = default(T))
        {
            if (!FieldNameLookup.ContainsKey(name))
            {
                return(default(T));
            }

            var index = FieldNameLookup[name];

            return(Get(index, defaultValue));
        }
Ejemplo n.º 12
0
 public virtual int GetOrdinal(string name)
 {
     this.EnsureSubclassOverride();
     if (this._fieldNameLookup == null)
     {
         string[] fieldNames = new string[this.FieldCount];
         for (int i = 0; i < fieldNames.Length; i++)
         {
             fieldNames[i] = this.GetSqlMetaData(i).Name;
         }
         this._fieldNameLookup = new FieldNameLookup(fieldNames, -1);
     }
     return(this._fieldNameLookup.GetOrdinal(name));
 }
Ejemplo n.º 13
0
        /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetOrdinal/*' />
        public virtual int GetOrdinal(string name)
        {
            if (_fieldNameLookup == null)
            {
                string[] names = new string[FieldCount];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = GetSqlMetaData(i).Name;
                }

                _fieldNameLookup = new FieldNameLookup(names, -1);
            }

            return(_fieldNameLookup.GetOrdinal(name));
        }
Ejemplo n.º 14
0
        public virtual int GetOrdinal(string name)
        {
            EnsureSubclassOverride();
            if (null == _fieldNameLookup)
            {
                string[] names = new string[FieldCount];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = GetSqlMetaData(i).Name;
                }

                _fieldNameLookup = new FieldNameLookup(names, -1);
            }

            return(_fieldNameLookup.GetOrdinal(name));
        }
        private void MetaDataAvailable(SmiQueryMetaData[] md, bool nextEventIsRow)
        {
            this._currentMetaData = md;
            this._hasRows         = nextEventIsRow;
            this._fieldNameLookup = null;
            this._currentPosition = PositionState.BeforeRows;
            this._indexMap        = new int[this._currentMetaData.Length];
            int index = 0;

            for (int i = 0; i < this._currentMetaData.Length; i++)
            {
                if (!this._currentMetaData[i].IsHidden.IsTrue)
                {
                    this._indexMap[index] = i;
                    index++;
                }
            }
            this._visibleColumnCount = index;
        }
Ejemplo n.º 16
0
        public RecordStateFactory(
            int stateSlotNumber,
            int columnCount,
            RecordStateFactory[] nestedRecordStateFactories,
            DataRecordInfo dataRecordInfo,
            Expression <Func <Shaper, bool> > gatherData,
            string[] propertyNames,
            TypeUsage[] typeUsages,
            bool[] isColumnNested)
        {
            this.StateSlotNumber            = stateSlotNumber;
            this.ColumnCount                = columnCount;
            this.NestedRecordStateFactories = new ReadOnlyCollection <RecordStateFactory>((IList <RecordStateFactory>)nestedRecordStateFactories);
            this.DataRecordInfo             = dataRecordInfo;
            this.GatherData      = gatherData.Compile();
            this.Description     = gatherData.ToString();
            this.ColumnNames     = new ReadOnlyCollection <string>((IList <string>)propertyNames);
            this.TypeUsages      = new ReadOnlyCollection <TypeUsage>((IList <TypeUsage>)typeUsages);
            this.FieldNameLookup = new FieldNameLookup(this.ColumnNames);
            if (isColumnNested == null)
            {
                isColumnNested = new bool[columnCount];
                for (int index = 0; index < columnCount; ++index)
                {
                    switch (typeUsages[index].EdmType.BuiltInTypeKind)
                    {
                    case BuiltInTypeKind.CollectionType:
                    case BuiltInTypeKind.ComplexType:
                    case BuiltInTypeKind.EntityType:
                    case BuiltInTypeKind.RowType:
                        isColumnNested[index] = true;
                        this.HasNestedColumns = true;
                        break;

                    default:
                        isColumnNested[index] = false;
                        break;
                    }
                }
            }
            this.IsColumnNested = new ReadOnlyCollection <bool>((IList <bool>)isColumnNested);
        }
Ejemplo n.º 17
0
        public RecordStateFactory(
            int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo,
            Expression <Func <Shaper, bool> > gatherData, string[] propertyNames, TypeUsage[] typeUsages, bool[] isColumnNested)
        {
            StateSlotNumber            = stateSlotNumber;
            ColumnCount                = columnCount;
            NestedRecordStateFactories = new ReadOnlyCollection <RecordStateFactory>(nestedRecordStateFactories);
            DataRecordInfo             = dataRecordInfo;
            GatherData  = gatherData.Compile();
            Description = gatherData.ToString();
            ColumnNames = new ReadOnlyCollection <string>(propertyNames);
            TypeUsages  = new ReadOnlyCollection <TypeUsage>(typeUsages);

            FieldNameLookup = new FieldNameLookup(ColumnNames);

            // pre-compute the nested objects from typeUsage, for performance
            if (isColumnNested == null)
            {
                isColumnNested = new bool[columnCount];

                for (var ordinal = 0; ordinal < columnCount; ordinal++)
                {
                    switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                    {
                    case BuiltInTypeKind.EntityType:
                    case BuiltInTypeKind.ComplexType:
                    case BuiltInTypeKind.RowType:
                    case BuiltInTypeKind.CollectionType:
                        isColumnNested[ordinal] = true;
                        HasNestedColumns        = true;
                        break;

                    default:
                        isColumnNested[ordinal] = false;
                        break;
                    }
                }
            }
            IsColumnNested = new ReadOnlyCollection <bool>(isColumnNested);
        }
 private void CloseInternal(bool closeReader)
 {
     TdsParser parser = this._parser;
     TdsParserStateObject stateObj = this._stateObj;
     bool flag2 = this.IsCommandBehavior(CommandBehavior.CloseConnection);
     this._parser = null;
     bool flag = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         if (((parser != null) && (stateObj != null)) && (stateObj._pendingData && (parser.State == TdsParserState.OpenLoggedIn)))
         {
             if (this._altRowStatus == ALTROWSTATUS.AltRow)
             {
                 this._dataReady = true;
             }
             if (this._dataReady)
             {
                 this.CleanPartialRead();
             }
             parser.Run(RunBehavior.Clean, this._command, this, null, stateObj);
         }
         this.RestoreServerSettings(parser, stateObj);
     }
     catch (OutOfMemoryException exception6)
     {
         this._isClosed = true;
         flag = true;
         if (this._connection != null)
         {
             this._connection.Abort(exception6);
         }
         throw;
     }
     catch (StackOverflowException exception5)
     {
         this._isClosed = true;
         flag = true;
         if (this._connection != null)
         {
             this._connection.Abort(exception5);
         }
         throw;
     }
     catch (ThreadAbortException exception4)
     {
         this._isClosed = true;
         flag = true;
         if (this._connection != null)
         {
             this._connection.Abort(exception4);
         }
         throw;
     }
     finally
     {
         if (flag)
         {
             this._isClosed = true;
             this._command = null;
             this._connection = null;
             this._statistics = null;
         }
         else if (closeReader)
         {
             this._stateObj = null;
             this._data = null;
             if (this.Connection != null)
             {
                 this.Connection.RemoveWeakReference(this);
             }
             RuntimeHelpers.PrepareConstrainedRegions();
             try
             {
                 if ((this._command != null) && (stateObj != null))
                 {
                     stateObj.CloseSession();
                 }
             }
             catch (OutOfMemoryException exception3)
             {
                 this._isClosed = true;
                 flag = true;
                 if (this._connection != null)
                 {
                     this._connection.Abort(exception3);
                 }
                 throw;
             }
             catch (StackOverflowException exception2)
             {
                 this._isClosed = true;
                 flag = true;
                 if (this._connection != null)
                 {
                     this._connection.Abort(exception2);
                 }
                 throw;
             }
             catch (ThreadAbortException exception)
             {
                 this._isClosed = true;
                 flag = true;
                 if (this._connection != null)
                 {
                     this._connection.Abort(exception);
                 }
                 throw;
             }
             this.SetMetaData(null, false);
             this._dataReady = false;
             this._isClosed = true;
             this._fieldNameLookup = null;
             if (flag2 && (this.Connection != null))
             {
                 this.Connection.Close();
             }
             if (this._command != null)
             {
                 this._recordsAffected = this._command.InternalRecordsAffected;
             }
             this._command = null;
             this._connection = null;
             this._statistics = null;
         }
     }
 }
 private void ClearMetaData()
 {
     this._metaData = null;
     this._tableNames = null;
     this._fieldNameLookup = null;
     this._metaDataConsumed = false;
     this._browseModeInfoConsumed = false;
 }
Ejemplo n.º 20
0
 override public Int32 GetOrdinal(String name) {
     if (null == _fieldNameLookup) {
         if (null == _metadata) {
             throw ADP.DataReaderNoData();
         }
         _fieldNameLookup = new FieldNameLookup(this, -1);
     }
     return _fieldNameLookup.GetOrdinal(name); // MDAC 71470
 }
Ejemplo n.º 21
0
        internal void DumpToSchemaTable(UnsafeNativeMethods.IRowset rowset) {
            List<MetaData> metainfo = new List<MetaData>();

            object hiddenColumns = null;
            using (OleDbDataReader dataReader = new OleDbDataReader(_connection, _command, Int32.MinValue, 0)) {
                dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero);
                dataReader.BuildSchemaTableInfo(rowset, true, false);

                hiddenColumns = GetPropertyValue(ODB.DBPROP_HIDDENCOLUMNS); // MDAC 55611, 72106
                if (0 == dataReader.FieldCount) {
                    return;
                }

                Debug.Assert(null == dataReader._fieldNameLookup, "lookup already exists");
                FieldNameLookup lookup = new FieldNameLookup(dataReader, -1);
                dataReader._fieldNameLookup = lookup;

                // This column, together with the DBCOLUMN_GUID and DBCOLUMN_PROPID
                // columns, forms the ID of the column. One or more (but not all) of these columns
                // will be NULL, depending on which elements of the DBID structure the provider uses.
                MetaData columnidname = dataReader.FindMetaData(ODB.DBCOLUMN_IDNAME);
                MetaData columnguid = dataReader.FindMetaData(ODB.DBCOLUMN_GUID);
                MetaData columnpropid = dataReader.FindMetaData(ODB.DBCOLUMN_PROPID);

                MetaData columnname = dataReader.FindMetaData(ODB.DBCOLUMN_NAME);
                MetaData columnordinal = dataReader.FindMetaData(ODB.DBCOLUMN_NUMBER);
                MetaData dbtype = dataReader.FindMetaData(ODB.DBCOLUMN_TYPE);
                MetaData columnsize = dataReader.FindMetaData(ODB.DBCOLUMN_COLUMNSIZE);
                MetaData numericprecision = dataReader.FindMetaData(ODB.DBCOLUMN_PRECISION);
                MetaData numericscale = dataReader.FindMetaData(ODB.DBCOLUMN_SCALE);
                MetaData columnflags = dataReader.FindMetaData(ODB.DBCOLUMN_FLAGS);
                MetaData baseschemaname = dataReader.FindMetaData(ODB.DBCOLUMN_BASESCHEMANAME);
                MetaData basecatalogname = dataReader.FindMetaData(ODB.DBCOLUMN_BASECATALOGNAME);
                MetaData basetablename = dataReader.FindMetaData(ODB.DBCOLUMN_BASETABLENAME);
                MetaData basecolumnname = dataReader.FindMetaData(ODB.DBCOLUMN_BASECOLUMNNAME);
                MetaData isautoincrement = dataReader.FindMetaData(ODB.DBCOLUMN_ISAUTOINCREMENT);
                MetaData isunique = dataReader.FindMetaData(ODB.DBCOLUMN_ISUNIQUE);
                MetaData iskeycolumn = dataReader.FindMetaData(ODB.DBCOLUMN_KEYCOLUMN);

                // @devnote: because we want to use the DBACCESSOR_OPTIMIZED bit,
                // we are required to create the accessor before fetching any rows
                dataReader.CreateAccessors(false);

                ColumnBinding binding;
                while (dataReader.ReadRowset()) {
                    dataReader.GetRowDataFromHandle();

                    MetaData info = new MetaData();

                    binding = columnidname.columnBinding; // MDAC 72627
                    if (!binding.IsValueNull()) {
                        info.idname = (string)binding.Value();
                        info.kind = ODB.DBKIND_NAME;
                    }

                    binding = columnguid.columnBinding;
                    if (!binding.IsValueNull()) {
                        info.guid = binding.Value_GUID();
                        info.kind = ((ODB.DBKIND_NAME == info.kind) ? ODB.DBKIND_GUID_NAME : ODB.DBKIND_GUID);
                    }

                    binding = columnpropid.columnBinding;
                    if (!binding.IsValueNull()) {
                        info.propid = new IntPtr(binding.Value_UI4());
                        info.kind = ((ODB.DBKIND_GUID == info.kind) ? ODB.DBKIND_GUID_PROPID : ODB.DBKIND_PROPID);
                    }

                    binding = columnname.columnBinding;
                    if (!binding.IsValueNull()) {
                        info.columnName = (string)binding.Value();
                    }
                    else {
                        info.columnName = "";
                    }

                    if (4 == ADP.PtrSize) {
                        info.ordinal = (IntPtr)columnordinal.columnBinding.Value_UI4();
                    }
                    else {
                        info.ordinal = (IntPtr)columnordinal.columnBinding.Value_UI8();
                    }
                    short wType = unchecked((short) dbtype.columnBinding.Value_UI2());

                    if (4 == ADP.PtrSize) {
                        info.size = unchecked((int) columnsize.columnBinding.Value_UI4()); // WebData 99298
                    }
                    else {
                        info.size = ADP.IntPtrToInt32((IntPtr)unchecked((long)columnsize.columnBinding.Value_UI8()));
                    }

                    binding = numericprecision.columnBinding;
                    if (!binding.IsValueNull()) {
                        info.precision = (byte)binding.Value_UI2();
                    }

                    binding = numericscale.columnBinding;
                    if (!binding.IsValueNull()) {
                        info.scale = (byte)binding.Value_I2();
                    }

                    info.flags = unchecked((int) columnflags.columnBinding.Value_UI4());

                    bool islong = OleDbDataReader.IsLong(info.flags);
                    bool isfixed = OleDbDataReader.IsFixed(info.flags);
                    NativeDBType dbType = NativeDBType.FromDBType(wType, islong, isfixed);

                    info.type = dbType;

                    if (null != isautoincrement) {
                        binding = isautoincrement.columnBinding;
                        if (!binding.IsValueNull()) {
                            info.isAutoIncrement = binding.Value_BOOL();
                        }
                    }
                    if (null != isunique) {
                        binding = isunique.columnBinding;
                        if (!binding.IsValueNull()) {
                            info.isUnique = binding.Value_BOOL();
                        }
                    }
                    if (null != iskeycolumn) {
                        binding = iskeycolumn.columnBinding;
                        if (!binding.IsValueNull()) {
                            info.isKeyColumn = binding.Value_BOOL();
                        }
                    }
                    if (null != baseschemaname) {
                        binding = baseschemaname.columnBinding;
                        if (!binding.IsValueNull()) {
                            info.baseSchemaName = binding.ValueString();
                        }
                    }
                    if (null != basecatalogname) {
                        binding = basecatalogname.columnBinding;
                        if (!binding.IsValueNull()) {
                            info.baseCatalogName = binding.ValueString();
                        }
                    }
                    if (null != basetablename) {
                        binding = basetablename.columnBinding;
                        if (!binding.IsValueNull()) {
                            info.baseTableName = binding.ValueString();
                        }
                    }
                    if (null != basecolumnname) {
                        binding = basecolumnname.columnBinding;
                        if (!binding.IsValueNull()) {
                            info.baseColumnName = binding.ValueString();
                        }
                    }
                    metainfo.Add(info);
                }
            }

            int visibleCount = metainfo.Count;
            if (hiddenColumns is Int32) {
                visibleCount -= (int)hiddenColumns;
            }

            // VSTFDevDiv 479578: 
            //  if one key column is invalidated, they all need to be invalidated. The SET is the key,
            //  and subsets likely are not accurate keys. Note the assumption that the two loops below
            //  will traverse the entire set of columns.
            bool disallowKeyColumns = false;

            for (int index = metainfo.Count - 1; visibleCount <= index; --index) {
                MetaData info = metainfo[index];

                info.isHidden = true;

                if (disallowKeyColumns) {
                    info.isKeyColumn = false;
                }
                else if (info.guid.Equals(ODB.DBCOL_SPECIALCOL)) { // MDAC 90827
                    info.isKeyColumn = false;

                    // This is the first key column to be invalidated, scan back through the 
                    //  columns we already processed to make sure none of those are marked as keys.
                    disallowKeyColumns = true;
                    for (int index2 = metainfo.Count-1; index < index2; --index2) {
                        metainfo[index2].isKeyColumn = false;
                    }
                }
            }

            for (int index = visibleCount - 1; 0 <= index; --index) {
                MetaData info = metainfo[index];

                if (disallowKeyColumns) {
                    info.isKeyColumn = false;
                }

                if (info.guid.Equals(ODB.DBCOL_SPECIALCOL)) { // MDAC 72390
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceVerbose) {
                        Debug.WriteLine("Filtered Column: DBCOLUMN_GUID=DBCOL_SPECIALCOL DBCOLUMN_NAME=" + info.columnName + " DBCOLUMN_KEYCOLUMN=" + info.isKeyColumn);
                    }
#endif
                    info.isHidden = true;
                    visibleCount--;
                }
#if WIN32
                else if (0 >= (int)info.ordinal) {
#else
                else if (0 >= (long)info.ordinal) {
#endif
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceVerbose) {
                        Debug.WriteLine("Filtered Column: DBCOLUMN_NUMBER=" + info.ordinal.ToInt64().ToString(CultureInfo.InvariantCulture) + " DBCOLUMN_NAME=" + info.columnName);
                    }
#endif
                    info.isHidden = true;
                    visibleCount--;
                }
                else if (OleDbDataReader.DoColumnDropFilter(info.flags)) {
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceVerbose) {
                        Debug.WriteLine("Filtered Column: DBCOLUMN_FLAGS=" + info.flags.ToString("X8", (System.IFormatProvider)null) + " DBCOLUMN_NAME=" + info.columnName);
                    }
#endif
                    info.isHidden = true;
                    visibleCount--;
                }
            }

            // 
            metainfo.Sort(); // MDAC 68319
            _visibleFieldCount = visibleCount;
            _metadata = metainfo.ToArray();
        }
Ejemplo n.º 22
0
        public virtual int GetOrdinal( string name ) {
            EnsureSubclassOverride();
            if (null == _fieldNameLookup) {
                string[] names = new string [ FieldCount ];
                for( int i=0; i < names.Length; i++ ) {
                    names[i] = GetSqlMetaData( i ).Name;
                }

                _fieldNameLookup = new FieldNameLookup( names, -1 );  // 
            }

            return _fieldNameLookup.GetOrdinal( name );
        }
Ejemplo n.º 23
0
        private bool NextResult(bool disposing, bool allresults) {
            // if disposing, loop through all the remaining results and ignore error messages
            // if allresults, loop through all results and collect all error messages for a single exception
            // callers are via Close(false, true), Dispose(true, false), NextResult(false,false)
            Debug.Assert(!disposing || !allresults, "both disposing & allresults are true");
            const int MaxConsecutiveFailure = 2000; // see WebData 72126 for why more than 1000

            SQLLEN cRowsAffected;
            Int16 cColsAffected;
            ODBC32.RetCode retcode, firstRetCode = ODBC32.RetCode.SUCCESS;
            bool hasMoreResults;
            bool hasColumns = false;
            bool singleResult = IsCommandBehavior(CommandBehavior.SingleResult);

            if (IsClosed) {
                throw ADP.DataReaderClosed("NextResult");
            }
            _fieldNameLookup = null;

            if (IsCancelingCommand || _noMoreResults) {
                return false;
            }

            //Blow away the previous cache (since the next result set will have a different shape,
            //different schema data, and different data.
            _isRead = false;
            _hasRows = HasRowsStatus.DontKnow;
            _fieldNameLookup = null;
            this.metadata = null;
            this.schemaTable = null;

            int loop = 0; // infinite loop protection, max out after 2000 consecutive failed results
            OdbcErrorCollection errors = null; // SQLBU 342112
            do {
                _isValidResult = false;
                retcode = StatementHandle.MoreResults();
                hasMoreResults = ((retcode == ODBC32.RetCode.SUCCESS)
                                ||(retcode == ODBC32.RetCode.SUCCESS_WITH_INFO));

                if (retcode == ODBC32.RetCode.SUCCESS_WITH_INFO) {
                    Connection.HandleErrorNoThrow(StatementHandle, retcode);
                }
                else if (!disposing && (retcode != ODBC32.RetCode.NO_DATA) && (ODBC32.RetCode.SUCCESS != retcode)) {
                    // allow for building comulative error messages.
                    if (null == errors) {
                        firstRetCode = retcode;
                        errors = new OdbcErrorCollection();
                    }
                    ODBC32.GetDiagErrors(errors, null, StatementHandle, retcode);
                    ++loop;
                }

                if (!disposing && hasMoreResults) {
                    loop = 0;
                    cRowsAffected = GetRowCount();              // get rowcount of the current resultset (if any)
                    CalculateRecordsAffected(cRowsAffected);    // update recordsaffected
                    if (!singleResult) {
                        // update row- and columncount
                        FieldCountNoThrow(out cColsAffected);
                        hasColumns = (0 != cColsAffected);
                        _isValidResult = hasColumns;
                    }
                }
            } while ((!singleResult && hasMoreResults && !hasColumns)  // repeat for results with no columns
                     || ((ODBC32.RetCode.NO_DATA != retcode) && allresults && (loop < MaxConsecutiveFailure)) // or process all results until done
                     || (singleResult && hasMoreResults));           // or for any result in singelResult mode
            if (MaxConsecutiveFailure <= loop) {
                Bid.Trace("<odbc.OdbcDataReader.NextResult|INFO> 2000 consecutive failed results");
            }

            if(retcode == ODBC32.RetCode.NO_DATA) {
                this.dataCache = null;
                _noMoreResults = true;
            }
            if (null != errors) {
                Debug.Assert(!disposing, "errors while disposing");
                errors.SetSource(Connection.Driver);
                OdbcException exception = OdbcException.CreateException(errors, firstRetCode);
                Connection.ConnectionIsAlive(exception);
                throw exception;
            }
            return (hasMoreResults);
        }
Ejemplo n.º 24
0
 /// <summary>
 ///
 /// </summary>
 public override int GetOrdinal(string name)
 {
     if (null == _fieldNameLookup)
     {
         _fieldNameLookup = new FieldNameLookup(this, -1);
     }
     return _fieldNameLookup.GetOrdinal(name);
 }
 private void DisposeManagedRowset()
 {
     this._isRead = false;
     this._hasRowsReadCheck = false;
     this._nextAccessorForRetrieval = 0;
     this._nextValueForRetrieval = 0;
     Bindings[] bindingsArray = this._bindings;
     this._bindings = null;
     if (bindingsArray != null)
     {
         for (int i = 0; i < bindingsArray.Length; i++)
         {
             if (bindingsArray[i] != null)
             {
                 bindingsArray[i].Dispose();
             }
         }
     }
     this._currentRow = 0;
     this._rowFetchedCount = IntPtr.Zero;
     this._dbSchemaTable = null;
     this._visibleFieldCount = 0;
     this._metadata = null;
     this._fieldNameLookup = null;
 }
 private void MetaDataAvailable(SmiQueryMetaData[] md, bool nextEventIsRow)
 {
     this._currentMetaData = md;
     this._hasRows = nextEventIsRow;
     this._fieldNameLookup = null;
     this._currentPosition = PositionState.BeforeRows;
     this._indexMap = new int[this._currentMetaData.Length];
     int index = 0;
     for (int i = 0; i < this._currentMetaData.Length; i++)
     {
         if (!this._currentMetaData[i].IsHidden.IsTrue)
         {
             this._indexMap[index] = i;
             index++;
         }
     }
     this._visibleColumnCount = index;
 }
Ejemplo n.º 27
0
        public RecordStateFactory(int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo, Expression gatherData, string[] propertyNames, TypeUsage[] typeUsages)
        {
            this.StateSlotNumber = stateSlotNumber;
            this.ColumnCount = columnCount;
            this.NestedRecordStateFactories = new System.Collections.ObjectModel.ReadOnlyCollection<RecordStateFactory>(nestedRecordStateFactories);
            this.DataRecordInfo = dataRecordInfo;
            this.GatherData = Translator.Compile<bool>(gatherData);
            this.Description = gatherData.ToString();
            this.ColumnNames = new System.Collections.ObjectModel.ReadOnlyCollection<string>(propertyNames);
            this.TypeUsages = new System.Collections.ObjectModel.ReadOnlyCollection<TypeUsage>(typeUsages);

            this.FieldNameLookup = new FieldNameLookup(this.ColumnNames, -1);

            // pre-compute the nested objects from typeUsage, for performance
            bool[] isColumnNested = new bool[columnCount];

            for (int ordinal = 0; ordinal < columnCount; ordinal++)
            {
                switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                {
                    case BuiltInTypeKind.EntityType:
                    case BuiltInTypeKind.ComplexType:
                    case BuiltInTypeKind.RowType:
                    case BuiltInTypeKind.CollectionType:
                        isColumnNested[ordinal] = true;
                        this.HasNestedColumns = true;
                        break;
                    default:
                        isColumnNested[ordinal] = false;
                        break;
                }
            }
            this.IsColumnNested = new System.Collections.ObjectModel.ReadOnlyCollection<bool>(isColumnNested);
        }
Ejemplo n.º 28
0
        private void BuildSchemaInfo() {
            int count = _reader.FieldCount;
            string[] fieldnames = new string[count];
            for (int i = 0; i < count; ++i) {
                fieldnames[i] = _reader.GetName(i);
            }
            ADP.BuildSchemaTableInfoTableNames(fieldnames); // MDAC 71401

            SchemaInfo[] si = new SchemaInfo[count];
            PropertyDescriptor[] props = new PropertyDescriptor[_reader.FieldCount];
            for (int i = 0; i < si.Length; i++) {
                SchemaInfo s = new SchemaInfo();
                s.name = _reader.GetName(i);
                s.type = _reader.GetFieldType(i);
                s.typeName = _reader.GetDataTypeName(i);
                props[i] = new DbColumnDescriptor(i, fieldnames[i], s.type);
                si[i] = s;
            }

            _schemaInfo = si;
            _fieldNameLookup = new FieldNameLookup(_reader, -1); // MDAC 71470
            _descriptors = new PropertyDescriptorCollection(props);
        }
Ejemplo n.º 29
0
        private void BuildSchemaInfo()
        {
            int count = _reader.FieldCount;
            string[] fieldnames = new string[count];
            for (int i = 0; i < count; ++i)
            {
                fieldnames[i] = _reader.GetName(i);
            }
            ADP.BuildSchemaTableInfoTableNames(fieldnames);

            SchemaInfo[] si = new SchemaInfo[count];
            for (int i = 0; i < si.Length; i++)
            {
                SchemaInfo s = new SchemaInfo();
                s.name = _reader.GetName(i);
                s.type = _reader.GetFieldType(i);
                s.typeName = _reader.GetDataTypeName(i);
                si[i] = s;
            }

            _schemaInfo = si;
            _fieldNameLookup = new FieldNameLookup(_reader, -1);
        }
 public override bool NextResult()
 {
     bool flag2;
     IntPtr ptr2;
     Bid.ScopeEnter(out ptr2, "<oledb.OleDbDataReader.NextResult|API> %d#\n", this.ObjectID);
     try
     {
         bool flag = false;
         if (this.IsClosed)
         {
             throw ADP.DataReaderClosed("NextResult");
         }
         this._fieldNameLookup = null;
         OleDbCommand command = this._command;
         UnsafeNativeMethods.IMultipleResults results = this._imultipleResults;
         if (results != null)
         {
             this.DisposeOpenResults();
             this._hasRows = false;
             do
             {
                 IntPtr ptr;
                 object ppRowset = null;
                 if ((command != null) && command.canceling)
                 {
                     this.Close();
                     goto Label_0116;
                 }
                 Bid.Trace("<oledb.IMultipleResults.GetResult|API|OLEDB> %d#, IID_IRowset\n", this.ObjectID);
                 OleDbHResult result = results.GetResult(ADP.PtrZero, ODB.DBRESULTFLAG_DEFAULT, ref ODB.IID_IRowset, out ptr, out ppRowset);
                 Bid.Trace("<oledb.IMultipleResults.GetResult|API|OLEDB|RET> %08X{HRESULT}, RecordAffected=%Id\n", result, ptr);
                 if ((OleDbHResult.S_OK <= result) && (ppRowset != null))
                 {
                     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|RowSet> %d#, IRowset\n", this.ObjectID);
                     this._irowset = (System.Data.Common.UnsafeNativeMethods.IRowset) ppRowset;
                 }
                 this._recordsAffected = AddRecordsAffected(this._recordsAffected, ptr);
                 if (OleDbHResult.DB_S_NORESULT == result)
                 {
                     this.DisposeNativeMultipleResults();
                     goto Label_0116;
                 }
                 this.ProcessResults(result);
             }
             while (this._irowset == null);
             this.BuildMetaInfo();
             this.HasRowsRead();
             flag = true;
         }
         else
         {
             this.DisposeOpenResults();
             this._hasRows = false;
         }
     Label_0116:
         flag2 = flag;
     }
     finally
     {
         Bid.ScopeLeave(ref ptr2);
     }
     return flag2;
 }
Ejemplo n.º 31
0
        override public bool NextResult() {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<oledb.OleDbDataReader.NextResult|API> %d#\n", ObjectID);
            try {
                bool retflag = false;
                if (IsClosed) {
                    throw ADP.DataReaderClosed("NextResult");
                }
                _fieldNameLookup = null;

                OleDbCommand command = _command;
                UnsafeNativeMethods.IMultipleResults imultipleResults = _imultipleResults;
                if (null != imultipleResults) {
                    DisposeOpenResults();
                    _hasRows = false;
                    
                    for (;;) {
                        Debug.Assert(null == _irow, "NextResult: row loop check");
                        Debug.Assert(null == _irowset, "NextResult: rowset loop check");

                        object result = null;
                        OleDbHResult hr;
                        IntPtr affected;

                        if ((null != command) && command.canceling) { // MDAC 69986
                            Close();
                            break;
                        }

                        Bid.Trace("<oledb.IMultipleResults.GetResult|API|OLEDB> %d#, IID_IRowset\n", ObjectID);
                        hr = imultipleResults.GetResult(ADP.PtrZero, ODB.DBRESULTFLAG_DEFAULT, ref ODB.IID_IRowset, out affected, out result);
                        Bid.Trace("<oledb.IMultipleResults.GetResult|API|OLEDB|RET> %08X{HRESULT}, RecordAffected=%Id\n", hr, affected);

                        if ((0 <= hr) && (null != result)) {
                            Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|RowSet> %d#, IRowset\n", ObjectID);
                            _irowset = (UnsafeNativeMethods.IRowset) result;
                        }
                        _recordsAffected = AddRecordsAffected(_recordsAffected, affected);

                        if (OleDbHResult.DB_S_NORESULT == hr) {
                            DisposeNativeMultipleResults();
                            break;
                        }
                        // @devnote: infomessage events may be fired from here
                        ProcessResults(hr);

                        if (null != _irowset) {
                            BuildMetaInfo();
                            HasRowsRead();
                            retflag = true;
                            break;
                        }
                    }
                }
                else {
                    DisposeOpenResults(); // MDAC 70934
                    _hasRows = false; // MDAC 85850
                }
                return retflag;
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
 public override int GetOrdinal(string name)
 {
     if (this._fieldNameLookup == null)
     {
         if (this._metadata == null)
         {
             throw ADP.DataReaderNoData();
         }
         this._fieldNameLookup = new FieldNameLookup(this, -1);
     }
     return this._fieldNameLookup.GetOrdinal(name);
 }
Ejemplo n.º 33
0
        private void DisposeManagedRowset() {
            //not cleared after last rowset
            //_hasRows = false;

            _isRead = false;
            _hasRowsReadCheck = false;

            _nextAccessorForRetrieval = 0;
            _nextValueForRetrieval = 0;

            Bindings[] bindings = _bindings;
            _bindings = null;

            if (null != bindings) {
                for (int i = 0; i < bindings.Length; ++i) {
                    if (null != bindings[i]) { // MDAC 77007
                        bindings[i].Dispose();
                    }
                }
            }

            _currentRow = 0;
            _rowFetchedCount = IntPtr.Zero;

            _dbSchemaTable = null;
            _visibleFieldCount = 0;
            _metadata = null;
            _fieldNameLookup = null;
        }
 internal void SetMetaData(_SqlMetaDataSet metaData, bool moreInfo)
 {
     this._metaData = metaData;
     this._tableNames = null;
     if (this._metaData != null)
     {
         this._metaData.schemaTable = null;
         this._data = SqlBuffer.CreateBufferArray(metaData.Length);
     }
     this._fieldNameLookup = null;
     if (metaData != null)
     {
         if (!moreInfo)
         {
             this._metaDataConsumed = true;
             if (this._parser != null)
             {
                 byte num = this._stateObj.PeekByte();
                 if (num == 0xa9)
                 {
                     this._parser.Run(RunBehavior.ReturnImmediately, null, null, null, this._stateObj);
                     num = this._stateObj.PeekByte();
                 }
                 this._hasRows = 0xd1 == num;
                 if (0x88 == num)
                 {
                     this._metaDataConsumed = false;
                 }
             }
         }
     }
     else
     {
         this._metaDataConsumed = false;
     }
     this._browseModeInfoConsumed = false;
 }
 public override int GetOrdinal(string name)
 {
     SqlStatistics statistics = null;
     int ordinal;
     try
     {
         statistics = SqlStatistics.StartTimer(this.Statistics);
         if (this._fieldNameLookup == null)
         {
             if (this.MetaData == null)
             {
                 throw SQL.InvalidRead();
             }
             this._fieldNameLookup = new FieldNameLookup(this, this._defaultLCID);
         }
         ordinal = this._fieldNameLookup.GetOrdinal(name);
     }
     finally
     {
         SqlStatistics.StopTimer(statistics);
     }
     return ordinal;
 }
 internal void DumpToSchemaTable(System.Data.Common.UnsafeNativeMethods.IRowset rowset)
 {
     List<System.Data.OleDb.MetaData> list = new List<System.Data.OleDb.MetaData>();
     object propertyValue = null;
     using (OleDbDataReader reader = new OleDbDataReader(this._connection, this._command, -2147483648, CommandBehavior.Default))
     {
         reader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero);
         reader.BuildSchemaTableInfo(rowset, true, false);
         propertyValue = this.GetPropertyValue(0x102);
         if (reader.FieldCount == 0)
         {
             return;
         }
         FieldNameLookup lookup = new FieldNameLookup(reader, -1);
         reader._fieldNameLookup = lookup;
         System.Data.OleDb.MetaData data20 = reader.FindMetaData("DBCOLUMN_IDNAME");
         System.Data.OleDb.MetaData data19 = reader.FindMetaData("DBCOLUMN_GUID");
         System.Data.OleDb.MetaData data18 = reader.FindMetaData("DBCOLUMN_PROPID");
         System.Data.OleDb.MetaData data17 = reader.FindMetaData("DBCOLUMN_NAME");
         System.Data.OleDb.MetaData data12 = reader.FindMetaData("DBCOLUMN_NUMBER");
         System.Data.OleDb.MetaData data16 = reader.FindMetaData("DBCOLUMN_TYPE");
         System.Data.OleDb.MetaData data11 = reader.FindMetaData("DBCOLUMN_COLUMNSIZE");
         System.Data.OleDb.MetaData data15 = reader.FindMetaData("DBCOLUMN_PRECISION");
         System.Data.OleDb.MetaData data14 = reader.FindMetaData("DBCOLUMN_SCALE");
         System.Data.OleDb.MetaData data13 = reader.FindMetaData("DBCOLUMN_FLAGS");
         System.Data.OleDb.MetaData data10 = reader.FindMetaData("DBCOLUMN_BASESCHEMANAME");
         System.Data.OleDb.MetaData data9 = reader.FindMetaData("DBCOLUMN_BASECATALOGNAME");
         System.Data.OleDb.MetaData data8 = reader.FindMetaData("DBCOLUMN_BASETABLENAME");
         System.Data.OleDb.MetaData data7 = reader.FindMetaData("DBCOLUMN_BASECOLUMNNAME");
         System.Data.OleDb.MetaData data6 = reader.FindMetaData("DBCOLUMN_ISAUTOINCREMENT");
         System.Data.OleDb.MetaData data5 = reader.FindMetaData("DBCOLUMN_ISUNIQUE");
         System.Data.OleDb.MetaData data4 = reader.FindMetaData("DBCOLUMN_KEYCOLUMN");
         reader.CreateAccessors(false);
         while (reader.ReadRowset())
         {
             reader.GetRowDataFromHandle();
             System.Data.OleDb.MetaData item = new System.Data.OleDb.MetaData();
             ColumnBinding columnBinding = data20.columnBinding;
             if (!columnBinding.IsValueNull())
             {
                 item.idname = (string) columnBinding.Value();
                 item.kind = 2;
             }
             columnBinding = data19.columnBinding;
             if (!columnBinding.IsValueNull())
             {
                 item.guid = columnBinding.Value_GUID();
                 item.kind = (2 == item.kind) ? 0 : 6;
             }
             columnBinding = data18.columnBinding;
             if (!columnBinding.IsValueNull())
             {
                 item.propid = new IntPtr((long) columnBinding.Value_UI4());
                 item.kind = (6 == item.kind) ? 1 : 5;
             }
             columnBinding = data17.columnBinding;
             if (!columnBinding.IsValueNull())
             {
                 item.columnName = (string) columnBinding.Value();
             }
             else
             {
                 item.columnName = "";
             }
             if (4 == ADP.PtrSize)
             {
                 item.ordinal = (IntPtr) data12.columnBinding.Value_UI4();
             }
             else
             {
                 item.ordinal = (IntPtr) data12.columnBinding.Value_UI8();
             }
             short dbType = (short) data16.columnBinding.Value_UI2();
             if (4 == ADP.PtrSize)
             {
                 item.size = (int) data11.columnBinding.Value_UI4();
             }
             else
             {
                 item.size = ADP.IntPtrToInt32((IntPtr) data11.columnBinding.Value_UI8());
             }
             columnBinding = data15.columnBinding;
             if (!columnBinding.IsValueNull())
             {
                 item.precision = (byte) columnBinding.Value_UI2();
             }
             columnBinding = data14.columnBinding;
             if (!columnBinding.IsValueNull())
             {
                 item.scale = (byte) columnBinding.Value_I2();
             }
             item.flags = (int) data13.columnBinding.Value_UI4();
             bool isLong = IsLong(item.flags);
             bool isFixed = IsFixed(item.flags);
             NativeDBType type = NativeDBType.FromDBType(dbType, isLong, isFixed);
             item.type = type;
             if (data6 != null)
             {
                 columnBinding = data6.columnBinding;
                 if (!columnBinding.IsValueNull())
                 {
                     item.isAutoIncrement = columnBinding.Value_BOOL();
                 }
             }
             if (data5 != null)
             {
                 columnBinding = data5.columnBinding;
                 if (!columnBinding.IsValueNull())
                 {
                     item.isUnique = columnBinding.Value_BOOL();
                 }
             }
             if (data4 != null)
             {
                 columnBinding = data4.columnBinding;
                 if (!columnBinding.IsValueNull())
                 {
                     item.isKeyColumn = columnBinding.Value_BOOL();
                 }
             }
             if (data10 != null)
             {
                 columnBinding = data10.columnBinding;
                 if (!columnBinding.IsValueNull())
                 {
                     item.baseSchemaName = columnBinding.ValueString();
                 }
             }
             if (data9 != null)
             {
                 columnBinding = data9.columnBinding;
                 if (!columnBinding.IsValueNull())
                 {
                     item.baseCatalogName = columnBinding.ValueString();
                 }
             }
             if (data8 != null)
             {
                 columnBinding = data8.columnBinding;
                 if (!columnBinding.IsValueNull())
                 {
                     item.baseTableName = columnBinding.ValueString();
                 }
             }
             if (data7 != null)
             {
                 columnBinding = data7.columnBinding;
                 if (!columnBinding.IsValueNull())
                 {
                     item.baseColumnName = columnBinding.ValueString();
                 }
             }
             list.Add(item);
         }
     }
     int count = list.Count;
     if (propertyValue is int)
     {
         count -= (int) propertyValue;
     }
     bool flag = false;
     for (int i = list.Count - 1; count <= i; i--)
     {
         System.Data.OleDb.MetaData data3 = list[i];
         data3.isHidden = true;
         if (flag)
         {
             data3.isKeyColumn = false;
         }
         else if (data3.guid.Equals(ODB.DBCOL_SPECIALCOL))
         {
             data3.isKeyColumn = false;
             flag = true;
             for (int k = list.Count - 1; i < k; k--)
             {
                 list[k].isKeyColumn = false;
             }
         }
     }
     for (int j = count - 1; 0 <= j; j--)
     {
         System.Data.OleDb.MetaData data2 = list[j];
         if (flag)
         {
             data2.isKeyColumn = false;
         }
         if (data2.guid.Equals(ODB.DBCOL_SPECIALCOL))
         {
             data2.isHidden = true;
             count--;
         }
         else if (0 >= ((int) data2.ordinal))
         {
             data2.isHidden = true;
             count--;
         }
         else if (DoColumnDropFilter(data2.flags))
         {
             data2.isHidden = true;
             count--;
         }
     }
     list.Sort();
     this._visibleFieldCount = count;
     this._metadata = list.ToArray();
 }
Ejemplo n.º 37
0
 override public int GetOrdinal(string value) {
     if (null == _fieldNameLookup) {
         if (null == this.dataCache) {
             throw ADP.DataReaderNoData();
         }
         _fieldNameLookup = new FieldNameLookup(this, -1);
     }
     return _fieldNameLookup.GetOrdinal(value); // MDAC 71470
 }
        public override bool NextResult()
        {
            bool flag;
            SqlStatistics statistics = null;
            IntPtr ptr;
            Bid.ScopeEnter(out ptr, "<sc.SqlDataReader.NextResult|API> %d#", this.ObjectID);
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                statistics = SqlStatistics.StartTimer(this.Statistics);
                this.SetTimeout();
                if (this.IsClosed)
                {
                    throw ADP.DataReaderClosed("NextResult");
                }
                this._fieldNameLookup = null;
                bool flag2 = false;
                this._hasRows = false;
                if (this.IsCommandBehavior(CommandBehavior.SingleResult))
                {
                    this.CloseInternal(false);
                    this.ClearMetaData();
                    return flag2;
                }
                if (this._parser != null)
                {
                    while (this.ReadInternal(false))
                    {
                    }
                }
                if (this._parser != null)
                {
                    if (this.HasMoreResults())
                    {
                        this._metaDataConsumed = false;
                        this._browseModeInfoConsumed = false;
                        switch (this._altRowStatus)
                        {
                            case ALTROWSTATUS.AltRow:
                            {
                                int altRowId = this._parser.GetAltRowId(this._stateObj);
                                _SqlMetaDataSet altMetaData = this._altMetaDataSetCollection.GetAltMetaData(altRowId);
                                if (altMetaData != null)
                                {
                                    this._metaData = altMetaData;
                                    this._metaData.indexMap = altMetaData.indexMap;
                                }
                                break;
                            }
                            case ALTROWSTATUS.Done:
                                this._metaData = this._altMetaDataSetCollection.metaDataSet;
                                this._altRowStatus = ALTROWSTATUS.Null;
                                break;

                            default:
                                this.ConsumeMetaData();
                                if (this._metaData == null)
                                {
                                    return false;
                                }
                                break;
                        }
                        return true;
                    }
                    this.CloseInternal(false);
                    this.SetMetaData(null, false);
                    return flag2;
                }
                this.ClearMetaData();
                return flag2;
            }
            catch (OutOfMemoryException exception3)
            {
                this._isClosed = true;
                if (this._connection != null)
                {
                    this._connection.Abort(exception3);
                }
                throw;
            }
            catch (StackOverflowException exception2)
            {
                this._isClosed = true;
                if (this._connection != null)
                {
                    this._connection.Abort(exception2);
                }
                throw;
            }
            catch (ThreadAbortException exception)
            {
                this._isClosed = true;
                if (this._connection != null)
                {
                    this._connection.Abort(exception);
                }
                throw;
            }
            finally
            {
                SqlStatistics.StopTimer(statistics);
                Bid.ScopeLeave(ref ptr);
            }
            return flag;
        }
        public RecordStateFactory(
            int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo,
            Expression<Func<Shaper, bool>> gatherData, string[] propertyNames, TypeUsage[] typeUsages, bool[] isColumnNested)
        {
            StateSlotNumber = stateSlotNumber;
            ColumnCount = columnCount;
            NestedRecordStateFactories = new ReadOnlyCollection<RecordStateFactory>(nestedRecordStateFactories);
            DataRecordInfo = dataRecordInfo;
            GatherData = gatherData.Compile();
            Description = gatherData.ToString();
            ColumnNames = new ReadOnlyCollection<string>(propertyNames);
            TypeUsages = new ReadOnlyCollection<TypeUsage>(typeUsages);

            FieldNameLookup = new FieldNameLookup(ColumnNames, -1);

            // pre-compute the nested objects from typeUsage, for performance
            if (isColumnNested == null)
            {
                isColumnNested = new bool[columnCount];

                for (var ordinal = 0; ordinal < columnCount; ordinal++)
                {
                    switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                    {
                        case BuiltInTypeKind.EntityType:
                        case BuiltInTypeKind.ComplexType:
                        case BuiltInTypeKind.RowType:
                        case BuiltInTypeKind.CollectionType:
                            isColumnNested[ordinal] = true;
                            HasNestedColumns = true;
                            break;
                        default:
                            isColumnNested[ordinal] = false;
                            break;
                    }
                }
            }
            IsColumnNested = new ReadOnlyCollection<bool>(isColumnNested);
        }
Ejemplo n.º 40
0
 private int IndexOf(string value) {
     if (null == _fieldNameLookup) {
         if (null == this.dataCache) {
             throw ADP.DataReaderNoData();
         }
         _fieldNameLookup = new FieldNameLookup(this, -1);
     }
     return _fieldNameLookup.IndexOf(value);
 }
Ejemplo n.º 41
-1
        private void Close(bool disposing) {
            Exception error = null;

            CMDWrapper wrapper = _cmdWrapper;
            if (null != wrapper && wrapper.StatementHandle != null) {
                        // disposing
                        // true to release both managed and unmanaged resources; false to release only unmanaged resources.
                        //
                if (IsNonCancelingCommand) {
                            //Read any remaining results off the wire
                    // some batch statements may not be executed until SQLMoreResults is called.
                    // We want the user to be able to do ExecuteNonQuery or ExecuteReader
                    // and close without having iterate to get params or batch.
                    //
                    NextResult(disposing, !disposing); // false,true or true,false
                            if (null != command) {
                        if (command.HasParameters) {
                            // Output Parameters are not guareenteed to be returned until all the data
                            // from any restssets are read, so we do this after the above NextResult call(s)
                            command.Parameters.GetOutputValues(_cmdWrapper);
                        }
                        wrapper.FreeStatementHandle(ODBC32.STMT.CLOSE);
                                command.CloseFromDataReader();
                            }
                        }
                wrapper.FreeKeyInfoStatementHandle(ODBC32.STMT.CLOSE);
                }

                // if the command is still around we call CloseFromDataReader,
                // otherwise we need to dismiss the statement handle ourselves
                //
                if (null != command) {
                    command.CloseFromDataReader();

                if(IsCommandBehavior(CommandBehavior.CloseConnection)) {
                        Debug.Assert(null != Connection, "null cmd connection");
                    command.Parameters.RebindCollection = true;
                        Connection.Close();
                    }
                }
            else if (null != wrapper) {
                wrapper.Dispose();
            }

            this.command = null;
            _isClosed=true;
            this.dataCache = null;
            this.metadata = null;
            this.schemaTable = null;
            _isRead = false;
            _hasRows = HasRowsStatus.DontKnow;
            _isValidResult = false;
            _noMoreResults = true;
            _noMoreRows = true;
            _fieldNameLookup = null;

            SetCurrentRowColumnInfo(-1, 0);

            if ((null != error) && !disposing) {
                throw error;
            }
            _cmdWrapper = null;
        }