Ejemplo n.º 1
0
int MADB_KeyTypeCount(MADB_Dbc *Connection, char *TableName, int KeyFlag)
{
  int Count= 0;
  unsigned int i;
  char StmtStr[1024];
  char *p= StmtStr;
  char Database[65];
  SQLHSTMT Stmt= NULL;
  MADB_Stmt *KeyStmt;
  
  SQLGetConnectAttr((SQLHDBC)Connection, SQL_ATTR_CURRENT_CATALOG, Database, 65, NULL);
  p+= my_snprintf(p, 1024, "SELECT * FROM ");
  if (Database)
    p+= my_snprintf(p, 1024 - strlen(p), "`%s`.", Database);
  p+= my_snprintf(p, 1024 - strlen(p), "%s LIMIT 0", TableName);
  if (SQLAllocStmt((SQLHDBC)Connection, &Stmt) == SQL_ERROR ||
      SQLPrepare(Stmt, (SQLCHAR *)StmtStr, SQL_NTS) == SQL_ERROR ||
      SQLExecute(Stmt) == SQL_ERROR ||
      SQLFetch(Stmt) == SQL_ERROR)
      goto end;
  KeyStmt= (MADB_Stmt *)Stmt;
  for (i=0; i < mysql_stmt_field_count(KeyStmt->stmt); i++)
    if (KeyStmt->stmt->fields[i].flags & KeyFlag)
      Count++;
end:
  if (Stmt)
    SQLFreeHandle(SQL_HANDLE_STMT, Stmt);
  return Count;
}
Ejemplo n.º 2
0
LONG CODBCDatabase::GetConnectionTimeout()
{
	LONG nSeconds;

	SQLGetConnectAttr(m_hDbc, SQL_ATTR_CONNECTION_TIMEOUT, &nSeconds, NULL, 0);

	return nSeconds;
}
Ejemplo n.º 3
0
/************************************************************************
* name: SQLGetConnectAttrW
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
ODBC_INTERFACE RETCODE SQL_API
SQLGetConnectAttrW (SQLHDBC hdbc, SQLINTEGER attribute, SQLPOINTER value,
                    SQLINTEGER value_max, SQLINTEGER *value_len)
{
  RETCODE ret = ODBC_ERROR;
  OutputDebugString ("SQLGetConnectAttrW called.\n");

  ret = SQLGetConnectAttr (hdbc, attribute, value, value_max, value_len);
  return ret;
}
Ejemplo n.º 4
0
Poco::UInt32 SessionImpl::getTransactionIsolation()
{
	SQLULEN isolation = 0;
	checkError(SQLGetConnectAttr(_db, SQL_ATTR_TXN_ISOLATION,
		&isolation,
		0,
		0));

	return transactionIsolation(isolation);
}
Ejemplo n.º 5
0
/* server status: SQL_CD_TRUE or SQL_CD_FALSE */
int	IBM_DB2server_status()
{
	int	server_status = SQL_CD_TRUE;

	if (SUCCEED != zbx_ibm_db2_success(SQLGetConnectAttr(ibm_db2.hdbc, SQL_ATTR_CONNECTION_DEAD,
								&server_status, SQL_IS_POINTER, NULL)))
	{
		zabbix_log(LOG_LEVEL_WARNING, "cannot determine IBM DB2 server status, assuming not connected");
	}

	return (SQL_CD_FALSE == server_status ? SQL_CD_TRUE : SQL_CD_FALSE);
}
Ejemplo n.º 6
0
SQLRETURN SQL_API
SQLGetConnectAttrA(SQLHDBC ConnectionHandle,
		   SQLINTEGER Attribute,
		   SQLPOINTER ValuePtr,
		   SQLINTEGER BufferLength,
		   SQLINTEGER *StringLengthPtr)
{
	return SQLGetConnectAttr(ConnectionHandle,
				 Attribute,
				 ValuePtr,
				 BufferLength,
				 StringLengthPtr);
}
Ejemplo n.º 7
0
static int
get_autocommit(Con& con)
{
  int ret;
  SQLUINTEGER v;
  ret = SQLGetConnectAttr(con.hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)&v, SQL_IS_UINTEGER, 0);
  if (ret != SQL_SUCCESS) {
    ndbout << "Get autocommit failed" << endl;
    print_err(SQL_HANDLE_DBC, con.hdbc);
    return -1;
  }
  return v;
}
Ejemplo n.º 8
0
int DBConnection::checkConnectionState(){
	int closed;
	int res =  SQLGetConnectAttr(dbc,SQL_ATTR_CONNECTION_DEAD,(SQLPOINTER)&closed, SQL_IS_INTEGER,0);
	return res;
}
Ejemplo n.º 9
0
static int odbc_dispatch10(void)
{
	unsigned long retval;
	PWord rval; int rtype;
	PWord arg1; int type1;
	PWord arg2; int type2;
	PWord arg3; int type3;
	PWord arg4; int type4;
	PWord arg5; int type5;
	PWord arg6; int type6;
	PWord arg7; int type7;

	PI_getan(&arg1,&type1,1);
	if (type1 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg1,type1))
			PI_FAIL;
	PI_getan(&arg2,&type2,2);
	if (type2 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg2,type2))
			PI_FAIL;
	PI_getan(&arg3,&type3,3);
	if (type3 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg3,type3))
			PI_FAIL;
	PI_getan(&arg4,&type4,4);
	if (type4 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg4,type4))
			PI_FAIL;
	PI_getan(&arg5,&type5,5);
	if (type5 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg5,type5))
			PI_FAIL;
	PI_getan(&arg6,&type6,6);
	if (type6 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg6,type6))
			PI_FAIL;
	PI_getan(&arg7,&type7,7);


	switch(arg1)
	{
		case 0:
			retval = (unsigned long) SQLExtendedFetch(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLINTEGER  ) arg4),((SQLUINTEGER * ) arg5),((SQLUSMALLINT * ) arg6));
			break;
		case 1:
			retval = (unsigned long) SQLSetDescField(((SQLHDESC  ) arg2),((SQLSMALLINT  ) arg3),((SQLSMALLINT  ) arg4),((SQLPOINTER  ) arg5),((SQLINTEGER  ) arg6));
			break;
		case 2:
			retval = (unsigned long) SQLGetStmtAttr(((SQLHSTMT  ) arg2),((SQLINTEGER  ) arg3),((SQLPOINTER  ) arg4),((SQLINTEGER  ) arg5),((SQLINTEGER * ) arg6));
			break;
		case 3:
			retval = (unsigned long) SQLGetInfo(((SQLHDBC  ) arg2),((SQLUSMALLINT  ) arg3),((SQLPOINTER  ) arg4),((SQLSMALLINT  ) arg5),((SQLSMALLINT * ) arg6));
			break;
		case 4:
			retval = (unsigned long) SQLGetEnvAttr(((SQLHENV  ) arg2),((SQLINTEGER  ) arg3),((SQLPOINTER  ) arg4),((SQLINTEGER  ) arg5),((SQLINTEGER * ) arg6));
			break;
		case 5:
			retval = (unsigned long) SQLGetConnectAttr(((SQLHDBC  ) arg2),((SQLINTEGER  ) arg3),((SQLPOINTER  ) arg4),((SQLINTEGER  ) arg5),((SQLINTEGER * ) arg6));
			break;
		default:
			PI_FAIL;
	}
	PI_makedouble(&rval,&rtype,(double) retval);
	if (PI_unify(arg7,type7,rval,rtype))
		PI_SUCCEED;
	PI_FAIL;
}
Ejemplo n.º 10
0
PassFail TestQueryID (TestInfo *pTestInfo)
{
	TEST_DECLARE;
 	char			Heading[MAX_STRING_SIZE];
 	RETCODE			returncode;
 	SQLHANDLE 		henv, henv2;
 	SQLHANDLE 		hdbc, hdbc2 = (SQLHANDLE)NULL;
 	SQLHANDLE		hstmt, hstmt2;

	int				loop = 0;
	//char			preparedStmt[1024];
	char			infoStatsStmt[ 1024 ];
	SQLCHAR			cursorName[ 1024 ];
	CHAR			jobid[SQL_MAX_SESSIONNAME_LEN];
	CHAR			queryID[256];
	SQLINTEGER		jobidlen;
	SQLLEN			queryIDPtr;
	CHAR			tempStr[256];
                              
	char *droptab   =  "DROP TABLE JOBID cascade";
  	char *createtab =  "CREATE TABLE JOBID (C int) NO PARTITION";
  	char *inserttab =  "INSERT INTO JOBID VALUES (10)";
  	char *selecttab =  "SELECT * FROM JOBID";

	struct
	{
		RETCODE		returncode;
		CHAR		*jobID;
		CHAR		*jobIDExpected;
	} jobIDMatrix[] = {
        { SQL_SUCCESS, "1"                                                  , "1"},
        { SQL_SUCCESS, "11"                                                  , "11"},
		{ SQL_SUCCESS, ""                                                   , "" },
		{ SQL_SUCCESS, "H"                                                  , "H" },
		{ SQL_SUCCESS, "hh"                                                  , "hh" },
		{ SQL_SUCCESS, "0"                                                  , "0" },
		{ SQL_SUCCESS, "_"                                                  , "_" },
		{ SQL_SUCCESS, "________________________"                           , "________________________" },
		{ SQL_SUCCESS, "odbcqa"                                             , "odbcqa" },
		{ SQL_SUCCESS, "odbcqa00"                                           , "odbcqa00" },
		{ SQL_SUCCESS, "00odbcqa"                                           , "00odbcqa" },
		{ SQL_SUCCESS, "0123_HELLOKITTY"                                    , "0123_HELLOKITTY" },
		{ SQL_SUCCESS, "_Hello_Kitty_123"                                   , "_Hello_Kitty_123" },
		{ SQL_SUCCESS, "Hello_Kitty_Went_To_The_"							, "Hello_Kitty_Went_To_The_" },
		{ SQL_SUCCESS, "Hello_Kitty_Went_To_The_"							, "Hello_Kitty_Went_To_The_" },
		{ SQL_SUCCESS, "1234567890_1234567890"								, "1234567890_1234567890" },
		{ SQL_SUCCESS, "123456789012345678901234"                           , "123456789012345678901234" },
		{ SQL_SUCCESS, "123456789012345678901234"                           , "123456789012345678901234" },
		{ SQL_SUCCESS, "1234567890123456789012345"                          , "123456789012345678901234" },
		{ SQL_SUCCESS, "Hello_Kitty_Went_To_The_Store_To_Buy"				, "Hello_Kitty_Went_To_The_" },
		{ SQL_SUCCESS_WITH_INFO, " "										, "" },
		{ SQL_SUCCESS_WITH_INFO, " HelloKitty"                              , "" },
		{ SQL_SUCCESS_WITH_INFO, "Hello Kitty"                              , "" },
		{ SQL_SUCCESS_WITH_INFO, "HelloKitty "                              , "" },
		{ SQL_SUCCESS_WITH_INFO, "1 2"						                , "" },
		{ SQL_SUCCESS_WITH_INFO, "12345.67890.123456789012"                 , "" },
		{ SQL_SUCCESS_WITH_INFO, "Hello$Kitty"                              , "" },
		{ SQL_SUCCESS_WITH_INFO, "\"HelloKitty\""							, "" },
		{ SQL_SUCCESS_WITH_INFO, "'HelloKitty'"								, "" },
		{ SQL_SUCCESS_WITH_INFO, "\" \""                                    , "" },
		{ SQL_SUCCESS_WITH_INFO, "\"\""                                     , "" },
		{ SQL_SUCCESS_WITH_INFO, "\"#@*()-_=+[]{}|:;'<>,.?\""               , "" },
		{ -101				   , ""                                         , "" }
	};

	//struct
	//{
	//	RETCODE		rtc;
	//	CHAR		*queryID;
	//	CHAR		*queryIDExpected;
	//} queryIDMatrix[] = {
	//	{ SQL_SUCCESS, "HELLOKITTY"	                                        , "HELLOKITTY" },
	//	{ SQL_SUCCESS, "H"                                                  , "H" },
	//	{ SQL_SUCCESS, "HELLOKITTYWENTTOTHESTORETOBUYDRI"                   , "HELLOKITTYWENTTOTHESTORETOBUYDRI" },
	//	{ SQL_SUCCESS, "HELLOKITTYWENTTOTHESTORETOBUYDRINKSFORTHEPARTY"     , "HELLOKITTYWENTTOTHESTORETOBUYDRI" },
	//	{ SQL_SUCCESS, "HelloKitty"                                         , "HELLOKITTY" },
	//	{ SQL_SUCCESS, "h"                                                  , "H" },
	//	{ SQL_SUCCESS, "HelloKittyWentToTheStoreToBuyDri"                   , "HELLOKITTYWENTTOTHESTORETOBUYDRI" },
	//	{ SQL_SUCCESS, "HelloKittyWentToTheStoreToBuyDrinksForTheParty"     , "HELLOKITTYWENTTOTHESTORETOBUYDRI" },
	//	{ SQL_SUCCESS, "H_1"                                                , "H_1" },
	//	{ SQL_SUCCESS, "HELLO_KITTY_1234"                                   , "HELLO_KITTY_1234" },
	//	{ SQL_SUCCESS, "HELLO_KITTY_1234_ABCDEFGHIJKLMNO"                   , "HELLO_KITTY_1234_ABCDEFGHIJKLMNO" },
	//	{ SQL_SUCCESS, "HELLO_KITTY_1234_ABCDEFGHIJKLMNOPQRSTUVWXYZ"        , "HELLO_KITTY_1234_ABCDEFGHIJKLMNO" },
	//	{ SQL_SUCCESS, "Hello_Kitty_1234"                                   , "HELLO_KITTY_1234" },
	//	{ SQL_SUCCESS, "Hello_Kitty_1234_abcdefghijklmno"                   , "HELLO_KITTY_1234_ABCDEFGHIJKLMNO" },
	//	{ SQL_SUCCESS, "Hello_Kitty_1234_abcdefghijklmnopqrstuvwxyz"        , "HELLO_KITTY_1234_ABCDEFGHIJKLMNO" },
	//	{ SQL_SUCCESS, "\"HELLOKITTY\""                                     , "HELLOKITTY" },
	//	{ SQL_SUCCESS, "\"H\""                                              , "H" },
	//	{ SQL_SUCCESS, "\"HELLOKITTYWENTTOTHESTORETOBUYDRI\""               , "HELLOKITTYWENTTOTHESTORETOBUYDRI" },
	//	{ SQL_SUCCESS, "\"HELLOKITTYWENTTOTHESTORETOBUYDRINKSFORTHEPARTY\"" , "HELLOKITTYWENTTOTHESTORETOBUYDRI" },
	//	{ SQL_SUCCESS, "\"HelloKitty\""                                     , "HelloKitty" },
	//	{ SQL_SUCCESS, "\"h\""                                              , "h" },
	//	{ SQL_SUCCESS, "\"HelloKittyWentToTheStoreToBuyDri\""               , "HelloKittyWentToTheStoreToBuyDri" },
	//	{ SQL_SUCCESS, "\"HelloKittyWentToTheStoreToBuyDrinksForTheParty\"" , "HelloKittyWentToTheStoreToBuyDri" },
	//	{ SQL_SUCCESS, "\"H_1\""                                            , "H_1" },
	//	{ SQL_SUCCESS, "\"HELLO_KITTY_1234\""                               , "HELLO_KITTY_1234" },
	//	{ SQL_SUCCESS, "\"HELLO_KITTY_1234_ABCDEFGHIJKLMNO\""               , "HELLO_KITTY_1234_ABCDEFGHIJKLMNO" },
	//	{ SQL_SUCCESS, "\"HELLO_KITTY_1234_ABCDEFGHIJKLMNOPQRSTUVWXYZ\""    , "HELLO_KITTY_1234_ABCDEFGHIJKLMNO" },
	//	{ SQL_SUCCESS, "\"Hello_Kitty_1234\""                               , "Hello_Kitty_1234" },
	//	{ SQL_SUCCESS, "\"Hello_Kitty_1234_abcdefghijklmno\""               , "Hello_Kitty_1234_abcdefghijklmno" },
	//	{ SQL_SUCCESS, "\"Hello_Kitty_1234_abcdefghijklmnopqrstuvwxyz\""    , "Hello_Kitty_1234_abcdefghijklmno" },
	//	{ SQL_SUCCESS, "\"Hello Kitty\""                                    , "Hello Kitty" },
	//	{ SQL_SUCCESS, "\"Hello Kitty says \"\"MEOW!\"\"\""                 , "Hello Kitty says \"MEOW\"" },
	//	{ SQL_SUCCESS, "\"Hello Kitty's Pruse\""                            , "Hello Kitty's Purse" },
	//	{ SQL_SUCCESS, "\"CREATE\""                                         , "CREATE" },
	//	{ SQL_SUCCESS, "\"SELECT * FROM T1\""								, "SELECT * FROM T1" },
	//	{ SQL_ERROR  , ""                                                   , "" },
	//	{ SQL_ERROR  , "	"                                               , "" },
	//	{ SQL_ERROR  , "1HelloKitty"                                        , "" },
	//	{ SQL_ERROR  , "_A"                                                 , "" },
	//	{ SQL_ERROR  , "Hello Kitty"                                        , "" },
	//	{ SQL_ERROR  , "Hello$Kitty"                                        , "" },
	//	{ SQL_ERROR  , "\"\\HelloKitty\""                                   , "" },
	//	{ SQL_ERROR  , "\"$HelloKitty\""                                    , "" },
	//	{ SQL_ERROR  , "\" \""                                              , "" },
	//	{ SQL_ERROR  , "\"\""                                               , "" },
	//	{ SQL_ERROR  , "\"@*()-_=+[]{}|:;'<>,.?\""                          , "" },
	//	{ SQL_ERROR  , "CREATE"												, "" },
	//	{ -101       , ""                                                   , "" }
	//};

	//struct
	//{
	//	char*	sqlStmt;
	//} sqlPrepareMatrix[] = {
	//	{ "CREATE CATALOG STMNT" },
	//	{ "CREATE SCHEMA STMNT.TEST" },
	//	{ "CREATE TABLE T2 ( C1 INTEGER NOT NULL NOT DROPPABLE, C2 INTEGER, PRIMARY KEY( C1 ) )" },
	//	{ "CREATE INDEX T2_INDEX ON T2 ( C1 ) NO POPULATE" },
	//	{ "CREATE PROCEDURE T2_PROC (IN IN1 TIME) EXTERNAL NAME 'Procs.N4210' EXTERNAL PATH '/usr/spjqa/Testware/Class' LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL NO ISOLATE" },
	//	{ "CREATE VIEW T2_VIEW AS SELECT C1 FROM T2" },
	//	{ "INSERT INTO T2 VALUES ( 1 , 1) " },
	//	{ "SELECT C1 FROM T2" },
	//	{ "UPDATE T2 SET C2 = 2 WHERE C1 = 1" },
	//	{ "DELETE FROM T2" },
	//	{ "ALTER INDEX T2_INDEX ON T2 ( C2 ) NO POPULATE" },
	//	{ "ALTER TABLE T2 ( C1 INTEGER NOT NULL NOT DROPPABLE, C2 INTEGER NOT NULL, PRIMARY KEY( C1 ) )" },
	//	{ "ALTER TRIGGER" },
	//	{ "DROP SCHEMA STMT.TEST" },
	//	{ "DROP CATALOG STMT" },
	//	{ "DROP INDEX T2_INDEX" },
	//	{ "DROP VIEW T2_VIEW" },
	//	{ "DROP PROCEDURE T2_PROC" },
	//	{ "DROP TABLE T2" },
	//	{ "STOP" }
	//};

//======================================================================================================

	LogMsg(LINEBEFORE+SHORTTIMESTAMP,"Begin testing API => JobID | QueryID | QueryID.cpp\n");

	TEST_INIT;

	TESTCASE_BEGIN("Setup for JobID tests\n");

	if(!FullConnectWithOptions(pTestInfo, CONNECT_ODBC_VERSION_3))
	{
		LogMsg(NONE,"Unable to connect as ODBC3.0 application.\n");
		TEST_FAILED;
		TEST_RETURN;
	}

	henv = pTestInfo->henv;
 	hdbc = pTestInfo->hdbc;
 	hstmt = (SQLHANDLE)pTestInfo->hstmt;

	returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt);	
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLExecDirect(hstmt, (SQLCHAR*)droptab,SQL_NTS);

	returncode = SQLExecDirect(hstmt, (SQLCHAR*)createtab,SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLExecDirect(hstmt, (SQLCHAR*)inserttab,SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	FullDisconnect(pTestInfo);
	TESTCASE_END;

//======================================================================================================
	sprintf(Heading,"Test positive functionality of SessionName, single connection\n");
	TESTCASE_BEGIN( Heading);

	// Allocate Environment Handle
	returncode = SQLAllocEnv(&henv);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocEnv")) {
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetEnvAttr"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		SQLFreeEnv(henv);
		TEST_FAILED;
		TEST_RETURN;
	}

	// Allocate Connection handle
	returncode = SQLAllocConnect(henv,&hdbc);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocConnect")) {
		LogAllErrors(henv,hdbc,hstmt);
		SQLFreeEnv(henv);
		TEST_FAILED;
		TEST_RETURN;
	}
	TESTCASE_END;
	
	loop = 0;
	while( jobIDMatrix[ loop ].returncode != -101 )
	{
		sprintf(Heading,"Test #%d: Testing for jobID: %s\n", loop, jobIDMatrix[ loop ].jobID);
		TESTCASE_BEGIN( Heading);

		returncode = SQLSetConnectAttr(hdbc, (SQLINTEGER)SQL_ATTR_SESSIONNAME,(SQLCHAR*) jobIDMatrix[ loop ].jobID, SQL_NTS);
		if (jobIDMatrix[ loop ].returncode == SQL_SUCCESS) {
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnectAttr")) {
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				loop++;
				continue;
			}

		}
		else {
#ifdef unixcli
			if(returncode != SQL_ERROR) {
#else
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnectAttr")) {
#endif
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				loop++;
				continue;
			}
		}
		returncode = SQLGetConnectAttr(hdbc, (SQLINTEGER)SQL_ATTR_SESSIONNAME, jobid, SQL_MAX_SESSIONNAME_LEN, &jobidlen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetConnectAttr")) {
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			loop++;
			continue;
		}
		if (jobIDMatrix[ loop ].returncode == SQL_SUCCESS) {
			if (strcmp(jobIDMatrix[ loop ].jobIDExpected, jobid) == 0) {
				LogMsg(NONE, "JobIDs are matched. Expected: \"%s\", Actual: \"%s\" for SQLGetConnectAttr\n", jobIDMatrix[ loop ].jobIDExpected, jobid);
				TESTCASE_END;
			}
			else {
				LogMsg(ERRMSG, "JobIDs are not matched. Expected: \"%s\", Actual: \"%s\", at line=%d for SQLGetConnectAttr\n", jobIDMatrix[ loop ].jobIDExpected, jobid, __LINE__);
				TEST_FAILED;
			}
		}
		else {
#ifdef unixcli
			if (strcmp(jobIDMatrix[ loop ].jobIDExpected, jobid) == 0) {
#else
			if (strcmp(jobIDMatrix[ loop ].jobID, jobid) == 0) {
#endif
				LogMsg(NONE, "JobIDs are matched. Expected: \"%s\", Actual: \"%s\" for SQLGetConnectAttr\n", jobIDMatrix[ loop ].jobID, jobid);
				TESTCASE_END;
			}
			else {
				LogMsg(ERRMSG, "JobIDs are not matched. Expected: \"%s\", Actual: \"%s\", at line=%d for SQLGetConnectAttr\n", jobIDMatrix[ loop ].jobID, jobid, __LINE__);
				TEST_FAILED;
			}
		}

		returncode = SQLConnect(hdbc,
							   (SQLCHAR*)pTestInfo->DataSource,(SWORD)strlen(pTestInfo->DataSource),
							   (SQLCHAR*)pTestInfo->UserID,(SWORD)strlen(pTestInfo->UserID),
							   (SQLCHAR*)pTestInfo->Password,(SWORD)strlen(pTestInfo->Password)
							   );	
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLConnect")) {
			LogAllErrors(henv,hdbc,hstmt);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

#ifndef unixcli
		if (jobIDMatrix[ loop ].returncode ==  SQL_SUCCESS_WITH_INFO) {
			if (returncode != jobIDMatrix[ loop ].returncode) {
				LogMsg(ERRMSG, "The retcode has to be SQL_SUCCESS_WITH_INFO, with the error message \"Driver's SQLSetConnectAttr failed.\" in it, at line=%d\n", __LINE__);
				SQLFreeConnect(hdbc);
				SQLFreeEnv(henv);
				TEST_FAILED;
				TEST_RETURN;
			}
//			LogAllErrors(henv,hdbc,NULL);
			if (!FindError("IM006",henv,hdbc,NULL)) {
				LogMsg(ERRMSG, "Couldn't find state error IM006, with the error message \"Driver's SQLSetConnectAttr failed.\", at line=%d\n", __LINE__);
				SQLFreeConnect(hdbc);
				SQLFreeEnv(henv);
				TEST_FAILED;
				TEST_RETURN;
			}
		}
#endif

		returncode = SQLAllocStmt(hdbc,&hstmt);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")) {
			LogAllErrors(henv,hdbc,hstmt);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLAllocStmt(hdbc,&hstmt2);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")) {
			LogAllErrors(henv,hdbc,hstmt);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLPrepare( hstmt, (SQLCHAR *)selecttab, SQL_NTS );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) {
			LogAllErrors(henv,hdbc,hstmt);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLGetCursorName(hstmt, cursorName, sizeof(cursorName), NULL );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) {
			LogAllErrors(henv,hdbc,hstmt);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		//Get queryID
		sprintf( infoStatsStmt, "INFOSTATS %s", (char*)cursorName );
		returncode = SQLBindCol( hstmt2, 1, SQL_C_CHAR, &queryID, 256, &queryIDPtr );
 		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLExecDirect( hstmt2, (SQLCHAR *)infoStatsStmt, SQL_NTS );
 		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLFetch( hstmt2 );
 		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		LogMsg(NONE, "queryID: \"%s\"\n", queryID);
		SQLFreeStmt(hstmt2,SQL_CLOSE);
		SQLFreeStmt(hstmt2,SQL_UNBIND);

		//Get Jobid
		if(isCharSet || isUCS2)
			sprintf( infoStatsStmt, "SELECT queryid_extract( _ISO88591'%s',_ISO88591'SESSIONNAME') FROM JOBID", (char*)queryID );
		else
			sprintf( infoStatsStmt, "SELECT queryid_extract('%s','SESSIONNAME') FROM JOBID", (char*)queryID );

		returncode = SQLBindCol( hstmt2, 1, SQL_C_CHAR, &queryID, 256, &queryIDPtr );
 		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLExecDirect( hstmt2, (SQLCHAR *)infoStatsStmt, SQL_NTS );
 		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLFetch( hstmt2 );
 		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		LogMsg(NONE, "JobID: \"%s\"\n", queryID);
		if (strcmp(jobIDMatrix[ loop ].jobIDExpected, queryID) == 0) {
			LogMsg(NONE, "JobIDs are matched. Expected: \"%s\", Actual: \"%s\" for after queryid_extract\n", jobIDMatrix[ loop ].jobIDExpected, queryID);
			TESTCASE_END;
		}
		else {
			LogMsg(ERRMSG, "JobIDs are not matched. Expected: \"%s\", Actual: \"%s\", at line=%d for after queryid_extract\n", jobIDMatrix[ loop ].jobIDExpected, queryID, __LINE__);
			TEST_FAILED;
		}

		SQLFreeStmt(hstmt,SQL_CLOSE);
		SQLFreeStmt(hstmt,SQL_UNBIND);
		SQLFreeStmt(hstmt2,SQL_CLOSE);
		SQLFreeStmt(hstmt2,SQL_UNBIND);

		returncode = SQLDisconnect(hdbc);
		if (returncode != SQL_SUCCESS)
		{
			LogAllErrors(henv,hdbc,hstmt);
			SQLDisconnect(hdbc);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
		}
   		loop++;
	}

	returncode = SQLFreeConnect(hdbc);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv,hdbc,hstmt);
		SQLDisconnect(hdbc);
		SQLFreeConnect(hdbc);
		SQLFreeEnv(henv);
	}

	returncode = SQLFreeEnv(henv);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv,hdbc,hstmt);
		SQLDisconnect(hdbc);
		SQLFreeConnect(hdbc);
		SQLFreeEnv(henv);
	}

