Example #1
0
/* prepare a cursor; return the ID number of that cursor */
static int
prepareCursor(const char *stmt, bool scrollflag)
{
    struct OCURS *o = findNewCursor();
    stmt = lineFormatStack(stmt, 0, &sqlargs);
    va_end(sqlargs);

    hstmt = o->hstmt;
    if(sql_debug)
	appendFile(sql_debuglog, "new cursor %d", o->cid);
    if(sql_debug2)
	printf("new cursor %d\n", o->cid);
    rc = SQLSetStmtOption(hstmt, SQL_CURSOR_TYPE,
       scrollflag ? SQL_CURSOR_STATIC : SQL_CURSOR_FORWARD_ONLY);
    if(errorTrap(0))
	return -1;

    if(!prepareInternal(stmt))
	return -1;
    o->numrets = rv_numRets;
    memcpy(o->rv_type, rv_type, NUMRETS);
    o->flag = (openfirst ? CURSOR_OPENED : CURSOR_PREPARED);
    o->rownum = 0;
    return o->cid;
}				/* prepareCursor */
Example #2
0
void t1_bind (HSTMT stmt, t1_t * t1)
{
  OBINDL (stmt, 1, t1->t1_row_no, t1->t1_row_no_len);
  OBINDFIX (stmt, 2, t1->t1_string1, t1->t1_string1_len);
  OBINDFIX (stmt, 3, t1->t1_string2, t1->t1_string2_len);
  OBINDFIX (stmt, 4, t1->t1_fs1, t1->t1_fs1_len);
  OBINDL (stmt, 5, t1->t1_fi2, t1->t1_fi2_len);

  IF_ERR_GO (stmt, end, SQLSetStmtOption (stmt, SQL_BIND_TYPE, sizeof (t1_t)));
 end: ;
}
Example #3
0
int
main (int argc, char *argv[])
{
   rc = SQLAllocEnv (&henv);
   IF_EERR_EXIT (henv, rc);

   rc = SQLAllocConnect (henv, &hdbc);
   IF_CERR_EXIT (hdbc, rc);

   rc = SQLConnect (hdbc,
       argc > 1 ? argv[1] : "1111", SQL_NTS,
       argc > 2 ? argv[2] : "dba", SQL_NTS,
       argc > 3 ? argv[3] : "dba", SQL_NTS);
   IF_CERR_EXIT (hdbc, rc);

   rc = SQLAllocStmt (hdbc, &hstmt);
   IF_CERR_EXIT (hdbc, rc);

   rc = SQLSetStmtOption (hstmt, SQL_ROWSET_SIZE, 10);
   rc = SQLSetStmtOption (hstmt, SQL_CURSOR_TYPE, SQL_CURSOR_KEYSET_DRIVEN);

   rc = SQLExecDirect (hstmt, "select distinct name_part (KEY_TABLE, 0) as DB from DB.DBA.SYS_KEYS", SQL_NTS);
   while (SQL_SUCCESS == (rc = SQLFetch (hstmt)))
     {
       char data[128];
       SDWORD len = sizeof (data);
       IF_ERR_EXIT (hstmt, rc);
       rc = SQLGetData (hstmt, 1, SQL_C_CHAR, data, sizeof (data), &len);
       IF_ERR_EXIT (hstmt, rc);
       if (rc == SQL_SUCCESS)
	 fprintf (stdout, "%s\n", data);
     }
   IF_ERR_EXIT (hstmt, rc);
   SQLDisconnect (hdbc);
   SQLFreeConnect (hdbc);
   SQLFreeEnv (henv);

   return 0;
}
Example #4
0
void
t1_window (t1_window_t * tw, char * name,  HDBC hdbc, char * text,
	   int cr_type, long kssz, long rssz, int conc,
	   option_t * opts)
{
  option_t * o = opts;
  SQLAllocStmt (hdbc, &tw->tw_stmt);
  tw->tw_name = name;


  IF_ERR_GO (tw->tw_stmt, cerr, SQLSetStmtOption (tw->tw_stmt, SQL_CONCURRENCY, conc));
 cerr: ;
  IF_ERR_GO (tw->tw_stmt, err, SQLSetStmtOption (tw->tw_stmt, SQL_CURSOR_TYPE, cr_type));
  IF_ERR_GO (tw->tw_stmt, err, SQLSetStmtOption (tw->tw_stmt, SQL_KEYSET_SIZE, kssz));
  IF_ERR_GO (tw->tw_stmt, err, SQLSetStmtOption (tw->tw_stmt, SQL_ROWSET_SIZE, rssz));
  IF_ERR_GO (tw->tw_stmt, err, SQLSetCursorName (tw->tw_stmt, (SQLCHAR *) name, SQL_NTS));

  if (o)
    {
      while (o->o_f != -1)
	{
	  IF_ERR_GO (tw->tw_stmt, err, SQLSetStmtOption (tw->tw_stmt, o->o_f, o->o_v));
	  o++;
	}
    }

  IF_ERR_GO (tw->tw_stmt, err, (tw->tw_rc = SQLExecDirect (tw->tw_stmt, (SQLCHAR *) text, SQL_NTS)));

  tw->tw_set = (t1_t*) malloc (sizeof (t1_t) * (rssz + 1));
  tw->tw_stat = (UWORD*) malloc (sizeof (UWORD) * (rssz + 1));
  tw->tw_size = rssz;
  t1_bind (tw->tw_stmt, tw->tw_set);

  printf ("\n\nWindow %s = %s\n", tw->tw_name, text);
  tw->tw_hdbc = hdbc;
 err: ;
}
RETCODE
backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
{
	RETCODE		rc;

	rc = SQLAllocStmt( dbh, sth );
	if ( rc != SQL_SUCCESS ) {
		return rc;
	}

#ifdef BACKSQL_TRACE
	Debug( LDAP_DEBUG_TRACE, "==>backsql_Prepare()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */

#ifdef BACKSQL_MSSQL_WORKAROUND
	{
		char		drv_name[ 30 ];
		SWORD		len;

		SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len );

#ifdef BACKSQL_TRACE
		Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n",
				drv_name, 0, 0 );
#endif /* BACKSQL_TRACE */

		ldap_pvt_str2upper( drv_name );
		if ( !strncmp( drv_name, "SQLSRV32.DLL", STRLENOF( "SQLSRV32.DLL" ) ) ) {
			/*
			 * stupid default result set in MS SQL Server
			 * does not support multiple active statements
			 * on the same connection -- so we are trying 
			 * to make it not to use default result set...
			 */
			Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "
				"enabling MS SQL Server default result "
				"set workaround\n", 0, 0, 0 );
			rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, 
					SQL_CONCUR_ROWVER );
			if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
				Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): "
					"SQLSetStmtOption(SQL_CONCURRENCY,"
					"SQL_CONCUR_ROWVER) failed:\n", 
					0, 0, 0 );
				backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc );
				SQLFreeStmt( *sth, SQL_DROP );
				return rc;
			}
		}
	}
