Beispiel #1
0
static sql_rcode_t sql_select_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query)
{
	rlm_sql_unixodbc_conn_t *conn = handle->conn;
	SQLINTEGER i;
	SQLLEN len;
	int colcount;
	int state;

	/* Only state = 0 means success */
	if ((state = sql_query(handle, config, query))) {
		return state;
	}

	colcount = sql_num_fields(handle, config);
	if (colcount < 0) {
		return RLM_SQL_ERROR;
	}

	/* Reserving memory for result */
	conn->row = talloc_zero_array(conn, char *, colcount + 1); /* Space for pointers */

	for (i = 1; i <= colcount; i++) {
		SQLColAttributes(conn->stmt, ((SQLUSMALLINT) i), SQL_COLUMN_LENGTH, NULL, 0, NULL, &len);
		conn->row[i - 1] = talloc_array(conn->row, char, ++len);
		SQLBindCol(conn->stmt, i, SQL_C_CHAR, (SQLCHAR *)conn->row[i - 1], len, NULL);
	}

	return RLM_SQL_OK;
}
/*************************************************************************
 *
 *	Function: sql_select_query
 *
 *	Purpose: Issue a select query to the database
 *
 *************************************************************************/
static int sql_select_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config, char *querystr) {
	rlm_sql_unixodbc_conn_t *conn = handle->conn;
	SQLINTEGER column;
	SQLLEN len;
	int numfields;
	int state;

	/* Only state = 0 means success */
	if ((state = sql_query(handle, config, querystr))) {
		return state;
	}

	numfields=sql_num_fields(handle, config);
	if (numfields < 0) {
		return -1;
	}

	/* Reserving memory for result */
	conn->row = (char **) rad_malloc((numfields+1)*sizeof(char *));
	conn->row[numfields] = NULL;

	for(column = 1; column <= numfields; column++) {
		SQLColAttributes(conn->statement,((SQLUSMALLINT) column),SQL_COLUMN_LENGTH,NULL,0,NULL,&len);
		conn->row[column-1] = (char*)rad_malloc((int)++len);
		SQLBindCol(conn->statement, column, SQL_C_CHAR, (SQLCHAR *)conn->row[column-1], len, NULL);
	}
	return 0;
}
Beispiel #3
0
int CSQLDirect::GetColumnID( CString svField,CString svTable )
{
	UCHAR svColName[256];
	UCHAR ucOwner[256];
	SWORD swCol,swType,swScale,swNull;
	UDWORD pcbColDef;
	SDWORD wColLen;

	int nCol=1;

	// Get the total # of columns in this query.
	SQLColAttributes( m_hStmt,0,SQL_COLUMN_COUNT,ucOwner,256,&swScale,&wColLen );
	int nMaxCols=(int)wColLen;

	while( nCol<=nMaxCols ) {
		int nRet=SQLDescribeCol( m_hStmt,nCol,svColName,256,&swCol,&swType,&pcbColDef,&swScale,&swNull );
		SQLColAttributes( m_hStmt,nCol,SQL_COLUMN_TABLE_NAME,ucOwner,256,&swScale,&wColLen );

		// If we hit this condition, then our field is not in the dataset.
		if( nRet!=SQL_SUCCESS ) {
			nCol=0;
			break;
		}

		CString svName=svColName;
		CString svOwner=ucOwner;

		svName.TrimRight();
		svOwner.TrimRight();

		if( ( svName==svField ) ) {
			if(  !svTable.IsEmpty() ) {
				if( svOwner==svTable )
					break;
				else
					nCol++;
			}
			else
				break;
		}
		else
			nCol++;
	}

	return nCol;
}
Beispiel #4
0
/* Reads the field info using SQLDescribeCol and creates
   a gsql_field with the descriptive information filled in. */
static gsql_field *
get_gsql_field_from_result (gsql_result *result, int colnum)
{
  gsql_field *gfield = (gsql_field *)xmalloc (sizeof (gsql_field));
  short colType;
  UDWORD colPrecision;
  short colScale;
  short colNullable;
  char colName[512];
  RETCODE status;

  colName[0] = '\000';

  initialize_gsql_field (gfield);

  /* Get column name */
  status = SQLDescribeCol
    (result->hstmt, colnum, (UCHAR *) colName,
     sizeof (colName), NULL, &colType, &colPrecision,
     &colScale, &colNullable);

  if (status != SQL_SUCCESS)
    {
      gsql_save_error_message (result->db, "SQLDescribeCol");
    }
  else
    {
#if defined (SQL_COLUMN_TABLE_NAME)
      char tablename[512];
      SWORD FAR tablename_len = 0;
      SDWORD FAR ignore_return = 0;

      status = SQLColAttributes
	(result->hstmt, colnum, SQL_COLUMN_TABLE_NAME,
	 (PTR)tablename, sizeof (tablename), &tablename_len, &ignore_return);

      if (status == SQL_SUCCESS)
	{
	  tablename[tablename_len] = '\0';
	  gfield->table = strdup (tablename);
	}
#endif /* SQL_COLUMN_TABLE_NAME */

      gfield->name = strdup (colName);
      gfield->type = colType;
      gfield->length = colPrecision;
      gfield->nullable = colNullable;
    }

  return (gfield);
}
SQLRETURN SQL_API
SQLColAttributesA(SQLHSTMT StatementHandle,
		  SQLUSMALLINT ColumnNumber,
		  SQLUSMALLINT FieldIdentifier,
		  SQLPOINTER CharacterAttributePtr,
		  SQLSMALLINT BufferLength,
		  SQLSMALLINT *StringLengthPtr,
		  SQLLEN *NumericAttributePtr)
{
	return SQLColAttributes(StatementHandle,
				ColumnNumber,
				FieldIdentifier,
				CharacterAttributePtr,
				BufferLength,
				StringLengthPtr,
				NumericAttributePtr);
}
/*************************************************************************
 *
 *	Function: sql_select_query
 *
 *	Purpose: Issue a select query to the database
 *
 *************************************************************************/
