Ejemplo n.º 1
0
 // IDBSchemaRowset.GetSchemas
 internal DualCoTaskMem(UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset, out int schemaCount, out IntPtr schemaGuids, out IntPtr schemaRestrictions, out OleDbHResult hr) : this() {
     Bid.Trace("<oledb.IDBSchemaRowset.GetSchemas|API|OLEDB>\n");
     hr = dbSchemaRowset.GetSchemas(out schemaCount, out base.handle, out this.handle2);
     schemaGuids = base.handle;
     schemaRestrictions = this.handle2;
     Bid.Trace("<oledb.IDBSchemaRowset.GetSchemas|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsInfo columnsInfo, out IntPtr columnCount, out IntPtr columnInfos, out OleDbHResult hr) : this()
 {
     Bid.Trace("<oledb.IColumnsInfo.GetColumnInfo|API|OLEDB>\n");
     hr = columnsInfo.GetColumnInfo(out columnCount, out this.handle, out this.handle2);
     columnInfos = base.handle;
     Bid.Trace("<oledb.IColumnsInfo.GetColumnInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
Ejemplo n.º 3
0
        // IDBInfo.GetLiteralInfo
        internal DualCoTaskMem(UnsafeNativeMethods.IDBInfo dbInfo, int[] literals, out int literalCount, out IntPtr literalInfo, out OleDbHResult hr) : this() {
            int count = (null != literals) ? literals.Length : 0;

            Bid.Trace("<oledb.IDBInfo.GetLiteralInfo|API|OLEDB>\n");
            hr = dbInfo.GetLiteralInfo(count, literals, out literalCount, out base.handle, out this.handle2);
            literalInfo = base.handle;
            Bid.Trace("<oledb.IDBInfo.GetLiteralInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
        }
 internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction) {
     int transactionLevel = 0;
     Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB>\n");
     RuntimeHelpers.PrepareConstrainedRegions();
     try { } finally {
         hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out transactionLevel);
         if (0 <= hr) {
             _mustComplete = true;
         }
     }
     Bid.Trace("<oledb.ITransactionLocal.StartTransaction|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
Ejemplo n.º 5
0
 internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, PropertyIDSet propIDSet) : base(IntPtr.Zero, true) {
     OleDbHResult hr;
     int propIDSetCount = propIDSet.Count; // avoid need for ReliabilityContract on get_Count
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB>\n");
     RuntimeHelpers.PrepareConstrainedRegions();
     try {} finally {
         hr = idbProperties.GetPropertyInfo(propIDSetCount, propIDSet, out this.setCount, out base.handle, out this.descBuffer);
     }
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);
     if ((0 <= hr) && (ADP.PtrZero != handle)) {
         SafeNativeMethods.Wrapper.ClearErrorInfo();
     }
 }
 internal DBPropSet(UnsafeNativeMethods.IRowsetInfo properties, PropertyIDSet propidset, out OleDbHResult hr) : this()
 {
     int cPropertyIDSets = 0;
     if (propidset != null)
     {
         cPropertyIDSets = propidset.Count;
     }
     Bid.Trace("<oledb.IRowsetInfo.GetProperties|API|OLEDB>\n");
     hr = properties.GetProperties(cPropertyIDSets, propidset, out this.propertySetCount, out this.handle);
     Bid.Trace("<oledb.IRowsetInfo.GetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);
     if (hr < OleDbHResult.S_OK)
     {
         this.SetLastErrorInfo(hr);
     }
 }
Ejemplo n.º 7
0
        internal DBPropSet(UnsafeNativeMethods.ICommandProperties properties, PropertyIDSet propidset, out OleDbHResult hr) : this() {
            Debug.Assert(null != properties, "null ICommandProperties");

            int propidsetcount = 0;
            if (null != propidset) {
                propidsetcount = propidset.Count;
            }
            Bid.Trace("<oledb.ICommandProperties.GetProperties|API|OLEDB>\n");
            hr = properties.GetProperties(propidsetcount, propidset, out this.propertySetCount, out base.handle);
            Bid.Trace("<oledb.ICommandProperties.GetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);

            if (hr < 0) {
                // VSDD 621427: remember the last HRESULT. Note we do not want to raise exception now to avoid breaking change from Orcas RTM/SP1
                SetLastErrorInfo(hr);
            }
        }
Ejemplo n.º 8
0
        readonly private ArrayList items; // WebData 106655

        internal OleDbErrorCollection(UnsafeNativeMethods.IErrorInfo errorInfo) {
            ArrayList items = new ArrayList();

            Bid.Trace("<oledb.IUnknown.QueryInterface|API|OS> IErrorRecords\n");
            UnsafeNativeMethods.IErrorRecords errorRecords = (errorInfo as UnsafeNativeMethods.IErrorRecords);
            if (null != errorRecords) {

                int recordCount = errorRecords.GetRecordCount();
                Bid.Trace("<oledb.IErrorRecords.GetRecordCount|API|OS|RET> RecordCount=%d\n", recordCount);

                for (int i = 0; i < recordCount; ++i) {
                    OleDbError error = new OleDbError(errorRecords, i);
                    items.Add(error);
                }
            }
            this.items = items;
        }
 internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, PropertyIDSet propIDSet) : base(IntPtr.Zero, true)
 {
     OleDbHResult result;
     int count = propIDSet.Count;
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB>\n");
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         result = idbProperties.GetPropertyInfo(count, propIDSet, out this.setCount, out this.handle, out this.descBuffer);
     }
     Bid.Trace("<oledb.IDBProperties.GetPropertyInfo|API|OLEDB|RET> %08X{HRESULT}\n", result);
     if ((OleDbHResult.S_OK <= result) && (ADP.PtrZero != base.handle))
     {
         SafeNativeMethods.Wrapper.ClearErrorInfo();
     }
 }
Ejemplo n.º 10
0
        static internal OleDbException CreateException(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode, Exception inner) { // MDAC 84364
            OleDbErrorCollection errors = new OleDbErrorCollection(errorInfo);
            string message = null;
            string source = null;
            OleDbHResult hr = 0;

            if (null != errorInfo) {
                hr = errorInfo.GetDescription(out message);
                Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Description='%ls'\n", hr, message);

                hr = errorInfo.GetSource(out source);
                Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> %08X{HRESULT}, Source='%ls'\n", hr, source);
            }

            int count = errors.Count;
            if (0 < errors.Count) {
                StringBuilder builder = new StringBuilder();

                if ((null != message) && (message != errors[0].Message)) { // WebData 103032
                    builder.Append(message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707
                    if (1 < count) {
                        builder.Append(Environment.NewLine);
                    }
                }
                for (int i = 0; i < count; ++i) {
                    if (0 < i) {
                        builder.Append(Environment.NewLine);
                    }
                    builder.Append(errors[i].Message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707
                }
                message = builder.ToString();
            }
            if (ADP.IsEmpty(message)) {
                message = ODB.NoErrorMessage(errorCode); // MDAC 71170
            }
            return new OleDbException(message, inner, source, errorCode, errors);
        }
 internal OleDbHResult CreateAccessor(UnsafeNativeMethods.IAccessor iaccessor, int flags, ColumnBinding[] bindings)
 {
     OleDbHResult result = OleDbHResult.S_OK;
     int[] rgStatus = new int[this.BindingCount()];
     this._iaccessor = iaccessor;
     Bid.Trace("<oledb.IAccessor.CreateAccessor|API|OLEDB>\n");
     result = iaccessor.CreateAccessor(flags, (IntPtr) rgStatus.Length, this, (IntPtr) this._dataLength, out this._accessorHandle, rgStatus);
     Bid.Trace("<oledb.IAccessor.CreateAccessor|API|OLEDB|RET> %08X{HRESULT}\n", result);
     for (int i = 0; i < rgStatus.Length; i++)
     {
         if (rgStatus[i] != 0)
         {
             if (4 == flags)
             {
                 throw ODB.BadStatus_ParamAcc(bindings[i].ColumnBindingOrdinal, (DBBindStatus) rgStatus[i]);
             }
             if (2 == flags)
             {
                 throw ODB.BadStatusRowAccessor(bindings[i].ColumnBindingOrdinal, (DBBindStatus) rgStatus[i]);
             }
         }
     }
     return result;
 }
Ejemplo n.º 12
0
        private void ApplyParameterBindings(UnsafeNativeMethods.ICommandWithParameters commandWithParameters, tagDBPARAMBINDINFO[] bindInfo) {
            IntPtr[] ordinals = new IntPtr[bindInfo.Length];
            for (int i = 0; i < ordinals.Length; ++i) {
                ordinals[i] = (IntPtr)(i+1);
            }

            Bid.Trace("<oledb.ICommandWithParameters.SetParameterInfo|API|OLEDB> %d#\n", ObjectID);
            OleDbHResult hr = commandWithParameters.SetParameterInfo((IntPtr)bindInfo.Length, ordinals, bindInfo);
            Bid.Trace("<oledb.ICommandWithParameters.SetParameterInfo|API|OLEDB|RET> %08X{HRESULT}\n", hr);

            if (hr < 0) {
                ProcessResults(hr);
            }
        }
Ejemplo n.º 13
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.º 14
0
        static internal OleDbException NextResults(UnsafeNativeMethods.IMultipleResults imultipleResults, OleDbConnection connection, OleDbCommand command, out IntPtr recordsAffected) {
            recordsAffected = ADP.RecordsUnaffected;
            List<OleDbException> exceptions = null; // WebData 104564
            if (null != imultipleResults) {
                object result;
                IntPtr affected;
                OleDbHResult hr;


                // MSOLAP provider doesn't move onto the next result when calling GetResult with IID_NULL, but does return S_OK with 0 affected records.
                // we want to break out of that infinite loop for ExecuteNonQuery and the multiple result Close scenarios
                for (int loop = 0;; ++loop) {
                    if ((null != command) && command.canceling) { // MDAC 68964
                        break;
                    }

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

                    // If a provider doesn't support IID_NULL and returns E_NOINTERFACE we want to break out
                    // of the loop without throwing an exception.  Our behavior will match ADODB in that scenario
                    // where Recordset.Close just releases the interfaces without proccessing remaining results
                    if ((OleDbHResult.DB_S_NORESULT == hr) || (OleDbHResult.E_NOINTERFACE == hr)) { // MDAC 70874
                        break;
                    }
                    if (null != connection) {
                        Exception e = OleDbConnection.ProcessResults(hr, connection, command);
                        if (null != e) {
                            OleDbException excep = (e as OleDbException);
                            if (null != excep) {
                                if (null == exceptions) {
                                    exceptions = new List<OleDbException>();
                                }
                                exceptions.Add(excep);
                            }
                            else {
                                Debug.Assert(OleDbHResult.DB_E_OBJECTOPEN == hr, "unexpected");
                                throw e; // we don't expect to be here, but it could happen
                            }
                        }
                    }
                    else if (hr < 0) {
                        SafeNativeMethods.Wrapper.ClearErrorInfo();
                        break; // MDAC 72694
                    }
                    recordsAffected = AddRecordsAffected(recordsAffected, affected);

                    if (0 != (int)affected) {
                        loop = 0;
                    }
                    else if (2000 <= loop) { // MDAC 72126 (reason for more than 1000 iterations)
                        NextResultsInfinite(); // MDAC 72738
                        break;
                    }
                }
            }
            if (null != exceptions) {
                return OleDbException.CombineExceptions(exceptions);
            }
            return null;
        }
 internal void BeginInternal(UnsafeNativeMethods.ITransactionLocal transaction)
 {
     OleDbHResult result;
     this._transaction = new WrappedTransaction(transaction, (int) this._isolationLevel, out result);
     if (result < OleDbHResult.S_OK)
     {
         this._transaction.Dispose();
         this._transaction = null;
         this.ProcessResults(result);
     }
 }
Ejemplo n.º 16
0
        internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index) {
            OleDbHResult hr;
            int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID;

            Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS>\n");
            UnsafeNativeMethods.IErrorInfo errorInfo = errorRecords.GetErrorInfo(index, lcid);
            if (null != errorInfo) {

                Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
                hr = errorInfo.GetDescription(out this.message);
                Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message);

                if (OleDbHResult.DB_E_NOLOCALE == hr) { // MDAC 87303
                    Bid.Trace("<oledb.ReleaseComObject|API|OS> ErrorInfo\n");
                    Marshal.ReleaseComObject(errorInfo);

                    Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n");
                    lcid = SafeNativeMethods.GetUserDefaultLCID();

                    Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lcid);
                    errorInfo = errorRecords.GetErrorInfo(index, lcid);

                    if (null != errorInfo) {

                        Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
                        hr = errorInfo.GetDescription(out this.message);
                        Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message);
                    }
                }
                if ((hr < 0) && ADP.IsEmpty(this.message)) {
                    this.message = ODB.FailedGetDescription(hr);
                }
                if (null != errorInfo) {

                    Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n");
                    hr = errorInfo.GetSource(out this.source);
                    Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source);

                    if (OleDbHResult.DB_E_NOLOCALE == hr) { // MDAC 87303
                        Marshal.ReleaseComObject(errorInfo);

                        Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n");
                        lcid = SafeNativeMethods.GetUserDefaultLCID();

                        Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lcid);
                        errorInfo = errorRecords.GetErrorInfo(index, lcid);

                        if (null != errorInfo) {

                            Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n");
                            hr = errorInfo.GetSource(out this.source);
                            Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source);
                        }
                    }
                    if ((hr < 0) && ADP.IsEmpty(this.source)) {
                        this.source = ODB.FailedGetSource(hr);
                    }
                    Bid.Trace("<oledb.Marshal.ReleaseComObject|API|OS> ErrorInfo\n");
                    Marshal.ReleaseComObject(errorInfo);
                }
            }

            UnsafeNativeMethods.ISQLErrorInfo sqlErrorInfo;

            Bid.Trace("<oledb.IErrorRecords.GetCustomErrorObject|API|OS> IID_ISQLErrorInfo\n");
            hr = errorRecords.GetCustomErrorObject(index, ref ODB.IID_ISQLErrorInfo, out sqlErrorInfo);

            if (null != sqlErrorInfo) {

                Bid.Trace("<oledb.ISQLErrorInfo.GetSQLInfo|API|OS>\n");
                this.nativeError = sqlErrorInfo.GetSQLInfo(out this.sqlState);

                Bid.Trace("<oledb.ReleaseComObject|API|OS> SQLErrorInfo\n");
                Marshal.ReleaseComObject(sqlErrorInfo);
            }
        }
        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;
        }
 internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index)
 {
     OleDbHResult description;
     UnsafeNativeMethods.ISQLErrorInfo info2;
     int lCID = CultureInfo.CurrentCulture.LCID;
     Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS>\n");
     UnsafeNativeMethods.IErrorInfo errorInfo = errorRecords.GetErrorInfo(index, lCID);
     if (errorInfo != null)
     {
         Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
         description = errorInfo.GetDescription(out this.message);
         Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message);
         if (OleDbHResult.DB_E_NOLOCALE == description)
         {
             Bid.Trace("<oledb.ReleaseComObject|API|OS> ErrorInfo\n");
             Marshal.ReleaseComObject(errorInfo);
             Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n");
             lCID = SafeNativeMethods.GetUserDefaultLCID();
             Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lCID);
             errorInfo = errorRecords.GetErrorInfo(index, lCID);
             if (errorInfo != null)
             {
                 Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
                 description = errorInfo.GetDescription(out this.message);
                 Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message);
             }
         }
         if ((description < OleDbHResult.S_OK) && ADP.IsEmpty(this.message))
         {
             this.message = ODB.FailedGetDescription(description);
         }
         if (errorInfo != null)
         {
             Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n");
             description = errorInfo.GetSource(out this.source);
             Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source);
             if (OleDbHResult.DB_E_NOLOCALE == description)
             {
                 Marshal.ReleaseComObject(errorInfo);
                 Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n");
                 lCID = SafeNativeMethods.GetUserDefaultLCID();
                 Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lCID);
                 errorInfo = errorRecords.GetErrorInfo(index, lCID);
                 if (errorInfo != null)
                 {
                     Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n");
                     description = errorInfo.GetSource(out this.source);
                     Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source);
                 }
             }
             if ((description < OleDbHResult.S_OK) && ADP.IsEmpty(this.source))
             {
                 this.source = ODB.FailedGetSource(description);
             }
             Bid.Trace("<oledb.Marshal.ReleaseComObject|API|OS> ErrorInfo\n");
             Marshal.ReleaseComObject(errorInfo);
         }
     }
     Bid.Trace("<oledb.IErrorRecords.GetCustomErrorObject|API|OS> IID_ISQLErrorInfo\n");
     description = errorRecords.GetCustomErrorObject(index, ref ODB.IID_ISQLErrorInfo, out info2);
     if (info2 != null)
     {
         Bid.Trace("<oledb.ISQLErrorInfo.GetSQLInfo|API|OS>\n");
         this.nativeError = info2.GetSQLInfo(out this.sqlState);
         Bid.Trace("<oledb.ReleaseComObject|API|OS> SQLErrorInfo\n");
         Marshal.ReleaseComObject(info2);
     }
 }
 internal static OleDbException NextResults(UnsafeNativeMethods.IMultipleResults imultipleResults, OleDbConnection connection, OleDbCommand command, out IntPtr recordsAffected)
 {
     recordsAffected = ADP.RecordsUnaffected;
     List<OleDbException> exceptions = null;
     if (imultipleResults != null)
     {
         int num = 0;
         while (true)
         {
             IntPtr ptr;
             object obj2;
             if ((command != null) && command.canceling)
             {
                 break;
             }
             Bid.Trace("<oledb.IMultipleResults.GetResult|API|OLEDB> DBRESULTFLAG_DEFAULT, IID_NULL\n");
             OleDbHResult result = imultipleResults.GetResult(ADP.PtrZero, ODB.DBRESULTFLAG_DEFAULT, ref ODB.IID_NULL, out ptr, out obj2);
             Bid.Trace("<oledb.IMultipleResults.GetResult|API|OLEDB|RET> %08X{HRESULT}, RecordAffected=%Id\n", result, ptr);
             if ((OleDbHResult.DB_S_NORESULT == result) || (OleDbHResult.E_NOINTERFACE == result))
             {
                 break;
             }
             if (connection != null)
             {
                 Exception exception = OleDbConnection.ProcessResults(result, connection, command);
                 if (exception != null)
                 {
                     OleDbException item = exception as OleDbException;
                     if (item == null)
                     {
                         throw exception;
                     }
                     if (exceptions == null)
                     {
                         exceptions = new List<OleDbException>();
                     }
                     exceptions.Add(item);
                 }
             }
             else if (result < OleDbHResult.S_OK)
             {
                 SafeNativeMethods.Wrapper.ClearErrorInfo();
                 break;
             }
             recordsAffected = AddRecordsAffected(recordsAffected, ptr);
             if (((int) ptr) != 0)
             {
                 num = 0;
             }
             else if (0x7d0 <= num)
             {
                 NextResultsInfinite();
                 break;
             }
             num++;
         }
     }
     if (exceptions != null)
     {
         return OleDbException.CombineExceptions(exceptions);
     }
     return null;
 }