//======================================================================================================
	sprintf(Heading,"Test positive functionality of SessionName, mutiple connection using the same session name\n");
	TESTCASE_BEGIN( Heading);

	// Allocate Environment Handle
	returncode = SQLAllocEnv(&henv);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocEnv")) {
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	returncode = SQLAllocEnv(&henv2);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocEnv2")) {
		LogAllErrors(henv2,hdbc2,hstmt2);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetEnvAttr"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		SQLFreeEnv(henv);
		TEST_FAILED;
		TEST_RETURN;
	}
	returncode = SQLSetEnvAttr(henv2, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetEnvAttr2"))
	{
		LogAllErrors(henv2,hdbc2,hstmt2);
		SQLFreeEnv(henv2);
		TEST_FAILED;
		TEST_RETURN;
	}

	// Allocate Connection handle
	returncode = SQLAllocConnect(henv,&hdbc);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocConnect")) {
		LogAllErrors(henv,hdbc,hstmt);
		SQLFreeEnv(henv);
		TEST_FAILED;
		TEST_RETURN;
	}
	returncode = SQLAllocConnect(henv2,&hdbc2);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocConnect2")) {
		LogAllErrors(henv2,hdbc2,hstmt2);
		SQLFreeEnv(henv2);
		TEST_FAILED;
		TEST_RETURN;
	}
	TESTCASE_END;
	

	strcpy(tempStr,"123456789012345678901234");
	sprintf(Heading,"Testing for jobID: %s\n", tempStr);
	TESTCASE_BEGIN( Heading);

	returncode = SQLSetConnectAttr(hdbc, (SQLINTEGER)SQL_ATTR_SESSIONNAME,(SQLCHAR*) tempStr, SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetConnectAttr")) {
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	returncode = SQLSetConnectAttr(hdbc2, (SQLINTEGER)SQL_ATTR_SESSIONNAME,(SQLCHAR*) tempStr, SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetConnectAttr2")) {
		LogAllErrors(henv2,hdbc2,hstmt2);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLGetConnectAttr(hdbc, (SQLINTEGER)SQL_ATTR_SESSIONNAME, jobid, SQL_MAX_SESSIONNAME_LEN, &jobidlen);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetConnectAttr")) {
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
	}
	if (strcmp(tempStr, jobid) == 0) {
		LogMsg(NONE, "JobID1 are matched. Expected: \"%s\", Actual: \"%s\" for hdbc\n", tempStr, jobid);
	}
	else {
		LogMsg(ERRMSG, "JobID1 are not matched. Expected: \"%s\", Actual: \"%s\", at line=%d for hdbc\n", tempStr, jobid, __LINE__);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLGetConnectAttr(hdbc2, (SQLINTEGER)SQL_ATTR_SESSIONNAME, jobid, SQL_MAX_SESSIONNAME_LEN, &jobidlen);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetConnectAttr2")) {
		LogAllErrors(henv2,hdbc2,hstmt2);
		TEST_FAILED;
		TEST_RETURN;
	}
	if (strcmp(tempStr, jobid) == 0) {
		LogMsg(NONE, "JobID2 are matched. Expected: \"%s\", Actual: \"%s\" for hdbc2\n", tempStr, jobid);
	}
	else {
		LogMsg(ERRMSG, "JobID2 are not matched. Expected: \"%s\", Actual: \"%s\", at line=%d for hdbc2\n", tempStr, jobid, __LINE__);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLConnect(hdbc,
						   (SQLCHAR*)pTestInfo->DataSource,(SWORD)strlen(pTestInfo->DataSource),
						   (SQLCHAR*)pTestInfo->UserID,(SWORD)strlen(pTestInfo->UserID),
						   (SQLCHAR*)pTestInfo->Password,(SWORD)strlen(pTestInfo->Password)
						   );	
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLConnect")) {
		LogAllErrors(henv,hdbc,hstmt);
		SQLFreeConnect(hdbc);
		SQLFreeEnv(henv);
		TEST_FAILED;
		TEST_RETURN;
	}
	returncode = SQLConnect(hdbc2,
						   (SQLCHAR*)pTestInfo->DataSource,(SWORD)strlen(pTestInfo->DataSource),
						   (SQLCHAR*)pTestInfo->UserID,(SWORD)strlen(pTestInfo->UserID),
						   (SQLCHAR*)pTestInfo->Password,(SWORD)strlen(pTestInfo->Password)
						   );	
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLConnect2")) {
		LogAllErrors(henv2,hdbc2,hstmt2);
		SQLFreeConnect(hdbc2);
		SQLFreeEnv(henv2);
		TEST_FAILED;
		TEST_RETURN;
	}

	for (loop=0; loop<2; loop++) {
		if (loop == 0) {
			returncode = SQLAllocStmt(hdbc,&hstmt);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")) {
				LogAllErrors(henv,hdbc,hstmt);
				SQLFreeConnect(hdbc);
				SQLFreeEnv(henv);
				TEST_FAILED;
				TEST_RETURN;
			}
			returncode = SQLAllocStmt(hdbc,&hstmt2);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt3")) {
				LogAllErrors(henv,hdbc,hstmt2);
				SQLFreeConnect(hdbc);
				SQLFreeEnv(henv);
				TEST_FAILED;
				TEST_RETURN;
			}
		}
		else {
			returncode = SQLAllocStmt(hdbc2,&hstmt);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")) {
				LogAllErrors(henv2,hdbc2,hstmt);
				SQLFreeConnect(hdbc2);
				SQLFreeEnv(henv2);
				TEST_FAILED;
				TEST_RETURN;
			}
			returncode = SQLAllocStmt(hdbc2,&hstmt2);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt3")) {
				LogAllErrors(henv2,hdbc2,hstmt2);
				SQLFreeConnect(hdbc2);
				SQLFreeEnv(henv2);
				TEST_FAILED;
				TEST_RETURN;
			}
		}

		returncode = SQLPrepare( hstmt, (SQLCHAR *)selecttab, SQL_NTS );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) {
			LogAllErrors(henv,hdbc,hstmt);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLGetCursorName(hstmt, cursorName, sizeof(cursorName), NULL );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) {
			LogAllErrors(henv,hdbc,hstmt);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		//Get queryID
		sprintf( infoStatsStmt, "INFOSTATS %s", (char*)cursorName );
		returncode = SQLBindCol( hstmt2, 1, SQL_C_CHAR, &queryID, 256, &queryIDPtr );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLExecDirect( hstmt2, (SQLCHAR *)infoStatsStmt, SQL_NTS );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLFetch( hstmt2 );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		LogMsg(NONE, "queryID%d: \"%s\"\n", loop, queryID);
		SQLFreeStmt(hstmt2,SQL_CLOSE);
		SQLFreeStmt(hstmt2,SQL_UNBIND);

		//Get Jobid
		if(isCharSet || isUCS2)
			sprintf( infoStatsStmt, "SELECT queryid_extract( _ISO88591'%s', _ISO88591'SESSIONNAME') FROM JOBID", (char*)queryID );
		else
			sprintf( infoStatsStmt, "SELECT queryid_extract('%s','SESSIONNAME') FROM JOBID", (char*)queryID );

		returncode = SQLBindCol( hstmt2, 1, SQL_C_CHAR, &queryID, 256, &queryIDPtr );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLExecDirect( hstmt2, (SQLCHAR *)infoStatsStmt, SQL_NTS );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		returncode = SQLFetch( hstmt2 );
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")) {
			LogAllErrors(henv,hdbc,hstmt2);
			SQLFreeConnect(hdbc);
			SQLFreeEnv(henv);
			TEST_FAILED;
			TEST_RETURN;
		}

		LogMsg(NONE, "JobID%d: \"%s\"\n", loop, queryID);
		if (strcmp(tempStr, queryID) == 0) {
			LogMsg(NONE, "JobID%d are matched. Expected: \"%s\", Actual: \"%s\" for after queryid_extract\n", loop, tempStr, queryID);
			TESTCASE_END;
		}
		else {
			LogMsg(ERRMSG, "JobID%d are not matched. Expected: \"%s\", Actual: \"%s\", at line=%d for after queryid_extract\n", loop, tempStr, queryID, __LINE__);
			TEST_FAILED;
		}

		SQLFreeStmt(hstmt,SQL_CLOSE);
		SQLFreeStmt(hstmt,SQL_UNBIND);
		SQLFreeStmt(hstmt2,SQL_CLOSE);
		SQLFreeStmt(hstmt2,SQL_UNBIND);
	}

	returncode = SQLDisconnect(hdbc);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv,hdbc,hstmt);
		SQLDisconnect(hdbc);
		SQLFreeConnect(hdbc);
		SQLFreeEnv(henv);
	}
	returncode = SQLDisconnect(hdbc2);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv2,hdbc2,hstmt2);
		SQLDisconnect(hdbc2);
		SQLFreeConnect(hdbc2);
		SQLFreeEnv(henv2);
	}

	returncode = SQLFreeConnect(hdbc);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv,hdbc,hstmt);
		SQLDisconnect(hdbc);
		SQLFreeConnect(hdbc);
		SQLFreeEnv(henv);
	}
	returncode = SQLFreeConnect(hdbc2);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv2,hdbc2,hstmt2);
		SQLDisconnect(hdbc2);
		SQLFreeConnect(hdbc2);
		SQLFreeEnv(henv2);
	}

	returncode = SQLFreeEnv(henv);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv,hdbc,hstmt);
		SQLDisconnect(hdbc);
		SQLFreeConnect(hdbc);
		SQLFreeEnv(henv);
	}
	returncode = SQLFreeEnv(henv2);
	if (returncode != SQL_SUCCESS)
	{
		LogAllErrors(henv2,hdbc2,hstmt2);
		SQLDisconnect(hdbc2);
		SQLFreeConnect(hdbc2);
		SQLFreeEnv(henv2);
	}

	//=========================================================================================

	//FullDisconnect(pTestInfo);
	LogMsg(SHORTTIMESTAMP+LINEAFTER,"End testing API => JobID.\n");
	TEST_RETURN;
}
Ejemplo n.º 11
0
void SessionImpl::open(const std::string& connect)
{
	if (connect != connectionString())
	{
		if (isConnected())
			throw InvalidAccessException("Session already connected");

		if (!connect.empty())
			setConnectionString(connect);
	}

	poco_assert_dbg (!connectionString().empty());

	SQLULEN tout = static_cast<SQLULEN>(getLoginTimeout());
	if (Utility::isError(SQLSetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) tout, 0)))
	{
		if (Utility::isError(SQLGetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, &tout, 0, 0)) ||
				getLoginTimeout() != tout)
		{
			ConnectionError e(_db);
			throw ConnectionFailedException(e.toString());
		}
	}

	SQLCHAR connectOutput[512] = {0};
	SQLSMALLINT result;

	if (Utility::isError(Poco::Data::ODBC::SQLDriverConnect(_db
		, NULL
		,(SQLCHAR*) connectionString().c_str()
		,(SQLSMALLINT) SQL_NTS
		, connectOutput
		, sizeof(connectOutput)
		, &result
		, SQL_DRIVER_NOPROMPT)))
	{
		ConnectionError err(_db);
		std::string errStr = err.toString();
		close();
		throw ConnectionFailedException(errStr);
	}

	_dataTypes.fillTypeInfo(_db);
		addProperty("dataTypeInfo",
		&SessionImpl::setDataTypeInfo,
		&SessionImpl::dataTypeInfo);

	addFeature("autoCommit",
		&SessionImpl::autoCommit,
		&SessionImpl::isAutoCommit);

	addFeature("autoBind",
		&SessionImpl::autoBind,
		&SessionImpl::isAutoBind);

	addFeature("autoExtract",
		&SessionImpl::autoExtract,
		&SessionImpl::isAutoExtract);

	addProperty("maxFieldSize",
		&SessionImpl::setMaxFieldSize,
		&SessionImpl::getMaxFieldSize);

	addProperty("queryTimeout",
		&SessionImpl::setQueryTimeout,
		&SessionImpl::getQueryTimeout);

	Poco::Data::ODBC::SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, 0, 0);

	if (!canTransact()) autoCommit("", true);
}
Ejemplo n.º 12
0
/*
---------------------------------------------------------
   TestHash2
---------------------------------------------------------
*/
PassFail TestHash2(TestInfo *pTestInfo)
{                  
	TEST_DECLARE;
	SQLRETURN		returncode;      
	SQLHENV			henv = 0;
	SQLHDBC			hdbc = 0;
	SQLHSTMT		hstmt= 0;
	SQLUSMALLINT	ParamStatusArray[ARRAY_SIZE];
	SQLUSMALLINT	expParamStatusArray[ARRAY_SIZE];
	SQLUSMALLINT	lastExpParamStatusArray[ARRAY_SIZE];
	SQLULEN			lastParamsProcessed=ARRAY_SIZE, ParamsProcessed = 0;
	SQLLEN			rowcount = 0, expRowcount = 0, lastExpRowcount = 0;
	int				i,j,k,counter = 1, loopcount = 0;
	TCHAR			buffer[256];

	typedef struct {
    		TCHAR	num[15];	SQLLEN numLenOrInd;
    		TCHAR	val[15];	SQLLEN valLenOrInd;
	}nameStruct;
	nameStruct  nameArray1[ARRAY_SIZE];

	SQLUINTEGER mode = 1; 
	SQLUINTEGER startnode = 2;
	SQLUINTEGER streams_per_node = 4;
	SQLUINTEGER delay_error = 1;
	SQLUINTEGER suggested_rowset_size=0;

	SQLTCHAR *sqlDrvInsert = (SQLTCHAR*)_T("PLANLOADTABLE HASH2_TABLE");
	SQLTCHAR *dropTbl = (SQLTCHAR *)_T("DROP TABLE HASH2_TABLE cascade");
	SQLTCHAR *crtTbl = (SQLTCHAR *)_T("CREATE TABLE HASH2_TABLE (A int NOT NULL NOT DROPPABLE, B varchar(10), PRIMARY KEY (A))");
	SQLTCHAR *insTbl = (SQLTCHAR *)_T("INSERT INTO HASH2_TABLE values (?,?)");
//	SQLTCHAR *selTbl = (SQLTCHAR *)_T("SELECT * HASH2_TABLE");

	//==================================================================================================
	LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing feature => Hash2.\n"));
	TEST_INIT;

	returncode = SQLAllocEnv(&henv);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocEnv"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLAllocConnect( henv, &hdbc);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocConnect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON,0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnectAttr"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	//==================================================================================================
	// Set Mode to Loader
	returncode = SQLSetConnectAttr(hdbc, SQL_MODE_LOADER, (void *) mode, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_MODE_LOADER"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	// Set Start mode
	returncode = SQLSetConnectAttr(hdbc,  SQL_START_NODE,  (void *) startnode,  0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_START_NODE"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	// Set Desired Streams Per Node
	returncode = SQLSetConnectAttr(hdbc,  SQL_STREAMS_PER_SEG,  (void *) streams_per_node,  0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_STREAMS_PER_SEG"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	// Set delay_error mode
	returncode = SQLSetConnectAttr(hdbc,  SQL_LOADER_DELAYERROR, (void *) delay_error, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_LOADER_DELAYERROR"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	//==================================================================================================

	returncode = SQLConnect(hdbc,
					   (SQLTCHAR*)pTestInfo->DataSource,(SWORD)_tcslen(pTestInfo->DataSource),
					   (SQLTCHAR*)pTestInfo->UserID,(SWORD)_tcslen(pTestInfo->UserID),
					   (SQLTCHAR*)pTestInfo->Password,(SWORD)_tcslen(pTestInfo->Password)
					   );
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLConnect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLAllocStmt(hdbc, &hstmt);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLConnect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLExecDirect(hstmt, dropTbl, SQL_NTS);
	returncode = SQLExecDirect(hstmt, crtTbl, SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLPrepare(hstmt, (SQLTCHAR *) sqlDrvInsert, SQL_NTS);
	if (returncode != SQL_SUCCESS) {
		LogMsg(ERRMSG,_T("PLANLOADTABLE is expected to return SQL_SUCCESS, actual is %d\n"), returncode);
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLGetConnectAttr(hdbc, SQL_ATTR_SUG_ROWSET_SIZE, &suggested_rowset_size, 0, NULL);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_ATTR_SUG_ROWSET_SIZE"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	LogMsg(LINEAFTER,_T("suggested_rowset_size=%d\n"), suggested_rowset_size);

	//==================================================================================================
	// Set the SQL_ATTR_PARAM_BIND_TYPE statement attribute to use row-wise binding.
	returncode = SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, (void *)sizeof(nameStruct), 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_ATTR_PARAM_BIND_TYPE"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	// Specify the number of elements in each parameter array.
	returncode = SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMSET_SIZE, (void *)ARRAY_SIZE, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_ATTR_PARAMSET_SIZE"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	// Specify an array in which to return the status of each set of parameters.
	returncode = SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, ParamStatusArray, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_ATTR_PARAM_STATUS_PTR"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	// Specify an SQLUINTEGER value in which to return the number of sets of parameters processed.
	returncode = SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &ParamsProcessed, 0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_ATTR_PARAMS_PROCESSED_PTR"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLPrepare(hstmt, insTbl, SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TCHAR, SQL_INTEGER, 10, 0,
                 &nameArray1[0].num, 300, &nameArray1[0].numLenOrInd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	returncode = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_TCHAR, SQL_WCHAR, 10, 0,
                 &nameArray1[0].val, 300, &nameArray1[0].valLenOrInd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	for (j=0; j<ARRAY_SIZE; j++) {
		lastExpParamStatusArray[j] = SQL_PARAM_SUCCESS;
		expParamStatusArray[j] = SQL_PARAM_SUCCESS;
	}

	//==================================================================================================
	TESTCASE_BEGIN("Test the positive functionality of Hash2, with delay_error mode ON.\n");
	loopcount = 4;
	k = 0;
	while ( k < (loopcount+1)) {
		expRowcount = 0;

		if (k==loopcount) { //Send a dummy rowsets to get the status array of the previous rowsets in delay-mode
			LogMsg(LINEAFTER,_T("Insert dummy rowsets with size=0\n"));
			returncode = SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMSET_SIZE, (void *)0, 0);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQL_ATTR_PARAMSET_SIZE"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				TEST_RETURN;
			}
		}
		else {
			_stprintf(buffer, _T("Data inserted: "));
			for (j=0; j<ARRAY_SIZE; j++) {
				if ((j+1)%(3+2*k) == 0) {
					counter--;
					expParamStatusArray[j] = SQL_PARAM_ERROR;
				}
				else {
					expParamStatusArray[j] = SQL_PARAM_SUCCESS;
					expRowcount++;
				}
				_stprintf(nameArray1[j].num,_T("%d"),counter++);
				nameArray1[j].numLenOrInd = SQL_NTS;
				_stprintf(nameArray1[j].val,_T("%s"),_T("chochet"));
				nameArray1[j].valLenOrInd = SQL_NTS;
				_tcscat(buffer,nameArray1[j].num);
				_tcscat(buffer,_T(" "));
			}
			_tcscat(buffer,_T("\n"));
		}
		LogMsg(NONE,_T("%s\n"), buffer);

		returncode = SQLExecute(hstmt);
		if (delay_error == 1 && k != 0) {
			if(returncode != SQL_SUCCESS_WITH_INFO)
			{
				LogMsg(ERRMSG,_T("SQLExecute: returncode expected: SQL_SUCCESS_WITH_INFO, actual: %d at line=%d\n"), returncode, __LINE__);
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				TEST_RETURN;
			}
		}
		else {
			if(returncode != SQL_SUCCESS)
			{
				LogMsg(ERRMSG,_T("SQLExecute: returncode expected: SQL_SUCCESS, actual: %d at line=%d\n"), returncode, __LINE__);
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				TEST_RETURN;
			}
		}

		if ((k == loopcount && ParamsProcessed != 0) || (k != loopcount && ParamsProcessed != ARRAY_SIZE)) {
			LogMsg(ERRMSG,_T("ParamsProcessed is not the same as rowset size from client, at line=%d\n"), __LINE__);
			TEST_FAILED;
		}

		returncode = SQLRowCount(hstmt, &rowcount);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLRowCount"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
		}

		if (delay_error == 1) {
			if (lastExpRowcount != rowcount) {
				TEST_FAILED;
				LogMsg(ERRMSG,_T("Expected Rowcount=%d, Actual Rowcount=%d\n"), expRowcount, rowcount);
			}
			lastExpRowcount = expRowcount;

			LogMsg(NONE,_T("\n%d last rows processed, %d current rows processed, rowcount=%d\n"), lastParamsProcessed, ParamsProcessed, rowcount);
			for (i = 0; i < (int)lastParamsProcessed; i++) {
   				LogMsg(NONE,_T("Parameter Set  Status\n"));
				LogMsg(NONE,_T("-------------  -------------\n"));
				if (ParamStatusArray[i] != lastExpParamStatusArray[i]) {
					TEST_FAILED;
					LogMsg(ERRMSG,_T("Param status array at row #%d is expected: %d, actual %d\n"), i, lastExpParamStatusArray[i], ParamStatusArray[i]);
					continue;
				}
				switch (ParamStatusArray[i]) {
					case SQL_PARAM_SUCCESS:
					case SQL_PARAM_SUCCESS_WITH_INFO:
         					LogMsg(NONE,_T("%13d  Success\n"), i);
         					break;

      					case SQL_PARAM_ERROR:
         					LogMsg(NONE,_T("%13d  Error  <-------\n"), i);
         					break;

      					case SQL_PARAM_UNUSED:
        					LogMsg(NONE,_T("%13d  Not processed\n"), i);
        					break;

     					case SQL_PARAM_DIAG_UNAVAILABLE:
         					LogMsg(NONE,_T("%13d  Unknown\n"), i);
         					break;
   				}
			}
			LogMsg(NONE,_T("\n============================================================\n"));
			lastParamsProcessed = ParamsProcessed;
			for (j=0; j<ARRAY_SIZE; j++) {
				lastExpParamStatusArray[j] = expParamStatusArray[j];
			}
		}
		else {
			if (expRowcount != rowcount) {
				TEST_FAILED;
				LogMsg(ERRMSG,_T("Expected Rowcount=%d, Actual Rowcount=%d\n"), expRowcount, rowcount);
			}

			LogMsg(NONE,_T("\n%d current rows processed, rowcount=%d\n"), ParamsProcessed, rowcount);
			for (i = 0; i < (int)ParamsProcessed; i++) {
   				LogMsg(NONE,_T("Parameter Set  Status\n"));
				LogMsg(NONE,_T("-------------  -------------\n"));
				if (ParamStatusArray[i] != expParamStatusArray[i]) {
					TEST_FAILED;
					LogMsg(ERRMSG,_T("Param status array at row #%d is expected: %d, actual %d\n"), i, expParamStatusArray[i], ParamStatusArray[i]);
					continue;
				}
				switch (ParamStatusArray[i]) {
					case SQL_PARAM_SUCCESS:
					case SQL_PARAM_SUCCESS_WITH_INFO:
         					LogMsg(NONE,_T("%13d  Success\n"), i);
         					break;

      					case SQL_PARAM_ERROR:
         					LogMsg(NONE,_T("%13d  Error  <-------\n"), i);
         					break;

      					case SQL_PARAM_UNUSED:
        					LogMsg(NONE,_T("%13d  Not processed\n"), i);
        					break;

     					case SQL_PARAM_DIAG_UNAVAILABLE:
         					LogMsg(NONE,_T("%13d  Unknown\n"), i);
         					break;
   				}
			}
			LogMsg(NONE,_T("\n============================================================\n"));
		}
		k++;
	}
	TESTCASE_END;

	SQLFreeStmt( hstmt, SQL_CLOSE );
	SQLFreeStmt( hstmt, SQL_UNBIND );
	SQLDisconnect( hdbc );
	SQLFreeConnect( hdbc );
	SQLFreeEnv( henv );

	//==================================================================================================
	LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing feature => Hash2.\n"));
	TEST_RETURN;
}