static sql_rcode_t sql_select_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query) {

	int numfields = 0;
	int i = 0;
	char **row = NULL;
	long len = 0;
	rlm_sql_iodbc_conn_t *conn = handle->conn;

	if(sql_query(handle, config, query) < 0) {
		return -1;
	}

	numfields = sql_num_fields(handle, config);

	row = (char **) rad_malloc(sizeof(char *) * (numfields+1));
	memset(row, 0, (sizeof(char *) * (numfields)));
	row[numfields] = NULL;

	for(i=1; i<=numfields; i++) {
		SQLColAttributes(conn->stmt_handle, ((SQLUSMALLINT) i), SQL_COLUMN_LENGTH, NULL, 0, NULL, &len);
		len++;

		/*
		 * Allocate space for each column
		 */
		row[i - 1] = rad_malloc((size_t) len);

		/*
		 * This makes me feel dirty, but, according to Microsoft, it works.
		 * Any ODBC datatype can be converted to a 'char *' according to
		 * the following:
		 *
		 * http://msdn.microsoft.com/library/psdk/dasdk/odap4o4z.htm
		 */
		SQLBindCol(conn->stmt_handle, i, SQL_C_CHAR, (SQLCHAR *)row[i-1], len, 0);
	}

	conn->row = row;

	return 0;
}
Beispiel #7
0
/*
---------------------------------------------------------
   TestSQLTablePrivileges
---------------------------------------------------------
*/
PassFail TestMXSQLTablePrivileges( TestInfo *pTestInfo)
{
	TEST_DECLARE;
 	char			Heading[MAX_HEADING_SIZE];
	/*  */char	ColumnWC4_TabOwner[NAME_LEN];
 	RETCODE			returncode;
 	SQLHANDLE 		henv = (SQLHANDLE)NULL;
 	SQLHANDLE 		hdbc = (SQLHANDLE)NULL;
 	SQLHANDLE		hstmt = (SQLHANDLE)NULL, hstmt1 = (SQLHANDLE)NULL;
	CHAR			TableQualifier[NAME_LEN],TableOwner[NAME_LEN],*TableStr;

	CHAR			*TableName;
	
	// CHAR			*Grantor; //Assume that we log on as role.user
	CHAR            Grantor[SQL_MAX_ROLENAME_LEN+2];

	CHAR			oTableQualifier[NAME_LEN];  
	CHAR			oTableOwner[NAME_LEN];
	CHAR			oTableName[NAME_LEN];
	CHAR			oGrantor[NAME_LEN];
	CHAR			oGrantee[NAME_LEN];
	CHAR			oPrivilege[NAME_LEN];
	CHAR			oIs_Grantable[3];

	SQLLEN		oTableQualifierlen;
	SQLLEN		oTableOwnerlen;
	SQLLEN		oTableNamelen;
	SQLLEN		oGrantorlen = SQL_NTS;
	SQLLEN		oGranteelen;
	SQLLEN		oPrivilegelen;
	SQLLEN		oIs_Grantablelen;

/*  */
	struct
	{
		CHAR		*Col;
		CHAR		*Grantee;
		CHAR		*Is_Grantable;
		CHAR		*Privilege;
	} TableCol[] = {
		{"--",SQ_GRANTEE,"YES","DELETE"},
		{"--",SQ_GRANTEE,"NO","DELETE,SELECT"},
		{"--",SQ_GRANTEE,"YES","SELECT"},
		{"--",SQ_GRANTEE,"NO","DELETE"},
		{"--",SQ_GRANTEE,"YES","INSERT"},
		{"--",SQ_GRANTEE,"NO","UPDATE"},
		{"--",SQ_GRANTEE,"YES","REFERENCES"},
		{"--",SQ_GRANTEE,"NO","SELECT"},
		{"--",SQ_GRANTEE,"YES","INSERT"},
		{"--",SQ_GRANTEE,"NO","REFERENCES"},
		{"--",SQ_GRANTEE,"YES","UPDATE"},
		{"--",SQ_GRANTEE,"NO","REFERENCES"},
		{"--",SQ_GRANTEE,"YES","UPDATE"},
		{"--",SQ_GRANTEE,"NO","INSERT",},
		{"--",SQ_GRANTEE,"YES","SELECT"},
		{"--",SQ_GRANTEE,"NO","REFERENCES,SELECT"},
		{"--",SQ_GRANTEE,"YES","DELETE,INSERT,SELECT"},
		{"--",SQ_GRANTEE,"NO","INSERT,REFERENCES,UPDATE"},
		{"--",SQ_GRANTEE,"YES","SELECT,DELETE,INSERT,UPDATE"},
		{"--",SQ_GRANTEE,"NO","DELETE,INSERT,REFERENCES,UPDATE",},
		{"--",SQ_GRANTEE,"YES","DELETE,INSERT,REFERENCES,SELECT,UPDATE"},
		{"--",SQ_GRANTEE,"NO","DELETE"},						//Bignum
		{"--",SQ_GRANTEE,"YES","SELECT"},					//Bignum
		{"--",SQ_GRANTEE,"NO","INSERT"},						//Bignum
		{"--",SQ_GRANTEE,"YES","UPDATE"},					//Bignum
		{"--",SQ_GRANTEE,"NO","REFERENCES"},					//Bignum
		{"--",SQ_GRANTEE,"YES","SELECT,DELETE,INSERT,UPDATE"},//Bignum
		{"--",SQ_GRANTEE,"NO","INSERT,REFERENCES,UPDATE"},	//Bignum
		{"endloop",}
	};

	struct
	{
		CHAR		*TabQua;
		CHAR		*TabOwner;
		CHAR		*TabName;
		RETCODE		CheckCode;
		int			isEscape;
	} ColumnWC[] = {								// wild cards from here 
							{"--","--","--", SQL_SUCCESS,0},// Have a row with all valid values here so that 
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_ERROR,0},
							{"--","--","--", SQL_ERROR,0},
							{"--","--","--", SQL_ERROR,0},
							{"--","--","--", SQL_ERROR,0},
							{"--","--","--", SQL_ERROR,0}, 
							{"--","--","--", SQL_ERROR,0}, 
							{"--","--","--", SQL_ERROR,0}, 
							{"--","--","--", SQL_ERROR,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							{"--","--","--", SQL_SUCCESS,0},
							//	Testing escape sequences
							{"--","--","--", SQL_SUCCESS,1},
							{"--","--","--", SQL_SUCCESS,1},
							{"--","--","--", SQL_SUCCESS,1},
							{"--","--","--", SQL_SUCCESS,1},
							{"endloop",}
						};

	struct
	{
		CHAR		*TabQua;
		SWORD		TabQuaLen;
		CHAR		*TabOwner;
		SWORD		TabOwnerLen;
		CHAR		*TabName;
		SWORD		TabNameLen;
		CHAR		*ColName;
		SWORD		ColNameLen;
	} ColumnWC2[] = {								//	wild cards from here
							{"--", (SWORD)-1, "--",(SWORD)-1, "--",(SWORD)-1, "", (SWORD)-1},
							{"--", (SWORD)4,  "--",(SWORD)2,  "--",(SWORD)2,  "", (SWORD)2},
//							{"TEST_CATALOG", (SWORD)0, "TEST_SCHEMA",(SWORD)0, "TEST_TABLE",(SWORD)0, "", (SWORD)0},
							{"endloop",}
						};

	int cols;
	int	iatt;
	SWORD numOfCols = 0;
	SWORD pcbDesc;
	SQLLEN pfDesc;
	CHAR cn[COLNAME_LEN];
	SWORD cl;
	SWORD st;
	SQLULEN cp;
	SWORD cs, cnull;
	CHAR rgbDesc[RGB_MAX_LEN];
	CHAR *CharOutput[12];
	SQLLEN stringlength;	//	Attributes for columns added for negative testing
	UWORD DescrType[] = 
				{
					SQL_COLUMN_AUTO_INCREMENT,SQL_COLUMN_CASE_SENSITIVE,SQL_COLUMN_COUNT,
					SQL_COLUMN_DISPLAY_SIZE,SQL_COLUMN_LENGTH,SQL_COLUMN_MONEY,
					SQL_COLUMN_NULLABLE,SQL_COLUMN_PRECISION,SQL_COLUMN_SCALE,
					SQL_COLUMN_SEARCHABLE,SQL_COLUMN_TYPE,SQL_COLUMN_UNSIGNED,
					SQL_COLUMN_UPDATABLE,SQL_COLUMN_NAME,SQL_COLUMN_TYPE_NAME,
					SQL_COLUMN_OWNER_NAME,SQL_COLUMN_QUALIFIER_NAME,SQL_COLUMN_TABLE_NAME,
					SQL_COLUMN_LABEL
				};

	CHAR	*TestColumn;
	int		i = 0, k = 0;

    struct {
        char cat[STR_LEN];
        char sch[STR_LEN];
        char tab[STR_LEN];
    } displayBuf;

//	DWORD	nSize;


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

	TableName = var_mapping("SQLTablePrivileges_TableName", var_list);

	TestColumn = var_mapping("SQLTablePrivileges_TestColumn", var_list);

	TableCol[0].Col = var_mapping("SQLTablePrivileges_TableCol_Col_0", var_list);
	TableCol[1].Col = var_mapping("SQLTablePrivileges_TableCol_Col_1", var_list);
	TableCol[2].Col = var_mapping("SQLTablePrivileges_TableCol_Col_2", var_list);
	TableCol[3].Col = var_mapping("SQLTablePrivileges_TableCol_Col_3", var_list);
	TableCol[4].Col = var_mapping("SQLTablePrivileges_TableCol_Col_4", var_list);
	TableCol[5].Col = var_mapping("SQLTablePrivileges_TableCol_Col_5", var_list);
	TableCol[6].Col = var_mapping("SQLTablePrivileges_TableCol_Col_6", var_list);
	TableCol[7].Col = var_mapping("SQLTablePrivileges_TableCol_Col_7", var_list);
	TableCol[8].Col = var_mapping("SQLTablePrivileges_TableCol_Col_8", var_list);
	TableCol[9].Col = var_mapping("SQLTablePrivileges_TableCol_Col_9", var_list);
	TableCol[10].Col = var_mapping("SQLTablePrivileges_TableCol_Col_10", var_list);
	TableCol[11].Col = var_mapping("SQLTablePrivileges_TableCol_Col_11", var_list);
	TableCol[12].Col = var_mapping("SQLTablePrivileges_TableCol_Col_12", var_list);
	TableCol[13].Col = var_mapping("SQLTablePrivileges_TableCol_Col_13", var_list);
	TableCol[14].Col = var_mapping("SQLTablePrivileges_TableCol_Col_14", var_list);
	TableCol[15].Col = var_mapping("SQLTablePrivileges_TableCol_Col_15", var_list);
	TableCol[16].Col = var_mapping("SQLTablePrivileges_TableCol_Col_16", var_list);
	TableCol[17].Col = var_mapping("SQLTablePrivileges_TableCol_Col_17", var_list);
	TableCol[18].Col = var_mapping("SQLTablePrivileges_TableCol_Col_18", var_list);
	TableCol[19].Col = var_mapping("SQLTablePrivileges_TableCol_Col_19", var_list);
	TableCol[20].Col = var_mapping("SQLTablePrivileges_TableCol_Col_20", var_list);
	TableCol[21].Col = var_mapping("SQLTablePrivileges_TableCol_Col_21", var_list);
	TableCol[22].Col = var_mapping("SQLTablePrivileges_TableCol_Col_22", var_list);
	TableCol[23].Col = var_mapping("SQLTablePrivileges_TableCol_Col_23", var_list);
	TableCol[24].Col = var_mapping("SQLTablePrivileges_TableCol_Col_24", var_list);
	TableCol[25].Col = var_mapping("SQLTablePrivileges_TableCol_Col_25", var_list);
	TableCol[26].Col = var_mapping("SQLTablePrivileges_TableCol_Col_26", var_list);
	TableCol[27].Col = var_mapping("SQLTablePrivileges_TableCol_Col_27", var_list);

	ColumnWC[0].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_0", var_list);
	ColumnWC[0].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_0", var_list);
	ColumnWC[0].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_0", var_list);

	ColumnWC[1].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_1", var_list);
	ColumnWC[1].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_1", var_list);
	ColumnWC[1].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_1", var_list);

	ColumnWC[2].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_2", var_list);
	ColumnWC[2].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_2", var_list);
	ColumnWC[2].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_2", var_list);

	ColumnWC[3].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_3", var_list);
	ColumnWC[3].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_3", var_list);
	ColumnWC[3].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_3", var_list);

	ColumnWC[4].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_4", var_list);
        ColumnWC[4].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_4", var_list); 
	ColumnWC[4].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_4", var_list);

	ColumnWC[5].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_5", var_list);
	ColumnWC[5].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_5", var_list);
	ColumnWC[5].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_5", var_list);

	ColumnWC[6].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_6", var_list);
	ColumnWC[6].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_6", var_list);
	ColumnWC[6].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_6", var_list);

	ColumnWC[7].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_7", var_list);
	ColumnWC[7].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_7", var_list);
	ColumnWC[7].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_7", var_list);

	ColumnWC[8].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_8", var_list);
	ColumnWC[8].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_8", var_list);
	ColumnWC[8].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_8", var_list);

	ColumnWC[9].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_9", var_list);
	ColumnWC[9].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_9", var_list);
	ColumnWC[9].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_9", var_list);

	ColumnWC[10].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_10", var_list);
	ColumnWC[10].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_10", var_list);
	ColumnWC[10].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_10", var_list);

	ColumnWC[11].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_11", var_list);
	ColumnWC[11].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_11", var_list);
	ColumnWC[11].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_11", var_list);

	ColumnWC[12].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_12", var_list);
	ColumnWC[12].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_12", var_list);
	ColumnWC[12].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_12", var_list);

	ColumnWC[13].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_13", var_list);
	ColumnWC[13].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_13", var_list);
	ColumnWC[13].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_13", var_list);

	ColumnWC[14].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_14", var_list);
	ColumnWC[14].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_14", var_list);
	ColumnWC[14].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_14", var_list);

	ColumnWC[15].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_15", var_list);
	ColumnWC[15].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_15", var_list);
	ColumnWC[15].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_15", var_list);

	ColumnWC[16].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_16", var_list);
	ColumnWC[16].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_16", var_list);
	ColumnWC[16].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_16", var_list);

	ColumnWC[17].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_17", var_list);
	ColumnWC[17].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_17", var_list);
	ColumnWC[17].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_17", var_list);

	ColumnWC[18].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_18", var_list);
	ColumnWC[18].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_18", var_list);
	ColumnWC[18].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_18", var_list);

	ColumnWC[19].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_19", var_list);
	ColumnWC[19].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_19", var_list);
	ColumnWC[19].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_19", var_list);

	ColumnWC[20].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_20", var_list);
	ColumnWC[20].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_20", var_list);
	ColumnWC[20].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_20", var_list);

	ColumnWC[21].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_21", var_list);
	ColumnWC[21].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_21", var_list);
	ColumnWC[21].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_21", var_list);

	ColumnWC[22].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_22", var_list);
	ColumnWC[22].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_22", var_list);
	ColumnWC[22].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_22", var_list);

	ColumnWC[23].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_23", var_list);
	ColumnWC[23].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_23", var_list);
	ColumnWC[23].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_23", var_list);

	ColumnWC[24].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_24", var_list);
	ColumnWC[24].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_24", var_list);
	ColumnWC[24].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_24", var_list);

	ColumnWC[25].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_25", var_list);
	ColumnWC[25].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_25", var_list);
	ColumnWC[25].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_25", var_list);

	ColumnWC[26].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_26", var_list);
	ColumnWC[26].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_26", var_list);
	ColumnWC[26].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_26", var_list);

	ColumnWC[27].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_27", var_list);
	ColumnWC[27].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_27", var_list);
	ColumnWC[27].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_27", var_list);

	ColumnWC[28].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_28", var_list);
	ColumnWC[28].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_28", var_list);
	ColumnWC[28].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_28", var_list);

	ColumnWC[29].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_29", var_list);
	ColumnWC[29].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_29", var_list);
	ColumnWC[29].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_29", var_list);

	ColumnWC[30].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_30", var_list);
	ColumnWC[30].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_30", var_list);
	ColumnWC[30].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_30", var_list);

	ColumnWC[31].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_31", var_list);
	ColumnWC[31].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_31", var_list);
	ColumnWC[31].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_31", var_list);

	ColumnWC[32].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_32", var_list);
	ColumnWC[32].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_32", var_list);
	ColumnWC[32].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_32", var_list);

	ColumnWC[33].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_33", var_list);
	ColumnWC[33].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_33", var_list);
	ColumnWC[33].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_33", var_list);

	ColumnWC[34].TabQua = var_mapping("SQLTablePrivileges_ColumnWC_TabQua_34", var_list);
	ColumnWC[34].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC_TabOwner_34", var_list);
	ColumnWC[34].TabName = var_mapping("SQLTablePrivileges_ColumnWC_TabName_34", var_list);

	ColumnWC2[0].TabQua = var_mapping("SQLTablePrivileges_ColumnWC2_TabQua_0", var_list);
	ColumnWC2[0].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC2_TabOwner_0", var_list);
	ColumnWC2[0].TabName = var_mapping("SQLTablePrivileges_ColumnWC2_TabName_0", var_list);

	ColumnWC2[1].TabQua = var_mapping("SQLTablePrivileges_ColumnWC2_TabQua_1", var_list);
	ColumnWC2[1].TabOwner = var_mapping("SQLTablePrivileges_ColumnWC2_TabOwner_1", var_list);
	ColumnWC2[1].TabName = var_mapping("SQLTablePrivileges_ColumnWC2_TabName_1", var_list);

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

	LogMsg(LINEBEFORE+SHORTTIMESTAMP,"Begin testing API => SQLTablePrivileges | SQLTablePriv | tabpriv.c\n");

	TEST_INIT;

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

	if(!FullConnectWithOptions(pTestInfo, CONNECT_ODBC_VERSION_3))
	{
		LogMsg(NONE,"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;
	}

#ifdef LDAP
	// Grantor = var_mapping("SQLTablePrivileges_Grantor", var_list);
/*
	returncode = SQLGetConnectAttr(hdbc, (SQLINTEGER)SQL_ATTR_ROLENAME, (SQLCHAR*)Grantor, SQL_MAX_ROLENAME_LEN+2, (SQLINTEGER *) &oGrantorlen);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetConnectAttr"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
		TEST_RETURN;
	}
*/
/* hardcode it for now */ strcpy (Grantor, "DB__ROOT");
#else
        sprintf(Grantor, "%s", var_mapping("SQLTablePrivileges_Grantor", var_list)); 
#endif

	LogMsg(NONE,"Grantor is: %s\n", Grantor);

	TESTCASE_END;  // end of setup
 
	strcpy(TableQualifier,pTestInfo->Catalog);
	strcpy(TableOwner,pTestInfo->Schema);

	TableStr = (char *)malloc(MAX_NOS_SIZE);
	i = 0;
	while (_stricmp(TableCol[i].Col,"endloop") != 0)
	{
		sprintf(Heading,"Test #%d\n",i);
		TESTCASE_BEGIN(Heading);

		if (_stricmp(TableCol[i].Privilege,"ALL PRIVILEGES") == 0)
			strcpy(TableCol[i].Privilege,"DELETE");

		// clean up left over table, if any.  We don't care about returncode from SQLExecDirect
		sprintf(TableStr,"drop table %s",TableName);
		SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);
		
		// create table to test against
		sprintf(TableStr,"create table %s (%s) no partition;",TableName,TableCol[i].Col);
		returncode = SQLExecDirect(hstmt,(SQLCHAR*)TableStr,SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
		}
		else
		{
			// execute GRANT statement to set up some table privileges
			sprintf(TableStr,"GRANT %s ON %s TO \"%s\"",TableCol[i].Privilege,TableName,TableCol[i].Grantee);
			if (_stricmp(TableCol[i].Is_Grantable,"YES") == 0)
				strcat(TableStr, " WITH GRANT OPTION");
			LogMsg(NONE,"%s\n",TableStr);
			returncode = SQLExecDirect(hstmt,(SQLCHAR*)TableStr,SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
			}
			else
			{
				// Execute SQLTablePrivileges for test table
				if (strlen(TableQualifier) == 0)
					returncode = SQLTablePrivileges(hstmt,NULL,0,(SQLCHAR*)TableOwner,(SWORD)strlen(TableOwner),(SQLCHAR*)TableName,(SWORD)strlen(TableName));
				else
					returncode = SQLTablePrivileges(hstmt,(SQLCHAR*)TableQualifier,(SWORD)strlen(TableQualifier),(SQLCHAR*)TableOwner,(SWORD)strlen(TableOwner),(SQLCHAR*)TableName,(SWORD)strlen(TableName));
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTablePrivileges"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				else
				{
					LogMsg(NONE,"SQLTablePrivileges function call executed correctly.\n");

					// clear all buffers
					strcpy(oTableQualifier,"");
					strcpy(oTableOwner,"");
					strcpy(oTableName,"");
					strcpy(oGrantor,"");
					strcpy(oGrantee,"");
					strcpy(oPrivilege,"");
					strcpy(oIs_Grantable,"");

					// Bind all columns to recieve data returned from SQLTablePrivileges
					returncode = SQLBindCol(hstmt,1,SQL_C_CHAR,oTableQualifier,NAME_LEN,&oTableQualifierlen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					} 
					returncode = SQLBindCol(hstmt,2,SQL_C_CHAR,oTableOwner,NAME_LEN,&oTableOwnerlen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					returncode = SQLBindCol(hstmt,3,SQL_C_CHAR,oTableName,NAME_LEN,&oTableNamelen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					returncode = SQLBindCol(hstmt,4,SQL_C_CHAR,oGrantor,NAME_LEN,&oGrantorlen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					returncode = SQLBindCol(hstmt,5,SQL_C_CHAR,oGrantee,NAME_LEN,&oGranteelen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					returncode = SQLBindCol(hstmt,6,SQL_C_CHAR,oPrivilege,NAME_LEN,&oPrivilegelen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					returncode = SQLBindCol(hstmt,7,SQL_C_CHAR,oIs_Grantable,NAME_LEN,&oIs_Grantablelen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					
					
					// Loop, reading and checking all data retuned from SQLTablePrivileges call
					k = 0;
					while (returncode == SQL_SUCCESS)
					{
						returncode = SQLFetch(hstmt);
						if((returncode!=SQL_NO_DATA_FOUND) && (!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")))
						{
							LogAllErrors(henv,hdbc,hstmt);
							TEST_FAILED;
						}
						else 
						{
							// check for SQL_SUCCESS in case SQL_NO_DATA_FOUND was what was returned
							// compare results for rows where oGrantor is not the same as Grantor (super.super)
							if ((returncode == SQL_SUCCESS) && (_stricmp(Grantor,oGrantor) == 0) && (_stricmp(TableCol[i].Grantee,oGrantee) == 0))
							{
								k++;	// found a match, increment counter
								if ((_stricmp(TableQualifier,oTableQualifier) == 0) 
									&& (cstrcmp(TableOwner,oTableOwner,TRUE,isCharSet) == 0) 
									&& (cstrcmp(TableName,oTableName,TRUE,isCharSet) == 0) 
									//&& (_stricmp(oGrantor,Grantor) == 0) 
									//&& (_stricmp(TableCol[i].Grantee,oGrantee) == 0) // NOT NEEDED
									&& (strstr(TableCol[i].Privilege,oPrivilege) != NULL) 
									&& (_stricmp(TableCol[i].Is_Grantable,oIs_Grantable) == 0) )
								{
									LogMsg(NONE,"SQLTablePrivileges: compare results of rows fetched for following column.\n");
									LogMsg(NONE,"TableQualifier expect: %s and actual: %s are matched\n",TableQualifier,oTableQualifier);
									LogMsg(NONE,"TableOwner expect: %s and actual: %s are matched\n",TableOwner,oTableOwner);
									LogMsg(NONE,"TableName expect: %s and actual: %s are matched\n",TableName,oTableName);
									LogMsg(NONE,"Grantor expect: %s and actual: %s are matched\n",Grantor,oGrantor);
									LogMsg(NONE,"Grantee expect: %s and actual: %s are matched\n",TableCol[i].Grantee,oGrantee);
									LogMsg(NONE,"Privilege expect: %s and actual: %s are matched\n",TableCol[i].Privilege,oPrivilege);
									LogMsg(NONE,"Is_Grantable expect: %s and actual: %s are matched\n",TableCol[i].Is_Grantable,oIs_Grantable);
								}
								else
								{
									TEST_FAILED;	
									LogMsg(NONE,"SQLTablePrivileges: compare results of rows fetched for following column failed line %d.\n", __LINE__);
									if (_stricmp(TableQualifier,oTableQualifier) != 0)
										LogMsg(ERRMSG,"TableQualifier expect: %s and actual: %s are not matched\n",TableQualifier,oTableQualifier);
									if (cstrcmp(TableOwner,oTableOwner,TRUE,isCharSet) != 0) 
										LogMsg(ERRMSG,"TableOwner expect: %s and actual: %s are not matched\n",TableOwner,oTableOwner);
									if (cstrcmp(TableName,oTableName,TRUE,isCharSet) != 0) 
										LogMsg(ERRMSG,"TableName expect: %s and actual: %s are not matched\n",TableName,oTableName);
									//if (_stricmp(oGrantor,Grantor) != 0)
									//	LogMsg(ERRMSG,"Grantor expect: %s and actual: %s are not matched\n",Grantor,oGrantor);
									//if (_stricmp(TableCol[i].Grantee,oGrantee) != 0)
									//	LogMsg(ERRMSG,"Grantee expect: %s and actual: %s are not matched\n",TableCol[i].Grantee,oGrantee);
									if (strstr(TableCol[i].Privilege,oPrivilege) == NULL)
										LogMsg(ERRMSG,"Privilege expect: %s and actual: %s are not matched\n",TableCol[i].Privilege,oPrivilege);
									if (_stricmp(TableCol[i].Is_Grantable,oIs_Grantable) != 0)
										LogMsg(ERRMSG,"Is_Grantable expect: %s and actual: %s are not matched\n",TableCol[i].Is_Grantable,oIs_Grantable);
								}
							}
						}
					}
					if(k == 0){
						TEST_FAILED;
						LogMsg(ERRMSG,"No matching grantee record for '%s' found\n"
										  "   At least one row fetched should have matched\n",
										  TableCol[i].Grantee);
						}
					SQLFreeStmt(hstmt,SQL_UNBIND);
					SQLFreeStmt(hstmt,SQL_CLOSE);
				}
			}
		}
		TESTCASE_END;
		
		// clean up SQL table
		sprintf(TableStr,"drop table %s",TableName);
		SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);
		i++;
	} 

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

	i = 0;
	sprintf(TableStr,"drop table %s.%s.%s",ColumnWC[i].TabQua, ColumnWC[i].TabOwner, ColumnWC[i].TabName);
	SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);
	LogMsg(NONE,"%s\n",TableStr);
	sprintf(TableStr,"drop schema %s.%s cascade",ColumnWC[i].TabQua, ColumnWC[i].TabOwner);
	SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);
	LogMsg(NONE,"%s\n",TableStr);

	sprintf(TableStr,"create schema %s.%s",ColumnWC[i].TabQua, ColumnWC[i].TabOwner);
	LogMsg(NONE,"%s\n",TableStr);
	returncode = SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		TEST_FAILED;
	}
	else
	{
		sprintf(TableStr,"create table %s.%s.%s(%s char(10)) no partition;",ColumnWC[i].TabQua, ColumnWC[i].TabOwner, ColumnWC[i].TabName, TestColumn);
		returncode = SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
		}
	}
	LogMsg(NONE,"%s\n",TableStr);
	returncode = SQLSetStmtAttr(hstmt,SQL_ATTR_METADATA_ID,(SQLPOINTER)SQL_FALSE,0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtAttr"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}// end of setup
	if (returncode == SQL_SUCCESS) 
	{
		while ((_stricmp(ColumnWC[i].TabQua,"endloop") != 0) && (ColumnWC[i].isEscape == 0))
		{
			sprintf(Heading,"SQLTablePrivileges: wildcard options => \n"
				"Table Qualifier: %s \nTable Owner: %s \nTable Name: %s\n", 
				printSymbol(ColumnWC[i].TabQua,displayBuf.cat), 
				printSymbol(ColumnWC[i].TabOwner,displayBuf.sch), 
				printSymbol(ColumnWC[i].TabName,displayBuf.tab));
			TESTCASE_BEGIN(Heading);
			if (_stricmp(ColumnWC[i].TabQua,"NULL") == 0)
				ColumnWC[i].TabQua = NULL;
			if (_stricmp(ColumnWC[i].TabOwner,"NULL") == 0)
				ColumnWC[i].TabOwner = NULL;
			if (_stricmp(ColumnWC[i].TabName,"NULL") == 0)
				ColumnWC[i].TabName = NULL;

			if (ColumnWC[i].TabQua == NULL || ColumnWC[i].TabOwner == NULL || ColumnWC[i].TabName == NULL)
				returncode = SQLTablePrivileges(hstmt,(SQLCHAR*)ColumnWC[i].TabQua,SQL_NTS,
                                                      (SQLCHAR*)ColumnWC[i].TabOwner,SQL_NTS,
                                                      (SQLCHAR*)removeQuotes(ColumnWC[i].TabName,displayBuf.tab),SQL_NTS);
			else
				returncode = SQLTablePrivileges(hstmt,(SQLCHAR*)ColumnWC[i].TabQua,(SWORD)strlen(ColumnWC[i].TabQua),
                                                      (SQLCHAR*)ColumnWC[i].TabOwner,(SWORD)strlen(ColumnWC[i].TabOwner),
                                                      (SQLCHAR*)removeQuotes(ColumnWC[i].TabName,displayBuf.tab),(SWORD)strlen(displayBuf.tab));
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTablePrivileges"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
			}
			else
			{
				LogMsg(NONE,"SQLTablePrivileges: SQLTablePrivileges function call executed correctly.\n");
				strcpy(oTableQualifier,"");
				strcpy(oTableOwner,"");
				strcpy(oTableName,"");
				strcpy(oGrantor,"");
				strcpy(oGrantee,"");
				strcpy(oPrivilege,"");
				strcpy(oIs_Grantable,"");
				returncode = SQLBindCol(hstmt,1,SQL_C_CHAR,oTableQualifier,NAME_LEN,&oTableQualifierlen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
				} 
				returncode = SQLBindCol(hstmt,2,SQL_C_CHAR,oTableOwner,NAME_LEN,&oTableOwnerlen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
				}
				returncode = SQLBindCol(hstmt,3,SQL_C_CHAR,oTableName,NAME_LEN,&oTableNamelen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
				}

				returncode = SQLBindCol(hstmt,4,SQL_C_CHAR,oGrantor,NAME_LEN,&oGrantorlen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
				}
				returncode = SQLBindCol(hstmt,5,SQL_C_CHAR,oGrantee,NAME_LEN,&oGranteelen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
				}
				
				returncode = SQLBindCol(hstmt,6,SQL_C_CHAR,oPrivilege,NAME_LEN,&oPrivilegelen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
				}
				returncode = SQLBindCol(hstmt,7,SQL_C_CHAR,oIs_Grantable,NAME_LEN,&oIs_Grantablelen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
				}
				k = 0;
				while (returncode == SQL_SUCCESS) 
				{
					returncode = SQLFetch(hstmt);
					if((returncode!=SQL_NO_DATA_FOUND) && (!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")))
					{
						TEST_FAILED;
						LogAllErrors(henv,hdbc,hstmt);
					}
					if (returncode == SQL_SUCCESS)
						k++;
				}
				if(k == 0 && ColumnWC[i].CheckCode == SQL_SUCCESS)
				{
					if(ColumnWC[i].isEscape == 1)
						LogMsg(ERRMSG, "Search string pattern in Catalog's Name is not supported\n");
					else {
						TEST_FAILED;
						LogMsg(ERRMSG,"No Data Found => Atleast one row should be fetched\n");
					}
				}
			}
			SQLFreeStmt(hstmt,SQL_CLOSE);
			TESTCASE_END;
			i++;
		}
	}

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

	TESTCASE_BEGIN("SQLTablePrivileges: Negative test with invalid handle.\n");

	i = 0;
	returncode = SQLTablePrivileges(hstmt1,(SQLCHAR*)ColumnWC[i].TabQua,(SWORD)strlen(ColumnWC[i].TabQua),(SQLCHAR*)ColumnWC[i].TabOwner,(SWORD)strlen(ColumnWC[i].TabOwner),(SQLCHAR*)ColumnWC[i].TabName,(SWORD)strlen(ColumnWC[i].TabName));
	if(!CHECKRC(SQL_INVALID_HANDLE,returncode,"SQLTables"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}
	TESTCASE_END;

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

	TESTCASE_BEGIN("SQLTables: Negative test with NULL handle.\n");

	hstmt1 = (SQLHANDLE)NULL;
	i = 0;
	returncode = SQLTablePrivileges(hstmt1,(SQLCHAR*)ColumnWC[i].TabQua,(SWORD)strlen(ColumnWC[i].TabQua),(SQLCHAR*)ColumnWC[i].TabOwner,(SWORD)strlen(ColumnWC[i].TabOwner),(SQLCHAR*)ColumnWC[i].TabName,(SWORD)strlen(ColumnWC[i].TabName));
	if(!CHECKRC(SQL_INVALID_HANDLE,returncode,"SQLTables"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}
	TESTCASE_END;

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

	TESTCASE_BEGIN("SQLTablePrivileges: Negative test with invalid arg lengths.\n");

	returncode = SQLTablePrivileges(hstmt,(SQLCHAR*)ColumnWC2[0].TabQua,ColumnWC2[0].TabQuaLen,(SQLCHAR*)ColumnWC2[0].TabOwner,ColumnWC2[0].TabOwnerLen,(SQLCHAR*)ColumnWC2[0].TabName,ColumnWC2[0].TabNameLen);
	LogMsg(NONE, "Input parameters: CatalogLen %d SchemaLen %d TableLen %d\n", ColumnWC2[0].TabQuaLen, ColumnWC2[0].TabOwnerLen, ColumnWC2[0].TabNameLen);
	if(!CHECKRC(SQL_ERROR,returncode,"SQLTablePrivileges"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}

	TESTCASE_END;

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

	TESTCASE_BEGIN("SQLTablePrivileges: Positive test with invalid arg lengths.\n");

	returncode = SQLTablePrivileges(hstmt,(SQLCHAR*)ColumnWC2[1].TabQua,ColumnWC2[1].TabQuaLen,(SQLCHAR*)ColumnWC2[1].TabOwner,ColumnWC2[1].TabOwnerLen,(SQLCHAR*)ColumnWC2[1].TabName,ColumnWC2[1].TabNameLen);
	LogMsg(NONE, "Input parameters: CatalogLen %d SchemaLen %d TableLen %d\n", ColumnWC2[1].TabQuaLen, ColumnWC2[1].TabOwnerLen, ColumnWC2[1].TabNameLen);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTablePrivileges"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}
	else {
		LogMsg(NONE,"SQLTablePrivileges: SQLTablePrivileges function call executed correctly.\n");
		strcpy(oTableQualifier,"");
		strcpy(oTableOwner,"");
		strcpy(oTableName,"");
		strcpy(oGrantor,"");
		strcpy(oGrantee,"");
		strcpy(oPrivilege,"");
		strcpy(oIs_Grantable,"");
		returncode = SQLBindCol(hstmt,1,SQL_C_CHAR,oTableQualifier,NAME_LEN,&oTableQualifierlen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
		{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
		} 
		returncode = SQLBindCol(hstmt,2,SQL_C_CHAR,oTableOwner,NAME_LEN,&oTableOwnerlen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
		{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
		}
		returncode = SQLBindCol(hstmt,3,SQL_C_CHAR,oTableName,NAME_LEN,&oTableNamelen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
		{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
		}
		returncode = SQLBindCol(hstmt,4,SQL_C_CHAR,oGrantor,NAME_LEN,&oGrantorlen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
		{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
		}
		returncode = SQLBindCol(hstmt,5,SQL_C_CHAR,oGrantee,NAME_LEN,&oGranteelen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
		{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
		}
		
		returncode = SQLBindCol(hstmt,6,SQL_C_CHAR,oPrivilege,NAME_LEN,&oPrivilegelen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
		{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
		}
		returncode = SQLBindCol(hstmt,7,SQL_C_CHAR,oIs_Grantable,NAME_LEN,&oIs_Grantablelen);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
		{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
		}
		k = 0;
		while (returncode == SQL_SUCCESS) 
		{
			returncode = SQLFetch(hstmt);
			if (returncode == SQL_SUCCESS) k++;
		}
		if(k > 0)
		{
			TEST_FAILED;
			LogMsg(ERRMSG,"Should be no data found - check for similar objects unintentionally appear\n");
		}
	}

	TESTCASE_END;

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

	TESTCASE_BEGIN("Testing SQLColAttribute, SQLDescribeCol, SQLBindCol and SQLFetch functions for catalog names.\n");

	returncode = SQLSetStmtAttr(hstmt,SQL_ATTR_METADATA_ID,(SQLPOINTER)SQL_FALSE,0);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtAttr"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}// end of setup

	for(i = 0; i < 5; i++)
	{
		sprintf(Heading,"======================================\n"
						"SQLTablePrivileges: wildcard options => \n"
						"Table Qualifier: %s \nTable Owner: %s \nTable Name: %s\n", 
						printSymbol(ColumnWC[i].TabQua,displayBuf.cat), 
						printSymbol(ColumnWC[i].TabOwner,displayBuf.sch), 
						printSymbol(ColumnWC[i].TabName,displayBuf.tab));
		LogMsg(NONE,Heading);

		returncode = SQLTablePrivileges(hstmt,(SQLCHAR*)ColumnWC[i].TabQua,(SWORD)strlen(ColumnWC[i].TabQua),
											  (SQLCHAR*)removeQuotes(ColumnWC[i].TabOwner, displayBuf.sch),(SWORD)strlen(displayBuf.sch),
											  (SQLCHAR*)removeQuotes(ColumnWC[i].TabName, displayBuf.tab),(SWORD)strlen(displayBuf.tab));
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLColumns"))
		{
			TEST_FAILED;
			LogAllErrors(henv,hdbc,hstmt);
		}
		LogMsg(NONE,"after the call\n");

		returncode = SQLNumResultCols(hstmt, &numOfCols);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLNumResultsCol"))
		{
			TEST_FAILED;
			LogMsg(ERRMSG,"Test failed while executing call for SQLNUMRESULTSCOL");
			LogAllErrors(henv,hdbc,hstmt);
		}
		for(cols = 0; cols < numOfCols; cols++)
		{
			returncode = SQLDescribeCol(hstmt,(SWORD)(cols+1),(SQLCHAR*)cn,COLNAME_LEN,&cl,&st,&cp,&cs,&cnull);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLDescribeCol"))
			{
				TEST_FAILED;
				LogMsg(ERRMSG,"Test failed while executing call for SQLDESCRIBECOL of column");
				LogAllErrors(henv,hdbc,hstmt);
			}
			CharOutput[cols] = (char *)malloc(STR_LEN);
			for (iatt = 0; iatt <= TOTALATTRIBS; iatt++)
			{
				strcpy(rgbDesc,"");
				pcbDesc = 0;
				pfDesc = 0;
				returncode = SQLColAttributes(hstmt,(SWORD)(cols+1),DescrType[iatt],rgbDesc,STR_LEN,&pcbDesc,&pfDesc);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLColAttribute"))
				{
					TEST_FAILED;
					LogMsg(ERRMSG,"Test failed while executing call for SQLCOLATTRIBUTES of column : %d.\n",i+1);
					LogAllErrors(henv,hdbc,hstmt);
				}
			}
			returncode = SQLBindCol(hstmt,(SWORD)(cols+1),SQL_C_CHAR,CharOutput[cols],STR_LEN,&stringlength);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
			{
				TEST_FAILED;
				LogMsg(ERRMSG,"Test failed while executing call for SQLBindCols of column : %d.\n",cols);
				LogAllErrors(henv,hdbc,hstmt);
			}
		}

		k = 0;
		while (returncode == SQL_SUCCESS)
		{
			returncode = SQLFetch(hstmt);
			if(returncode == SQL_ERROR)
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
			} else if (returncode == SQL_NO_DATA_FOUND) {
				break;
			}
			else {
				if (returncode == SQL_SUCCESS_WITH_INFO)
					LogAllErrors(henv,hdbc,hstmt);
				k++;
			}
		}
		if(k == 0)
		{
			TEST_FAILED;
			LogMsg(ERRMSG,"No Data Found => Atleast one row should be fetched\n");
		}
		
		for(cols = 0; cols < numOfCols; cols++)
		{
			free(CharOutput[cols]);
		}
		TESTCASE_END;
	}

//=========================================================================================
	// Cleanup
	i=0;
	sprintf(TableStr,"drop table %s.%s.%s",ColumnWC[i].TabQua, ColumnWC[i].TabOwner, ColumnWC[i].TabName);
	SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);
	sprintf(TableStr,"drop schema %s.%s cascade",ColumnWC[i].TabQua, ColumnWC[i].TabOwner);
	SQLExecDirect(hstmt,(SQLCHAR*) TableStr,SQL_NTS);

	FullDisconnect3(pTestInfo);
	LogMsg(SHORTTIMESTAMP+LINEAFTER,"End testing API => SQLTablePrivileges.\n");
	free(TableStr); 
	free_list(var_list);
	TEST_RETURN;
}
Beispiel #8
0
int odbc_createrowset(ClipMachine* cm,SQLROWSET* rs,ClipVar* ap,ClipVar* idname,const char* gen_idSQL){
	ODBC_ROWSET* rowset = (ODBC_ROWSET*)rs;
	ODBC_STMT* stmt = rowset->stmt;
	SQLRETURN er;
	SQLSMALLINT cols;
	SQLINTEGER nullable;
	int i;

	odbc_bindpars(stmt,ap);
	if((er = SQLAllocStmt(stmt->conn->conn,&stmt->hstmt))) goto err;
	if((er = SQLPrepare(stmt->hstmt,stmt->sql,strlen(stmt->sql)))) goto err;
	rowset->rowset_item =
		_clip_store_c_item(cm,rowset,_C_ITEM_TYPE_SQL,destroy_odbc_rowset);

	if((er = SQLExecute(stmt->hstmt))) goto err;

	if((er = SQLNumResultCols(stmt->hstmt,&cols))) goto err;
	rowset->nfields = cols;
	rowset->fields = calloc(rowset->nfields,sizeof(SQLFIELD));
	rowset->id = -1;

	for(i=0;i<rowset->nfields;i++){
		if((er = SQLColAttributes(stmt->hstmt,i+1,
			SQL_COLUMN_NAME,rowset->fields[i].name,MAXFIELDNAME+1,0,0)))
			goto err;
		if((er = SQLColAttributes(stmt->hstmt,i+1,
			SQL_COLUMN_TYPE,0,0,0,(SQLPOINTER)&rowset->fields[i].type)))
			goto err;
		rowset->fields[i].ctype[0] = _odbc_ctype(rowset->fields[i].type);
		if((er = SQLColAttributes(stmt->hstmt,i+1,
			SQL_COLUMN_LENGTH,0,0,0,(SQLPOINTER)&rowset->fields[i].buflen)))
			goto err;
		if((er = SQLColAttributes(stmt->hstmt,i+1,
			SQL_COLUMN_DISPLAY_SIZE,0,0,0,(SQLPOINTER)&rowset->fields[i].len)))
			goto err;
		if((er = SQLColAttributes(stmt->hstmt,i+1,
			SQL_COLUMN_SCALE,0,0,0,(SQLPOINTER)&rowset->fields[i].dec)))
			goto err;
		if((er = SQLColAttributes(stmt->hstmt,i+1,
			SQL_COLUMN_UNSIGNED,0,0,0,(SQLPOINTER)&rowset->fields[i].unsign)))
			goto err;
		if((er = SQLColAttributes(stmt->hstmt,i+1,
			SQL_COLUMN_NULLABLE,0,0,0,(SQLPOINTER)&nullable)))
			goto err;
		rowset->fields[i].notnull = (nullable == SQL_NO_NULLS);
		/* silly PostgreSQL's ODBC driver */
		if(stmt->conn->postgres && (rowset->fields[i].type == SQL_NUMERIC ||
			rowset->fields[i].type == SQL_DECIMAL)){

			rowset->fields[i].dec = LOWORD(rowset->fields[i].len);
			rowset->fields[i].len = HIWORD(rowset->fields[i].len);
			rowset->fields[i].buflen = 8;
		}
		if(rowset->fields[i].type == SQL_LONGVARBINARY)
			rowset->fields[i].buflen *= 2;

		if(idname->t.type == CHARACTER_t){
			if(idname->s.str.buf && !strcasecmp(rowset->fields[i].name,idname->s.str.buf)){
				rowset->id = i;
				rowset->nids = 1;
			}
		} else if(idname->t.type == ARRAY_t){
			int j;
			for(j=0;j<idname->a.count;j++){
				ClipVar* vp = idname->a.items+j;
				if(vp->t.type == CHARACTER_t && vp->s.str.buf
					&& !strcasecmp(rowset->fields[i].name,vp->s.str.buf)){

					rowset->nids++;
					rowset->ids = realloc(rowset->ids,rowset->nids*sizeof(int));
					rowset->ids[rowset->nids-1] = i;
				}
			}
		}

		if(rowset->fields[i].type == SQL_BINARY ||
			rowset->fields[i].type == SQL_VARBINARY ||
			rowset->fields[i].type == SQL_LONGVARBINARY)
		rowset->fields[i].binary = 1;
	}
	rowset->lastrec = 0;
	rowset->data = malloc(sizeof(void*)*rowset->lastrec);
	rowset->unknownrows = 1;
	return 0;
err:
	odbc_error(cm,stmt->conn->loc,0,stmt->conn->conn,stmt->hstmt,__LINE__,er_createrowset);
	return 1;
}
Beispiel #9
0
/* ------------------------------------------------------------- */
PJXSQL jx_sqlOpen(PUCHAR sqlstmt , PJXNODE pSqlParms)
{

   PNPMPARMLISTADDRP pParms = _NPMPARMLISTADDR();
   // LONG    format   =  (pParms->OpDescList->NbrOfParms >= 3) ? formatP : 0;  // Status & result object

   LONG   attrParm;
   LONG   i;
//   PJXSQL pSQL = jx_sqlNewStatement (pParms->OpDescList->NbrOfParms >= 2 ? pSqlParms  :NULL);
   PJXSQL pSQL = jx_sqlNewStatement (NULL);

   pSQL->rc = SQLAllocStmt(pConnection->hdbc, &pSQL->hstmt);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }

   attrParm = SQL_TRUE;
   pSQL->rc = SQLSetStmtAttr  (pSQL->hstmt, SQL_ATTR_CURSOR_SCROLLABLE , &attrParm  , 0);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }

   /*
   attrParm = SQL_TRUE;
   pSQL->rc = SQLSetStmtAttr  (pSQL->hstmt, SQL_ATTR_EXTENDED_COL_INFO , &attrParm  , 0);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }
   */

   attrParm = SQL_CONCUR_READ_ONLY;
   pSQL->rc = SQLSetStmtAttr  (pSQL->hstmt, SQL_ATTR_CONCURRENCY , &attrParm  , 0);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }

   // run  the  statement in "sqlstr"
   if (pParms->OpDescList->NbrOfParms >= 2 && pSqlParms ) {
      UCHAR sqlTempStmt[32766];
      strFormat(sqlTempStmt , sqlstmt , pSqlParms);
      pSQL->sqlstmt = strdup(sqlTempStmt);
   } else {
      pSQL->sqlstmt = strdup(sqlstmt);
   }

   pSQL->rc = SQLExecDirect (pSQL->hstmt, pSQL->sqlstmt, SQL_NTS);

   if (pSQL->rc != SQL_SUCCESS && pSQL->rc != SQL_NO_DATA_FOUND) {
     check_error (pSQL);
     return NULL; // we have an error
   }


   // Number of rows? .. No does not work :(
   /*
   SQLGetDiagField(SQL_HANDLE_STMT,pSQL->hstmt, 0 ,SQL_DIAG_ROW_COUNT,&pSQL->rowcount,0, NULL);
   */

   /*
   // Row count is only affected row in a "delete" or "update" ..TODO find a solution for select
   pSQL->rc = SQLRowCount (pSQL->hstmt, &pSQL->rowcount);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return; // we have an error
   }
   */

   pSQL->rc = SQLNumResultCols (pSQL->hstmt, &pSQL->nresultcols);
   if (pSQL->rc != SQL_SUCCESS ) {
      check_error (pSQL);
      return NULL; // we have an error
   }

   for (i = 0; i < pSQL->nresultcols; i++) {
      PJXCOL pCol = &pSQL->cols[i];

      SQLDescribeCol (pSQL->hstmt, i+1, pCol->colname, sizeof (pCol->colname),
          &pCol->colnamelen, &pCol->coltype, &pCol->collen, &pCol->scale, &pCol->nullable);

      pCol->colname[pCol->colnamelen] = '\0';

      if (OFF == jx_IsTrue (pConnection->pOptions ,"uppercasecolname")) {
         str2lower  (pCol->colname , pCol->colname);
      }

      // get display label  for column
      /****************
      pSQL->rc = SQLColAttributes (hstmt, i+1, SQL_DESC_LABEL, Label , sizeof(Label)  , &len , NULL);
      if (pSQL->rc != SQL_SUCCESS ) {
        check_error (pSQL);
        return; // we have an error
      }
      ***********/


      // get display length for column
      SQLColAttributes (pSQL->hstmt, i+1, SQL_DESC_PRECISION, NULL, 0,NULL, &pCol->displaysize);

      // set column length to max of display length, and column name
      //   length.  Plus one byte for null terminator
      // collen[i] = max(displaysize, collen[i]);
      // collen[i] = max(collen[i], strlen((char *) colname) ) + 1;

      // printf ("%-*.*s", collen[i], collen[i], colname);

      // allocate memory to bind column

      // bind columns to program vars, converting all types to CHAR
      //*SQLBindCol (hstmt, i+1, SQL_C_CHAR, data[i], collen[i], &outlen[i]);
      switch( pCol->coltype) {
         case SQL_BLOB:
         case SQL_CLOB:
 //           pCol->collen = pCol->displaysize * 2;
 //           pCol->data = (SQLCHAR *) malloc (pCol->collen);
            pCol->collen = 1048576;  // 1MEGABYTES
            pCol->data = (SQLCHAR *) malloc (pCol->collen);  // 1MEGABYTES
            SQLBindCol (pSQL->hstmt, i+1, SQL_C_BINARY , pCol->data, pCol->collen, &pCol->outlen);
            break;

         case SQL_WCHAR:
         case SQL_WVARCHAR:
         case SQL_GRAPHIC:
         case SQL_VARGRAPHIC:
            pCol->collen = pCol->displaysize * 2;
            pCol->data = (SQLCHAR *) malloc (pCol->collen);
            SQLBindCol (pSQL->hstmt, i+1, pCol->coltype, pCol->data, pCol->collen, &pCol->outlen);
            break;

         default:
            pCol->collen = pCol->displaysize + 3; // + . and , and zero term
            pCol->data = (SQLCHAR *) malloc (pCol->collen);
            SQLBindCol (pSQL->hstmt, i+1, SQL_C_CHAR, pCol->data, pCol->collen, &pCol->outlen);
            break;
      }
      if (pCol->coltype >= SQL_NUMERIC && pCol->coltype <= SQL_DOUBLE) {
         pCol->nodeType = JX_LITERAL;
      } else {
         pCol->nodeType = JX_VALUE;
      }
   }


   return pSQL;

}
Beispiel #10
0
static int odbc_dispatch2(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;
	PWord arg8; int type8;
	PWord arg9; int type9;

	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);
	if (type7 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg7,type7))
			PI_FAIL;
	PI_getan(&arg8,&type8,8);
	if (type8 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg8,type8))
			PI_FAIL;
	PI_getan(&arg9,&type9,9);


	switch(arg1)
	{
		case 0:
			retval = (unsigned long) SQLColAttributes(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLUSMALLINT  ) arg4),((SQLPOINTER  ) arg5),((SQLSMALLINT  ) arg6),((SQLSMALLINT * ) arg7),((SQLINTEGER * ) arg8));
			break;
		case 1:
			retval = (unsigned long) SQLGetDiagField(((SQLSMALLINT  ) arg2),((SQLHANDLE  ) arg3),((SQLSMALLINT  ) arg4),((SQLSMALLINT  ) arg5),((SQLPOINTER  ) arg6),((SQLSMALLINT  ) arg7),((SQLSMALLINT * ) arg8));
			break;
		case 2:
			retval = (unsigned long) SQLColAttribute(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLUSMALLINT  ) arg4),((SQLPOINTER  ) arg5),((SQLSMALLINT  ) arg6),((SQLSMALLINT * ) arg7),((SQLPOINTER  ) arg8));
			break;
		default:
			PI_FAIL;
	}
	PI_makedouble(&rval,&rtype,(double) retval);
	if (PI_unify(arg9,type9,rval,rtype))
		PI_SUCCEED;
	PI_FAIL;
}
Beispiel #11
0
PassFail TestMXSQLTables (TestInfo *pTestInfo)
{
	TEST_DECLARE;
 	TCHAR			Heading[MAX_HEADING_SIZE];
 	RETCODE			returncode;
 	SQLHANDLE 		henv;
 	SQLHANDLE 		hdbc;
 	SQLHANDLE		hstmt, hstmt1;
	TCHAR			TableQualifier[NAME_LEN],TableOwner[NAME_LEN],Remark[REM_LEN],*TableStr;
	TCHAR			oTableQualifier[NAME_LEN];
	TCHAR			oTableOwner[NAME_LEN];
	TCHAR			oTableName[NAME_LEN];
	TCHAR			oTableType[NAME_LEN];
	TCHAR			oRemark[REM_LEN];
	SQLLEN			oTableQualifierlen,oTableOwnerlen,oTableNamelen,oTableTypelen,oRemarklen;

	int				cols, iatt;
	SWORD numOfCols = 0;
	SWORD pcbDesc;
	SQLLEN pfDesc;
	TCHAR cn[TabType_LEN];
	SWORD cl;
	SWORD st;
	SQLULEN cp;
	SWORD cs, cnull;
	TCHAR rgbDesc[RGB_MAX_LEN];
	TCHAR *CharOutput[12];
	SQLLEN stringlength;
	struct
	{
		TCHAR		*TableName;
		TCHAR		*TableType;
		TCHAR		*TableTypeIn;
	} Table[] = {
							{_T("--")	,_T("TABLE")	,_T("")},
							{_T("--")	,_T("TABLE")	,_T("TABLE")},
							{_T("--")	,_T("TABLE")	,_T("TABLE,VIEW,SYSTEM TABLE")}, 
							{_T("--")	,_T("TABLE")	,_T("TABLE,SYSTEM TABLE,VIEW")},
							{_T("--")	,_T("TABLE")	,_T("TABLE,VIEW,SYSTEM TABLE,SYNONYM,MV,MVG")},
							{_T("--")	,_T("VIEW"),_T("VIEW")},
							{_T("--")	,_T("VIEW"),_T("TABLE,VIEW,SYSTEM TABLE")},
							{_T("--")	,_T("MATERIALIZED VIEW"),_T("")}, 
							{_T("--")	,_T("MATERIALIZED VIEW"),_T("MV")},
							{_T("--")	,_T("SYNONYM"),_T("")}, 
							{_T("--")	,_T("SYNONYM"),_T("SYNONYM")},
							{_T("endloop"),}
					};

	struct
	{
		TCHAR		*TabQua;
		TCHAR		*TabOwner;
		TCHAR		*TabName;
		TCHAR		*TabType;
		int			changedSchema;
	} TableWC[] = 
						{		
							{_T(SQL_ALL_CATALOGS),_T("")			,_T("--")	,_T("")						,-1},		//0
							{_T("")				,_T(SQL_ALL_SCHEMAS),_T("--")	,_T("")						,-1},		//1
							{_T("")				,_T("")				,_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//2
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//3
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//4
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//5
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T("TABLE")				,-1},		//6
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//7
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//8
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T("TABLE")				,-1},		//9
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T("TABLE")				,1},		//10
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T("TABLE")				,1},		//11
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//12
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//13
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//14
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//15
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//16
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//17
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//18
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//19
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T("TABLE")				,-1},		//20
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T("TABLE")				,-1},		//21
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T("TABLE")				,1},		//22
							{pTestInfo->Catalog	,_T(SQL_ALL_SCHEMAS),_T("--")	,_T("TABLE")				,-1},		//23
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T("TABLE")				,1},		//24
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//25
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T("TABLE")				,1},		//26
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("VIEW")					,-1},		//27
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//28
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,-1},		//29
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//30
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("VIEW")					,-1},		//31
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//32
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//33
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//34
							{_T("NULL")			,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//35
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//36
							{pTestInfo->Catalog	,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//37
							{_T("NULL")			,_T("--")			,_T("--")	,_T("TABLE")				,0},		//38
							{_T("NULL")			,pTestInfo->Schema	,_T("--")	,_T("TABLE")				,-1},		//39
							{_T("NULL")			,_T("NULL")			,_T("--")	,_T("TABLE")				,-1},		//40
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,0},		//41
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,0},		//42
							{pTestInfo->Catalog	,_T("--")			,_T("--")	,_T(SQL_ALL_TABLE_TYPES)	,2},		//43
							{_T("endloop"),}
						};	

	struct
	{
		TCHAR		*TabQua;
		SWORD		TabQuaLen;
		TCHAR		*TabOwner;
		SWORD		TabOwnerLen;
		TCHAR		*TabName;
		SWORD		TabNameLen;
		TCHAR		*TabType;
		SWORD		TabTypeLen;
	} TableWC2[] = {		// wild cards from here
							{pTestInfo->Catalog, (SWORD)-1, pTestInfo->Schema,(SWORD)-1, _T("--"),(SWORD)-1, _T(""), (SWORD)-1},
							//{pTestInfo->Catalog, (SWORD)4, pTestInfo->Schema,(SWORD)2, "OBJECTS",(SWORD)2, _T(""), (SWORD)2},
							//{pTestInfo->Catalog, (SWORD)3, pTestInfo->Schema,(SWORD)7, "OBJECTS",(SWORD)3, _T(""), (SWORD)0},
							{_T("endloop"),}
						};
	//attributes for columns added for negative testing
	UWORD DescrType[] = 
				{
					SQL_COLUMN_AUTO_INCREMENT,SQL_COLUMN_CASE_SENSITIVE,SQL_COLUMN_COUNT,
					SQL_COLUMN_DISPLAY_SIZE,SQL_COLUMN_LENGTH,SQL_COLUMN_MONEY,
					SQL_COLUMN_NULLABLE,SQL_COLUMN_PRECISION,SQL_COLUMN_SCALE,
					SQL_COLUMN_SEARCHABLE,SQL_COLUMN_TYPE,SQL_COLUMN_UNSIGNED,
					SQL_COLUMN_UPDATABLE,SQL_COLUMN_NAME,SQL_COLUMN_TYPE_NAME,
					SQL_COLUMN_OWNER_NAME,SQL_COLUMN_QUALIFIER_NAME,SQL_COLUMN_TABLE_NAME,
					SQL_COLUMN_LABEL
				};

    struct {
        TCHAR cat[STR_LEN];
        TCHAR sch[STR_LEN];
        TCHAR tab[STR_LEN];
        TCHAR typ[STR_LEN];
    } displayBuf;
	
	int	i = 0, k = 0, NullValue = 0;
	TCHAR tmpSchema[129];
	TCHAR schemaList[3][256];
	int myInd=1;
	int len = _tcslen(pTestInfo->Schema);

	TCHAR *CrtCol[] = { _T("--"), _T("--") };
	TCHAR *DrpTab[] = { _T("--"), _T("--"), _T("--")};
	TCHAR *CrtTab[] = { _T("--"), _T("--"), _T("--")};

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

	Table[0].TableName = var_mapping(_T("SQLTables_Table_TableName_0"), var_list);
	Table[1].TableName = var_mapping(_T("SQLTables_Table_TableName_1"), var_list);
	Table[2].TableName = var_mapping(_T("SQLTables_Table_TableName_2"), var_list);
	Table[3].TableName = var_mapping(_T("SQLTables_Table_TableName_3"), var_list);
	Table[4].TableName = var_mapping(_T("SQLTables_Table_TableName_4"), var_list);
	Table[5].TableName = var_mapping(_T("SQLTables_Table_TableName_5"), var_list);
	Table[6].TableName = var_mapping(_T("SQLTables_Table_TableName_6"), var_list);
	Table[7].TableName = var_mapping(_T("SQLTables_Table_TableName_7"), var_list);
	Table[8].TableName = var_mapping(_T("SQLTables_Table_TableName_8"), var_list);
	Table[9].TableName = var_mapping(_T("SQLTables_Table_TableName_9"), var_list);
	Table[10].TableName = var_mapping(_T("SQLTables_Table_TableName_10"), var_list);
	
	TableWC[10].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_10"), var_list);
	TableWC[11].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_11"), var_list);
	TableWC[22].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_22"), var_list);
	TableWC[24].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_24"), var_list);
	TableWC[26].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_26"), var_list);
	TableWC[38].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_38"), var_list);
	TableWC[41].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_10"), var_list);
	TableWC[42].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_41"), var_list);
	TableWC[43].TabOwner = var_mapping(_T("SQLTables_TableWC_TabOwner_43"), var_list);

	TableWC[0].TabName = var_mapping(_T("SQLTables_TableWC_TabName_0"), var_list);
	TableWC[1].TabName = var_mapping(_T("SQLTables_TableWC_TabName_1"), var_list);
	TableWC[2].TabName = var_mapping(_T("SQLTables_TableWC_TabName_2"), var_list);
	TableWC[3].TabName = var_mapping(_T("SQLTables_TableWC_TabName_3"), var_list);
	TableWC[4].TabName = var_mapping(_T("SQLTables_TableWC_TabName_4"), var_list);
	TableWC[5].TabName = var_mapping(_T("SQLTables_TableWC_TabName_5"), var_list);
	TableWC[6].TabName = var_mapping(_T("SQLTables_TableWC_TabName_6"), var_list);
	TableWC[7].TabName = var_mapping(_T("SQLTables_TableWC_TabName_7"), var_list);
	TableWC[8].TabName = var_mapping(_T("SQLTables_TableWC_TabName_8"), var_list);
	TableWC[9].TabName = var_mapping(_T("SQLTables_TableWC_TabName_9"), var_list);
	TableWC[10].TabName = var_mapping(_T("SQLTables_TableWC_TabName_10"), var_list);
	TableWC[11].TabName = var_mapping(_T("SQLTables_TableWC_TabName_11"), var_list);
	TableWC[12].TabName = var_mapping(_T("SQLTables_TableWC_TabName_12"), var_list);
	TableWC[13].TabName = var_mapping(_T("SQLTables_TableWC_TabName_13"), var_list);
	TableWC[14].TabName = var_mapping(_T("SQLTables_TableWC_TabName_14"), var_list);
	TableWC[15].TabName = var_mapping(_T("SQLTables_TableWC_TabName_15"), var_list);
	TableWC[16].TabName = var_mapping(_T("SQLTables_TableWC_TabName_16"), var_list);
	TableWC[17].TabName = var_mapping(_T("SQLTables_TableWC_TabName_17"), var_list);
	TableWC[18].TabName = var_mapping(_T("SQLTables_TableWC_TabName_18"), var_list);
	TableWC[19].TabName = var_mapping(_T("SQLTables_TableWC_TabName_19"), var_list);
	TableWC[20].TabName = var_mapping(_T("SQLTables_TableWC_TabName_20"), var_list);
	TableWC[21].TabName = var_mapping(_T("SQLTables_TableWC_TabName_21"), var_list);
	TableWC[22].TabName = var_mapping(_T("SQLTables_TableWC_TabName_22"), var_list);
	TableWC[23].TabName = var_mapping(_T("SQLTables_TableWC_TabName_23"), var_list);
	TableWC[24].TabName = var_mapping(_T("SQLTables_TableWC_TabName_24"), var_list);
	TableWC[25].TabName = var_mapping(_T("SQLTables_TableWC_TabName_25"), var_list);
	TableWC[26].TabName = var_mapping(_T("SQLTables_TableWC_TabName_26"), var_list);
	TableWC[27].TabName = var_mapping(_T("SQLTables_TableWC_TabName_27"), var_list);
	TableWC[28].TabName = var_mapping(_T("SQLTables_TableWC_TabName_28"), var_list);
	TableWC[29].TabName = var_mapping(_T("SQLTables_TableWC_TabName_29"), var_list);
	TableWC[30].TabName = var_mapping(_T("SQLTables_TableWC_TabName_30"), var_list);
	TableWC[31].TabName = var_mapping(_T("SQLTables_TableWC_TabName_31"), var_list);
	TableWC[32].TabName = var_mapping(_T("SQLTables_TableWC_TabName_32"), var_list);
	TableWC[33].TabName = var_mapping(_T("SQLTables_TableWC_TabName_33"), var_list);
	TableWC[34].TabName = var_mapping(_T("SQLTables_TableWC_TabName_34"), var_list);
	TableWC[35].TabName = var_mapping(_T("SQLTables_TableWC_TabName_35"), var_list);
	TableWC[36].TabName = var_mapping(_T("SQLTables_TableWC_TabName_36"), var_list);
	TableWC[37].TabName = var_mapping(_T("SQLTables_TableWC_TabName_37"), var_list);
	TableWC[38].TabName = var_mapping(_T("SQLTables_TableWC_TabName_38"), var_list);
	TableWC[39].TabName = var_mapping(_T("SQLTables_TableWC_TabName_39"), var_list);
	TableWC[40].TabName = var_mapping(_T("SQLTables_TableWC_TabName_40"), var_list);
	TableWC[41].TabName = var_mapping(_T("SQLTables_TableWC_TabName_41"), var_list);
	TableWC[42].TabName = var_mapping(_T("SQLTables_TableWC_TabName_42"), var_list);
	TableWC[43].TabName = var_mapping(_T("SQLTables_TableWC_TabName_43"), var_list);

	TableWC2[0].TabName = var_mapping(_T("SQLTables_TableWC2_TabName_0"), var_list);

	CrtCol[0] = var_mapping(_T("SQLTables_CrtCol_0"), var_list);
	CrtCol[1] = var_mapping(_T("SQLTables_CrtCol_1"), var_list);

	DrpTab[0] = var_mapping(_T("SQLTables_DrpTab_0"), var_list);
	DrpTab[1] = var_mapping(_T("SQLTables_DrpTab_1"), var_list);
	DrpTab[2] = var_mapping(_T("SQLTables_DrpTab_2"), var_list);

	CrtTab[0] = var_mapping(_T("SQLTables_CrtTab_0"), var_list);
	CrtTab[1] = var_mapping(_T("SQLTables_CrtTab_1"), var_list);
	CrtTab[2] = var_mapping(_T("SQLTables_CrtTab_2"), var_list);
