Hello!
I have a problem with my library for ODBC access.
A sample program which worked in the past (I guess prior 5.0) does not with FTN95 v5. It calls ODBC routine SQLBindCol(...) whose import is defined as
STDCALL SQLBINDCOL 'SQLBindCol' VAL,VAL,VAL,REF,VAL,REF): INTEGER*2
! extension to allow for different column types
STDCALL SQLBINDCOLCHAR 'SQLBindCol' (VAL,VAL,VAL,REF,VAL,REF): INTEGER*2
Other interfaces declared similarly.
Variables are declared as follows
USE qt_ODBC ! to define SQL KINDs, INTERFACEs etc.
IMPLICIT NONE
...
INTEGER (SQLINTEGER), PARAMETER :: STR_LEN = 128+1, REM_LEN = 254+1
CHARACTER (LEN=STR_LEN) :: szCatalog, szSchema, szTableName, &
szColumnName, szTypeName, lastCatalogName
INTEGER (SQLSMALLINT) :: DataType, cb0 = 0
INTEGER (SQLINTEGER) :: cbDataType, cbCatalog, cbSchema, cbTableName, &
cbColumnName, cbTypeName, cbTableType
...
The routines are called as follows:
icol = 1
rtc = SQLBindColChar(stmt, icol, SQL_C_CHAR, szCatalog, STR_LEN, cbCatalog)
icol = 2
rtc = SQLBindColChar(stmt, icol, SQL_C_CHAR, szSchema, STR_LEN, cbSchema)
icol = 3
rtc = SQLBindColChar(stmt, icol, SQL_C_CHAR, szTableName, STR_LEN, cbTableName)
icol = 4
rtc = SQLBindColChar(stmt, icol, SQL_C_CHAR, szColumnName, STR_LEN, cbColumnName)
icol = 5
rtc = SQLBindColI2(stmt, icol, SQL_C_SSHORT, DataType, 0, cbDataType)
icol = 6
rtc = SQLBindColChar(stmt, icol, SQL_C_CHAR, szTypeName, STR_LEN, cbTypeName)
SQLBindCol passes the addresses of the 4th and the 6th argument to ODBC.
Then a few lines below, in a DO loop, the ODBC routine SQLFetch is called rtc = SQLFetch(stmt) which causes those variables bound before by SQLBINDCOL to be filled with values.
This worked with FTN95 in earlier versions (I think up to v4.90) so far and it does with any other Fortran compiler I use. But it does not with v5. The following happens: The variables szCatalog, szSchema, szTableName, szColumnName, DataType and their length arguments cbCatalog, cbSchema etc. are left unchanged. However, the variables szTypeName and cbTypeName of the last call to SQLBindColChar are changed and they receive the values which actually should be written to szCatalog and cbCatalog! Any idea why this isn't working anymore? The only thing I can imagine is that the address of those bound variables have changed. But this is something I can hardly believe since SQLBindCol and SQLFetch are called in the same SUBROUTINE. The calls of ODBC routines SQLSetEnvAttr, SQLAllocConnect, SQLDriverConnect, SQLAllocStmt and SQLExecDirect prior SQLBindCol seem to work. Please help. Thank you.
Jörg Kuthe www.qtsoftware.de