Пример #1
0
        // This adds a type to the list of types that are supported by the driver
        // (don't need to know that for all the types)
        //

        internal void SetSupportedType(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CVT sqlcvt;

            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.NUMERIC: {
                sqlcvt = ODBC32.SQL_CVT.NUMERIC;
                break;
            }

            case ODBC32.SQL_TYPE.WCHAR: {
                sqlcvt = ODBC32.SQL_CVT.WCHAR;
                break;
            }

            case ODBC32.SQL_TYPE.WVARCHAR: {
                sqlcvt = ODBC32.SQL_CVT.WVARCHAR;
                break;
            }

            case ODBC32.SQL_TYPE.WLONGVARCHAR: {
                sqlcvt = ODBC32.SQL_CVT.WLONGVARCHAR;
                break;
            }

            default:
                // other types are irrelevant at this time
                return;
            }
            ProviderInfo.TestedSQLTypes    |= (int)sqlcvt;
            ProviderInfo.SupportedSQLTypes |= (int)sqlcvt;
        }
Пример #2
0
        internal void SetSupportedType(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CVT wLONGVARCHAR;
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.WLONGVARCHAR:
                wLONGVARCHAR = ODBC32.SQL_CVT.WLONGVARCHAR;
                break;

            case ODBC32.SQL_TYPE.WVARCHAR:
                wLONGVARCHAR = ODBC32.SQL_CVT.WVARCHAR;
                break;

            case ODBC32.SQL_TYPE.WCHAR:
                wLONGVARCHAR = ODBC32.SQL_CVT.WCHAR;
                break;

            case ODBC32.SQL_TYPE.NUMERIC:
                wLONGVARCHAR = ODBC32.SQL_CVT.NUMERIC;
                break;

            default:
                return;
            }
            OdbcConnectionPoolGroupProviderInfo providerInfo = this.ProviderInfo;

            providerInfo.TestedSQLTypes |= wLONGVARCHAR;
            OdbcConnectionPoolGroupProviderInfo info2 = this.ProviderInfo;

            info2.SupportedSQLTypes |= wLONGVARCHAR;
        }
Пример #3
0
        internal bool TestTypeSupport(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CONVERT sqlconvert;
            ODBC32.SQL_CVT     sqlcvt;

            // we need to convert the sqltype to sqlconvert and sqlcvt first
            //
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.NUMERIC:
            {
                sqlconvert = ODBC32.SQL_CONVERT.NUMERIC;
                sqlcvt     = ODBC32.SQL_CVT.NUMERIC;
                break;
            }

            case ODBC32.SQL_TYPE.WCHAR:
            {
                sqlconvert = ODBC32.SQL_CONVERT.CHAR;
                sqlcvt     = ODBC32.SQL_CVT.WCHAR;
                break;
            }

            case ODBC32.SQL_TYPE.WVARCHAR:
            {
                sqlconvert = ODBC32.SQL_CONVERT.VARCHAR;
                sqlcvt     = ODBC32.SQL_CVT.WVARCHAR;
                break;
            }

            case ODBC32.SQL_TYPE.WLONGVARCHAR:
            {
                sqlconvert = ODBC32.SQL_CONVERT.LONGVARCHAR;
                sqlcvt     = ODBC32.SQL_CVT.WLONGVARCHAR;
                break;
            }

            default:
                Debug.Fail("Testing that sqltype is currently not supported");
                return(false);
            }
            // now we can check if we have already tested that type
            // if not we need to do so
            if (0 == (ProviderInfo.TestedSQLTypes & (int)sqlcvt))
            {
                int flags;

                flags = GetInfoInt32Unhandled((ODBC32.SQL_INFO)sqlconvert);
                flags = flags & (int)sqlcvt;

                ProviderInfo.TestedSQLTypes    |= (int)sqlcvt;
                ProviderInfo.SupportedSQLTypes |= flags;
            }

            // now check if the type is supported and return the result
            //
            return(0 != (ProviderInfo.SupportedSQLTypes & (int)sqlcvt));
        }
Пример #4
0
        static internal TypeMap FromSqlType(ODBC32.SQL_TYPE sqltype)
        {
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.CHAR: return(_Char);

            case ODBC32.SQL_TYPE.VARCHAR: return(_VarChar);

            case ODBC32.SQL_TYPE.LONGVARCHAR: return(_Text);

            case ODBC32.SQL_TYPE.WCHAR: return(_NChar);

            case ODBC32.SQL_TYPE.WVARCHAR: return(_NVarChar);

            case ODBC32.SQL_TYPE.WLONGVARCHAR: return(_NText);

            case ODBC32.SQL_TYPE.DECIMAL: return(_Decimal);

            case ODBC32.SQL_TYPE.NUMERIC: return(_Numeric);

            case ODBC32.SQL_TYPE.SMALLINT: return(_SmallInt);

            case ODBC32.SQL_TYPE.INTEGER: return(_Int);

            case ODBC32.SQL_TYPE.REAL: return(_Real);

            case ODBC32.SQL_TYPE.FLOAT: return(_Double);

            case ODBC32.SQL_TYPE.DOUBLE: return(_Double);

            case ODBC32.SQL_TYPE.BIT: return(_Bit);

            case ODBC32.SQL_TYPE.TINYINT: return(_TinyInt);

            case ODBC32.SQL_TYPE.BIGINT: return(_BigInt);

            case ODBC32.SQL_TYPE.BINARY: return(_Binary);

            case ODBC32.SQL_TYPE.VARBINARY: return(_VarBinary);

            case ODBC32.SQL_TYPE.LONGVARBINARY: return(_Image);

            case ODBC32.SQL_TYPE.TYPE_DATE: return(_Date);

            case ODBC32.SQL_TYPE.TYPE_TIME: return(_Time);

            case ODBC32.SQL_TYPE.TYPE_TIMESTAMP: return(_DateTime);

            case ODBC32.SQL_TYPE.GUID: return(_UniqueId);

            case (ODBC32.SQL_TYPE)ODBC32.SQL_SS.VARIANT: return(_Variant);

            default: throw ODC.UnknownSQLType(sqltype);
            }
        }
 private TypeMap(OdbcType odbcType, DbType dbType, Type type, ODBC32.SQL_TYPE sql_type, ODBC32.SQL_C sql_c, ODBC32.SQL_C param_sql_c, int bsize, int csize, bool signType)
 {
     this._odbcType = odbcType;
     this._dbType = dbType;
     this._type = type;
     this._sql_type = sql_type;
     this._sql_c = sql_c;
     this._param_sql_c = param_sql_c;
     this._bufferSize = bsize;
     this._columnSize = csize;
     this._signType = signType;
 }