//===========================================================================================================

	memset(schemaList[0],'\0', 256*sizeof(TCHAR));
	memset(schemaList[1],'\0', 256*sizeof(TCHAR));
	memset(schemaList[2],'\0', 256*sizeof(TCHAR));

	myInd = len - 2;
	if (len>5) myInd=4;

/*
#ifndef UNICODE
	if (_tcscmp("English", _tsetlocale(LC_ALL, _T(""))) != 0) {
		_mbsncpy(schemaList[0],pTestInfo->Schema,myInd);
		_mbscat(schemaList[0], "%");

		_mbsncpy(schemaList[1],pTestInfo->Schema,myInd+1);
		_mbscat(schemaList[1], "%");
	}
	else {
#endif
*/
		_tcsncpy(schemaList[0],pTestInfo->Schema,myInd);
		_tcscat(schemaList[0], _T("%"));

		_tcsncpy(schemaList[1],pTestInfo->Schema,myInd+1);
		_tcscat(schemaList[1], _T("%"));
/*
#ifndef UNICODE
	}
#endif
*/

	len = 0; myInd = 0;
	do {
		if (pTestInfo->Schema[myInd] == '_')
			schemaList[2][len++] = '\\';
		schemaList[2][len++] = pTestInfo->Schema[myInd];
	} while (pTestInfo->Schema[myInd++] != '\0');

    LogMsg(NONE,_T("%s %s %s\n"), schemaList[0], schemaList[1], schemaList[2]);

	if (isCharSet) {
		_stprintf(tmpSchema, _T("\"SQLTABLES_%s\""), pTestInfo->Schema);
	}
	else {
		_stprintf(tmpSchema, _T("SQLTABLES_%s"), pTestInfo->Schema);
	}
	_tcsupr(tmpSchema);
