Undocumented values of "Type" from sqlsrv_field_metadata()
sqlsrv_field_metadata() function returns also a value named Type for each of the columns, but the values itself are lacking documentation.
The SQLSRV documentation states that Type is "Numeric value that corresponds to a SQL type.", but the value itself does not map to any of SQLSRV_PHPTYPE_* or SQLSRV_SQLTYPE_* constants. The value comes is ODBC SQL_* type constant. These constants SHOULD be documented in the SQLSRV help. Without diving into the sourcecode, noone can guess what do they mean.
** More information about Type value meaning **
According the source (stmt.cpp, around line 674), the Type value comes from
SQLDescribeCol() function ( [ http://msdn.microsoft.com/en-
us/library/ms716289%28VS.85%29.aspx ](http://msdn.microsoft.com/en-
us/library/ms716289%28VS.85%29.aspx) ) and value can be one of SQL_* constants
listed here http://msdn.microsoft.com/en-us/library/ms710150%28VS.85%29.aspx
.
SQL_* constants values can be found in ODBC client header files "sql.h" and "sqlext.h" (I am running SQL Server 2000 with SDK, and these files are located in Program Files\Microsoft SQL Server\80\Tools\DevTools\Include).
** Selected SQL_* constants values **
According to previous information, I constructed following list of most common
values of Type:
SQL_UNKNOWN_TYPE = 0
SQL_CHAR = 1
SQL_VARCHAR = 12
SQL_DECIMAL = 3
SQL_NUMERIC = 2
SQL_SMALLINT = 5
SQL_INTEGER = 4
SQL_REAL = 7
SQL_FLOAT = 6
SQL_DOUBLE = 8
SQL_BIT = -7
SQL_TINYINT = -6
SQL_BIGINT = -5
SQL_BINARY = -2
SQL_VARBINARY = -3
SQL_LONGVARBINARY = -4
SQL_TYPE_DATE = 91
SQL_TYPE_TIME = 92
SQL_TYPE_TIMESTAMP = 93
Work Item Details
Original CodePlex Issue: Issue 16723 Status: Closed Reason Closed: Unassigned Assigned to: Unassigned Reported on: Mar 11, 2010 at 9:59 AM Reported by: michalkocarek Updated on: Jul 17, 2010 at 8:05 PM Updated by: AshayC Closed on: Jul 17, 2010 at 8:05 PM