Ejemplo n.º 20
0
 internal OleDbHResult CreateAccessor(UnsafeNativeMethods.IAccessor iaccessor, int flags) {
     Debug.Assert(null != _rowBinding, "no row binding");
     Debug.Assert(null != _columnBindings, "no column bindings");
     return _rowBinding.CreateAccessor(iaccessor, flags, _columnBindings);
 }
 internal static OleDbHResult GetErrorDescription(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult hresult, out string message)
 {
     Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
     OleDbHResult description = errorInfo.GetDescription(out message);
     Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Message='%ls'\n", description, message);
     if ((description < OleDbHResult.S_OK) && ADP.IsEmpty(message))
     {
         message = FailedGetDescription(description) + Environment.NewLine + ELookup(hresult);
     }
     if (ADP.IsEmpty(message))
     {
         message = ELookup(hresult);
     }
     return description;
 }
Ejemplo n.º 22
0
 static internal OleDbHResult GetErrorDescription(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult hresult, out string message) {
     Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
     OleDbHResult hr = errorInfo.GetDescription(out message);
     Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Message='%ls'\n", hr, message);
     if (((int)hr < 0) && ADP.IsEmpty(message)) {
         message = FailedGetDescription(hr) + Environment.NewLine + ODB.ELookup(hresult);
     }
     if (ADP.IsEmpty(message)) {
         message = ODB.ELookup(hresult);
     }
     return hr;
 }