//======================================================================================================

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

	TEST_INIT;

	TESTCASE_BEGIN("Setup for SQLTables tests\n");
	// for ODBC 3.0
	if(!FullConnectWithOptions(pTestInfo, CONNECT_ODBC_VERSION_3))
	{
		LogMsg(NONE,_T("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"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}
	else
	{
		LogMsg(NONE,_T("Allocate a stmt handle successfully.\n"));
	}

   TESTCASE_END;

   _tcscpy(pTestInfo->Catalog, _T("TRAFODION"));
	if (returncode == SQL_SUCCESS)
	{
        _stprintf(Heading,_T("drop schema %s.%s cascade"),pTestInfo->Catalog,tmpSchema);
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)Heading, SQL_NTS);
        _stprintf(Heading,_T("create schema %s.%s"),pTestInfo->Catalog,tmpSchema);
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)Heading, SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			TEST_RETURN;
		}

        _stprintf(Heading,_T("set schema %s.%s"),pTestInfo->Catalog,tmpSchema);
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)Heading, SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			TEST_RETURN;
		}

		_tcscpy(TableQualifier,pTestInfo->Catalog);
		_tcscpy(TableOwner, tmpSchema);
		_tcscpy(Remark,_T(""));
		TableStr = (TCHAR *)malloc(MAX_NOS_SIZE);

		i = 0;
		while (_tcsicmp(Table[i].TableName,_T("endloop")) != 0) // cleanup 
		{
			_tcscpy(TableStr,_T(""));
			_tcscat(TableStr,_T("drop "));
			_tcscat(TableStr,Table[i].TableType);
			_tcscat(TableStr,_T(" "));
			_tcscat(TableStr,Table[i].TableName);
			_tcscat(TableStr,_T(" cascade"));
			LogMsg(NONE,_T("Cleanup: %s\n"),TableStr);
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*) TableStr,SQL_NTS);
			i++;
		}
		
		i = 0;
		while (_tcsicmp(Table[i].TableName,_T("endloop")) != 0)
		{
			_tcscpy(TableStr,_T(""));
			_tcscat(TableStr,_T("create "));
			_tcscat(TableStr,Table[i].TableType);
			_tcscat(TableStr,_T(" "));
			_tcscat(TableStr,Table[i].TableName);
			if (_tcsicmp(Table[i].TableType,_T("VIEW")) == 0) {
				_tcscat(TableStr,CrtCol[1]);
				_tcscat(TableStr, Table[0].TableName);
			}
			else if (_tcsicmp(Table[i].TableType,_T("MATERIALIZED VIEW")) == 0) {
				_tcscat(TableStr, _T(" REFRESH ON REQUEST INITIALIZE ON REFRESH "));
				_tcscat(TableStr,CrtCol[1]);
				_tcscat(TableStr, Table[0].TableName); 
			}
			else if (_tcsicmp(Table[i].TableType,_T("SYNONYM")) == 0) {
				_tcscat(TableStr, _T(" FOR "));
				_tcscat(TableStr, Table[0].TableName);
			}
			else
			{
				_tcscat(TableStr,CrtCol[0]);
			}
		
			_stprintf(Heading,_T("SQLTables: Test %d: using the following table create command=> \n"),i);
			_tcscat(Heading,TableStr);
			_tcscat(Heading,_T("\n"));
			TESTCASE_BEGINW(Heading);
			
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*)TableStr,SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
			}
			else
			{
				LogMsg(NONE,_T("Created table successfully.\n"));
			}

			if(isCharSet) {
				returncode = SQLSetStmtAttr(hstmt,SQL_ATTR_METADATA_ID,(SQLPOINTER)SQL_TRUE,0);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtAttr(SQL_ATTR_METADATA_ID"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt);
				}
			}
			
			if (returncode == SQL_SUCCESS)
			{
				if (_tcslen(TableQualifier) > 0)
					returncode = SQLTables(hstmt,(SQLTCHAR*)TableQualifier,(SWORD)_tcslen(TableQualifier),(SQLTCHAR*)TableOwner,(SWORD)_tcslen(TableOwner),(SQLTCHAR*)Table[i].TableName,(SWORD)_tcslen(Table[i].TableName),(SQLTCHAR*)Table[i].TableTypeIn,(SWORD)_tcslen(Table[i].TableTypeIn));
				else
					returncode = SQLTables(hstmt,NULL,(SWORD)_tcslen(TableQualifier),(SQLTCHAR*)TableOwner,(SWORD)_tcslen(TableOwner),(SQLTCHAR*)Table[i].TableName,(SWORD)_tcslen(Table[i].TableName),(SQLTCHAR*)Table[i].TableTypeIn,(SWORD)_tcslen(Table[i].TableTypeIn));
				
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTables"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt);
				}
				else
				{
					LogMsg(NONE,_T("Call to SQLTables() executed successfully.\n"));
					
					_tcscpy(oTableQualifier,_T(""));
					_tcscpy(oTableOwner,_T(""));
					_tcscpy(oTableName,_T(""));
					_tcscpy(oTableType,_T(""));
					_tcscpy(oRemark,_T(""));
					returncode=SQLBindCol(hstmt,1,SQL_C_TCHAR,oTableQualifier,NAME_LEN,&oTableQualifierlen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")){
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
						}
				   returncode=SQLBindCol(hstmt,2,SQL_C_TCHAR,oTableOwner,NAME_LEN,&oTableOwnerlen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")){
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
						}
					returncode=SQLBindCol(hstmt,3,SQL_C_TCHAR,oTableName,NAME_LEN,&oTableNamelen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")){
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
						}
				   returncode=SQLBindCol(hstmt,4,SQL_C_TCHAR,oTableType,NAME_LEN,&oTableTypelen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")){
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
						}
					returncode=SQLBindCol(hstmt,5,SQL_C_TCHAR,oRemark,NAME_LEN,&oRemarklen);
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")){
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
						}

					k = 0;
					while (returncode == SQL_SUCCESS)
					{
						returncode = SQLFetch(hstmt);
						if((returncode != SQL_NO_DATA_FOUND)&&(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")))
						{
							LogAllErrors(henv,hdbc,hstmt);
							TEST_FAILED;
						}
						else if (returncode == SQL_SUCCESS)
						{
							if (_tcslen(TableQualifier) == 0)
							{
								//_tcscpy(TableQualifier, _T("TRAFODION"));
								_tcscpy(TableQualifier, _T("TRAFODION"));
							}
							if ((_tcsicmp(TableQualifier,oTableQualifier) == 0) 
								&& (cwcscmp(TableOwner,oTableOwner,TRUE) == 0) 
								&& (cwcscmp(Table[i].TableName,oTableName,TRUE) == 0) 
								&& (_tcsnicmp(Table[i].TableType,oTableType,_tcslen(Table[i].TableType)) == 0) 
								&& (_tcsicmp(Remark,oRemark) == 0))
							{
								LogMsg(NONE,_T("TableQualifier expect: '%s' and actual: '%s' are matched\n"),(SQLTCHAR*)TableQualifier,oTableQualifier);
								LogMsg(NONE,_T("TableOwner expect: '%s' and actual: '%s' are matched\n"),(SQLTCHAR*)TableOwner,oTableOwner);
								LogMsg(NONE,_T("TableName expect: '%s' and actual: '%s' are matched\n"),(SQLTCHAR*)Table[i].TableName,oTableName);
								LogMsg(NONE,_T("TableType expect: '%s' and actual: '%s' are matched\n"),Table[i].TableType,oTableType);
								LogMsg(NONE,_T("Remark expect: '%s' and actual: '%s' are matched\n"),Remark,oRemark);
							}	
							else
							{
								TEST_FAILED;	
								if (_tcsicmp(TableQualifier,oTableQualifier) != 0)
									LogMsg(ERRMSG,_T("TableQualifier expect: '%s' and actual: '%s' are not matched\n"),(SQLTCHAR*)TableQualifier,oTableQualifier);
								if (cwcscmp(TableOwner,oTableOwner,TRUE) != 0) 
									LogMsg(ERRMSG,_T("TableOwner expect: '%s' and actual: '%s' are not matched\n"),(SQLTCHAR*)TableOwner,oTableOwner);
								if (cwcscmp(Table[i].TableName,oTableName,TRUE) != 0) 
									LogMsg(ERRMSG,_T("TableName expect: '%s' and actual: '%s' are not matched\n"),(SQLTCHAR*)Table[i].TableName,oTableName);
								if (_tcsnicmp(Table[i].TableType,oTableType,10) != 0) 
									LogMsg(ERRMSG,_T("TableType expect: '%s' and actual: '%s' are not matched\n"),Table[i].TableType,oTableType);
								if (_tcsicmp(Remark,oRemark) != 0) 
									LogMsg(ERRMSG,_T("Remark expect: '%s' and actual: '%s' are not matched\n"),Remark,oRemark);
							}

							k++;
						}
					}//End while loop

					if(k != 1)
					{
						TEST_FAILED;
						LogMsg(ERRMSG,_T("Only one row should be fetched, the actual number of rows fetched: %d\n"), k);
					} else {
						LogMsg(NONE, _T("Number of rows fetched: %d\n"), k);
					}
				}
				SQLFreeStmt(hstmt,SQL_UNBIND);
				SQLFreeStmt(hstmt,SQL_CLOSE);
			}
			TESTCASE_END;
			i++;
		}
