freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Ken Bradley" <bradleyk AT mentorgen.com>
- To: freetds AT franklin.oit.unc.edu
- Subject: SQLBindParameter Problem
- Date: Wed, 22 May 2002 09:13:45 -0400
The following code seg faults in SQLBindParameter, because the "result
info" (line 397 in odbc.c) is NULL. Is this a bug in freetds or something
wrong with the code? The platform is RedHat 7.0, Freetds 0.53 and
SQLServer 2000. The exact same SQL command, using isql succeeds.
-Ken
#include <stdlib.h>
#include <stdio.h>
#include <odbc/sql.h>
#include <odbc/sqlext.h>
#include <odbc/sqltypes.h>
int main(int argc,char *argv[])
{
SQLHENV V_OD_Env;
long V_OD_erg;
SQLHDBC V_OD_hdbc;
SQLHSTMT newHstmt;
SQLLEN V_OD_err;
SQLINTEGER sizeInt;
SQLCHAR source[25];
V_OD_erg=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&V_OD_Env);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error AllocHandle\n");
}
V_OD_erg=SQLSetEnvAttr(V_OD_Env, SQL_ATTR_ODBC_VERSION,
(void*)SQL_OV_ODBC3, 0);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error SetEnv\n");
}
V_OD_erg = SQLAllocHandle(SQL_HANDLE_DBC, V_OD_Env, &V_OD_hdbc);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error AllocHDB %d\n",V_OD_erg);
}
V_OD_erg = SQLConnect(V_OD_hdbc, "FOO", SQL_NTS, "foo", SQL_NTS,
"foo", SQL_NTS);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error SQLConnect %d\n",V_OD_erg);
}
printf("%s,\n", "SQL Connected");
V_OD_erg=SQLAllocHandle(SQL_HANDLE_STMT, V_OD_hdbc, &newHstmt);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error in Statement Alloc %d\n",V_OD_erg);
}
V_OD_erg = SQLPrepare(newHstmt, "INSERT into snmp_header (source)
VALUES (?)", SQL_NTS);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error in Prepare %d\n",V_OD_erg);
}
sizeInt = SQL_NTS;
V_OD_erg = SQLBindParameter(newHstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_VARCHAR, 25, 0, source, 0, &sizeInt);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error in Source %d\n",V_OD_erg);
}
strcpy (source, "Junk String");
V_OD_erg = SQLExecute(newHstmt);
if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
{
printf("Error in Insert %d\n",V_OD_erg);
}
SQLFreeHandle(SQL_HANDLE_STMT,newHstmt);
SQLDisconnect(V_OD_hdbc);
SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env);
return(0);
}
- SQLBindParameter Problem, Ken Bradley, 05/22/2002
Archive powered by MHonArc 2.6.24.