Bug #53235 SQLColumns returns wrong transfer octet length and display size for DECIMAL
Submitted: 28 Apr 2010 6:29 Modified: 30 Jun 2010 9:35
Reporter: Bogdan Degtyariov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:5.1.6 OS:Any
Assigned to: Bogdan Degtyariov CPU Architecture:Any
Tags: decimal, SQLColumns, TRANSFER OCTET LENGTH

[28 Apr 2010 6:29] Bogdan Degtyariov
Description:
SQLColumns function returns wrong transfer octet length and display size for DECIMAL type.
Here is the example of transfer octet length for DECIMAL(10,3):

http://msdn.microsoft.com/en-us/library/ms713979%28VS.85%29.aspx

The MyODBC driver returns both columns wrong (10 instead of 12).

How to repeat:
DECLARE_TEST(t_decimal_bug)
{
  int col_size, buf_len, dec_digits;

  ok_sql(hstmt, "drop table if exists t_decimal_bug");
  ok_sql(hstmt, "create table t_decimal_bug (x decimal(10,3))");
  ok_stmt(hstmt, SQLColumns(hstmt, NULL, 0, NULL, 0,
			   (SQLCHAR *)"t_decimal_bug", SQL_NTS, NULL, 0));
  ok_stmt(hstmt, SQLFetch(hstmt));

  col_size= my_fetch_int(hstmt, 7);
  buf_len= my_fetch_int(hstmt, 8);

  is_num(col_size, 12);
  is_num(buf_len, 12);

  expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
  ok_sql(hstmt, "drop table if exists t_decimal_bug ");

  return OK;
}

Suggested fix:
This is not fix, just the suggestion where to change the code (utility.c).
....
get_column_size() function:

  case MYSQL_TYPE_DECIMAL:
  case MYSQL_TYPE_NEWDECIMAL:
    return (length -
            test(!(field->flags & UNSIGNED_FLAG)) - /* sign? */
            test(field->decimals));                 /* decimal point? */
....

get_decimal_digits() function:
....
  case MYSQL_TYPE_DECIMAL:
  case MYSQL_TYPE_NEWDECIMAL:
    return field->decimals;
....
[28 Apr 2010 10:54] Bogdan Degtyariov
patch

Attachment: bug53235.diff (text/x-diff), 2.77 KiB.

[28 Apr 2010 14:48] Lawrenty Novitsky
Bogdan, looks like you changed column size too. But according to http://msdn.microsoft.com/en-us/library/ms711786(v=VS.85).aspx
columns size unlike transfer octet length should be 10 for decimal(10,3)
Thus half of patch seems to be incorrect.
The rest - BUFFER_LENGTH part, looks fine.
[29 Apr 2010 8:34] Bogdan Degtyariov
patch v2

Attachment: bug53235v2.diff (text/x-diff), 1.91 KiB.

[21 May 2010 7:52] Lawrenty Novitsky
Patch has been pushed to the trunk as rev#896 and has good chances to be included in the next(after 5.1.6) release
[24 May 2010 10:36] Tony Bedford
An entry has been added to the 5.1.7 changelog:

The SQLColumns function returned the incorrect transfer octet length and display size for DECIMAL type.
[30 Jun 2010 9:35] Tony Bedford
Updated the changelog:

The SQLColumns function returned the incorrect transfer octet length into the column BUFFER_LENGTH for DECIMAL type.