Пример #6
0
 private TypeMap(OdbcType odbcType, DbType dbType, Type type, ODBC32.SQL_TYPE sql_type, ODBC32.SQL_C sql_c, ODBC32.SQL_C param_sql_c, int bsize, int csize, bool signType)
 {
     this._odbcType    = odbcType;
     this._dbType      = dbType;
     this._type        = type;
     this._sql_type    = sql_type;
     this._sql_c       = sql_c;
     this._param_sql_c = param_sql_c;
     this._bufferSize  = bsize;
     this._columnSize  = csize;
     this._signType    = signType;
 }
Пример #7
0
        internal readonly bool _signType;   // this type may be has signature information

        private TypeMap(OdbcType odbcType, DbType dbType, Type type, ODBC32.SQL_TYPE sql_type, ODBC32.SQL_C sql_c, ODBC32.SQL_C param_sql_c, int bsize, int csize, bool signType)
        {
            _odbcType = odbcType;
            _dbType   = dbType;
            _type     = type;

            _sql_type    = sql_type;
            _sql_c       = sql_c;
            _param_sql_c = param_sql_c; // alternative sql_c type for parameters

            _bufferSize = bsize;
            _columnSize = csize;
            _signType   = signType;
        }
Пример #8
0
        internal bool TestRestrictedSqlBindType(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CVT nUMERIC;
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.NUMERIC:
                nUMERIC = ODBC32.SQL_CVT.NUMERIC;
                break;

            case ODBC32.SQL_TYPE.DECIMAL:
                nUMERIC = ODBC32.SQL_CVT.DECIMAL;
                break;

            default:
                return(false);
            }
            return(0 != (this.ProviderInfo.RestrictedSQLBindTypes & nUMERIC));
        }
Пример #9
0
        internal void FlagRestrictedSqlBindType(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CVT nUMERIC;
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.NUMERIC:
                nUMERIC = ODBC32.SQL_CVT.NUMERIC;
                break;

            case ODBC32.SQL_TYPE.DECIMAL:
                nUMERIC = ODBC32.SQL_CVT.DECIMAL;
                break;

            default:
                return;
            }
            OdbcConnectionPoolGroupProviderInfo providerInfo = this.ProviderInfo;

            providerInfo.RestrictedSQLBindTypes |= nUMERIC;
        }
Пример #10
0
        internal bool TestRestrictedSqlBindType(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CVT sqlcvt;
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.NUMERIC: {
                sqlcvt = ODBC32.SQL_CVT.NUMERIC;
                break;
            }

            case ODBC32.SQL_TYPE.DECIMAL: {
                sqlcvt = ODBC32.SQL_CVT.DECIMAL;
                break;
            }

            default:
                Debug.Assert(false, "Testing that sqltype is currently not supported");
                return(false);
            }
            return(0 != (ProviderInfo.RestrictedSQLBindTypes & (int)sqlcvt));
        }
Пример #11
0
        internal void FlagRestrictedSqlBindType(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CVT sqlcvt;

            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.NUMERIC: {
                sqlcvt = ODBC32.SQL_CVT.NUMERIC;
                break;
            }

            case ODBC32.SQL_TYPE.DECIMAL: {
                sqlcvt = ODBC32.SQL_CVT.DECIMAL;
                break;
            }

            default:
                // other types are irrelevant at this time
                return;
            }
            ProviderInfo.RestrictedSQLBindTypes |= (int)sqlcvt;
        }
Пример #12
0
        internal bool TestTypeSupport(ODBC32.SQL_TYPE sqltype)
        {
            ODBC32.SQL_CVT     wLONGVARCHAR;
            ODBC32.SQL_CONVERT lONGVARCHAR;
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.WLONGVARCHAR:
                lONGVARCHAR  = ODBC32.SQL_CONVERT.LONGVARCHAR;
                wLONGVARCHAR = ODBC32.SQL_CVT.WLONGVARCHAR;
                break;

            case ODBC32.SQL_TYPE.WVARCHAR:
                lONGVARCHAR  = ODBC32.SQL_CONVERT.VARCHAR;
                wLONGVARCHAR = ODBC32.SQL_CVT.WVARCHAR;
                break;

            case ODBC32.SQL_TYPE.WCHAR:
                lONGVARCHAR  = ODBC32.SQL_CONVERT.CHAR;
                wLONGVARCHAR = ODBC32.SQL_CVT.WCHAR;
                break;

            case ODBC32.SQL_TYPE.NUMERIC:
                lONGVARCHAR  = ODBC32.SQL_CONVERT.NUMERIC;
                wLONGVARCHAR = ODBC32.SQL_CVT.NUMERIC;
                break;

            default:
                return(false);
            }
            if ((this.ProviderInfo.TestedSQLTypes & wLONGVARCHAR) == 0)
            {
                int num = this.GetInfoInt32Unhandled((ODBC32.SQL_INFO)lONGVARCHAR) & wLONGVARCHAR;
                OdbcConnectionPoolGroupProviderInfo providerInfo = this.ProviderInfo;
                providerInfo.TestedSQLTypes |= wLONGVARCHAR;
                OdbcConnectionPoolGroupProviderInfo info2 = this.ProviderInfo;
                info2.SupportedSQLTypes |= num;
            }
            return(0 != (this.ProviderInfo.SupportedSQLTypes & wLONGVARCHAR));
        }
