Hi again.
I understand there was little to act upon without some code. here's two examples. One with CODBC class and one with native ODBC.
Error messages differ with exact same(wrong) sql statement using SQLExedirect!
CODBC syntax.
#include once "Afx/COdbc/COdbc.inc"
USING Afx
' // Error callback procedure
SUB ODBC_ErrorCallback (BYVAL nResult AS SQLRETURN, BYREF wszSrc AS WSTRING, BYREF wszErrorMsg AS WSTRING)
PRINT "Error: " & STR(nResult) & " - Source: " & wszSrc
IF LEN(wszErrorMsg) THEN PRINT wszErrorMsg
END SUB
' // Create a connection object and connect with the database
DIM wszConStr AS WSTRING * 260 = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\northwind\biblio.mdb"
DIM pDbc AS CODBC = wszConStr
IF pDbc.Handle = NULL THEN PRINT "Unable to create the connection handle" : SLEEP : END
dim ret as long
' // Set the address of the error callback for the connection object
pDbc.SetErrorProc(@ODBC_ErrorCallback)
' // Allocate an statement object
DIM pStmt AS COdbcStmt = @pDbc
IF pStmt.Handle = NULL THEN PRINT "Unable to create the statement handle" : SLEEP : END
' // Generate a result set
ret = pStmt.ExecDirect ("SELECT gg FROM Authors ORDER BY Author")
if ret = sql_error then
print "Exedirect error:", pstmt.geterrorinfo
end if
sleep
end
Native ODBC
#include once "Afx/COdbc/COdbc.inc"
USING Afx
FUNCTION DBaddErr(Stmt AS sqlhandle, sError AS STRING) AS LONG
dim iLenRet AS short
dim iRecNum AS short
dim iErr AS LONG
dim zState AS wstring*6
dim zMsg AS wstring * 255
dim ret as long
iRecNum = 1
ret = SQLGetDiagRecW(SQL_HANDLE_STMT, Stmt, iRecNum,@zState,@iErr,@zMsg,sizeof(zMsg),@iLenRet)
sError = sError + "Error " + str(iErr) + " " + TRIM(zState) + " " + TRIM(zMsg)
function = ret
END FUNCTION
Dim As SQLHANDLE Ptr hEnv,hConn,hStmt
Dim As SQLRETURN h
Dim As wString*1024 sConnectString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\northwind\biblio.mdb"
Dim As Integer iStrLen
dim sError as string
dim sConn as wstring* 1048
dim ret as long
' // Create a connection object and connect with the database
'connect
h = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, @hEnv)
'set env attributes
h = SQLSetEnvAttr(hEnv,SQL_ATTR_ODBC_VERSION, Cast(Any Ptr,SQL_OV_ODBC3),0)
' // alloc conn handle
h = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, @hConn)
'connect to driver
h=SQLDriverConnectW(hConn, 0, @sConnectString, sizeof(sConnectString), @sConn, Sizeof(sConn),Cast(Any Ptr,@iStrLen), SQL_DRIVER_COMPLETE)
'Alloc stmt handle
SQLAllocHandle(SQL_HANDLE_STMT,hConn,@hStmt)
dim zSqlString as wstring*250
zSqlString = "SELECT gg FROM Authors ORDER BY Author"
' // Generate a result set
ret = SQLExecDirect(hStmt,@zSqlString,Len(zSqlString))
if ret = sql_error then
DBaddErr(hStmt, sError)
print "Exedirect error:", serror
end if
sleep
end