#endif /* BACKSQL_MSSQL_WORKAROUND */

	if ( timeout > 0 ) {
		Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "
			"setting query timeout to %d sec.\n", 
			timeout, 0, 0 );
		rc = SQLSetStmtOption( *sth, SQL_QUERY_TIMEOUT, timeout );
		if ( rc != SQL_SUCCESS ) {
			backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc );
			SQLFreeStmt( *sth, SQL_DROP );
			return rc;
		}
	}

#ifdef BACKSQL_TRACE
	Debug( LDAP_DEBUG_TRACE, "<==backsql_Prepare() calling SQLPrepare()\n",
			0, 0, 0 );
#endif /* BACKSQL_TRACE */

	return SQLPrepare( *sth, (SQLCHAR *)query, SQL_NTS );
}
Example #6
0
SQLRETURN SQLSetStmtOptionA( SQLHSTMT statement_handle,
           SQLUSMALLINT option,
           SQLULEN value )
{
	return SQLSetStmtOption( statement_handle, option, value );
}
Example #7
0
int
main (int argc, char *argv[])
{
  if (argc < 4)
    {
      fprintf (stderr,
	  "ERR : called as setcurs <dsn> <uid> <pwd> [<scroll>=1]\n");
      exit (-3);
    }
  rc = SQLAllocEnv (&henv);
  if (rc != SQL_SUCCESS)
    {
      fprintf (stderr, "ERR : cannot alloc ODBC environment\n");
      exit (-3);
    }
  rc = SQLAllocConnect (henv, &hdbc);
  CHK_ERR (SQL_NULL_HSTMT);
  rc = SQLConnect (hdbc, argv[1], SQL_NTS, argv[2], SQL_NTS, argv[3],
      SQL_NTS);
  CHK_ERR (SQL_NULL_HSTMT);
  /* Allocate the statements and set the cursor name. */

  rc = SQLAllocStmt (hdbc, &hstmtSelect);
  CHK_ERR (SQL_NULL_HSTMT);
  rc = SQLAllocStmt (hdbc, &hstmtUpdate);
  CHK_ERR (SQL_NULL_HSTMT);
  if (argc <= 4 || atoi (argv[4]) != 0)
    {
      rc = SQLSetStmtOption (hstmtSelect, SQL_CURSOR_TYPE, SQL_CURSOR_STATIC);
      CHK_ERR (hstmtSelect);
      rc = SQLSetScrollOptions (hstmtSelect, SQL_CONCUR_READ_ONLY, 1, 1);
      CHK_ERR (hstmtSelect);
    }
  rc = SQLSetCursorName (hstmtSelect, "C1", SQL_NTS);
  CHK_ERR (hstmtSelect);

  /* SELECT the result set and bind its columns to local buffers. */

  rc = SQLExecDirect (hstmtSelect, "SELECT NAME,PHONE from GOGO", SQL_NTS);
  CHK_ERR (hstmtSelect);
  rc = SQLBindCol (hstmtSelect, 1, SQL_C_CHAR, szName, NAME_LEN, &cbName);
  CHK_ERR (hstmtSelect);
  rc = SQLBindCol (hstmtSelect, 2, SQL_C_CHAR, szPhone, PHONE_LEN, &cbPhone);
  CHK_ERR (hstmtSelect);

  /* Read through the result set until the cursor is */
  /* positioned on the row for John Smith. */

  do
    retcode = SQLFetch (hstmtSelect);
  while ((retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) &&
      (strcmp (szName, "Smith, John") != 0));
  rc = retcode;
  CHK_ERR (hstmtSelect);
  /* Perform a positioned update of John Smith's name. */

  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
    {
      rc = SQLExecDirect (hstmtUpdate,
	  "UPDATE GOGO SET PHONE='2064890154' WHERE CURRENT OF C1", SQL_NTS);
      CHK_ERR (hstmtUpdate);
    }
#if 0
  SQLFreeStmt (hstmtUpdate, SQL_DROP);
  SQLFreeStmt (hstmtSelect, SQL_DROP);
  SQLDisconnect (hdbc);
  SQLFreeConnect (hdbc);
#endif
  printf ("PASSED: SetCursorName Test\n");
  exit (0);
}
Example #8
0
static int odbc_dispatch11(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;

	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);


	switch(arg1)
	{
		case 0:
			retval = (unsigned long) SQLAllocHandleStd(((SQLSMALLINT  ) arg2),((SQLHANDLE  ) arg3),((SQLHANDLE * ) arg4));
			break;
		case 1:
			retval = (unsigned long) SQLParamOptions(((SQLHSTMT  ) arg2),((SQLUINTEGER  ) arg3),((SQLUINTEGER * ) arg4));
			break;
		case 2:
			retval = (unsigned long) SQLTransact(((SQLHENV  ) arg2),((SQLHDBC  ) arg3),((SQLUSMALLINT  ) arg4));
			break;
		case 3:
			retval = (unsigned long) SQLSetStmtOption(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLUINTEGER  ) arg4));
			break;
		case 4:
			retval = (unsigned long) SQLSetConnectOption(((SQLHDBC  ) arg2),((SQLUSMALLINT  ) arg3),((SQLUINTEGER  ) arg4));
			break;
		case 5:
			retval = (unsigned long) SQLPutData(((SQLHSTMT  ) arg2),((SQLPOINTER  ) arg3),((SQLINTEGER  ) arg4));
			break;
		case 6:
			retval = (unsigned long) SQLGetStmtOption(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLPOINTER  ) arg4));
			break;
		case 7:
			retval = (unsigned long) SQLGetFunctions(((SQLHDBC  ) arg2),((SQLUSMALLINT  ) arg3),((SQLUSMALLINT * ) arg4));
			break;
		case 8:
			retval = (unsigned long) SQLGetConnectOption(((SQLHDBC  ) arg2),((SQLUSMALLINT  ) arg3),((SQLPOINTER  ) arg4));
			break;
		case 9:
			retval = (unsigned long) SQLFetchScroll(((SQLHSTMT  ) arg2),((SQLSMALLINT  ) arg3),((SQLINTEGER  ) arg4));
			break;
		case 10:
			retval = (unsigned long) SQLEndTran(((SQLSMALLINT  ) arg2),((SQLHANDLE  ) arg3),((SQLSMALLINT  ) arg4));
			break;
		case 11:
			retval = (unsigned long) SQLAllocHandle(((SQLSMALLINT  ) arg2),((SQLHANDLE  ) arg3),((SQLHANDLE * ) arg4));
			break;
		default:
			PI_FAIL;
	}
	PI_makedouble(&rval,&rtype,(double) retval);
	if (PI_unify(arg5,type5,rval,rtype))
		PI_SUCCEED;
	PI_FAIL;
}
Example #9
0
PassFail TestSQLFetch(TestInfo *pTestInfo)
{   
	TEST_DECLARE;
 	TCHAR				Heading[MAX_STRING_SIZE];
 	RETCODE				returncode;
 	SQLHANDLE 			henv;
 	SQLHANDLE 			hdbc;
 	SQLHANDLE			hstmt;
	SQLUSMALLINT		i, j, k, fn, h;
	SWORD				col;
	TCHAR				*CCharOutput1[MAX_NUM1], CCharOutput2[NAME_LEN];
	SQLLEN				OutputLen1[MAX_NUM1], OutputLen2;
	SQLSMALLINT			CType[] = {SQL_C_TCHAR};
	//TCHAR					*TestCType[] = 
	//							{
	//								"SQL_C_TCHAR","SQL_C_BINARY","SQL_C_SSHORT","SQL_C_USHORT","SQL_C_SHORT","SQL_C_SLONG",
	//								"SQL_C_ULONG","SQL_C_FLOAT","SQL_C_DOUBLE","SQL_C_DATE","SQL_C_TIME","SQL_C_TIMESTAMP"
	//							};
	//TCHAR					*TestSQLType[] = 
	//							{
	//								"SQL_CHAR","SQL_VARCHAR","SQL_DECIMAL","SQL_NUMERIC","SQL_SMALLINT","SQL_INTEGER","SQL_REAL",
	//								"SQL_FLOAT","SQL_DOUBLE","SQL_DATE","SQL_TIME","SQL_TIMESTAMP","SQL_BIGINT",
	//								"SQL_DECIMAL","SQL_DECIMAL","SQL_DECIMAL","SQL_DECIMAL","SQL_DECIMAL","SQL_DECIMAL","SQL_DECIMAL","SQL_DECIMAL"
	//								"SQL_LONGVARCHAR","SQL_WCHAR","SQL_WVARCHAR","SQL_WLONGVARCHAR"
	//							};
	TCHAR					*ExecDirStr[5];
	TCHAR					*CResults[] = 
								{
#ifndef _WM
									_T("--"),_T("--"),_T("1234.56789"),_T("1234.56789"),_T("1200"),_T("12000"),
									_T("12345.0"),_T("123450.0"),_T("1234500.0"),_T("1993-07-01"),_T("09:45:30"),
									_T("1993-08-02 08:44:31.001000"),_T("120000"),
									_T("1234567890123456789"),
									_T("1234567890123.456789"),
									_T("1234567890123456789012345678901234567890"),
									_T("0.12345678901234567890123456789012345678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
									_T("1234567890.1234567890123456789012345678901234567890000000000000000000000000"),
									_T("12345.56789"),
									_T("1234567890123.56789"),
									_T("12345678901234567890.0123456789"),
#ifdef UNICODE
									_T("--"),_T("--"),_T("--"),_T("--"),_T("--"),_T("--")
#else
									_T("--"),_T("--"),_T("--"),_T("--")
#endif

#else
									_T("--"),_T("--"),_T("1234.56789"),_T("1234.56789"),_T("1200"),_T("12000"),
									_T("12345.0"),_T("123450.0"),_T("1234500.0"),_T("93/07/01"),_T("09:45:30"),
									_T("1993-08-02 08:44:31.001000"),_T("120000"),
									_T("1234567890123456789"),
									_T("1234567890123.456789"),
									_T("1234567890123456789012345678901234567890"),
									_T(".12345678901234567890123456789012345678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
									_T("1234567890.1234567890123456789012345678901234567890000000000000000000000000"),
									_T("12345.56789"),
									_T("1234567890123.56789"),
									_T("12345678901234567890.0123456789"),
									_T("--"),_T("--"),_T("--"),_T("--"),_T("--")
#endif
								};

	TCHAR					*FetchNStr[5];

	struct 
	{
		SQLULEN	AccessParam[2];
		SQLULEN	TransactParam[2];
	} ConnOption = {
			SQL_MODE_READ_WRITE,
			SQL_MODE_READ_ONLY,
			SQL_TXN_READ_COMMITTED,
			SQL_TXN_READ_UNCOMMITTED
		};

	struct _timeb	fetchstarttime;
	struct _timeb fetchendtime;
	long		AccessTime[2];

	//Added for transaction isolation problems
	TCHAR *iso_level_cqd[] = {
		_T("control query default isolation_level 'READ_COMMITTED'"),
		_T("control query default isolation_level 'READ_UNCOMMITTED'"),
		_T("control query default isolation_level 'REPEATABLE_READ'"),
		_T("control query default isolation_level 'SERIALIZABLE'"),
		_T("endloop")
	};

	TCHAR *access_mode[] = {
		_T("default"),
		_T("set transaction READ ONLY"),
		_T("set transaction READ WRITE"),
		_T("endloop")
	};

	SQLTCHAR *sqlstring0 = (SQLTCHAR*)_T("DROP TABLE YRWK_TY_POS_2");
	SQLTCHAR *sqlstring1 = (SQLTCHAR*)_T("CREATE TABLE YRWK_TY_POS_2 ( C1 NUMERIC (9, 2) , C2 NUMERIC (9, 2)) NO PARTITION");
	SQLTCHAR *sqlstring2 = (SQLTCHAR*)_T("INSERT INTO YRWK_TY_POS_2 VALUES (119.28, 6)");
	SQLTCHAR *sqlstring3 = (SQLTCHAR*)_T("SELECT SUM(C1) + SUM(C2) FROM YRWK_TY_POS_2");
	//SQLTCHAR sqlstring0[] = _T("DROP TABLE YRWK_TY_POS_2");
	//SQLTCHAR sqlstring1[] = _T("CREATE TABLE YRWK_TY_POS_2 ( C1 NUMERIC (9, 2) , C2 NUMERIC (9, 2)) NO PARTITION");
	//SQLTCHAR sqlstring2[] = _T("INSERT INTO YRWK_TY_POS_2 VALUES (119.28, 6)");
	//SQLTCHAR sqlstring3[] = _T("SELECT SUM(C1) + SUM(C2) FROM YRWK_TY_POS_2");

//===========================================================================================================
	var_list_t *var_list;
	var_list = load_api_vars(_T("SQLFetch"), charset_file);
	if (var_list == NULL) return FAILED;

	//print_list(var_list);
	ExecDirStr[0] = var_mapping(_T("SQLFetch_ExecDirStr_1"), var_list);
	ExecDirStr[1] = var_mapping(_T("SQLFetch_ExecDirStr_2"), var_list);
	ExecDirStr[2] = var_mapping(_T("SQLFetch_ExecDirStr_3"), var_list);
	ExecDirStr[3] = var_mapping(_T("SQLFetch_ExecDirStr_4"), var_list);
	ExecDirStr[4] = var_mapping(_T("SQLFetch_ExecDirStr_5"), var_list);

	CResults[0] = var_mapping(_T("SQLFetch_CResults_1"), var_list);
	CResults[1] = var_mapping(_T("SQLFetch_CResults_2"), var_list);

#ifdef UNICODE	
	CResults[21] = var_mapping(_T("SQLFetch_datastr1"), var_list);
	CResults[22] = var_mapping(_T("SQLFetch_datastr2"), var_list);
	CResults[23] = var_mapping(_T("SQLFetch_datastr3"), var_list);

	CResults[24] = var_mapping(_T("SQLFetch_CResults_24"), var_list);
	CResults[25] = var_mapping(_T("SQLFetch_CResults_25"), var_list);
	CResults[26] = var_mapping(_T("SQLFetch_CResults_26"), var_list);
#else
	CResults[21] = var_mapping(_T("SQLFetch_CResults_21"), var_list);
	CResults[22] = var_mapping(_T("SQLFetch_CResults_22"), var_list);
	CResults[23] = var_mapping(_T("SQLFetch_CResults_23"), var_list);
	CResults[24] = var_mapping(_T("SQLFetch_CResults_24"), var_list);
#endif

	FetchNStr[0] = var_mapping(_T("SQLFetch_FetchNStr_1"), var_list);
	FetchNStr[1] = var_mapping(_T("SQLFetch_FetchNStr_2"), var_list);
	FetchNStr[2] = var_mapping(_T("SQLFetch_FetchNStr_3"), var_list);
	FetchNStr[3] = var_mapping(_T("SQLFetch_FetchNStr_4"), var_list);
	FetchNStr[4] = var_mapping(_T("SQLFetch_FetchNStr_5"), var_list);

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

	LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API =>SQLFetch.\n"));

	TEST_INIT;

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

	if(!FullConnect(pTestInfo))
	{
		LogMsg(ERRMSG,_T("Unable to connect\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;
	}

	SQLExecDirect(hstmt,(SQLTCHAR*) ExecDirStr[0],SQL_NTS); /* cleanup */
	returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[1],SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

	returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[2], SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	TESTCASE_END; // end of setup

	for (i = 0; i < 1; i++)
	{ // begin of 1st for loop 
		_stprintf(Heading,_T("Test 1.%d: Positive functionality of SQLFetch by doing SQLBindcol\n"),i);
		TESTCASE_BEGINW(Heading);
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[3], SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			TEST_RETURN;
		}

		for (j=0; j<MAX_NUM1; j++)
		{
			CCharOutput1[j] = (TCHAR *)malloc(sizeof(TCHAR)*NAME_LEN);
			*(CCharOutput1[j])=(TCHAR)'\0';
			returncode = SQLBindCol(hstmt,(SWORD)(j+1),CType[i],CCharOutput1[j],NAME_LEN,&OutputLen1[j]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
				TEST_RETURN;
			}
		}

		returncode = SQLFetch(hstmt);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch"))
		{
			TEST_FAILED;
			LogAllErrors(henv,hdbc,hstmt);
		}
		else
		{
			for (j=0; j<MAX_NUM1; j++)
			{
				if (_tcscmp(CCharOutput1[j],CResults[j]) == 0)
				{
					LogMsg(NONE,_T("expect: '%s' and actual: '%s' of column %d are matched\n"),CResults[j],CCharOutput1[j],j+1);
				}	
				else
				{
					TEST_FAILED;	
					LogMsg(ERRMSG,_T("expect: '%s' and actual: '%s' of column %d are not match, at line %d\n"), CResults[j],CCharOutput1[j],j+1,__LINE__);
				}
				free(CCharOutput1[j]);
			} 
		}

		SQLFreeStmt(hstmt,SQL_CLOSE);
		TESTCASE_END;
	} // end of 1st for loop 

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

	TESTCASE_BEGIN("Setup for more SQLFetch tests\n");
	SQLFreeStmt(hstmt,SQL_DROP);
	SQLAllocStmt((SQLHANDLE)hdbc, &hstmt);	
	SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS);
	returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[2], SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	TESTCASE_END;

	for (i = 0; i < 1; i++)
	{
		_stprintf(Heading,_T("Test 2.%d: Positive functionality of SQLFetch by doing SQLGetData\n"),i);
		TESTCASE_BEGINW(Heading);
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[3], SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			TEST_RETURN;
		}
		returncode = SQLFetch(hstmt);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch"))
		{
			TEST_FAILED;
			LogAllErrors(henv,hdbc,hstmt);
		}
		else
		{
			for (j=0; j<MAX_NUM1; j++)
			{
				returncode = SQLGetData(hstmt,(SWORD)(j+1),CType[i],CCharOutput2,NAME_LEN,&OutputLen2);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetData"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt);
				}

				if (_tcscmp(CCharOutput2,CResults[j]) == 0)
				{
					LogMsg(NONE,_T("expect: '%s' and actual: '%s' of column %d are matched\n"), CResults[j],CCharOutput2,j+1);
				}	
				else
				{
					TEST_FAILED;	
					LogMsg(ERRMSG,_T("expect: '%s' and actual: '%s' of column %d are not match, at line %d\n"),CResults[j],CCharOutput2,j+1,__LINE__);
				}
			}
		}

		SQLFreeStmt(hstmt,SQL_CLOSE);
		TESTCASE_END;
	} 
	
//============================================================================================

	for (fn = 0; fn < NUM_FETCH_LOOP; fn++)
	{
		_stprintf(Heading,_T("Setup for Fetch %d tests\n"),(ROWS_INSERTED*(fn+1)));
		TESTCASE_BEGINW(Heading);
		SQLFreeStmt(hstmt,SQL_DROP);
		SQLAllocStmt((SQLHANDLE)hdbc, &hstmt);	
		SQLSetConnectOption((SQLHANDLE)hdbc,SQL_ACCESS_MODE,SQL_MODE_READ_WRITE);
		SQLSetConnectOption((SQLHANDLE)hdbc,SQL_TXN_ISOLATION,SQL_TXN_READ_COMMITTED);
		SQLExecDirect(hstmt,(SQLTCHAR*) FetchNStr[0],SQL_NTS); /* cleanup */
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)FetchNStr[1],SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			TEST_RETURN;
		}
		for (i = 0; i < (ROWS_INSERTED*(fn+1)); i++)
		{ 
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*)FetchNStr[2], SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				TEST_RETURN;
			}
		}
		TESTCASE_END; // end of setup

		_stprintf(Heading,_T("Test Positive functionality of Fetch %d by doing SQLBindcol\n"),(ROWS_INSERTED*(fn+1)));
		TESTCASE_BEGINW(Heading);
		for (k = 0; k < 2; k++)
		{
			returncode = SQLSetConnectOption((SQLHANDLE)hdbc,SQL_ACCESS_MODE,ConnOption.AccessParam[k]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnection Access"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
				TEST_RETURN;
			}
			returncode = SQLSetConnectOption((SQLHANDLE)hdbc,SQL_TXN_ISOLATION,ConnOption.TransactParam[k]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnection Transact"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
				TEST_RETURN;
			}
			returncode = SQLSetStmtOption(hstmt,SQL_ROWSET_SIZE,1);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtOption"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
				TEST_RETURN;
			}
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*)FetchNStr[3], SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				TEST_RETURN;
			}
			returncode = SQLNumResultCols(hstmt, &col);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLNumResultCols"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
			}
			for (j = 0; j < col; j++)
			{
				CCharOutput1[j] = (TCHAR *)malloc(NAME_LEN);
				*(CCharOutput1[j])=(TCHAR)'\0';
				returncode = SQLBindCol(hstmt,(SWORD)(j+1),SQL_C_TCHAR,CCharOutput1[j],NAME_LEN,&OutputLen1[j]);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt);
					TEST_RETURN;
				}
			} // end of 2nd for loop 

			returncode = SQL_SUCCESS;
			_ftime(&fetchstarttime);
			j = 0;
			while (returncode == SQL_SUCCESS)
			{
				returncode = SQLFetch(hstmt);
				if((returncode != SQL_SUCCESS) && (j < col)) // need to make sure we haven't fallen off the end of the table
				{
				   if (returncode == SQL_NO_DATA_FOUND)
				   {
					    if (!FindError(_T("00000"),henv,hdbc,hstmt)) // SQLState should be "00000" when return code is SQL_NO_DATA_FOUND.
						{	
							TEST_FAILED;
							//assert(0);
							LogMsg(NONE,_T("Rows #: %d : array %d suppose to be %d at line %d.\n"),j,k, (ROWS_INSERTED*(fn+1)),__LINE__);
							LogAllErrors(henv,hdbc,hstmt);
						}
				   }     
				   else
				   {
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt);
				   }
				}
				if (returncode == SQL_SUCCESS)
					j++;
			}
			_ftime(&fetchendtime);
			if (j == (ROWS_INSERTED*(fn+1)))
			{
				LogMsg(NONE,_T("Rows inserted Expected: %d and Actual: %d.\n"),(ROWS_INSERTED*(fn+1)),j);
			}	
			else
			{
				TEST_FAILED;	
				LogMsg(ERRMSG,_T("Rows inserted Expected: %d and Actual: %d at line%d.\n"),(ROWS_INSERTED*(fn+1)),j,__LINE__);
			}

			AccessTime[k] = (long)(((fetchendtime.time - fetchstarttime.time) * 1000) + (fetchendtime.millitm - fetchstarttime.millitm));
			for (j = 0; j < col; j++)
			{
				free(CCharOutput1[j]);
			} // end of 3rd for loop 
			SQLFreeStmt(hstmt,SQL_CLOSE);
		}