Пример #13
0
 internal static Exception UnknownSQLType(ODBC32.SQL_TYPE sqltype)
 {
     return(ADP.Argument(SR.GetString(SR.Odbc_UnknownSQLType, sqltype.ToString())));
 }
Пример #14
0
 static internal Exception UnknownSQLType(ODBC32.SQL_TYPE sqltype)
 {
     return(Argument(Res.GetString(GetCultureInfo(), Res.Odbc_UnknownSQLType, sqltype.ToString())));
 }
 internal void Bind(OdbcStatementHandle hstmt, OdbcCommand command, short ordinal, CNativeBuffer parameterBuffer, bool allowReentrance)
 {
     ODBC32.SQL_C sql_c = this._prepared_Sql_C_Type;
     ODBC32.SQL_PARAM sql_param = this.SqlDirectionFromParameterDirection();
     int offset = this._preparedOffset;
     int sizeorprecision = this._preparedSize;
     object obj2 = this._preparedValue;
     int valueSize = this.GetValueSize(obj2, offset);
     int num4 = this.GetColumnSize(obj2, offset, ordinal);
     byte parameterPrecision = this.GetParameterPrecision(obj2);
     byte parameterScale = this.GetParameterScale(obj2);
     HandleRef buffer = parameterBuffer.PtrOffset(this._preparedValueOffset, this._preparedBufferSize);
     HandleRef intbuffer = parameterBuffer.PtrOffset(this._preparedIntOffset, IntPtr.Size);
     if (ODBC32.SQL_C.NUMERIC == sql_c)
     {
         if (((ODBC32.SQL_PARAM.INPUT_OUTPUT == sql_param) && (obj2 is decimal)) && (parameterScale < this._internalScale))
         {
             while (parameterScale < this._internalScale)
             {
                 obj2 = ((decimal) obj2) * 10M;
                 parameterScale = (byte) (parameterScale + 1);
             }
         }
         this.SetInputValue(obj2, sql_c, valueSize, parameterPrecision, 0, parameterBuffer);
         if (ODBC32.SQL_PARAM.INPUT != sql_param)
         {
             parameterBuffer.WriteInt16(this._preparedValueOffset, (short) ((parameterScale << 8) | parameterPrecision));
         }
     }
     else
     {
         this.SetInputValue(obj2, sql_c, valueSize, sizeorprecision, offset, parameterBuffer);
     }
     if (((this._hasChanged || (this._boundSqlCType != sql_c)) || ((this._boundParameterType != this._bindtype._sql_type) || (this._boundSize != num4))) || (((this._boundScale != parameterScale) || (this._boundBuffer != buffer.Handle)) || (this._boundIntbuffer != intbuffer.Handle)))
     {
         ODBC32.RetCode retcode = hstmt.BindParameter(ordinal, (short) sql_param, sql_c, this._bindtype._sql_type, (IntPtr) num4, (IntPtr) parameterScale, buffer, (IntPtr) this._preparedBufferSize, intbuffer);
         if (retcode != ODBC32.RetCode.SUCCESS)
         {
             if ("07006" == command.GetDiagSqlState())
             {
                 Bid.Trace("<odbc.OdbcParameter.Bind|ERR> Call to BindParameter returned errorcode [07006]\n");
                 command.Connection.FlagRestrictedSqlBindType(this._bindtype._sql_type);
                 if (allowReentrance)
                 {
                     this.Bind(hstmt, command, ordinal, parameterBuffer, false);
                     return;
                 }
             }
             command.Connection.HandleError(hstmt, retcode);
         }
         this._hasChanged = false;
         this._boundSqlCType = sql_c;
         this._boundParameterType = this._bindtype._sql_type;
         this._boundSize = num4;
         this._boundScale = parameterScale;
         this._boundBuffer = buffer.Handle;
         this._boundIntbuffer = intbuffer.Handle;
         if (ODBC32.SQL_C.NUMERIC == sql_c)
         {
             OdbcDescriptorHandle descriptorHandle = command.GetDescriptorHandle(ODBC32.SQL_ATTR.APP_PARAM_DESC);
             retcode = descriptorHandle.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.TYPE, (IntPtr) 2L);
             if (retcode != ODBC32.RetCode.SUCCESS)
             {
                 command.Connection.HandleError(hstmt, retcode);
             }
             int num2 = parameterPrecision;
             retcode = descriptorHandle.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.PRECISION, (IntPtr) num2);
             if (retcode != ODBC32.RetCode.SUCCESS)
             {
                 command.Connection.HandleError(hstmt, retcode);
             }
             num2 = parameterScale;
             retcode = descriptorHandle.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.SCALE, (IntPtr) num2);
             if (retcode != ODBC32.RetCode.SUCCESS)
             {
                 command.Connection.HandleError(hstmt, retcode);
             }
             retcode = descriptorHandle.SetDescriptionField2(ordinal, ODBC32.SQL_DESC.DATA_PTR, buffer);
             if (retcode != ODBC32.RetCode.SUCCESS)
             {
                 command.Connection.HandleError(hstmt, retcode);
             }
         }
     }
 }
        private void DataTableFromDataReaderDataTypes(DataTable dataTypesTable, OdbcDataReader dataReader, OdbcConnection connection)
        {
            DataTable schemaTable = null;

            schemaTable = dataReader.GetSchemaTable();
            if (schemaTable == null)
            {
                throw ADP.OdbcNoTypesFromProvider();
            }
            object[]   values   = new object[schemaTable.Rows.Count];
            DataColumn column19 = dataTypesTable.Columns[DbMetaDataColumnNames.TypeName];
            DataColumn column18 = dataTypesTable.Columns[DbMetaDataColumnNames.ProviderDbType];
            DataColumn column17 = dataTypesTable.Columns[DbMetaDataColumnNames.ColumnSize];
            DataColumn column16 = dataTypesTable.Columns[DbMetaDataColumnNames.CreateParameters];
            DataColumn column15 = dataTypesTable.Columns[DbMetaDataColumnNames.DataType];
            DataColumn column6  = dataTypesTable.Columns[DbMetaDataColumnNames.IsAutoIncrementable];
            DataColumn column14 = dataTypesTable.Columns[DbMetaDataColumnNames.IsCaseSensitive];
            DataColumn column5  = dataTypesTable.Columns[DbMetaDataColumnNames.IsFixedLength];
            DataColumn column13 = dataTypesTable.Columns[DbMetaDataColumnNames.IsFixedPrecisionScale];
            DataColumn column4  = dataTypesTable.Columns[DbMetaDataColumnNames.IsLong];
            DataColumn column3  = dataTypesTable.Columns[DbMetaDataColumnNames.IsNullable];
            DataColumn column2  = dataTypesTable.Columns[DbMetaDataColumnNames.IsSearchable];
            DataColumn column   = dataTypesTable.Columns[DbMetaDataColumnNames.IsSearchableWithLike];
            DataColumn column12 = dataTypesTable.Columns[DbMetaDataColumnNames.IsUnsigned];
            DataColumn column11 = dataTypesTable.Columns[DbMetaDataColumnNames.MaximumScale];
            DataColumn column10 = dataTypesTable.Columns[DbMetaDataColumnNames.MinimumScale];
            DataColumn column9  = dataTypesTable.Columns[DbMetaDataColumnNames.LiteralPrefix];
            DataColumn column8  = dataTypesTable.Columns[DbMetaDataColumnNames.LiteralSuffix];
            DataColumn column7  = dataTypesTable.Columns[OdbcMetaDataColumnNames.SQLType];

            while (dataReader.Read())
            {
                TypeMap map;
                dataReader.GetValues(values);
                DataRow row = dataTypesTable.NewRow();
                row[column19] = values[0];
                row[column7]  = values[1];
                ODBC32.SQL_TYPE sqltype = (ODBC32.SQL_TYPE)((short)((int)Convert.ChangeType(values[1], typeof(int), null)));
                if (!connection.IsV3Driver)
                {
                    if (sqltype == ~ODBC32.SQL_TYPE.WLONGVARCHAR)
                    {
                        sqltype = ODBC32.SQL_TYPE.TYPE_DATE;
                    }
                    else if (sqltype == ~ODBC32.SQL_TYPE.GUID)
                    {
                        sqltype = ODBC32.SQL_TYPE.TYPE_TIME;
                    }
                }
                try
                {
                    map = TypeMap.FromSqlType(sqltype);
                }
                catch (ArgumentException)
                {
                    map = null;
                }
                if (map != null)
                {
                    row[column18] = map._odbcType;
                    row[column15] = map._type.FullName;
                    switch (sqltype)
                    {
                    case ODBC32.SQL_TYPE.SS_TIME_EX:
                    case ODBC32.SQL_TYPE.SS_UTCDATETIME:
                    case ODBC32.SQL_TYPE.SS_VARIANT:
                    case ODBC32.SQL_TYPE.GUID:
                    case ODBC32.SQL_TYPE.WCHAR:
                    case ODBC32.SQL_TYPE.BIT:
                    case ODBC32.SQL_TYPE.TINYINT:
                    case ODBC32.SQL_TYPE.BIGINT:
                    case ODBC32.SQL_TYPE.BINARY:
                    case ODBC32.SQL_TYPE.CHAR:
                    case ODBC32.SQL_TYPE.NUMERIC:
                    case ODBC32.SQL_TYPE.DECIMAL:
                    case ODBC32.SQL_TYPE.INTEGER:
                    case ODBC32.SQL_TYPE.SMALLINT:
                    case ODBC32.SQL_TYPE.FLOAT:
                    case ODBC32.SQL_TYPE.REAL:
                    case ODBC32.SQL_TYPE.DOUBLE:
                    case ODBC32.SQL_TYPE.TIMESTAMP:
                    case ODBC32.SQL_TYPE.TYPE_DATE:
                    case ODBC32.SQL_TYPE.TYPE_TIME:
                    case ODBC32.SQL_TYPE.TYPE_TIMESTAMP:
                        goto Label_02F8;

                    case ODBC32.SQL_TYPE.SS_XML:
                    case ODBC32.SQL_TYPE.WLONGVARCHAR:
                    case ODBC32.SQL_TYPE.LONGVARBINARY:
                    case ODBC32.SQL_TYPE.LONGVARCHAR:
                        goto Label_02BC;

                    case ODBC32.SQL_TYPE.WVARCHAR:
                    case ODBC32.SQL_TYPE.VARBINARY:
                    case ODBC32.SQL_TYPE.VARCHAR:
                        goto Label_02DA;
                    }
                }
                goto Label_0314;
Label_02BC:
                row[column4] = true;
                row[column5] = false;
                goto Label_0314;
Label_02DA:
                row[column4] = false;
                row[column5] = false;
                goto Label_0314;
Label_02F8:
                row[column4] = false;
                row[column5] = true;
Label_0314:
                row[column17] = values[2];
                row[column16] = values[5];
                if ((values[11] == DBNull.Value) || (Convert.ToInt16(values[11], null) == 0))
                {
                    row[column6] = false;
                }
                else
                {
                    row[column6] = true;
                }
                row[column14] = this.BooleanFromODBC(values[7]);
                row[column13] = this.BooleanFromODBC(values[10]);
                if (values[6] != DBNull.Value)
                {
                    switch (((ODBC32.SQL_NULLABILITY)((ushort)Convert.ToInt16(values[6], null))))
                    {
                    case ODBC32.SQL_NULLABILITY.NO_NULLS:
                        row[column3] = false;
                        break;

                    case ODBC32.SQL_NULLABILITY.NULLABLE:
                        row[column3] = true;
                        break;

                    case ODBC32.SQL_NULLABILITY.UNKNOWN:
                        row[column3] = DBNull.Value;
                        break;
                    }
                }
                if (DBNull.Value != values[8])
                {
                    switch (Convert.ToInt16(values[8], null))
                    {
                    case 0:
                        row[column2] = false;
                        row[column]  = false;
                        break;

                    case 1:
                        row[column2] = false;
                        row[column]  = true;
                        break;

                    case 2:
                        row[column2] = true;
                        row[column]  = false;
                        break;

                    case 3:
                        row[column2] = true;
                        row[column]  = true;
                        break;
                    }
                }
                row[column12] = this.BooleanFromODBC(values[9]);
                if (values[14] != DBNull.Value)
                {
                    row[column11] = values[14];
                }
                if (values[13] != DBNull.Value)
                {
                    row[column10] = values[13];
                }
                if (values[3] != DBNull.Value)
                {
                    row[column9] = values[3];
                }
                if (values[4] != DBNull.Value)
                {
                    row[column8] = values[4];
                }
                dataTypesTable.Rows.Add(row);
            }
        }
