Beispiel #1
0
        private int FillFromRecord(object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable)
        {
            object?result = null;

            try
            {
                result = record.get_Row();
            }
            catch (Exception e)
            {
                // UNDONE - should not be catching all exceptions!!!
                if (!ADP.IsCatchableExceptionType(e))
                {
                    throw;
                }

                throw ODB.Fill_EmptyRecord("adodb", e);
            }

            if (null != result)
            {
                CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;
                behavior |= CommandBehavior.SequentialAccess | CommandBehavior.SingleRow;

                OleDbDataReader?dataReader = null;
                try
                {
                    dataReader = new OleDbDataReader(null, null, 0, behavior);
                    dataReader.InitializeIRow(result, ADP.RecordsUnaffected);
                    dataReader.BuildMetaInfo();

                    if (data is DataTable)
                    {
                        return(base.Fill((DataTable)data, dataReader));
                    }
                    else
                    {
                        return(base.Fill((DataSet)data, srcTable, dataReader, 0, 0));
                    }
                }
                finally
                {
                    if (null != dataReader)
                    {
                        dataReader.Close();
                    }
                }
            }
            return(0);
        }
Beispiel #2
0
        private int FillFromRecord(Object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable)
        {
            object result = null;

            try {
                Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB>\n");
                result = record.get_Row(); // MDAC 83342
                Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB|RET> %08X{HRESULT}\n", 0);
            }
            catch (Exception e) {
                //
                if (!ADP.IsCatchableExceptionType(e))
                {
                    throw;
                }

                throw ODB.Fill_EmptyRecord("adodb", e);
            }

            if (null != result)
            {
                CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;
                behavior |= CommandBehavior.SequentialAccess | CommandBehavior.SingleRow;

                OleDbDataReader dataReader = null;
                try {
                    dataReader = new OleDbDataReader(null, null, 0, behavior);
                    dataReader.InitializeIRow(result, ADP.RecordsUnaffected);
                    dataReader.BuildMetaInfo();

                    if (data is DataTable)
                    {
                        return(base.Fill((DataTable)data, dataReader)); // MDAC 65506
                    }
                    else
                    {
                        return(base.Fill((DataSet)data, srcTable, dataReader, 0, 0));
                    }
                }
                finally {
                    if (null != dataReader)
                    {
                        dataReader.Close();
                    }
                }
            }
            return(0);
        }
        private int FillFromRecord(Object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable)
        {
            object result = null;

            try {
                int hr;
#if DEBUG
                ODB.Trace_Begin("ADORecordConstruction", "get_Row");
#endif
                hr = record.get_Row(out result);
#if DEBUG
                ODB.Trace_End("ADORecordConstruction", "get_Row", hr);
#endif
            }
            catch (Exception e) {
                ADP.TraceException(e);
                throw ODB.Fill_EmptyRecord("adodb", e);
            }

            if (null != result)
            {
                CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;

                try {
                    using (OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, IntPtr.Zero)) {
                        dataReader.InitializeIRow(result, -1, behavior | CommandBehavior.SingleRow);
                        dataReader.BuildMetaInfo();

                        if (data is DataTable)
                        {
                            return(base.Fill((DataTable)data, dataReader)); // MDAC 65506
                        }
                        else
                        {
                            return(base.Fill((DataSet)data, srcTable, dataReader, 0, 0));
                        }
                    }
                }
                catch { // MDAC 80973
                    throw;
                }
            }
            return(0);
        }
        private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method) {
            OleDbDataReader dataReader = null;
            OleDbException nextResultsFailure = null;
            int state = ODB.InternalStateClosed;
            try {
                ValidateConnectionAndTransaction(method);

                if (0 != (CommandBehavior.SingleRow & behavior)) {
                    // CommandBehavior.SingleRow implies CommandBehavior.SingleResult
                    behavior |= CommandBehavior.SingleResult;
                }

                object executeResult;
                int resultType;

                switch(CommandType) {
                case 0: // uninitialized CommandType.Text
                case CommandType.Text:
                case CommandType.StoredProcedure:
                    resultType = ExecuteCommand(behavior, out executeResult);
                    break;

                case CommandType.TableDirect:
                    resultType = ExecuteTableDirect(behavior, out executeResult);
                    break;

                default:
                    throw ADP.InvalidCommandType(CommandType);
                }

                if (_executeQuery) {
                    try {
                        dataReader = new OleDbDataReader(_connection, this, 0, this.commandBehavior);

                        switch(resultType) {
                        case ODB.ExecutedIMultipleResults:
                            dataReader.InitializeIMultipleResults(executeResult);
                            dataReader.NextResult();
                            break;
                        case ODB.ExecutedIRowset:
                            dataReader.InitializeIRowset(executeResult, ChapterHandle.DB_NULL_HCHAPTER, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            dataReader.HasRowsRead();
                            break;
                        case ODB.ExecutedIRow:
                            dataReader.InitializeIRow(executeResult, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            break;
                        case ODB.PrepareICommandText:
                            if (!_isPrepared) {
                                PrepareCommandText(2);
                            }
                            OleDbDataReader.GenerateSchemaTable(dataReader, _icommandText, behavior);
                            break;
                        default:
                            Debug.Assert(false, "ExecuteReaderInternal: unknown result type");
                            break;
                        }
                        executeResult = null;
                        _hasDataReader = true;
                        _connection.AddWeakReference(dataReader, OleDbReferenceCollection.DataReaderTag);

                        // command stays in the executing state until the connection
                        // has a datareader to track for it being closed
                        state = ODB.InternalStateOpen; // MDAC 72655
                    }
                    finally {
                        if (ODB.InternalStateOpen != state) {
                            this.canceling = true;
                            if (null != dataReader) {
                                ((IDisposable) dataReader).Dispose();
                                dataReader = null;
                            }
                        }
                    }
                    Debug.Assert(null != dataReader, "ExecuteReader should never return a null DataReader");
                }
                else { // optimized code path for ExecuteNonQuery to not create a OleDbDataReader object
                    try {
                        if (ODB.ExecutedIMultipleResults == resultType) {
                            UnsafeNativeMethods.IMultipleResults multipleResults = (UnsafeNativeMethods.IMultipleResults) executeResult;

                            // may cause a Connection.ResetState which closes connection
                            nextResultsFailure = OleDbDataReader.NextResults(multipleResults, _connection, this, out _recordsAffected);
                        }
                    }
                    finally {
                        try {
                            if (null != executeResult) {
                                Marshal.ReleaseComObject(executeResult);
                                executeResult = null;
                            }
                            CloseFromDataReader(ParameterBindings);
                        }
                        catch(Exception e) {
                            // 
                            if (!ADP.IsCatchableExceptionType(e)) {
                                throw;
                            }
                            if (null != nextResultsFailure) {
                                nextResultsFailure = new OleDbException(nextResultsFailure, e);
                            }
                            else {
                                throw;
                            }
                        }
                    }
                }
            }
            finally { // finally clear executing state
                try {
                    if ((null == dataReader) && (ODB.InternalStateOpen != state)) { // MDAC 67218
                        ParameterCleanup();
                    }
                }
                catch(Exception e) {
                    // 
                    if (!ADP.IsCatchableExceptionType(e)) {
                        throw;
                    }
                    if (null != nextResultsFailure) {
                        nextResultsFailure = new OleDbException(nextResultsFailure, e);
                    }
                    else {
                        throw;
                    }
                }
                if (null != nextResultsFailure) {
                    throw nextResultsFailure;
                }
            }
            return dataReader;
        }
Beispiel #5
0
        private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method)
        {
            OleDbDataReader dataReader         = null;
            OleDbException  nextResultsFailure = null;
            int             state = ODB.InternalStateClosed;

            try
            {
                ValidateConnectionAndTransaction(method);

                if (0 != (CommandBehavior.SingleRow & behavior))
                {
                    // CommandBehavior.SingleRow implies CommandBehavior.SingleResult
                    behavior |= CommandBehavior.SingleResult;
                }

                object executeResult;
                int    resultType;

                switch (CommandType)
                {
                case 0:     // uninitialized CommandType.Text
                case CommandType.Text:
                case CommandType.StoredProcedure:
                    resultType = ExecuteCommand(behavior, out executeResult);
                    break;

                case CommandType.TableDirect:
                    resultType = ExecuteTableDirect(behavior, out executeResult);
                    break;

                default:
                    throw ADP.InvalidCommandType(CommandType);
                }

                if (_executeQuery)
                {
                    try
                    {
                        dataReader = new OleDbDataReader(_connection, this, 0, this.commandBehavior);

                        switch (resultType)
                        {
                        case ODB.ExecutedIMultipleResults:
                            dataReader.InitializeIMultipleResults(executeResult);
                            dataReader.NextResult();
                            break;

                        case ODB.ExecutedIRowset:
                            dataReader.InitializeIRowset(executeResult, ChapterHandle.DB_NULL_HCHAPTER, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            dataReader.HasRowsRead();
                            break;

                        case ODB.ExecutedIRow:
                            dataReader.InitializeIRow(executeResult, _recordsAffected);
                            dataReader.BuildMetaInfo();
                            break;

                        case ODB.PrepareICommandText:
                            if (!_isPrepared)
                            {
                                PrepareCommandText(2);
                            }
                            OleDbDataReader.GenerateSchemaTable(dataReader, _icommandText, behavior);
                            break;

                        default:
                            Debug.Assert(false, "ExecuteReaderInternal: unknown result type");
                            break;
                        }
                        executeResult  = null;
                        _hasDataReader = true;
                        _connection.AddWeakReference(dataReader, OleDbReferenceCollection.DataReaderTag);

                        // command stays in the executing state until the connection
                        // has a datareader to track for it being closed
                        state = ODB.InternalStateOpen;
                    }
                    finally
                    {
                        if (ODB.InternalStateOpen != state)
                        {
                            this.canceling = true;
                            if (null != dataReader)
                            {
                                ((IDisposable)dataReader).Dispose();
                                dataReader = null;
                            }
                        }
                    }
                    Debug.Assert(null != dataReader, "ExecuteReader should never return a null DataReader");
                }
                else
                { // optimized code path for ExecuteNonQuery to not create a OleDbDataReader object
                    try
                    {
                        if (ODB.ExecutedIMultipleResults == resultType)
                        {
                            UnsafeNativeMethods.IMultipleResults multipleResults = (UnsafeNativeMethods.IMultipleResults)executeResult;

                            // may cause a Connection.ResetState which closes connection
                            nextResultsFailure = OleDbDataReader.NextResults(multipleResults, _connection, this, out _recordsAffected);
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (null != executeResult)
                            {
                                Marshal.ReleaseComObject(executeResult);
                                executeResult = null;
                            }
                            CloseFromDataReader(ParameterBindings);
                        }
                        catch (Exception e)
                        {
                            // UNDONE - should not be catching all exceptions!!!
                            if (!ADP.IsCatchableExceptionType(e))
                            {
                                throw;
                            }
                            if (null != nextResultsFailure)
                            {
                                nextResultsFailure = new OleDbException(nextResultsFailure, e);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }
            finally
            { // finally clear executing state
                try
                {
                    if ((null == dataReader) && (ODB.InternalStateOpen != state))
                    {
                        ParameterCleanup();
                    }
                }
                catch (Exception e)
                {
                    // UNDONE - should not be catching all exceptions!!!
                    if (!ADP.IsCatchableExceptionType(e))
                    {
                        throw;
                    }
                    if (null != nextResultsFailure)
                    {
                        nextResultsFailure = new OleDbException(nextResultsFailure, e);
                    }
                    else
                    {
                        throw;
                    }
                }
                if (null != nextResultsFailure)
                {
                    throw nextResultsFailure;
                }
            }
            return(dataReader);
        }
        private int FillFromRecord(Object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable) {
            object result = null;
            try {
                Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB>\n");
                result = record.get_Row(); // MDAC 83342
                Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB|RET> %08X{HRESULT}\n", 0);
            }
            catch(Exception e) {
                // 
                if (!ADP.IsCatchableExceptionType(e)) {
                    throw;
                }                        
            
                throw ODB.Fill_EmptyRecord("adodb", e);
            }

            if (null != result) {
                CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;
                behavior |= CommandBehavior.SequentialAccess | CommandBehavior.SingleRow;

                OleDbDataReader dataReader = null;
                try {
                    dataReader = new OleDbDataReader(null, null, 0, behavior);
                    dataReader.InitializeIRow(result, ADP.RecordsUnaffected);
                    dataReader.BuildMetaInfo();

                    if (data is DataTable) {
                        return base.Fill((DataTable) data, dataReader); // MDAC 65506
                    }
                    else {
                        return base.Fill((DataSet) data, srcTable, dataReader, 0, 0);
                    }
                }
                finally {
                    if (null != dataReader) {
                        dataReader.Close();
                    }
                }
            }
            return 0;
        }
 private int FillFromRecord(object data, System.Data.Common.UnsafeNativeMethods.ADORecordConstruction record, string srcTable)
 {
     object result = null;
     try
     {
         Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB>\n");
         result = record.get_Row();
         Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB|RET> %08X{HRESULT}\n", 0);
     }
     catch (Exception exception)
     {
         if (!ADP.IsCatchableExceptionType(exception))
         {
             throw;
         }
         throw ODB.Fill_EmptyRecord("adodb", exception);
     }
     if (result != null)
     {
         CommandBehavior commandBehavior = (MissingSchemaAction.AddWithKey != base.MissingSchemaAction) ? CommandBehavior.Default : CommandBehavior.KeyInfo;
         commandBehavior |= CommandBehavior.SequentialAccess | CommandBehavior.SingleRow;
         OleDbDataReader dataReader = null;
         try
         {
             dataReader = new OleDbDataReader(null, null, 0, commandBehavior);
             dataReader.InitializeIRow(result, ADP.RecordsUnaffected);
             dataReader.BuildMetaInfo();
             if (data is DataTable)
             {
                 return base.Fill((DataTable) data, dataReader);
             }
             return base.Fill((DataSet) data, srcTable, dataReader, 0, 0);
         }
         finally
         {
             if (dataReader != null)
             {
                 dataReader.Close();
             }
         }
     }
     return 0;
 }
        private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method)
        {
            OleDbDataReader dataReader = null;
            OleDbException previous = null;
            int num2 = 0;
            try
            {
                object obj2;
                int num;
                this.ValidateConnectionAndTransaction(method);
                if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default)
                {
                    behavior |= CommandBehavior.SingleResult;
                }
                switch (this.CommandType)
                {
                    case ((System.Data.CommandType) 0):
                    case System.Data.CommandType.Text:
                    case System.Data.CommandType.StoredProcedure:
                        num = this.ExecuteCommand(behavior, out obj2);
                        break;

                    case System.Data.CommandType.TableDirect:
                        num = this.ExecuteTableDirect(behavior, out obj2);
                        break;

                    default:
                        throw ADP.InvalidCommandType(this.CommandType);
                }
                if (this._executeQuery)
                {
                    try
                    {
                        dataReader = new OleDbDataReader(this._connection, this, 0, this.commandBehavior);
                        switch (num)
                        {
                            case 0:
                                dataReader.InitializeIMultipleResults(obj2);
                                dataReader.NextResult();
                                break;

                            case 1:
                                dataReader.InitializeIRowset(obj2, ChapterHandle.DB_NULL_HCHAPTER, this._recordsAffected);
                                dataReader.BuildMetaInfo();
                                dataReader.HasRowsRead();
                                break;

                            case 2:
                                dataReader.InitializeIRow(obj2, this._recordsAffected);
                                dataReader.BuildMetaInfo();
                                break;

                            case 3:
                                if (!this._isPrepared)
                                {
                                    this.PrepareCommandText(2);
                                }
                                OleDbDataReader.GenerateSchemaTable(dataReader, this._icommandText, behavior);
                                break;
                        }
                        obj2 = null;
                        this._hasDataReader = true;
                        this._connection.AddWeakReference(dataReader, 2);
                        num2 = 1;
                        return dataReader;
                    }
                    finally
                    {
                        if (1 != num2)
                        {
                            this.canceling = true;
                            if (dataReader != null)
                            {
                                dataReader.Dispose();
                                dataReader = null;
                            }
                        }
                    }
                }
                try
                {
                    if (num == 0)
                    {
                        UnsafeNativeMethods.IMultipleResults imultipleResults = (UnsafeNativeMethods.IMultipleResults) obj2;
                        previous = OleDbDataReader.NextResults(imultipleResults, this._connection, this, out this._recordsAffected);
                    }
                }
                finally
                {
                    try
                    {
                        if (obj2 != null)
                        {
                            Marshal.ReleaseComObject(obj2);
                            obj2 = null;
                        }
                        this.CloseFromDataReader(this.ParameterBindings);
                    }
                    catch (Exception exception3)
                    {
                        if (!ADP.IsCatchableExceptionType(exception3))
                        {
                            throw;
                        }
                        if (previous == null)
                        {
                            throw;
                        }
                        previous = new OleDbException(previous, exception3);
                    }
                }
            }
            finally
            {
                try
                {
                    if ((dataReader == null) && (1 != num2))
                    {
                        this.ParameterCleanup();
                    }
                }
                catch (Exception exception2)
                {
                    if (!ADP.IsCatchableExceptionType(exception2))
                    {
                        throw;
                    }
                    if (previous == null)
                    {
                        throw;
                    }
                    previous = new OleDbException(previous, exception2);
                }
                if (previous != null)
                {
                    throw previous;
                }
            }
            return dataReader;
        }
        private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method)
        {
            OleDbDataReader dataReader = null;
            OleDbException  previous   = null;
            int             num2       = 0;

            try
            {
                object obj2;
                int    num;
                this.ValidateConnectionAndTransaction(method);
                if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default)
                {
                    behavior |= CommandBehavior.SingleResult;
                }
                switch (this.CommandType)
                {
                case ((System.Data.CommandType) 0):
                case System.Data.CommandType.Text:
                case System.Data.CommandType.StoredProcedure:
                    num = this.ExecuteCommand(behavior, out obj2);
                    break;

                case System.Data.CommandType.TableDirect:
                    num = this.ExecuteTableDirect(behavior, out obj2);
                    break;

                default:
                    throw ADP.InvalidCommandType(this.CommandType);
                }
                if (this._executeQuery)
                {
                    try
                    {
                        dataReader = new OleDbDataReader(this._connection, this, 0, this.commandBehavior);
                        switch (num)
                        {
                        case 0:
                            dataReader.InitializeIMultipleResults(obj2);
                            dataReader.NextResult();
                            break;

                        case 1:
                            dataReader.InitializeIRowset(obj2, ChapterHandle.DB_NULL_HCHAPTER, this._recordsAffected);
                            dataReader.BuildMetaInfo();
                            dataReader.HasRowsRead();
                            break;

                        case 2:
                            dataReader.InitializeIRow(obj2, this._recordsAffected);
                            dataReader.BuildMetaInfo();
                            break;

                        case 3:
                            if (!this._isPrepared)
                            {
                                this.PrepareCommandText(2);
                            }
                            OleDbDataReader.GenerateSchemaTable(dataReader, this._icommandText, behavior);
                            break;
                        }
                        obj2 = null;
                        this._hasDataReader = true;
                        this._connection.AddWeakReference(dataReader, 2);
                        num2 = 1;
                        return(dataReader);
                    }
                    finally
                    {
                        if (1 != num2)
                        {
                            this.canceling = true;
                            if (dataReader != null)
                            {
                                dataReader.Dispose();
                                dataReader = null;
                            }
                        }
                    }
                }
                try
                {
                    if (num == 0)
                    {
                        UnsafeNativeMethods.IMultipleResults imultipleResults = (UnsafeNativeMethods.IMultipleResults)obj2;
                        previous = OleDbDataReader.NextResults(imultipleResults, this._connection, this, out this._recordsAffected);
                    }
                }
                finally
                {
                    try
                    {
                        if (obj2 != null)
                        {
                            Marshal.ReleaseComObject(obj2);
                            obj2 = null;
                        }
                        this.CloseFromDataReader(this.ParameterBindings);
                    }
                    catch (Exception exception3)
                    {
                        if (!ADP.IsCatchableExceptionType(exception3))
                        {
                            throw;
                        }
                        if (previous == null)
                        {
                            throw;
                        }
                        previous = new OleDbException(previous, exception3);
                    }
                }
            }
            finally
            {
                try
                {
                    if ((dataReader == null) && (1 != num2))
                    {
                        this.ParameterCleanup();
                    }
                }
                catch (Exception exception2)
                {
                    if (!ADP.IsCatchableExceptionType(exception2))
                    {
                        throw;
                    }
                    if (previous == null)
                    {
                        throw;
                    }
                    previous = new OleDbException(previous, exception2);
                }
                if (previous != null)
                {
                    throw previous;
                }
            }
            return(dataReader);
        }