//		i = 0;
//		while (_tcsicmp(Table[i].TableName,"endloop") != 0) // cleanup
//		{
//			_tcscpy(TableStr,_T(""));
//			_tcscat(TableStr,"drop ");
//			_tcscat(TableStr,Table[i].TableType);
//			_tcscat(TableStr," ");
//			_tcscat(TableStr,Table[i].TableName);
//			SQLExecDirect(hstmt,(SQLTCHAR*) TableStr,SQL_NTS);
//			i++;
//		}

        _stprintf(Heading,_T("drop schema %s.%s cascade"),pTestInfo->Catalog,tmpSchema);
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)Heading, SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			TEST_RETURN;
		}

		if (isCharSet) {
			_stprintf(Heading,_T("set schema %s.\"%s\""),pTestInfo->Catalog,pTestInfo->Schema);
		}
		else {
			_stprintf(Heading,_T("set schema %s.%s"),pTestInfo->Catalog,pTestInfo->Schema);
		}
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)Heading, SQL_NTS);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
			TEST_RETURN;
		}

//======================================================================================================
		_stprintf(Heading,_T("Setting up Table & view to test SQLTables for wildcard options => \n"));
		_tcscat(Heading,_T("\n"));
		TESTCASE_BEGINW(Heading);
		SQLExecDirect(hstmt,(SQLTCHAR*)DrpTab[0],SQL_NTS);
		SQLExecDirect(hstmt,(SQLTCHAR*)DrpTab[1],SQL_NTS);
		SQLExecDirect(hstmt,(SQLTCHAR*)DrpTab[2],SQL_NTS);
		LogMsg(NONE,_T("%s\n"), CrtTab[0]);
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)CrtTab[0],SQL_NTS);

		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
		}
		else
		{
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*)CrtTab[1],SQL_NTS);
			LogMsg(NONE,_T("%s\n"), CrtTab[1]);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
			}
			else
			{
				LogMsg(NONE,_T("setting up tables & views executed successfully.\n"));
				TESTCASE_END;
			}
		}
		returncode = SQLExecDirect(hstmt,(SQLTCHAR*)CrtTab[2],SQL_NTS);
		LogMsg(NONE,_T("%s\n"), CrtTab[2]);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			TEST_FAILED;
		}
		i = 0;
		while (_tcsicmp(TableWC[i].TabQua,_T("endloop")) != 0)
		{
			if(TableWC[i].changedSchema == -1) {
				printSymbol(TableWC[i].TabQua,displayBuf.cat);
                printSymbol(TableWC[i].TabOwner,displayBuf.sch);
				printSymbol(TableWC[i].TabName,displayBuf.tab);
                printSymbol(TableWC[i].TabType,displayBuf.typ);

				_stprintf(Heading,_T("Test Positive Functionality of SQLTables for following wildcard options => \n TableQualifier: %s\n TableOwner: %s\n TableName: %s\n TableType: %s\n"),
				displayBuf.cat, displayBuf.sch,	displayBuf.tab, displayBuf.typ);
			}
			else {
				printSymbol(TableWC[i].TabQua,displayBuf.cat);
                printSymbol(schemaList[TableWC[i].changedSchema],displayBuf.sch);
				printSymbol(TableWC[i].TabName,displayBuf.tab);
                printSymbol(TableWC[i].TabType,displayBuf.typ);

				_stprintf(Heading,_T("Test Positive Functionality of SQLTables for following wildcard options => \n TableQualifier: %s\n TableOwner: %s\n TableName: %s\n TableType: %s\n"),
				displayBuf.cat, displayBuf.sch, displayBuf.tab, displayBuf.typ);
			}

			TESTCASE_BEGINW(Heading);
			NullValue = 0;

			returncode = SQLSetStmtAttr(hstmt,SQL_ATTR_METADATA_ID,(SQLPOINTER)SQL_FALSE,0);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtAttr(SQL_ATTR_METADATA_ID"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
			}

			if (_tcsicmp(TableWC[i].TabType,_T("NULL")) == 0)
			{
				TableWC[i].TabType = NULL;
				NullValue = 1;
				returncode = SQLTables(hstmt,NULL,0,NULL,0,NULL,0,NULL,0);
			}
			else if (_tcsicmp(TableWC[i].TabName,_T("NULL")) == 0)
			{
				TableWC[i].TabName = NULL;
				NullValue = 1;
				returncode = SQLTables(hstmt,NULL,0,NULL,0,NULL,0,(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
			}
			else if (_tcsicmp(TableWC[i].TabOwner,_T("NULL")) == 0)
			{
				TableWC[i].TabOwner = NULL;
				NullValue = 1;
				returncode = SQLTables(hstmt,NULL,0,NULL,0,(SQLTCHAR*)removeQuotes(TableWC[i].TabName,displayBuf.tab),(SWORD)_tcslen(displayBuf.tab),(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
			}
			else if (_tcsicmp(TableWC[i].TabQua,_T("NULL")) == 0)
			{
				TableWC[i].TabQua = NULL;
				NullValue = 1;
				if (TableWC[i].changedSchema == -1)
					returncode = SQLTables(hstmt,NULL,0,(SQLTCHAR*)TableWC[i].TabOwner,(SWORD)_tcslen(TableWC[i].TabOwner),(SQLTCHAR*)removeQuotes(TableWC[i].TabName,displayBuf.tab),(SWORD)_tcslen(displayBuf.tab),(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
				else
					returncode = SQLTables(hstmt,NULL,0,(SQLTCHAR*)schemaList[TableWC[i].changedSchema],(SWORD)_tcslen(schemaList[TableWC[i].changedSchema]),(SQLTCHAR*)removeQuotes(TableWC[i].TabName,displayBuf.tab),(SWORD)_tcslen(displayBuf.tab),(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
			}
			else
			{
				if (TableWC[i].changedSchema == -1)
					returncode = SQLTables(hstmt,(SQLTCHAR*)TableWC[i].TabQua,(SWORD)_tcslen(TableWC[i].TabQua),(SQLTCHAR*)TableWC[i].TabOwner,(SWORD)_tcslen(TableWC[i].TabOwner),(SQLTCHAR*)removeQuotes(TableWC[i].TabName,displayBuf.tab),(SWORD)_tcslen(displayBuf.tab),(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
				else
					returncode = SQLTables(hstmt,(SQLTCHAR*)TableWC[i].TabQua,(SWORD)_tcslen(TableWC[i].TabQua),(SQLTCHAR*)schemaList[TableWC[i].changedSchema],(SWORD)_tcslen(schemaList[TableWC[i].changedSchema]),(SQLTCHAR*)removeQuotes(TableWC[i].TabName,displayBuf.tab),(SWORD)_tcslen(displayBuf.tab),(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
			}

			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTables"))
			{
				TEST_FAILED;
				LogAllErrors(henv,hdbc,hstmt);
			}
			else
			{
				LogMsg(NONE,_T("Call to SQLTables() executed successfully.\n"));
				_tcscpy(oTableQualifier,_T(""));
				_tcscpy(oTableOwner,_T(""));
				_tcscpy(oTableName,_T(""));
				_tcscpy(oTableType,_T(""));
				_tcscpy(oRemark,_T(""));
				returncode=SQLBindCol(hstmt,1,SQL_C_TCHAR,oTableQualifier,NAME_LEN,&oTableQualifierlen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				returncode=SQLBindCol(hstmt,2,SQL_C_TCHAR,oTableOwner,NAME_LEN,&oTableOwnerlen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				returncode=SQLBindCol(hstmt,3,SQL_C_TCHAR,oTableName,NAME_LEN,&oTableNamelen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				returncode=SQLBindCol(hstmt,4,SQL_C_TCHAR,oTableType,NAME_LEN,&oTableTypelen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				returncode=SQLBindCol(hstmt,5,SQL_C_TCHAR,oRemark,NAME_LEN,&oRemarklen);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				k = 0;
				while (returncode == SQL_SUCCESS)
				{
					returncode = SQLFetch(hstmt);
					if((returncode!=SQL_NO_DATA_FOUND) && (!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					if (returncode == SQL_SUCCESS)
						k++;
				}
				if(k == 0)
				{
					TEST_FAILED;
					LogMsg(ERRMSG,_T("No Data Found => Atleast one row should be fetched\n"));
                } else {
                    LogMsg(NONE, _T("Number of rows fetched: %d\n"), k);
                }
			}
			SQLFreeStmt(hstmt,SQL_CLOSE);
			i++;
			TESTCASE_END;
		}
		free(TableStr);
	}

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

	TESTCASE_BEGIN("SQLTables: Negative test with NULL handle.\n");

	hstmt1 = (SQLHANDLE)NULL;
	i = 0;
	returncode = SQLTables(hstmt1,(SQLTCHAR*)TableWC[i].TabQua,(SWORD)_tcslen(TableWC[i].TabQua),(SQLTCHAR*)TableWC[i].TabOwner,(SWORD)_tcslen(TableWC[i].TabOwner),(SQLTCHAR*)TableWC[i].TabName,(SWORD)_tcslen(TableWC[i].TabName),(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
	if(!CHECKRC(SQL_INVALID_HANDLE,returncode,"SQLTables"))
	{
		TEST_FAILED;
		LogAllErrors(henv,hdbc,hstmt);
	}
	TESTCASE_END;

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

	TESTCASE_BEGIN("SQLTables: Negative test with invalid arg lengths.\n");
	i = 0;
	while (_tcsicmp(TableWC2[i].TabQua,_T("endloop")) != 0)
	{
		returncode = SQLTables(hstmt,(SQLTCHAR*)TableWC2[i].TabQua,TableWC2[i].TabQuaLen,(SQLTCHAR*)TableWC2[i].TabOwner,TableWC2[i].TabOwnerLen,(SQLTCHAR*)TableWC2[i].TabName,TableWC2[i].TabNameLen,(SQLTCHAR*)TableWC2[i].TabType,TableWC2[i].TabTypeLen);
		if(!CHECKRC(SQL_ERROR,returncode,"SQLTables"))
		{
			TEST_FAILED;
			LogAllErrors(henv,hdbc,hstmt);
		}
		i++;
	}
	TESTCASE_END;

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

	TESTCASE_BEGIN("Testing SQLColAttribute, SQLDescribeCol, SQLBindCol and SQLFetch functions for catalog names.\n");

    if(isCharSet) {
		returncode = SQLSetStmtAttr(hstmt,SQL_ATTR_METADATA_ID,(SQLPOINTER)SQL_FALSE,0);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtAttr(SQL_ATTR_METADATA_ID"))
		{
			TEST_FAILED;
			LogAllErrors(henv,hdbc,hstmt);
		}
	}

	for(i = 0; i < 5; i++)
	{
		returncode = SQLTables(hstmt,(SQLTCHAR*)TableWC[i].TabQua,(SWORD)_tcslen(TableWC[i].TabQua),(SQLTCHAR*)TableWC[i].TabOwner,(SWORD)_tcslen(TableWC[i].TabOwner),(SQLTCHAR*)TableWC[i].TabName,(SWORD)_tcslen(TableWC[i].TabName),(SQLTCHAR*)TableWC[i].TabType,(SWORD)_tcslen(TableWC[i].TabType));
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLColumns"))
		{
			TEST_FAILED;
			LogAllErrors(henv,hdbc,hstmt);
		}
		returncode = SQLNumResultCols(hstmt, &numOfCols);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLNumResultsCol"))
		{
			TEST_FAILED;
			LogMsg(ERRMSG,_T("Test failed while executing call for SQLNUMRESULTSCOL"));
			LogAllErrors(henv,hdbc,hstmt);
		}
		for(cols = 0; cols < numOfCols; cols++)
		{
			returncode = SQLDescribeCol(hstmt,(SWORD)(cols+1),(SQLTCHAR*)cn,TabType_LEN,&cl,&st,&cp,&cs,&cnull);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLDescribeCol"))
			{
				TEST_FAILED;
				LogMsg(ERRMSG,_T("Test failed while executing call for SQLDESCRIBECOL of column"));
				LogAllErrors(henv,hdbc,hstmt);
			}
			CharOutput[cols] = (TCHAR *)malloc(STR_LEN);
			for (iatt = 0; iatt <= TOTALATTRIBS; iatt++)
			{
				_tcscpy(rgbDesc,_T(""));
				pcbDesc = 0;
				pfDesc = 0;
				returncode = SQLColAttributes(hstmt,(SWORD)(cols+1),DescrType[iatt],(SQLTCHAR*)rgbDesc,STR_LEN,&pcbDesc,&pfDesc);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLColAttribute"))
				{
					TEST_FAILED;
					LogAllErrors(henv,hdbc,hstmt);
				}
			}
			returncode = SQLBindCol(hstmt,(SWORD)(cols+1),SQL_C_TCHAR,(SQLTCHAR*)CharOutput[cols],STR_LEN,&stringlength);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
			{
				TEST_FAILED;
				LogMsg(ERRMSG,_T("Test failed while executing call for SQLBindCols of column : %d.\n"),cols);
				LogAllErrors(henv,hdbc,hstmt);
			}
		}

		k = 0;
		while (returncode == SQL_SUCCESS)
		{
			returncode = SQLFetch(hstmt);
			if((returncode!=SQL_NO_DATA_FOUND) && (!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
			}
			if (returncode == SQL_SUCCESS)
				k++;
		}
		if(k == 0)
		{
            _stprintf(Heading,_T("\n TableQualifier: %s\n TableOwner: %s\n TableName: %s\n TableType: %s\n"),
				printSymbol(TableWC[i].TabQua,displayBuf.cat),
                printSymbol(TableWC[i].TabOwner,displayBuf.sch),
				printSymbol(TableWC[i].TabName,displayBuf.tab),
                printSymbol(TableWC[i].TabType,displayBuf.typ));
            LogMsg(NONE,Heading);
			TEST_FAILED;
			LogMsg(ERRMSG,_T("No Data Found => Atleast one row should be fetched\n"));
		} else {
            LogMsg(NONE, _T("Number of rows fetched: %d\n"), k);
        }

		for(cols = 0; cols < numOfCols; cols++)
		{
			free(CharOutput[cols]);
		}
		TESTCASE_END;
	}

	// Clean up
	SQLExecDirect(hstmt,(SQLTCHAR*)DrpTab[0],SQL_NTS);
	SQLExecDirect(hstmt,(SQLTCHAR*)DrpTab[1],SQL_NTS);
	SQLExecDirect(hstmt,(SQLTCHAR*)DrpTab[2],SQL_NTS);

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

	FullDisconnect(pTestInfo);
	LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLTables.\n"));
	free_list(var_list);
	TEST_RETURN;
}