Пример #17
0
        internal void Bind(OdbcStatementHandle hstmt, OdbcCommand command, short ordinal, CNativeBuffer parameterBuffer, bool allowReentrance)
        {
            ODBC32.RetCode   retcode;
            ODBC32.SQL_C     sql_c_type   = _prepared_Sql_C_Type;
            ODBC32.SQL_PARAM sqldirection = SqlDirectionFromParameterDirection();

            int    offset      = _preparedOffset;
            int    size        = _preparedSize;
            object value       = _preparedValue;
            int    cbValueSize = GetValueSize(value, offset);           // count of bytes for the data
            int    cchSize     = GetColumnSize(value, offset, ordinal); // count of bytes for the data, used to allocate the buffer length
            byte   precision   = GetParameterPrecision(value);
            byte   scale       = GetParameterScale(value);
            int    cbActual;

            HandleRef valueBuffer = parameterBuffer.PtrOffset(_preparedValueOffset, _preparedBufferSize);
            HandleRef intBuffer   = parameterBuffer.PtrOffset(_preparedIntOffset, IntPtr.Size);

            // for the numeric datatype we need to do some special case handling ...
            //
            if (ODBC32.SQL_C.NUMERIC == sql_c_type)
            {
                // for input/output parameters we need to adjust the scale of the input value since the convert function in
                // sqlsrv32 takes this scale for the output parameter (possible bug in sqlsrv32?)
                //
                if ((ODBC32.SQL_PARAM.INPUT_OUTPUT == sqldirection) && (value is decimal))
                {
                    if (scale < _internalScale)
                    {
                        while (scale < _internalScale)
                        {
                            value = ((decimal)value) * 10;
                            scale++;
                        }
                    }
                }
                SetInputValue(value, sql_c_type, cbValueSize, precision, 0, parameterBuffer);

                // for output parameters we need to write precision and scale to the buffer since the convert function in
                // sqlsrv32 expects these values there (possible bug in sqlsrv32?)
                //
                if (ODBC32.SQL_PARAM.INPUT != sqldirection)
                {
                    parameterBuffer.WriteInt16(_preparedValueOffset, (short)(((ushort)scale << 8) | (ushort)precision));
                }
            }
            else
            {
                SetInputValue(value, sql_c_type, cbValueSize, size, offset, parameterBuffer);
            }


            // Try to reuse existing bindings if
            //  the binding is valid (means we already went through binding all parameters)
            //  the parametercollection is bound already
            //  the bindtype ParameterType did not change (forced upgrade)

            if (!_hasChanged &&
                (_boundSqlCType == sql_c_type) &&
                (_boundParameterType == _bindtype._sql_type) &&
                (_boundSize == cchSize) &&
                (_boundScale == scale) &&
                (_boundBuffer == valueBuffer.Handle) &&
                (_boundIntbuffer == intBuffer.Handle)
                )
            {
                return;
            }

            //SQLBindParameter
            retcode = hstmt.BindParameter(
                ordinal,                                        // Parameter Number
                (short)sqldirection,                            // InputOutputType
                sql_c_type,                                     // ValueType
                _bindtype._sql_type,                            // ParameterType
                (IntPtr)cchSize,                                // ColumnSize
                (IntPtr)scale,                                  // DecimalDigits
                valueBuffer,                                    // ParameterValuePtr
                (IntPtr)_preparedBufferSize,
                intBuffer);                                     // StrLen_or_IndPtr

            if (ODBC32.RetCode.SUCCESS != retcode)
            {
                if ("07006" == command.GetDiagSqlState())
                {
                    command.Connection.FlagRestrictedSqlBindType(_bindtype._sql_type);
                    if (allowReentrance)
                    {
                        this.Bind(hstmt, command, ordinal, parameterBuffer, false);
                        return;
                    }
                }
                command.Connection.HandleError(hstmt, retcode);
            }
            _hasChanged         = false;
            _boundSqlCType      = sql_c_type;
            _boundParameterType = _bindtype._sql_type;
            _boundSize          = cchSize;
            _boundScale         = scale;
            _boundBuffer        = valueBuffer.Handle;
            _boundIntbuffer     = intBuffer.Handle;

            if (ODBC32.SQL_C.NUMERIC == sql_c_type)
            {
                OdbcDescriptorHandle hdesc = command.GetDescriptorHandle(ODBC32.SQL_ATTR.APP_PARAM_DESC);
                // descriptor handle is cached on command wrapper, don't release it

                // Set descriptor Type
                //
                //SQLSetDescField(hdesc, i+1, SQL_DESC_TYPE, (void *)SQL_C_NUMERIC, 0);
                retcode = hdesc.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.TYPE, (IntPtr)ODBC32.SQL_C.NUMERIC);

                if (ODBC32.RetCode.SUCCESS != retcode)
                {
                    command.Connection.HandleError(hstmt, retcode);
                }


                // Set precision
                //
                cbActual = (int)precision;
                //SQLSetDescField(hdesc, i+1, SQL_DESC_PRECISION, (void *)precision, 0);
                retcode = hdesc.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.PRECISION, (IntPtr)cbActual);

                if (ODBC32.RetCode.SUCCESS != retcode)
                {
                    command.Connection.HandleError(hstmt, retcode);
                }


                // Set scale
                //
                // SQLSetDescField(hdesc, i+1, SQL_DESC_SCALE,  (void *)llen, 0);
                cbActual = (int)scale;
                retcode  = hdesc.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.SCALE, (IntPtr)cbActual);

                if (ODBC32.RetCode.SUCCESS != retcode)
                {
                    command.Connection.HandleError(hstmt, retcode);
                }

                // Set data pointer
                //
                // SQLSetDescField(hdesc, i+1, SQL_DESC_DATA_PTR,  (void *)&numeric, 0);
                retcode = hdesc.SetDescriptionField2(ordinal, ODBC32.SQL_DESC.DATA_PTR, valueBuffer);

                if (ODBC32.RetCode.SUCCESS != retcode)
                {
                    command.Connection.HandleError(hstmt, retcode);
                }
            }
        }