Ejemplo n.º 23
0
        internal void OnInfoMessage(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode) {
            OleDbInfoMessageEventHandler handler = (OleDbInfoMessageEventHandler) Events[EventInfoMessage];
            if (null != handler) {
                try {
                    OleDbException exception = OleDbException.CreateException(errorInfo, errorCode, null);
                    OleDbInfoMessageEventArgs e = new OleDbInfoMessageEventArgs(exception);
                    if (Bid.TraceOn) {
                        Bid.Trace("<oledb.OledbConnection.OnInfoMessage|API|INFO> %d#, Message='%ls'\n", ObjectID, e.Message);
                    }
                    handler(this, e);
                }
                catch (Exception e) { // eat the exception
                    // 
                    if (!ADP.IsCatchableOrSecurityExceptionType(e)) {
                        throw;
                    }

                    ADP.TraceExceptionWithoutRethrow(e);
                }
            }
#if DEBUG
            else {
                OleDbException exception = OleDbException.CreateException(errorInfo, errorCode, null);
                Bid.Trace("<oledb.OledbConnection.OnInfoMessage|API|INFO> %d#, Message='%ls'\n", ObjectID, exception.Message);
            }
#endif
        }
Ejemplo n.º 24
0
        internal OleDbHResult CreateAccessor(UnsafeNativeMethods.IAccessor iaccessor, int flags, ColumnBinding[] bindings) {
            OleDbHResult hr = 0;
            int[] rowBindStatus = new int[BindingCount()];

            _iaccessor = iaccessor;

            Bid.Trace("<oledb.IAccessor.CreateAccessor|API|OLEDB>\n");
            hr = iaccessor.CreateAccessor(flags, (IntPtr)rowBindStatus.Length, this, (IntPtr)_dataLength, out _accessorHandle, rowBindStatus); // MDAC 69530
            Bid.Trace("<oledb.IAccessor.CreateAccessor|API|OLEDB|RET> %08X{HRESULT}\n", hr);

            for (int k = 0; k < rowBindStatus.Length; ++k) {
                if (DBBindStatus.OK != (DBBindStatus)rowBindStatus[k]) {
                    if (ODB.DBACCESSOR_PARAMETERDATA == flags) {
                        throw ODB.BadStatus_ParamAcc(bindings[k].ColumnBindingOrdinal, (DBBindStatus)rowBindStatus[k]);
                    }
                    else if (ODB.DBACCESSOR_ROWDATA == flags) {
                        throw ODB.BadStatusRowAccessor(bindings[k].ColumnBindingOrdinal, (DBBindStatus)rowBindStatus[k]);
                    }
                    else Debug.Assert(false, "unknown accessor buffer");
                }
            }
            return hr;
        }
