BUG: MS Oracle ODBC Driver Truncates Trailing Spaces in Column Name (271852)



The information in this article applies to:

  • Microsoft ODBC for Oracle version 2.5 Build 2.573.2927
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.3513
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.3711
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.4202
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.4403
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.5303
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.6019
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.6526
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.7326
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.7626
  • Microsoft ODBC for Oracle version 2.5 Build 2.573.7713.2
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7

This article was previously published under Q271852

SYMPTOMS

When you use Microsoft's Oracle ODBC driver with the ODBC SQLDescribeCol function, incorrect values may be returned for the column name and column name length.

CAUSE

This problem occurs when you have a trailing space in the table's column name. The Microsoft Oracle ODBC driver truncates any trailing spaces when the column information is returned by the SQLDescribeCol function.

RESOLUTION

You can work around this problem in either of the following ways:
  • Use the SQLColumns ODBC API instead of SQLDescribeCol to retrieve the exact name of the column. SQLColumns returns the correct name, without truncating the trailing spaces.

    -or-
  • You can also query the catalog information from Oracle to retrieve the column name. To do this, use the USER_TAB_COLUMNS table with the following SQL statement:
    Select COLUMN_NAME from USER_TAB_COLUMNS WHERE TABLE_NAME='TEST'
    					
    This statement returns the correct column name, including the trailing spaces.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Use the ODBC Test program (the Obdcte32.exe file that comes with the Microsoft Data Access Components Software Development Kit) to connect to any Oracle server.
  2. Create a table by using the following commands and script. Call SQLExecDirect to execute the following SQL statement:
    Create table Test(" Col " VarChar2(10))
    					
  3. Call SQLExecDirect to execute the following SQL statement:
    Select * from Test
    					
  4. Call SQLDescribeCol for column number 1. The output window displays the following:
    SQLDescribeCol:
    ...
    Return:	SQL_SUCCESS=0
    Out: *ColumnName = " col", *NameLengthPtr = 4, *DataTypePtr = SQL_CHAR=1, *ColumnSizePtr = 10, *DecimalDigits = 0, *NullablePtr = SQL_NULLABLE=1
    					
NOTE: We have created a column whose name is of length 5. SqlDescribeCol has returned *NameLengthPtr = 4, instead of 5 as expected. Also note that the column name is returned as " col" instead of as " col ". The trailing space has been truncated by the driver.

Modification Type:MajorLast Reviewed:12/5/2003
Keywords:kbBug kbDatabase kbDriver kbOracle kbpending KB271852