Пример #18
0
 internal static Exception UnknownSQLType(ODBC32.SQL_TYPE sqltype)
 {
     return(ADP.Argument(Res.GetString("Odbc_UnknownSQLType", new object[] { sqltype.ToString() })));
 }
Пример #19
0
 internal ODBC32.RetCode BindParameter(short ordinal, short parameterDirection, ODBC32.SQL_C sqlctype, ODBC32.SQL_TYPE sqltype, IntPtr cchSize, IntPtr scale, HandleRef buffer, IntPtr bufferLength, HandleRef intbuffer)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLBindParameter(this,
                                                            checked ((ushort)ordinal), // Parameter Number
                                                            parameterDirection,        // InputOutputType
                                                            sqlctype,                  // ValueType
                                                            checked ((short)sqltype),  // ParameterType
                                                            cchSize,                   // ColumnSize
                                                            scale,                     // DecimalDigits
                                                            buffer,                    // ParameterValuePtr
                                                            bufferLength,              // BufferLength
                                                            intbuffer);                // StrLen_or_IndPtr
     ODBC.TraceODBC(3, "SQLBindParameter", retcode);
     return(retcode);
 }
Пример #20
0
        internal void Bind(OdbcStatementHandle hstmt, OdbcCommand command, short ordinal, CNativeBuffer parameterBuffer, bool allowReentrance) {
            ODBC32.RetCode  retcode;
            ODBC32.SQL_C    sql_c_type = _prepared_Sql_C_Type;
            ODBC32.SQL_PARAM sqldirection = SqlDirectionFromParameterDirection();

            int offset      = _preparedOffset;
            int size        = _preparedSize;
            object value    = _preparedValue;
            int cbValueSize = GetValueSize(value, offset);             // count of bytes for the data
            int cchSize     = GetColumnSize(value, offset, ordinal);   // count of bytes for the data, used to allocate the buffer length
            byte precision  = GetParameterPrecision(value);
            byte scale      = GetParameterScale(value);
            int cbActual;

            HandleRef valueBuffer  = parameterBuffer.PtrOffset(_preparedValueOffset, _preparedBufferSize);
            HandleRef intBuffer    = parameterBuffer.PtrOffset(_preparedIntOffset, IntPtr.Size);

            // for the numeric datatype we need to do some special case handling ...
            //
            if (ODBC32.SQL_C.NUMERIC == sql_c_type) {

                // for input/output parameters we need to adjust the scale of the input value since the convert function in
                // sqlsrv32 takes this scale for the output parameter (possible bug in sqlsrv32?)
                //
                if ((ODBC32.SQL_PARAM.INPUT_OUTPUT == sqldirection) && (value is Decimal)) {
                    if (scale < _internalScale) {
                        while (scale < _internalScale) {
                            value = ((decimal)value ) * 10;
                            scale++;
                        }
                    }
                }
                SetInputValue(value, sql_c_type, cbValueSize, precision, 0, parameterBuffer);

                // for output parameters we need to write precision and scale to the buffer since the convert function in
                // sqlsrv32 expects these values there (possible bug in sqlsrv32?)
                //
                if (ODBC32.SQL_PARAM.INPUT != sqldirection) {
                    parameterBuffer.WriteInt16(_preparedValueOffset, (short)(((ushort)scale << 8) | (ushort)precision));
                }
            }
            else {
                SetInputValue(value, sql_c_type, cbValueSize, size, offset, parameterBuffer);
            }


            // Try to reuse existing bindings if
            //  the binding is valid (means we already went through binding all parameters)
            //  the parametercollection is bound already
            //  the bindtype ParameterType did not change (forced upgrade)

            if (!_hasChanged
                && (_boundSqlCType == sql_c_type)
                && (_boundParameterType == _bindtype._sql_type)
                && (_boundSize == cchSize)
                && (_boundScale == scale)
                && (_boundBuffer == valueBuffer.Handle)
                && (_boundIntbuffer == intBuffer.Handle)
            ) {
                return;
            }

            //SQLBindParameter
            retcode = hstmt.BindParameter(
                                    ordinal,                    // Parameter Number
                                    (short)sqldirection,        // InputOutputType
                                    sql_c_type,                 // ValueType
                                    _bindtype._sql_type,        // ParameterType
                                    (IntPtr)cchSize,            // ColumnSize
                                    (IntPtr)scale,              // DecimalDigits
                                    valueBuffer,                // ParameterValuePtr
                                    (IntPtr)_preparedBufferSize,
                                    intBuffer);                 // StrLen_or_IndPtr

            if (ODBC32.RetCode.SUCCESS != retcode) {
                if ("07006" == command.GetDiagSqlState()) {
                    Bid.Trace("<odbc.OdbcParameter.Bind|ERR> Call to BindParameter returned errorcode [07006]\n");
                    command.Connection.FlagRestrictedSqlBindType(_bindtype._sql_type);
                    if (allowReentrance) {
                        this.Bind(hstmt, command, ordinal, parameterBuffer, false);
                        return;
                    }
                }
                command.Connection.HandleError(hstmt, retcode);
            }
            _hasChanged = false;
            _boundSqlCType = sql_c_type;
            _boundParameterType = _bindtype._sql_type;
            _boundSize = cchSize;
            _boundScale = scale;
            _boundBuffer = valueBuffer.Handle;
            _boundIntbuffer = intBuffer.Handle;

            if (ODBC32.SQL_C.NUMERIC == sql_c_type) {
                OdbcDescriptorHandle hdesc = command.GetDescriptorHandle(ODBC32.SQL_ATTR.APP_PARAM_DESC);
                // descriptor handle is cached on command wrapper, don't release it

                // Set descriptor Type
                //
                //SQLSetDescField(hdesc, i+1, SQL_DESC_TYPE, (void *)SQL_C_NUMERIC, 0);
                retcode = hdesc.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.TYPE, (IntPtr)ODBC32.SQL_C.NUMERIC);

                if (ODBC32.RetCode.SUCCESS != retcode) {
                    command.Connection.HandleError(hstmt, retcode);
                }


                // Set precision
                //
                cbActual= (int)precision;
                //SQLSetDescField(hdesc, i+1, SQL_DESC_PRECISION, (void *)precision, 0);
                retcode = hdesc.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.PRECISION, (IntPtr)cbActual);

                if (ODBC32.RetCode.SUCCESS != retcode) {
                    command.Connection.HandleError(hstmt, retcode);
                }


                // Set scale
                //
                // SQLSetDescField(hdesc, i+1, SQL_DESC_SCALE,  (void *)llen, 0);
                cbActual= (int)scale;
                retcode = hdesc.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.SCALE, (IntPtr)cbActual);

                if (ODBC32.RetCode.SUCCESS != retcode) {
                    command.Connection.HandleError(hstmt, retcode);
                }

                // Set data pointer
                //
                // SQLSetDescField(hdesc, i+1, SQL_DESC_DATA_PTR,  (void *)&numeric, 0);
                retcode = hdesc.SetDescriptionField2(ordinal, ODBC32.SQL_DESC.DATA_PTR, valueBuffer);

                if (ODBC32.RetCode.SUCCESS != retcode) {
                    command.Connection.HandleError(hstmt, retcode);
                }
            }
        }
