tfsrdbc/rdbcTfsAllocDefault.c
#include "sqlrtypes.h"
#include <stdio.h>
RDM_RETCODE exampleTfs_rdbcTfsAllocDefault (const char *databaseName)
{
RDM_TFS tfs;
SQLRETURN ret;
SQLHENV hEnv;
SQLHDBC hDbc;
char connectStrIn[255];
char connectStrOut[255];
SQLSMALLINT outLen;
/* This creates a default TFS handle */
rc = rdm_rdmAllocTFS (&tfs);
if (rc == sOKAY)
{
rc = rdm_tfsInitialize (tfs);
if (rc == sOKAY)
{
ret = SQL_SUCCESS;
}
else
{
rdm_tfsFree (tfs);
ret = SQL_ERROR;
}
}
if (SQL_SUCCEEDED (ret))
{
ret = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &hEnv);
if (SQL_SUCCEEDED (ret))
{
ret = SQLAllocHandle (SQL_HANDLE_DBC, hEnv, &hDbc);
if (SQL_SUCCEEDED (ret))
{
/* Pass the TFS handle to the ODBC driver */
if (SQL_SUCCEEDED (ret))
{
/* Connect to the TFS and open the database */
sprintf (connectStrIn, "databases=%s", databaseName);
hDbc, NULL, (SQLTCHAR *) connectStrIn, SQL_NTS,
(SQLTCHAR *) connectStrOut, sizeof (connectStrOut),
if (SQL_SUCCEEDED (ret))
{
(void) SQLDisconnect (hDbc);
}
else
{
SQLINTEGER native;
(void) SQLGetDiagRec (
SQL_HANDLE_DBC, hDbc, 1, NULL, &native, NULL, 0,
NULL);
rc = (RDM_RETCODE) native;
}
}
(void) SQLFreeHandle (SQL_HANDLE_DBC, hDbc);
}
(void) SQLFreeHandle (SQL_HANDLE_ENV, hEnv);
}
(void) rdm_tfsFree (tfs);
}
return rc;
}