language-extensions/R/test/src/RExtensionGetResultColumnTests.cpp
//----------------------------------------------------------------------------------------------
// Name: GetDifferentResultColumnsTest
//
// Description:
//  Tests GetResultColumn with default script using an OutputDataSet of different column types.
//
GetDifferentResultColumnsTest
Description:
Tests GetResultColumn with default script using an OutputDataSet of different column types.
GetDifferentResultColumnsTest Description : Tests GetResultColumn with default script using an OutputDataSet of different column types .
TEST_F(RExtensionApiTests, GetDifferentResultColumnsTest)
	{
		InitializeSession(
			3,                inputSchemaColumnsNumber
			m_scriptString);
		string integerColumnName = "IntegerColumn";
		InitializeColumn(0,  columnNumber
			integerColumnName,
			SQL_C_SLONG,
			m_IntSize,
			0,               decimalDigits
			SQL_NULLABLE);
		string doubleColumnName = "DoubleColumn";
		InitializeColumn(1,  columnNumber
			doubleColumnName,
			SQL_C_DOUBLE,
			m_DoubleSize,
			0,               decimalDigits
			SQL_NO_NULLS);
		string charColumnName = "CharColumn";
		InitializeColumn(2,  columnNumber
			charColumnName,
			SQL_C_CHAR,
			m_CharSize,
			0,               decimalDigits
			SQL_NULLABLE);
		SQLULEN rowsNumber = 5;
		vector<SQLINTEGER> intColData{ m_MaxInt, m_MinInt, NA_INTEGER, NA_INTEGER, -1 };
		vector<SQLDOUBLE> doubleColData{ m_MinDouble, 1.33, 83.98, 72.45, m_MaxDouble };
		vector<const char*> charCol{ "Hello", "test", "data", "RExtension", "-123" };
		vector<SQLINTEGER> strLenOrIndCol1 = { 0, 0, SQL_NULL_DATA, SQL_NULL_DATA, 0 };
		vector<SQLINTEGER> strLenOrIndCol3 =
			{ static_cast<SQLINTEGER>(strlen(charCol[0])),
			  static_cast<SQLINTEGER>(strlen(charCol[1])),
			  static_cast<SQLINTEGER>(strlen(charCol[2])),
			  static_cast<SQLINTEGER>(strlen(charCol[3])),
			  static_cast<SQLINTEGER>(strlen(charCol[4])) };
		vector<SQLINTEGER*> strLen_or_Ind{ strLenOrIndCol1.data(), nullptr, strLenOrIndCol3.data()};
		vector<char> charColData = GenerateContiguousData<char>(charCol, strLenOrIndCol3.data());
		vector<void *> dataSet { intColData.data(), doubleColData.data(), charColData.data()};
		SQLUSMALLINT outputschemaColumnsNumber = 0;
		SQLRETURN result = (*sm_executeFuncPtr)(
			*m_sessionId,
			m_taskId,
			rowsNumber,
			dataSet.data(),
			strLen_or_Ind.data(),
			&outputschemaColumnsNumber);
		ASSERT_EQ(result, SQL_SUCCESS);
		GetResultColumn(0,  columnNumber
			SQL_C_SLONG,    dataType
			m_IntSize,      columnSize
			0,              decimalDigits
			SQL_NULLABLE);  nullable
		GetResultColumn(1,  columnNumber
			SQL_C_DOUBLE,   dataType
			m_DoubleSize,   columnSize
			0,              decimalDigits
			SQL_NO_NULLS);  nullable
		SQLULEN maxLen = Utilities::GetMaxLength(strLenOrIndCol3.data(), rowsNumber);
		GetResultColumn(2,  columnNumber
			SQL_C_CHAR,     dataType
			maxLen,         columnSize
			0,              decimalDigits
			SQL_NO_NULLS);  nullable
	}
TEST_F ( RExtensionApiTests , GetDifferentResultColumnsTest ) { InitializeSession ( 3 , m_scriptString ) ; string integerColumnName = " " ; InitializeColumn ( 0 , integerColumnName , SQL_C_SLONG , m_IntSize , 0 , SQL_NULLABLE ) ; string doubleColumnName = " " ; InitializeColumn ( 1 , doubleColumnName , SQL_C_DOUBLE , m_DoubleSize , 0 , SQL_NO_NULLS ) ; string charColumnName = " " ; InitializeColumn ( 2 , charColumnName , SQL_C_CHAR , m_CharSize , 0 , SQL_NULLABLE ) ; SQLULEN rowsNumber = 5 ; vector < SQLINTEGER > intColData { m_MaxInt , m_MinInt , NA_INTEGER , NA_INTEGER , -1 } ; vector < SQLDOUBLE > doubleColData { m_MinDouble , 1.33 , 83.98 , 72.45 , m_MaxDouble } ; vector < const char * > charCol { " " , " " , " " , " " , " " } ; vector < SQLINTEGER > strLenOrIndCol1 = { 0 , 0 , SQL_NULL_DATA , SQL_NULL_DATA , 0 } ; vector < SQLINTEGER > strLenOrIndCol3 = { static_cast < SQLINTEGER > ( strlen ( charCol [ 0 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 1 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 2 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 3 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 4 ] ) ) } ; vector < SQLINTEGER * > strLen_or_Ind { strLenOrIndCol1 . data ( ) , nullptr , strLenOrIndCol3 . data ( ) } ; vector < char > charColData = GenerateContiguousData < char > ( charCol , strLenOrIndCol3 . data ( ) ) ; vector < void * > dataSet { intColData . data ( ) , doubleColData . data ( ) , charColData . data ( ) } ; SQLUSMALLINT outputschemaColumnsNumber = 0 ; SQLRETURN result = ( * sm_executeFuncPtr ) ( * m_sessionId , m_taskId , rowsNumber , dataSet . data ( ) , strLen_or_Ind . data ( ) , & outputschemaColumnsNumber ) ; ASSERT_EQ ( result , SQL_SUCCESS ) ; GetResultColumn ( 0 , SQL_C_SLONG , m_IntSize , 0 , SQL_NULLABLE ) ; GetResultColumn ( 1 , SQL_C_DOUBLE , m_DoubleSize , 0 , SQL_NO_NULLS ) ; SQLULEN maxLen = Utilities :: GetMaxLength ( strLenOrIndCol3 . data ( ) , rowsNumber ) ; GetResultColumn ( 2 , SQL_C_CHAR , maxLen , 0 , SQL_NO_NULLS ) ; }
Name: GetDifferentResultColumnsTest
Description:
Tests GetResultColumn with default script using an OutputDataSet of different column types.
Name : GetDifferentResultColumnsTest Description : Tests GetResultColumn with default script using an OutputDataSet of different column types .
// Initialize with a default Session that prints Hello RExtension // and assigns InputDataSet to OutputDataSet // // inputSchemaColumnsNumber // columnNumber // decimalDigits // columnNumber // decimalDigits // columnNumber // decimalDigits // columnNumber // dataType // columnSize // decimalDigits // nullable // columnNumber // dataType // columnSize // decimalDigits // nullable // columnNumber // dataType // columnSize // decimalDigits // nullable