Пример #21
0
        internal readonly bool _signType;   // this type may be has signature information

        private TypeMap(OdbcType odbcType, DbType dbType, Type type, ODBC32.SQL_TYPE sql_type, ODBC32.SQL_C sql_c, ODBC32.SQL_C param_sql_c, int bsize, int csize, bool signType) {
            _odbcType = odbcType;
            _dbType = dbType;
            _type = type;

            _sql_type = sql_type;
            _sql_c = sql_c;
            _param_sql_c = param_sql_c; // alternative sql_c type for parameters

            _bufferSize = bsize;
            _columnSize = csize;
            _signType = signType;
        }
Пример #22
0
        internal static TypeMap FromSqlType(ODBC32.SQL_TYPE sqltype)
        {
            switch (sqltype)
            {
            case ODBC32.SQL_TYPE.CHAR: return(_Char);

            case ODBC32.SQL_TYPE.VARCHAR: return(_VarChar);

            case ODBC32.SQL_TYPE.LONGVARCHAR: return(_Text);

            case ODBC32.SQL_TYPE.WCHAR: return(s_NChar);

            case ODBC32.SQL_TYPE.WVARCHAR: return(_NVarChar);

            case ODBC32.SQL_TYPE.WLONGVARCHAR: return(_NText);

            case ODBC32.SQL_TYPE.DECIMAL: return(s_decimal);

            case ODBC32.SQL_TYPE.NUMERIC: return(s_numeric);

            case ODBC32.SQL_TYPE.SMALLINT: return(s_smallInt);

            case ODBC32.SQL_TYPE.INTEGER: return(s_int);

            case ODBC32.SQL_TYPE.REAL: return(s_real);

            case ODBC32.SQL_TYPE.FLOAT: return(s_double);

            case ODBC32.SQL_TYPE.DOUBLE: return(s_double);

            case ODBC32.SQL_TYPE.BIT: return(s_bit);

            case ODBC32.SQL_TYPE.TINYINT: return(s_tinyInt);

            case ODBC32.SQL_TYPE.BIGINT: return(s_bigInt);

            case ODBC32.SQL_TYPE.BINARY: return(s_binary);

            case ODBC32.SQL_TYPE.VARBINARY: return(s_varBinary);

            case ODBC32.SQL_TYPE.LONGVARBINARY: return(_Image);

            case ODBC32.SQL_TYPE.TYPE_DATE: return(s_date);

            case ODBC32.SQL_TYPE.TYPE_TIME: return(s_time);

            case ODBC32.SQL_TYPE.TIMESTAMP:
            case ODBC32.SQL_TYPE.TYPE_TIMESTAMP: return(s_dateTime);

            case ODBC32.SQL_TYPE.GUID: return(s_uniqueId);

            case ODBC32.SQL_TYPE.SS_VARIANT: return(s_variant);

            case ODBC32.SQL_TYPE.SS_UDT: return(s_UDT);

            case ODBC32.SQL_TYPE.SS_XML: return(s_XML);

            case ODBC32.SQL_TYPE.SS_UTCDATETIME:
            case ODBC32.SQL_TYPE.SS_TIME_EX:
                throw ODBC.UnknownSQLType(sqltype);

            default:
                throw ODBC.UnknownSQLType(sqltype);
            }
        }
 internal ODBC32.RetCode BindParameter(short ordinal, short parameterDirection, ODBC32.SQL_C sqlctype, ODBC32.SQL_TYPE sqltype, IntPtr cchSize, IntPtr scale, HandleRef buffer, IntPtr bufferLength, HandleRef intbuffer)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLBindParameter(this, (ushort)ordinal, parameterDirection, sqlctype, (short)sqltype, cchSize, scale, buffer, bufferLength, intbuffer);
     ODBC.TraceODBC(3, "SQLBindParameter", retcode);
     return(retcode);
 }