/*
		if (AccessTime[0] >= 	AccessTime[1])
		{
			LogMsg(NONE,_T("FETCH ONE: %d millisecs and FETCH N: %d millisecs.\n"),AccessTime[0],AccessTime[1]);
		}	
		else
		{
			TEST_FAILED;	
			LogMsg(ERRMSG,_T("FETCH ONE: %d millisecs and FETCH N: %d millisecs.\n"),AccessTime[0],AccessTime[1]);
		}
*/
		LogMsg(NONE,_T("FETCH ONE: %d millisecs and FETCH N: %d millisecs.\n"),AccessTime[0],AccessTime[1]);
		TESTCASE_END;
		SQLSetConnectOption((SQLHANDLE)hdbc,SQL_ACCESS_MODE,SQL_MODE_READ_WRITE);
		SQLSetConnectOption((SQLHANDLE)hdbc,SQL_TXN_ISOLATION,SQL_TXN_READ_COMMITTED);
		SQLExecDirect(hstmt,(SQLTCHAR*) FetchNStr[0],SQL_NTS); /* cleanup */
	}
	SQLExecDirect(hstmt,(SQLTCHAR*) ExecDirStr[0],SQL_NTS); /* cleanup */

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

	TESTCASE_BEGIN("Setup for SQLFetch isolation level tests\n");
	SQLFreeStmt(hstmt,SQL_DROP);
	SQLAllocStmt((SQLHANDLE)hdbc, &hstmt);	
	SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[0],SQL_NTS);/*clean up*/
	returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[1], SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[2], SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
	TESTCASE_END;

	i = 0; k = 0;
	while (_tcsicmp(iso_level_cqd[k],_T("endloop")) != 0)
	{
		h = 0;
		while (_tcsicmp(access_mode[h],_T("endloop")) != 0) {
			if ((_tcsstr(iso_level_cqd[k],_T("READ_UNCOMMITTED")) != NULL && _tcsstr(access_mode[h],_T("READ WRITE")) != NULL) ||
				(_tcsstr(iso_level_cqd[k],_T("REPEATABLE_READ")) != NULL && _tcsstr(access_mode[h],_T("default")) != NULL) ||
				(_tcsstr(iso_level_cqd[k],_T("SERIALIZABLE")) != NULL && _tcsstr(access_mode[h],_T("default")) != NULL))
			{
				h++;
				continue;
			}

			FullDisconnect(pTestInfo);

			_stprintf(Heading, _T("Setup for SQLFetch with: %s\nAnd access-mode: %s\n"), iso_level_cqd[k], access_mode[h]);
			TESTCASE_BEGINW(Heading);
			if(!FullConnect(pTestInfo))
			{
				LogMsg(ERRMSG,_T("Unable to connect\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,(SQLTCHAR*)iso_level_cqd[k],SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				TEST_RETURN;
			}

			if (_tcsicmp(access_mode[h],_T("default")) != 0) {
				returncode = SQLExecDirect(hstmt,(SQLTCHAR*)access_mode[h],SQL_NTS);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
					TEST_RETURN;
				}
			}

			TESTCASE_END; // end of setup

			_stprintf(Heading,_T("SQLFetch by doing SQLGetData\n"));
			TESTCASE_BEGINW(Heading);
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[3], SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
				//TEST_RETURN;
			}
			returncode = SQLFetch(hstmt);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
			}
			else
			{
				for (j=0; j<MAX_NUM1; j++)
				{
					returncode = SQLGetData(hstmt,(SWORD)(j+1),CType[i],CCharOutput2,NAME_LEN,&OutputLen2);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetData"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt);
					}

					if (_tcscmp(CCharOutput2,CResults[j]) == 0)
					{
						LogMsg(NONE,_T("expect: '%s' and actual: '%s' of column %d are matched\n"),CResults[j],CCharOutput2,j+1);
					}	
					else
					{
						TEST_FAILED;	
						LogMsg(ERRMSG,_T("expect: '%s' and actual: '%s' of column %d are not match, at line %d\n"),CResults[j],CCharOutput2,j+1,__LINE__);
					}
				}
			}

			SQLFreeStmt(hstmt,SQL_CLOSE);
			TESTCASE_END;
			h++;
		}

		k++;
	}//End while

	SQLExecDirect(hstmt,(SQLTCHAR*) ExecDirStr[0],SQL_NTS); /* cleanup */
	
