internal void GetOutputValue(CNativeBuffer parameterBuffer) { if (!this._hasChanged && ((this._bindtype != null) && (this._internalDirection != ParameterDirection.Input))) { TypeMap map = this._bindtype; this._bindtype = null; int cb = (int)parameterBuffer.ReadIntPtr(this._preparedIntOffset); if (-1 == cb) { this.Value = DBNull.Value; } else if ((0 <= cb) || (cb == -3)) { this.Value = parameterBuffer.MarshalToManaged(this._preparedValueOffset, this._boundSqlCType, cb); if (((this._boundSqlCType == ODBC32.SQL_C.CHAR) && (this.Value != null)) && !Convert.IsDBNull(this.Value)) { CultureInfo info = new CultureInfo(CultureInfo.CurrentCulture.LCID); this.Value = Encoding.GetEncoding(info.TextInfo.ANSICodePage).GetString((byte[])this.Value); } if (((map != this._typemap) && (this.Value != null)) && (!Convert.IsDBNull(this.Value) && (this.Value.GetType() != this._typemap._type))) { this.Value = decimal.Parse((string)this.Value, CultureInfo.CurrentCulture); } } } }
// Helpers public static OdbcErrorCollection GetDiagErrors(string source, HandleRef hrHandle, SQL_HANDLE hType, RETCODE retcode) { switch (retcode) { case RETCODE.SUCCESS: return(null); case RETCODE.INVALID_HANDLE: throw ODC.InvalidHandle(); default: { Int32 NativeError; Int16 iRec = 0; Int16 cchActual = 0; OdbcErrorCollection errors = new OdbcErrorCollection(); try { using (CNativeBuffer message = new CNativeBuffer(1024)) { using (CNativeBuffer state = new CNativeBuffer(12)) { bool moreerrors = true; while (moreerrors) { retcode = (RETCODE)UnsafeNativeMethods.Odbc32.SQLGetDiagRecW( (short)hType, hrHandle, ++iRec, //Orindals are 1:base in odbc state, out NativeError, message, (short)(message.Length / 2), //cch out cchActual); //cch //Note: SUCCESS_WITH_INFO from SQLGetDiagRec would be because //the buffer is not large enough for the error string. moreerrors = (retcode == RETCODE.SUCCESS || retcode == RETCODE.SUCCESS_WITH_INFO); if (moreerrors) { //Sets up the InnerException as well... errors.Add(new OdbcError( source, (string)message.MarshalToManaged(SQL_C.WCHAR, SQL_NTS), (string)state.MarshalToManaged(SQL_C.WCHAR, SQL_NTS), NativeError ) ); } } } } } catch { throw; } return(errors); } } }
internal void GetOutputValue(IntPtr stmt, CNativeBuffer buffer, CNativeBuffer intbuffer) //Handle any output params { if ((null != _bindtype) && (ODBC32.SQL_PARAM.INPUT != _sqldirection)) { TypeMap typemap = _bindtype; _bindtype = null; ODBC32.SQL_C sql_c_type; sql_c_type = (_parent.Connection.OdbcMajorVersion >= 3) ? typemap._sql_c : typemap._param_sql_c; int cbActual = Marshal.ReadInt32(intbuffer.Ptr); if (ODBC32.SQL_NULL_DATA == cbActual) { Value = DBNull.Value; } else if ((0 <= cbActual) || (cbActual == ODBC32.SQL_NTS)) // safeguard { Value = buffer.MarshalToManaged(sql_c_type, cbActual); if (sql_c_type == ODBC32.SQL_C.CHAR) { if ((null != Value) && !Convert.IsDBNull(Value)) { int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; CultureInfo culInfo = new CultureInfo(lcid); Encoding cpe = System.Text.Encoding.GetEncoding(culInfo.TextInfo.ANSICodePage); Value = cpe.GetString((Byte[])Value); } } if ((typemap != _typemap) && (null != Value) && !Convert.IsDBNull(Value) && (Value.GetType() != _typemap._type)) { Debug.Assert(ODBC32.SQL_C.NUMERIC == _typemap._sql_c, "unexpected"); Value = Decimal.Parse((string)Value, System.Globalization.CultureInfo.CurrentCulture); } } #if DEBUG if (AdapterSwitches.DataValue.TraceVerbose) { Debug.WriteLine("Odbc OutputParam:" + _typemap._odbcType.ToString("G") + " " + typemap._odbcType.ToString("G") + " " + ADP.ValueToString(Value)); } #endif } }
internal void GetOutputValue(CNativeBuffer parameterBuffer) { //Handle any output params // No value is available if the user fiddles with the parameters properties // if (_hasChanged) { return; } if ((null != _bindtype) && (_internalDirection != ParameterDirection.Input)) { TypeMap typemap = _bindtype; _bindtype = null; int cbActual = (int)parameterBuffer.ReadIntPtr(_preparedIntOffset); if (ODBC32.SQL_NULL_DATA == cbActual) { Value = DBNull.Value; } else if ((0 <= cbActual) || (cbActual == ODBC32.SQL_NTS)) { // safeguard Value = parameterBuffer.MarshalToManaged(_preparedValueOffset, _boundSqlCType, cbActual); if (_boundSqlCType == ODBC32.SQL_C.CHAR) { if ((null != Value) && !Convert.IsDBNull(Value)) { int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; CultureInfo culInfo = new CultureInfo(lcid); Encoding cpe = System.Text.Encoding.GetEncoding(culInfo.TextInfo.ANSICodePage); Value = cpe.GetString((byte[])Value); } } if ((typemap != _typemap) && (null != Value) && !Convert.IsDBNull(Value) && (Value.GetType() != _typemap._type)) { Debug.Assert(ODBC32.SQL_C.NUMERIC == _typemap._sql_c, "unexpected"); Value = decimal.Parse((string)Value, System.Globalization.CultureInfo.CurrentCulture); } } } }
internal void GetOutputValue(CNativeBuffer parameterBuffer) { //Handle any output params // No value is available if the user fiddles with the parameters properties // if (_hasChanged) return; if ((null != _bindtype) && (_internalDirection != ParameterDirection.Input)) { TypeMap typemap = _bindtype; _bindtype = null; int cbActual = (int)parameterBuffer.ReadIntPtr(_preparedIntOffset); if (ODBC32.SQL_NULL_DATA == cbActual) { Value = DBNull.Value; } else if ((0 <= cbActual) || (cbActual == ODBC32.SQL_NTS)){ // safeguard Value = parameterBuffer.MarshalToManaged(_preparedValueOffset, _boundSqlCType, cbActual); if (_boundSqlCType== ODBC32.SQL_C.CHAR) { if ((null != Value) && !Convert.IsDBNull(Value)) { int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; CultureInfo culInfo = new CultureInfo(lcid); Encoding cpe = System.Text.Encoding.GetEncoding(culInfo.TextInfo.ANSICodePage); Value = cpe.GetString((Byte[])Value); } } if ((typemap != _typemap) && (null != Value) && !Convert.IsDBNull(Value) && (Value.GetType() != _typemap._type)) { Debug.Assert(ODBC32.SQL_C.NUMERIC == _typemap._sql_c, "unexpected"); Value = Decimal.Parse((string)Value, System.Globalization.CultureInfo.CurrentCulture); } } } }
internal void GetOutputValue(CNativeBuffer parameterBuffer) { if (!this._hasChanged && ((this._bindtype != null) && (this._internalDirection != ParameterDirection.Input))) { TypeMap map = this._bindtype; this._bindtype = null; int cb = (int) parameterBuffer.ReadIntPtr(this._preparedIntOffset); if (-1 == cb) { this.Value = DBNull.Value; } else if ((0 <= cb) || (cb == -3)) { this.Value = parameterBuffer.MarshalToManaged(this._preparedValueOffset, this._boundSqlCType, cb); if (((this._boundSqlCType == ODBC32.SQL_C.CHAR) && (this.Value != null)) && !Convert.IsDBNull(this.Value)) { CultureInfo info = new CultureInfo(CultureInfo.CurrentCulture.LCID); this.Value = Encoding.GetEncoding(info.TextInfo.ANSICodePage).GetString((byte[]) this.Value); } if (((map != this._typemap) && (this.Value != null)) && (!Convert.IsDBNull(this.Value) && (this.Value.GetType() != this._typemap._type))) { this.Value = decimal.Parse((string) this.Value, CultureInfo.CurrentCulture); } } } }