Пример #24
0
        internal void Bind(OdbcStatementHandle hstmt, OdbcCommand command, short ordinal, CNativeBuffer parameterBuffer, bool allowReentrance)
        {
            ODBC32.SQL_C     sql_c       = this._prepared_Sql_C_Type;
            ODBC32.SQL_PARAM sql_param   = this.SqlDirectionFromParameterDirection();
            int       offset             = this._preparedOffset;
            int       sizeorprecision    = this._preparedSize;
            object    obj2               = this._preparedValue;
            int       valueSize          = this.GetValueSize(obj2, offset);
            int       num4               = this.GetColumnSize(obj2, offset, ordinal);
            byte      parameterPrecision = this.GetParameterPrecision(obj2);
            byte      parameterScale     = this.GetParameterScale(obj2);
            HandleRef buffer             = parameterBuffer.PtrOffset(this._preparedValueOffset, this._preparedBufferSize);
            HandleRef intbuffer          = parameterBuffer.PtrOffset(this._preparedIntOffset, IntPtr.Size);

            if (ODBC32.SQL_C.NUMERIC == sql_c)
            {
                if (((ODBC32.SQL_PARAM.INPUT_OUTPUT == sql_param) && (obj2 is decimal)) && (parameterScale < this._internalScale))
                {
                    while (parameterScale < this._internalScale)
                    {
                        obj2           = ((decimal)obj2) * 10M;
                        parameterScale = (byte)(parameterScale + 1);
                    }
                }
                this.SetInputValue(obj2, sql_c, valueSize, parameterPrecision, 0, parameterBuffer);
                if (ODBC32.SQL_PARAM.INPUT != sql_param)
                {
                    parameterBuffer.WriteInt16(this._preparedValueOffset, (short)((parameterScale << 8) | parameterPrecision));
                }
            }
            else
            {
                this.SetInputValue(obj2, sql_c, valueSize, sizeorprecision, offset, parameterBuffer);
            }
            if (((this._hasChanged || (this._boundSqlCType != sql_c)) || ((this._boundParameterType != this._bindtype._sql_type) || (this._boundSize != num4))) || (((this._boundScale != parameterScale) || (this._boundBuffer != buffer.Handle)) || (this._boundIntbuffer != intbuffer.Handle)))
            {
                ODBC32.RetCode retcode = hstmt.BindParameter(ordinal, (short)sql_param, sql_c, this._bindtype._sql_type, (IntPtr)num4, (IntPtr)parameterScale, buffer, (IntPtr)this._preparedBufferSize, intbuffer);
                if (retcode != ODBC32.RetCode.SUCCESS)
                {
                    if ("07006" == command.GetDiagSqlState())
                    {
                        Bid.Trace("<odbc.OdbcParameter.Bind|ERR> Call to BindParameter returned errorcode [07006]\n");
                        command.Connection.FlagRestrictedSqlBindType(this._bindtype._sql_type);
                        if (allowReentrance)
                        {
                            this.Bind(hstmt, command, ordinal, parameterBuffer, false);
                            return;
                        }
                    }
                    command.Connection.HandleError(hstmt, retcode);
                }
                this._hasChanged         = false;
                this._boundSqlCType      = sql_c;
                this._boundParameterType = this._bindtype._sql_type;
                this._boundSize          = num4;
                this._boundScale         = parameterScale;
                this._boundBuffer        = buffer.Handle;
                this._boundIntbuffer     = intbuffer.Handle;
                if (ODBC32.SQL_C.NUMERIC == sql_c)
                {
                    OdbcDescriptorHandle descriptorHandle = command.GetDescriptorHandle(ODBC32.SQL_ATTR.APP_PARAM_DESC);
                    retcode = descriptorHandle.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.TYPE, (IntPtr)2L);
                    if (retcode != ODBC32.RetCode.SUCCESS)
                    {
                        command.Connection.HandleError(hstmt, retcode);
                    }
                    int num2 = parameterPrecision;
                    retcode = descriptorHandle.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.PRECISION, (IntPtr)num2);
                    if (retcode != ODBC32.RetCode.SUCCESS)
                    {
                        command.Connection.HandleError(hstmt, retcode);
                    }
                    num2    = parameterScale;
                    retcode = descriptorHandle.SetDescriptionField1(ordinal, ODBC32.SQL_DESC.SCALE, (IntPtr)num2);
                    if (retcode != ODBC32.RetCode.SUCCESS)
                    {
                        command.Connection.HandleError(hstmt, retcode);
                    }
                    retcode = descriptorHandle.SetDescriptionField2(ordinal, ODBC32.SQL_DESC.DATA_PTR, buffer);
                    if (retcode != ODBC32.RetCode.SUCCESS)
                    {
                        command.Connection.HandleError(hstmt, retcode);
                    }
                }
            }
        }