[Mono-bugs] [Bug 608491] OdbcCommand Parameters Collection fails to set size when setting Value

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue May 25 09:46:56 EDT 2010



Bobby White <bobbywhitenc at yahoo.com> changed:

           What    |Removed                     |Added
                 CC|                            |bobbywhitenc at yahoo.com

--- Comment #1 from Bobby White <bobbywhitenc at yahoo.com> 2010-05-25 13:46:55 UTC ---
(In reply to comment #0)
> Created an attachment (id=364356)
 --> (http://bugzilla.novell.com/attachment.cgi?id=364356) [details]
> A short sample program to reproduce the bug
> User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> Gecko/20100315 (CK-IBM) Firefox/3.5.9 ( .NET CLR 3.5.30729; .NET4.0E)
> Using the System.Data.Odbc package in the Mono 2.4.2 runtime
> When running any SQL the requires Parameter markers and parameter binding,  the
> call to set the Value of the parameter fails to properly set the length causing
> the Value to be truncated.
> OdbcConnection myConnection = new OdbcConnection(connectString);
> myConnection.Open();
> OdbcCommand cmd = myConnection.CreateCommand();
> cmd.CommandText = "INSERT INTO myTable (col1) VALUES(?);
> cmd.Parameters.Add("@col1Value",OdbcType.VarChar).Value(myNewValue);
> // the above should have set the Size, but it doesn't
> Reproducible: Always
> Steps to Reproduce:
> 1. Open an OdbcConnection
> 2. Create an OdbcCommand
> 3. Set the CommandText to an SQL statement with a Parameter marker ?
> 4. Add a parameter to the OdbcCommand.Parameters collection
> 5. Set the value of that Parameter (but dont' explicitly set the length)
> Actual Results:  
> With the Informix database, you get an Exception:
> Odbc Parameter Test
> OdbcException: ERROR [22001] [unixODBC][String data right truncation.]
> ErrorCode: -2147467259
> SQL State: 22001
> Native Error: -11023
> Expected Results:  
> A valid OdbcDataReader() containing results.

To further clarify, this behavior isn't limited to a single database, it also
happens for others such as Microsoft SQL Server AND the behavior is different
than native Microsoft .Net when run on windows.

Both, MS Framework and Mono don't set the .Size of the parameter, but the
difference between the two, is that Microsoft is "clever" and sets the ColSize
of for the SQLBindParameter() ODBC API, when Mono doesnt. 

This is the source code of the Mono Bind() 

ret = libodbc.SQLBindParameter (hstmt, (ushort) ParamNum, (short) paramdir, 
 _typeMap.NativeType, _typeMap.SqlType, Convert.ToUInt32 (Size), 0, (IntPtr)
_nativeBuffer, 0, _cbLengthInd); 

6th element (Size) is taken directly from the .Size attribute of the
OdbcParameter object, which was never set. 

Microsoft framework does it this way: 

        ODBC32.RetCode retcode = hstmt.BindParameter(ordinal, (short)
sql_param, sql_c, this._bindtype._sql_type, (IntPtr) num4, (IntPtr)
parameterScale, buffer, (IntPtr) this._preparedBufferSize, intbuffer); 

The 6th one, "num4" is initialize with the Column size: 

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); 

So, it means Microsoft will always send the size of the column to the
SQLBindParameter api, even if the .Size of the Parameter is not manually set.

Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list