There are a couple of modes for the sql to be performed.
I can’t remember the exact details, but for one case it will put whatever is in the buffer in the variable, as seen in your case where there is garbage data at the end.
You can use SQL_NTS to overcome this, but you have to make sure the data is not NULL, otherwise it will fail.
Most of what I have is something along the lines of the following:
set mySql “select nvl( field,’ ‘) from table”
odbc SQLExecDirect $HSTMT $mySql SQL_NTS
nvl sets the result to a space if it is null.
For the initialisation, I’m using an oracle database, and have something along the lines of:
odbc SQLAllocHandle SQL_HANDLE_ENV SQL_NULL_HANDLE HENV
odbc SQLSetEnvAttr $HENV SQL_ATTR_ODBC_VERSION SQL_OV_ODBC3 0
odbc SQLAllocHandle SQL_HANDLE_DBC $HENV HDBC
odbc SQLDriverConnect $HDBC NULL
“DSN=Oracle Wire Protocol; HostName=$aHost; PortNumber=$aPort; LogonID=$aLogin; Password=$aPasswd; SID=$aSid;” SQL_NTS
OutConnectionString 246 StringLengthPtr SQL_DRIVER_NOPROMPT