theLizard wrote:I am using this statement to get the datatype for a column in an sql table using ODBC
SQLBindCol(q.hstmt, 5, SQL_C_SSHORT, &DataType, 0, &cbDataType)
If your goal is to determine the data type used for record data in a specific column, SQLBindCol() is the wrong way to do it (I guess you did not read the
Binding Columns documentation). Use
SQLDescribeCol() or SQLColAttribute() instead. A
value stored in a record's column is a totally different thing than the
data type of the column itself.
SQLBindCol() is used to receive data for a specific column when fetching records, or to provide data for a specific column when committing records.
If you
read the documentation for SQLBindCol(), it clearly states the following for the 4th parameter:
TargetValuePtr
[Deferred Input/Output] Pointer to the data buffer to bind to the column. SQLFetch and SQLFetchScroll return data in this buffer. SQLBulkOperations returns data in this buffer when Operation is SQL_FETCH_BY_BOOKMARK; it retrieves data from this buffer when Operation is SQL_ADD or SQL_UPDATE_BY_BOOKMARK. SQLSetPos returns data in this buffer when Operation is SQL_REFRESH; it retrieves data from this buffer when Operation is SQL_UPDATE.
The 3rd parameter tells ODBC the type of data that is stored in that buffer:
TargetType
[Input] The identifier of the C data type of the *TargetValuePtr buffer. When it is retrieving data from the data source with SQLFetch, SQLFetchScroll, SQLBulkOperations, or SQLSetPos, the driver converts the data to this type; when it sends data to the data source with SQLBulkOperations or SQLSetPos, the driver converts the data from this type.
So, in this case, you are telling ODBC that the data in your &DataType buffer is a "signed short int". Meaning, when ODBC is fetching record data to return to you, it will write a "signed short int" value into the buffer, and when ODBC is requesting record data from you, it will read a "signed short int" value from the buffer.
The 6th parameter is an output parameter used to report things like string lengths, NULL data flag, etc.
StrLen_or_IndPtr
[Deferred Input/Output]
Pointer to the length/indicator buffer to bind to the column. SQLFetch and SQLFetchScroll return a value in this buffer. SQLBulkOperations retrieves a value from this buffer when Operation is SQL_ADD, SQL_UPDATE_BY_BOOKMARK, or SQL_DELETE_BY_BOOKMARK. SQLBulkOperations returns a value in this buffer when Operation is SQL_FETCH_BY_BOOKMARK. SQLSetPos returns a value in this buffer when Operation is SQL_REFRESH; it retrieves a value from this buffer when Operation is SQL_UPDATE.
SQLFetch, SQLFetchScroll, SQLBulkOperations, and SQLSetPos can return the following values in the length/indicator buffer:
- The length of the data available to return
- SQL_NO_TOTAL
- SQL_NULL_DATA
The application can put the following values in the length/indicator buffer for use with SQLBulkOperations or SQLSetPos:
- The length of the data being sent
- SQL_NTS
- SQL_NULL_DATA
- SQL_DATA_AT_EXEC
- The result of the SQL_LEN_DATA_AT_EXEC macro
- SQL_COLUMN_IGNORE
For instance, when fetching a record, or when committing a record, that contains a NULL value in the column, you use the 6th parameter to determine/specify that.
theLizard wrote:DataType returns -9 for VARCHAR Just trying to workout where -9 fits into the TFieldType Enumeration.
It doesn't fit anywhere.
For one thing, TFieldType only contains positive values, no negatives. The TFieldType value for "signed short int" is ftSmallint (2).
For another thing, your DataType variable (which you are using as an output buffer when fetching a record) will receive a value of -9
only if you fetch a record whose value in column 5 is convertible to a "signed short int".
theLizard wrote:is SQL_C_SSHORT the right choice?
You tell us. What is the actual SQL data type of column 5 in the table/recordset that is represented by q.hstmt?
theLizard wrote:should I be using something else?
What are you trying to accomplish in the first place?