//============================================================================================
	TESTCASE_BEGIN("Testcase for Mode_special_1\n");

	returncode = SQLExecDirect(hstmt,sqlstring0,SQL_NTS);

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

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

	returncode = SQLBindCol(hstmt,1,SQL_C_TCHAR,CCharOutput2,300,NULL);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}

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

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

#ifndef _WM
	if (_tcscmp(CCharOutput2,_T("125.2")) == 0)
	{
		LogMsg(NONE,_T("expect: '125.2' and actual: '%s' are matched\n"),CCharOutput2);
	}	
	else
	{
		TEST_FAILED;	
		LogMsg(ERRMSG,_T("expect: '125.2' and actual: '%s' are not match, at line %d\n"),CCharOutput2,__LINE__);
	}
#else
	if (_tcscmp(CCharOutput2,"125.28") == 0)
	{
		LogMsg(NONE,_T("expect: '125.28' and actual: '%s' are matched\n"),CCharOutput2);
	}	
	else
	{
		TEST_FAILED;	
		LogMsg(ERRMSG,_T("expect: '125.28' and actual: '%s' are not match, at line %d\n"),CCharOutput2,__LINE__);
	}
#endif

//============================================================================================
	
	FullDisconnect(pTestInfo);
	LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLFetch.\n"));
	free_list(var_list);
	TEST_RETURN;
}
Example #10
0
//---------------------------------------------------------
//   TestSQLAllocStmt()
//---------------------------------------------------------
PassFail TestSQLAllocStmt (TestInfo *pTestInfo, int MX_MP_SPECIFIC)
{
	TEST_DECLARE;
 	char			Heading[MAX_STRING_SIZE];
 	RETCODE			returncode;
 	SQLHANDLE 		henv;
 	SQLHANDLE 		hdbc;
 	SQLHANDLE		hstmt[NUM_STMT];
	//RETCODE		AsyncStmt[NUM_ASYNC_STMT];
	char			*StmtHndlStr;
	int				i = 0, j = 0, k = 0;
	int				AnyAsync;
	int				AsyncOper[] = {CREATE_TABLE,INSERT_TABLE,SELECT_TABLE,DROP_TABLE,999};

	char			*teststmthndl[21];

//===========================================================================================================
	var_list_t *var_list;
	var_list = load_api_vars("SQLAllocateStatement", charset_file);
	if (var_list == NULL) return FAILED;

	teststmthndl[0] = var_mapping("TestStmtHndl_0", var_list);
	teststmthndl[1] = var_mapping("TestStmtHndl_1", var_list);
	teststmthndl[2] = var_mapping("TestStmtHndl_2", var_list);
	teststmthndl[3] = var_mapping("TestStmtHndl_3", var_list);
	teststmthndl[4] = var_mapping("TestStmtHndl_4", var_list);
	teststmthndl[5] = var_mapping("TestStmtHndl_5", var_list);
	teststmthndl[6] = var_mapping("TestStmtHndl_6", var_list);
	teststmthndl[7] = var_mapping("TestStmtHndl_7", var_list);
	teststmthndl[8] = var_mapping("TestStmtHndl_8", var_list);
	teststmthndl[9] = var_mapping("TestStmtHndl_9", var_list);
	teststmthndl[10] = var_mapping("TestStmtHndl_10", var_list);
	teststmthndl[11] = var_mapping("TestStmtHndl_11", var_list);
	teststmthndl[12] = var_mapping("TestStmtHndl_12", var_list);
	teststmthndl[13] = var_mapping("TestStmtHndl_13", var_list);
	teststmthndl[14] = var_mapping("TestStmtHndl_14", var_list);
	teststmthndl[15] = var_mapping("TestStmtHndl_15", var_list);
	teststmthndl[16] = var_mapping("TestStmtHndl_16", var_list);
	teststmthndl[17] = var_mapping("TestStmtHndl_17", var_list);
	teststmthndl[18] = var_mapping("TestStmtHndl_18", var_list);
	teststmthndl[19] = var_mapping("TestStmtHndl_19", var_list);
	teststmthndl[20] = var_mapping("TestStmtHndl_20", var_list);
//======================================================================================

	if (MX_MP_SPECIFIC == MX_SPECIFIC)
		LogMsg(LINEBEFORE+SHORTTIMESTAMP,"Begin testing API => MX specific SQLAllocStmt | SQLAllocStmt | alocstmt.c\n");
	else
		LogMsg(LINEBEFORE+SHORTTIMESTAMP,"Begin testing API => MP specific SQLAllocStmt | SQLAllocStmt | alocstmt.c\n");

	TEST_INIT;

	TESTCASE_BEGIN("Setup for SQLAllocStmt/SQLFreeStmt tests\n");

	/* 6-5-00:
	Need to turn Autocommit off since MX will close all open cursors that are
	open if the end of ANY of the cursors is reached. */
	if(!FullConnectWithOptions(pTestInfo, CONNECT_ODBC_VERSION_2))
	{
		LogMsg(NONE,"Unable to connect\n");
		TEST_FAILED;
		TEST_RETURN;
	}

	henv = pTestInfo->henv;
 	hdbc = pTestInfo->hdbc;
	//set the connection attribute to SQL_AUTOCOMMIT_OFF to enable use of multiple stmt  without errors 
	SQLSetConnectAttr((SQLHANDLE)hdbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER);

	TESTCASE_END;  // end of setup

	StmtHndlStr = (char *)malloc(MAX_NOS_SIZE);

//====================================================================================================
// General statement handle exercise testcases.

	for (k = 0; k < 2; k++)
	{
		for (i = 0; i < NUM_STMT; i++)
		{
			hstmt[i] = (SQLHANDLE)pTestInfo->hstmt;

			sprintf(Heading,"SQLAllocstmt: Test #%d\n",i);
			TESTCASE_BEGIN(Heading);
			returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt[i]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}
			TESTCASE_END;
			if (returncode == SQL_SUCCESS)
			{
		 		if (i == 0)									// cleanup 
				{
					for (j = 0; j < NUM_STMT; j++)
					{
						SQLExecDirect(hstmt[0],StmtQueries(DROP_TABLE,teststmthndl[j],StmtHndlStr),SQL_NTS); 
					}
				}
				sprintf(Heading,"SQLAllocStmt: create table teststmthndl%d\n",i+1);
				TESTCASE_BEGIN(Heading);
				if (k == 0)	// prepare & execute 
				{
					returncode = SQLPrepare(hstmt[i],StmtQueries(CREATE_TABLE,teststmthndl[i],StmtHndlStr),SQL_NTS); 
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
					else{
						returncode = SQLExecute(hstmt[i]);
						if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){
							TEST_FAILED;
							LogAllErrors(henv,hdbc,hstmt[i]);
							}
						}
					}
				else	// execdirect 
				{
					returncode = SQLExecDirect(hstmt[i],StmtQueries(CREATE_TABLE,teststmthndl[i],StmtHndlStr),SQL_NTS);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
				}
				}
				if (returncode == SQL_SUCCESS) TESTCASE_END;
			}

		for (i = 0; i < NUM_STMT; i++)
		{
			sprintf(Heading,"SQLAllocStmt: inserts on Stmt Handle(%d)\n",i);
			TESTCASE_BEGIN(Heading);
			if (k == 0)	// prepare & execute 
			{
				returncode = SQLPrepare(hstmt[i],StmtQueries(INSERT_TABLE,teststmthndl[i],StmtHndlStr),SQL_NTS); 
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt[i]);
				}
				else
				{
					returncode = SQLExecute(hstmt[i]);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
				}
			}
			else	// execdirect 
			{
				returncode = SQLExecDirect(hstmt[i],StmtQueries(INSERT_TABLE,teststmthndl[i],StmtHndlStr),SQL_NTS); 
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt[i]);
				}
			}
			if (returncode == SQL_SUCCESS)TESTCASE_END;
		}

		for (i = 0; i < NUM_STMT; i++)
		{
			sprintf(Heading,"SQLAllocStmt: selects on Stmt Handle(%d)\n",i);
			TESTCASE_BEGIN(Heading);
			if (k == 0)	// prepare & execute 
			{
				returncode = SQLPrepare(hstmt[i],StmtQueries(SELECT_TABLE,teststmthndl[i],StmtHndlStr),SQL_NTS); 
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt[i]);
				}
				else{
					returncode = SQLExecute(hstmt[i]);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
						}
					}
			}
			else	// execdirect 
			{
				returncode = SQLExecDirect(hstmt[i],StmtQueries(SELECT_TABLE,teststmthndl[i],StmtHndlStr),SQL_NTS); 
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt[i]);
				}
			}
			if (returncode == SQL_SUCCESS) TESTCASE_END;
		}

		for (i = (NUM_STMT-1); i > -1; i--)
		{
			sprintf(Heading,"SQLAllocStmt: fetches on selects on Stmt Handle(%d)\n",i);
			TESTCASE_BEGIN(Heading);
			returncode = SQLFetch(hstmt[i]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}			
			if (returncode == SQL_SUCCESS) TESTCASE_END;
		}

		for (i = 0; i < NUM_STMT; i++)
		{
			sprintf(Heading,"SQLAllocStmt: SQLFreeStmt(%d) with SQL_CLOSE\n",i);
			TESTCASE_BEGIN(Heading);
			returncode = SQLFreeStmt(hstmt[i],SQL_CLOSE);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeStmt"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}
			else{
				TESTCASE_END;
				}

			if (i == (NUM_STMT-1))					// cleanup 
			{
				for (j = 0; j < NUM_STMT; j++)
				{
					SQLExecDirect(hstmt[0],StmtQueries(DROP_TABLE,teststmthndl[j],StmtHndlStr),SQL_NTS); 
				}
			}
		}

		for (i = 0; i < NUM_STMT; i++)
		{
			sprintf(Heading,"SQLAllocStmt: SQLFreeStmt(%d) with SQL_DROP\n",i);
			TESTCASE_BEGIN(Heading);
			returncode = SQLFreeStmt(hstmt[i],SQL_DROP);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeStmt"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}
			else{
				TESTCASE_END;
				}
		}

		sprintf(Heading,"SLQAllocStmt: same sql operations on different of SQLAllocstmt(%d)s\n",i);
		TESTCASE_BEGIN(Heading);
 		for (i = 0; i < NUM_STMT; i++)
		{
			hstmt[i] = (SQLHANDLE)pTestInfo->hstmt;
			returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt[i]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}
			if (returncode == SQL_SUCCESS)
			{
		 		if (i == 0)									// cleanup
				{
					SQLExecDirect(hstmt[0],StmtQueries(DROP_TABLE,teststmthndl[20],StmtHndlStr),SQL_NTS); 
					returncode = SQLExecDirect(hstmt[0],StmtQueries(CREATE_TABLE,teststmthndl[20],StmtHndlStr),SQL_NTS); 
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[0]);
					}			
				}
				if (k == 0)	// prepare & execute 
				{
					returncode = SQLPrepare(hstmt[i],StmtQueries(INSERT_TABLE,teststmthndl[20],StmtHndlStr),SQL_NTS);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}			
					returncode = SQLExecute(hstmt[i]);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
				}
				else	// execdirect
				{
					returncode = SQLExecDirect(hstmt[i],StmtQueries(INSERT_TABLE,teststmthndl[20],StmtHndlStr),SQL_NTS);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
				}
				if (k == 0)	// prepare & execute 
				{
					returncode = SQLPrepare(hstmt[i],StmtQueries(SELECT_TABLE,teststmthndl[20],StmtHndlStr),SQL_NTS);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}			
					returncode = SQLExecute(hstmt[i]);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
				}
				else
				{
					returncode = SQLExecDirect(hstmt[i],StmtQueries(SELECT_TABLE,teststmthndl[20],StmtHndlStr),SQL_NTS);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
				}
				returncode = SQLFetch(hstmt[i]); 
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt[i]);
				}
			}
		}
 		for (i = 0; i < NUM_STMT; i++)
		{
			returncode = SQLFreeStmt(hstmt[i],SQL_CLOSE);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}
			if (i == 0)
			{
				SQLExecDirect(hstmt[0],StmtQueries(DROP_TABLE,teststmthndl[20],StmtHndlStr),SQL_NTS); 
			}
			returncode = SQLFreeStmt(hstmt[i],SQL_DROP);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeStmt"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}
		}
		TESTCASE_END;
	}