Ejemplo n.º 25
0
 internal void BeginInternal(UnsafeNativeMethods.ITransactionLocal transaction) {
     OleDbHResult hr;
     _transaction = new WrappedTransaction(transaction, (int) _isolationLevel, out hr);
     if (hr < 0) {
         _transaction.Dispose();
         _transaction = null;                
         ProcessResults(hr);
     }
 }
 internal OleDbHResult CreateAccessor(UnsafeNativeMethods.IAccessor iaccessor, int flags)
 {
     return this._rowBinding.CreateAccessor(iaccessor, flags, this._columnBindings);
 }
Ejemplo n.º 27
0
 internal DualCoTaskMem(UnsafeNativeMethods.IColumnsRowset icolumnsRowset, out IntPtr cOptColumns, out OleDbHResult hr) : base(IntPtr.Zero, true) {
     Bid.Trace("<oledb.IColumnsRowset.GetAvailableColumns|API|OLEDB>\n");
     hr = icolumnsRowset.GetAvailableColumns(out cOptColumns, out base.handle);
     Bid.Trace("<oledb.IColumnsRowset.GetAvailableColumns|API|OLEDB|RET> %08X{HRESULT}\n", hr);
 }
        //override protected int Fill(DataTable dataTable, IDataReader dataReader) { // MDAC 65506
        //    return base.Fill(dataTable, dataReader);
        //}

        private int FillFromRecordset(Object data, UnsafeNativeMethods.ADORecordsetConstruction recordset, string srcTable, out bool incrementResultCount) {
            incrementResultCount = false;

            IntPtr chapter; /*ODB.DB_NULL_HCHAPTER*/
            object result = null;
            try {
                Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB>\n");
                result = recordset.get_Rowset(); // MDAC 83342
                Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB|RET> %08X{HRESULT}\n", 0);

                Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB>\n");
                chapter = recordset.get_Chapter(); // MDAC 83342
                Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB|RET> %08X{HRESULT}\n", 0);
            }
            catch (Exception e) {
                // 
                if (!ADP.IsCatchableExceptionType(e)) {
                    throw;
                }
            
                throw ODB.Fill_EmptyRecordSet("ADODBRecordSet", e);
            }

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

                OleDbDataReader dataReader = null;
                try {
                     // intialized with chapter only since we don't want ReleaseChapter called for this chapter handle
                    ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(chapter);
                     
                    dataReader = new OleDbDataReader(null, null, 0, behavior);
                    dataReader.InitializeIRowset(result, chapterHandle, ADP.RecordsUnaffected);
                    dataReader.BuildMetaInfo();

                    incrementResultCount = (0 < dataReader.FieldCount); // MDAC 59632
                    if (incrementResultCount) {
                        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;
        }