Hi,
I have a function that connects to the DB, makes a query and closes the DB and it works fine.
I need to separate it to 3 different functions:
1) open connection and returns a handle to the connection.
2) making the query - getting the connection as parameter and making the query.
3) closing the connection - getting the connection as parameter and closing it.
see in Detailed requirements the function i have now.
Thanks,
Dodly
## Deliverables
void test1(long ParamAll1 [14],char *dsnName,char* userID,char* passwd,char* Stable,char* Wsid,int swApp){
SQLHANDLE sqlenvhandle;
SQLHANDLE sqlconnectionhandle;
SQLHANDLE sqlstatementhandle;
SQLRETURN retcode;
if(SQL_SUCCESS!=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlenvhandle))
goto FINISHED;
if(SQL_SUCCESS!=SQLSetEnvAttr(sqlenvhandle,SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0))
goto FINISHED;
if(SQL_SUCCESS!=SQLAllocHandle(SQL_HANDLE_DBC, sqlenvhandle, &sqlconnectionhandle))
goto FINISHED;
SQLCHAR retconstring[1024];
char toConnect[1024]="";
char* temb1Buf;
temb1Buf="DRIVER={SQL Server};SERVER=";
strcat(toConnect, temb1Buf);
strcat(toConnect, Wsid);
temb1Buf=";DATABASE=";
strcat(toConnect, temb1Buf);
strcat(toConnect, dsnName);
temb1Buf=";UID=";
strcat(toConnect, temb1Buf);
strcat(toConnect, userID);
temb1Buf=";PWD=";
strcat(toConnect, temb1Buf);
strcat(toConnect, passwd);
temb1Buf=";APP=Generic32";
strcat(toConnect, temb1Buf);
cout<<" --> "<<toConnect <<" "<<endl;
switch(SQLDriverConnect (sqlconnectionhandle,
NULL,
(SQLCHAR*)toConnect,
SQL_NTS,
retconstring,
1024,
NULL,
SQL_DRIVER_NOPROMPT)){
case SQL_SUCCESS_WITH_INFO:
show_error(SQL_HANDLE_DBC, sqlconnectionhandle);
break;
case SQL_INVALID_HANDLE:
case SQL_ERROR:
show_error(SQL_HANDLE_DBC, sqlconnectionhandle);
goto FINISHED;
default:
break;
}
if(SQL_SUCCESS!=SQLAllocHandle(SQL_HANDLE_STMT, sqlconnectionhandle, &sqlstatementhandle))
goto FINISHED;
/*char* ContqueryUP=AddContQuery(ParamAll1,Stable) ;
if(SQL_SUCCESS!=SQLExecDirect(sqlstatementhandle, (SQLCHAR*) ContqueryUP, SQL_NTS))
{
show_error(SQL_HANDLE_STMT, sqlstatementhandle);
goto FINISHED;
}*/
//send buffer to it
/*if (swApp==1)
{
char* NextqueryUP=AddToQuery6020(ParamAll1,Stable) ;
if(SQL_SUCCESS!=SQLExecDirect(sqlstatementhandle, (SQLCHAR*) NextqueryUP, SQL_NTS))
{
show_error(SQL_HANDLE_STMT, sqlstatementhandle);
goto FINISHED;
}
}
else
{*/
SQLVARCHAR COLUMN1[50];
int ret=SQLExecDirect(sqlstatementhandle,(SQLCHAR*)"select count(*) from ivr_t_netuni_app_itd where ApplicationID=0", SQL_NTS );
SQLBindCol(sqlstatementhandle, 1, SQL_C_CHAR, &COLUMN1, sizeof(COLUMN1), NULL );
ret = SQLFetch(sqlstatementhandle);
if (retcode != SQL_NO_DATA_FOUND)
cout << COLUMN1 ;
FINISHED:
SQLFreeHandle(SQL_HANDLE_STMT, sqlstatementhandle );
SQLDisconnect(sqlconnectionhandle);
SQLFreeHandle(SQL_HANDLE_DBC, sqlconnectionhandle);
SQLFreeHandle(SQL_HANDLE_ENV, sqlenvhandle);
}