//====================================================================================================
// Asynchronus Testcases

	if (MX_MP_SPECIFIC == MX_SPECIFIC)
	{
		for (i = 0; i < NUM_ASYNC_STMT; i++)
		{
			hstmt[i] = (SQLHANDLE)pTestInfo->hstmt;
			// Creating statement handles
			sprintf(Heading,"SQLAllocstmt: Test #%d and Enable the ASYNC MODE ON.\n",i);
			TESTCASE_BEGIN(Heading);
			returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt[i]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt[i]);
			}
			else
			{
		 		if (i == 0)									// cleanup 
				{
					// Creating tables to be used by each of the stmt handles
					for (j = 0; j < NUM_ASYNC_STMT; j++)
					{
						SQLExecDirect(hstmt[0],StmtQueries(DROP_TABLE,teststmthndl[j],StmtHndlStr),SQL_NTS); 
					}
				}
				// Putting each stmthandle into Asynchronus mode
				returncode = SQLSetStmtOption(hstmt[i],SQL_ASYNC_ENABLE,SQL_ASYNC_ENABLE_ON);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtOptions"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt[i]);
				}
			}
			TESTCASE_END;
		}

		// Running the Asynchronus tests
		// WHAT IS GOING ON
		//   Two tests cases are being checked:
		//     1. That the status of an asynchronus stmt handle CAN be checked.
		//     2. That the stmt handle completes correctly.
		//
		// HOW IT'S BEING RUN
		//   Steps being performed until all handles are no longer executing:
		//     1. Prepare the async test data structure.
		//     2. Generate table name based on statement handle being used.
		//     3. If handle's status has not been checked already, check as test case 1.
		//        Else, check it's status NOT as a test case.
		//     4. Run the statement (also used to check the status of the handle).
		//     5. If the stmt completes, verify that it does so successfully. Test case 2.
		//
		//   Once all of the handles have completed, perform the next Async Operation
		//   until the terminating operation (a.k.a "999") is reached.
		k = 0;
		while (AsyncOper[k] != 999)
		{
			// 1. Preparing the async test data structure
			for (i = 0; i < NUM_ASYNC_STMT; i++)
			{
				AsyncStmt[i].status = SQL_STILL_EXECUTING;
				AsyncStmt[i].checked = FALSE;
			}
			AnyAsync = 1;
			// Testing begins
			while (AnyAsync > 0)
			{
				for (i = 0; i < NUM_ASYNC_STMT; i++)
				{
					if (AsyncStmt[i].status == SQL_STILL_EXECUTING)
					{
						// 3. Has the handle been checked for its status?
						if (AsyncStmt[i].checked)
						{
							// 4. Run the statement.
							returncode = SQLExecDirect(hstmt[i],StmtQueries(AsyncOper[k],teststmthndl[i],StmtHndlStr),SQL_NTS);
							AsyncStmt[i].status = returncode;
							// 5. Result Test: Verifying that the statement completes correctly.
							if (returncode != SQL_STILL_EXECUTING)
							{
								sprintf(Heading,"SQLAllocStmt: Result Test: %d; SQLStmt: %s.\n",i,StmtQueries(AsyncOper[k],teststmthndl[i],StmtHndlStr));
								TESTCASE_BEGIN(Heading);
								if (returncode != SQL_SUCCESS)
								{
									TEST_FAILED;
									LogAllErrors(henv,hdbc,hstmt[i]);
								}
								TESTCASE_END;
							}
						}
						else
						{
							// Status Test (Test case 1):
							// Only EXECUTING and SUCCESS are acceptable, others are errors.
							//   This test is only run once!
							sprintf(Heading,"SQLAllocStmt: Status Test: %d; SQLStmt: %s.\n",i,StmtQueries(AsyncOper[k],teststmthndl[i],StmtHndlStr));
							TESTCASE_BEGIN(Heading);
							
							// 4. Run the statement.
							returncode = SQLExecDirect(hstmt[i],StmtQueries(AsyncOper[k],teststmthndl[i],StmtHndlStr),SQL_NTS);
							AsyncStmt[i].status = returncode;
							AsyncStmt[i].checked = TRUE;
							if ((returncode != SQL_STILL_EXECUTING) && (returncode != SQL_SUCCESS))
							{
								TEST_FAILED;
								LogAllErrors(henv,hdbc,hstmt[i]);
							}
							TESTCASE_END;
							
							// 5. If the stmt completes, verify that it does so successfully.
							if (returncode != SQL_STILL_EXECUTING)
							{
								// Result Test: Verifying that the stmt completes successfully.
								sprintf(Heading,"SQLAllocStmt: Result Test: %d; SQLStmt: %s.\n",i,StmtQueries(AsyncOper[k],teststmthndl[i],StmtHndlStr));
								TESTCASE_BEGIN(Heading);
								if (returncode != SQL_SUCCESS)
								{
									TEST_FAILED;
									LogAllErrors(henv,hdbc,hstmt[i]);
								}
								TESTCASE_END;
							}
							//Sleep (500);
						}
					}
				}
				AnyAsync = 0;
				for (i = 0; i < NUM_ASYNC_STMT; i++)
				{
					if (AsyncStmt[i].status == SQL_STILL_EXECUTING)
					{
						AnyAsync = AnyAsync + 1;
					}
				}
			}

			// Special tests for Fetching after doing a SELECT
			// Steps are identical to the above steps.
			if (AsyncOper[k] == SELECT_TABLE)
			{
				// Preparing data structure
				for (i = 0; i < NUM_ASYNC_STMT; i++)
				{
					AsyncStmt[i].status = SQL_STILL_EXECUTING;
					AsyncStmt[i].checked = FALSE;
				}
				AnyAsync = 1;
				// Select testing begins
				while (AnyAsync > 0)
				{
					for (i = 0; i < NUM_ASYNC_STMT; i++)
					{
						if (AsyncStmt[i].status == SQL_STILL_EXECUTING)
						{
							if (AsyncStmt[i].checked)
							{
								returncode = SQLFetch(hstmt[i]);
								AsyncStmt[i].status = returncode;									
								if (returncode != SQL_STILL_EXECUTING)
								{
									// Result Test
									sprintf(Heading,"SQLAllocStmt: Result Test:%d; performing SQLFetch.\n",i);
									TESTCASE_BEGIN(Heading);
									if (returncode != SQL_SUCCESS)
									{
										TEST_FAILED;
										LogAllErrors(henv,hdbc,hstmt[i]);
									}
									TESTCASE_END;
								}
							}
							else
							{
								// Status Test
								sprintf(Heading,"SQLAllocStmt: Status Test:%d; performing SQLFetch.\n",i);
								TESTCASE_BEGIN(Heading);
								returncode = SQLFetch(hstmt[i]);
								AsyncStmt[i].status = returncode;
								AsyncStmt[i].checked = TRUE;
								if ((returncode != SQL_STILL_EXECUTING) && (returncode != SQL_SUCCESS))
								{
									TEST_FAILED;
									LogAllErrors(henv,hdbc,hstmt[i]);
								}
								TESTCASE_END;

								// Result Test
								if (returncode != SQL_STILL_EXECUTING)
								{
									sprintf(Heading,"SQLAllocStmt: Result Test:%d; performing SQLFetch.\n",i);
									TESTCASE_BEGIN(Heading);
									if (returncode != SQL_SUCCESS)
									{
										TEST_FAILED;
										LogAllErrors(henv,hdbc,hstmt[i]);
									}
									TESTCASE_END;
								}
							}
						}
					}
					AnyAsync = 0;
					for (i = 0; i < NUM_ASYNC_STMT; i++)
					{
						if (AsyncStmt[i].status == SQL_STILL_EXECUTING)
						{
							AnyAsync = AnyAsync + 1;
						}
					}
				}
				// Closing the cursor from the SELECT stmt result set.
				for (i = 0; i < NUM_ASYNC_STMT; i++)
				{
					sprintf(Heading,"SQLFreeStmt: %d.\n",i);
					TESTCASE_BEGIN(Heading);
					returncode = SQLFreeStmt(hstmt[i],SQL_CLOSE);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeStmt"))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt[i]);
					}
					TESTCASE_END;
				}
			} // End of async SELECT test.

			// Resetting the checked status for the next operation.
			for (i = 0; i < NUM_ASYNC_STMT; i++)
			{
				AsyncStmt[i].checked = FALSE;
			}

			k++;
		}
	}
//====================================================================================================

	free(StmtHndlStr);
	returncode = SQLDisconnect((SQLHANDLE)hdbc);
    if(!CHECKRC(SQL_ERROR,returncode,"SQLDisconnect")) 
	{
		TEST_FAILED;	
		LogAllErrorsVer3(henv,hdbc,hstmt[0]);
	}	
	
	// Free the open transactions.
	returncode=SQLTransact((SQLHANDLE)henv,(SQLHANDLE)hdbc,SQL_ROLLBACK);
	Sleep(2);	

	returncode=FullDisconnect(pTestInfo);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFullDisconnect"))
	{
		TEST_FAILED;
		LogAllErrorsVer3(henv,hdbc,hstmt[0]);
	}
	
	LogMsg(SHORTTIMESTAMP+LINEAFTER,"End testing API => SQLAllocStmt.\n");

	free_list(var_list);

	TEST_RETURN;
}