freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: Nilesh Dhawale <ndhawale AT gmail.com>
- To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
- Subject: [freetds] bug in SQLGetDiagField (odbc driver)?
- Date: Tue, 19 Oct 2004 12:37:23 -0400
I am using SQLGetDiagField to find out the number od rows inserted
into a Database. "SQLGetDiagField" is supported according to the
documentation for the freeTDS odbc driver. Attached at hte end of the
email is a small program that inserts a row in a table successfully
but SQLGetDiagField fails. Moreover, the diagnostic fields are not set
to tell why the call failed. Here is the run result from the program:
[sybase@sun] ./sqlGetDiagField.exe <DSN> <user> <passwd>
SQLExecute RET CODE : 0
SQLGetDiagField failed with return code -1
MESSAGE: ÿ¾ø
MESSAGE: ÿ¾ø
Is this a known issue or am I missing something? I am using 0.62.4 and
would be installing the next stable release when available.
Rgds,
Nilesh
test program:
------------------
#include <stdio.h>
#include <string.h>
//#include <windows.h>
#include <sql.h>
#include <sqlext.h>
//#include <odbcss.h>
#define MAXBUFLEN 255
#define MAXNAME 20
#define SALES_PERSON_LEN 10
#define STATUS_LEN 6
#define STR_LEN 128+1
#define REM_LEN 254+1
void checkStatus(SQLRETURN retcode, char* function,
SQLSMALLINT handleType,
SQLHANDLE handle,
SQLSMALLINT recNumber)
{
if (retcode != SQL_SUCCESS)
{
char messageText[256];
SQLSMALLINT errorMessageLength;
SQLCHAR sqlState[6];
SQLRETURN sqlReturn =
SQLGetDiagRec(handleType,handle,1/*recNumber*/,sqlState,NULL,
messageText,sizeof(messageText),&errorMessageLength);
printf("%s failed with return code %d\n", function, retcode);
printf("MESSAGE: %s\n", messageText);
sqlReturn =
SQLGetDiagRec(handleType,handle,2/*recNumber*/,sqlState,NULL,
messageText,sizeof(messageText),&errorMessageLength);
printf("MESSAGE: %s\n", messageText);
}
if(!SQL_SUCCEEDED(retcode))
{
exit(1);
}
}
int main(int argc, char* argv[])
{
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1 = SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
SQLRETURN retcode;
SQLCHAR version[MAXBUFLEN];
SQLSMALLINT driverInformationSize = 0;
int numberOfRecords;
SQLCHAR* sqlText;
// Allocate the ODBC Environment and save handle.
retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
checkStatus(retcode, "SQLAllocHandle", SQL_HANDLE_ENV, henv, 0);
// Notify ODBC that this is an ODBC 3.0 application.
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER);
checkStatus(retcode, "SQLSetEnvAttr", SQL_HANDLE_ENV, henv, 0);
// Allocate an ODBC connection and connect.
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
checkStatus(retcode, "SQLAllocHandle", SQL_HANDLE_DBC, hdbc1, 0);
retcode = SQLConnect(hdbc1, argv[1], SQL_NTS, argv[2], SQL_NTS,
argv[3], SQL_NTS);
//checkStatus(retcode, "SQLConnect", SQL_HANDLE_DBC, hdbc1, 0);
// Allocate a statement handle.
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt1);
checkStatus(retcode, "SQLAllocHandle", SQL_HANDLE_STMT, hstmt1, 0);
/* Prepare the SQL statement */
retcode = SQLPrepare(hstmt1, "insert into TABLE_UP0007_1 values
('cat')", SQL_NTS);
checkStatus(retcode, "SQLPrepare", SQL_HANDLE_STMT, hstmt1, 0);
// execute
retcode = SQLExecute(hstmt1);
printf("SQLExecute RET CODE : %d\n", retcode);
checkStatus(retcode, "SQLExecute", SQL_HANDLE_STMT, hstmt1, 0);
// get number of records
retcode = SQLGetDiagField(SQL_HANDLE_STMT, hstmt1, 0,
SQL_DIAG_ROW_COUNT, &numberOfRecords, SQL_IS_INTEGER, NULL);
checkStatus(retcode, "SQLGetDiagField", SQL_HANDLE_STMT, hstmt1, 0);
printf("NUMBER OF RECORDS: %d\n", numberOfRecords);
/* Clean up. */
SQLFreeHandle(SQL_HANDLE_STMT, hstmt1);
SQLDisconnect(hstmt1);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
return(0);
}
- [freetds] bug in SQLGetDiagField (odbc driver)?, Nilesh Dhawale, 10/19/2004
Archive powered by MHonArc 2.6.24.