freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Michael Kochetkov" <Michael.Kochetkov AT synartra.com>
- To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
- Subject: [freetds] The next two issues with FreeTDS
- Date: Tue, 26 Oct 2004 17:10:20 +0400
Hello,
I have found the next two issues with FreeTDS. The first one is
informational (marked as AAAA in the code below) the second one (BBBB) may
appear to be a bug.
1. At AAAA below MS ODBC driver return 0 (SQL_SUCCESS) and FreeTDS returns
100 (SQL_NO_DATA).
2. At BBBB below MS ODBC driver return 0 (SQL_SUCCESS) and FreeTDS returns
-1 (SQL_ERROR) - function sequence error.
-
Michael Kochetkov.
P.S. Test case code:
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sql.h>
#include <sqlext.h>
#define MAXBUFLEN 255
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1 = SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
void Cleanup();
int main() {
RETCODE retcode;
// SQLBindParameter variables.
SWORD sParm1=0, sParm2=1;
SDWORD cbParm1=SQL_NTS, cbParm2=SQL_NTS;
SQLSMALLINT columnCount = 0;
// Allocate the ODBC environment and save handle.
retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
if( (retcode != SQL_SUCCESS_WITH_INFO) &&
(retcode != SQL_SUCCESS)) {
printf("SQLAllocHandle(Env) Failed\n\n");
Cleanup();
return(9);
}
// Notify ODBC that this is an ODBC 3.0 app.
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER);
if( (retcode != SQL_SUCCESS_WITH_INFO) &&
(retcode != SQL_SUCCESS)) {
printf("SQLSetEnvAttr(ODBC version) Failed\n\n");
Cleanup();
return(9);
}
// Allocate ODBC connection handle and connect.
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
if( (retcode != SQL_SUCCESS_WITH_INFO) &&
(retcode != SQL_SUCCESS)) {
printf("SQLAllocHandle(hdbc1) Failed\n\n");
Cleanup();
return(9);
}
retcode = SQLConnect(hdbc1, (UCHAR*)"Server", SQL_NTS,
(UCHAR*)"user",SQL_NTS, (UCHAR*)"password", SQL_NTS);
if( (retcode != SQL_SUCCESS) &&
(retcode != SQL_SUCCESS_WITH_INFO) ) {
printf("SQLConnect() Failed\n\n");
Cleanup();
return(9);
}
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt1);
if( (retcode != SQL_SUCCESS) &&
(retcode != SQL_SUCCESS_WITH_INFO) ) {
printf("SQLAllocHandle(hstmt1) Failed\n\n");
Cleanup();
return(9);
}
// Execute the command.
retcode = SQLExecDirect(hstmt1, (UCHAR*)"if exists (select 1 from
sysusers where name = 'TestRole')\n"
"exec sp_droprole TestRole",
SQL_NTS); /* AAAA */
if( (retcode != SQL_SUCCESS) &&
(retcode != SQL_SUCCESS_WITH_INFO) &&
(retcode != SQL_NO_DATA)
)
{
printf("SQLExecDirect Failed\n\n");
Cleanup();
return(9);
}
retcode = SQLNumResultCols(hstmt1,&columnCount); /* BBBB */
if( (retcode != SQL_SUCCESS) &&
(retcode != SQL_SUCCESS_WITH_INFO)
)
{
printf("SQLNumResultCols Failed\n\n");
Cleanup();
return(9);
}
while ( ( retcode = SQLMoreResults(hstmt1) ) != SQL_NO_DATA );
// Clean up.
SQLFreeHandle(SQL_HANDLE_STMT, hstmt1);
SQLDisconnect(hdbc1);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
return(0);
}
void Cleanup()
{
if (hstmt1 != SQL_NULL_HSTMT)
SQLFreeHandle(SQL_HANDLE_STMT, hstmt1);
if (hdbc1 != SQL_NULL_HDBC)
{
SQLDisconnect(hdbc1);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
}
if (henv != SQL_NULL_HENV)
SQLFreeHandle(SQL_HANDLE_ENV, henv);
}
- [freetds] The next two issues with FreeTDS, Michael Kochetkov, 10/26/2004
Archive powered by MHonArc 2.6.24.