language-extensions/python/test/src/PythonGetResultsTests.cpp
// Name: GetDifferentResultsTest
//
// Description:
//  Test GetResults with default script using an OutputDataSet of different column types.
//
GetDifferentResultsTest
Description:
Test GetResults with default script using an OutputDataSet of different column types.
GetDifferentResultsTest Description : Test GetResults with default script using an OutputDataSet of different column types .
TEST_F(PythonExtensionApiTests, GetDifferentColumnResultsTest)
	{
		int inputSchemaColumnsNumber = 3;
		InitializeSession(0,  parametersNumber
			inputSchemaColumnsNumber,
			m_scriptString);
		string integerColumnName = "IntegerColumn";
		InitializeColumn(0, integerColumnName, SQL_C_SLONG, m_IntSize);
		string doubleColumnName = "DoubleColumn";
		InitializeColumn(1, doubleColumnName, SQL_C_DOUBLE, m_DoubleSize);
		string stringColumnName = "CharColumn";
		InitializeColumn(2, stringColumnName, SQL_C_CHAR, m_CharSize);
		SQLULEN expectedRowsNumber = 5;
		vector<SQLINTEGER> intColData{ m_MaxInt, m_MinInt, 0, 0, -1 };
		vector<SQLDOUBLE> doubleColData{ m_MinDouble, 1.33, 83.98, 72.45, m_MaxDouble };
		vector<const char*> stringCol{ "Hello", "test", "data", "World", "-123" };
		vector<SQLINTEGER> strLenOrIndCol1 = { m_IntSize, m_IntSize, SQL_NULL_DATA,
			SQL_NULL_DATA, m_IntSize };
		vector<SQLINTEGER> strLenOrIndCol2(expectedRowsNumber, m_DoubleSize);
		vector<SQLINTEGER> strLenOrIndCol3 =
		{ static_cast<SQLINTEGER>(strlen(stringCol[0])),
		  static_cast<SQLINTEGER>(strlen(stringCol[1])),
		  static_cast<SQLINTEGER>(strlen(stringCol[2])),
		  static_cast<SQLINTEGER>(strlen(stringCol[3])),
		  static_cast<SQLINTEGER>(strlen(stringCol[4])) };
		vector<SQLINTEGER*> expectedStrLen_or_Ind{ strLenOrIndCol1.data(),
			strLenOrIndCol2.data(), strLenOrIndCol3.data() };
		vector<char> stringColData = GenerateContiguousData( stringCol, strLenOrIndCol3.data());
		vector<void *> expectedData{ intColData.data(), doubleColData.data(), stringColData.data() };
		SQLUSMALLINT outputschemaColumnsNumber = 0;
		SQLRETURN result = Execute(
			*m_sessionId,
			m_taskId,
			expectedRowsNumber,
			expectedData.data(),
			expectedStrLen_or_Ind.data(),
			&outputschemaColumnsNumber);
		ASSERT_EQ(result, SQL_SUCCESS);
		SQLULEN    rowsNumber = 0;
		SQLPOINTER *data = nullptr;
		SQLINTEGER **strLen_or_Ind = nullptr;
		result = GetResults(
			*m_sessionId,
			m_taskId,
			&rowsNumber,
			&data,
			&strLen_or_Ind);
		ASSERT_EQ(result, SQL_SUCCESS);
		EXPECT_EQ(rowsNumber, expectedRowsNumber);
		vector<SQLINTEGER> outputStrLenOrIndCol1 = { m_DoubleSize, m_DoubleSize, SQL_NULL_DATA,
			SQL_NULL_DATA, m_DoubleSize };
		 Test the data returned.
		CheckColumnDataEqualityForNullable<SQLINTEGER, SQLDOUBLE>(
			rowsNumber,
			static_cast<SQLINTEGER*>(expectedData[0]),
			static_cast<SQLINTEGER*>(data[0]),
			outputStrLenOrIndCol1.data(),
			strLen_or_Ind[0]);
		CheckColumnDataEquality<SQLDOUBLE>(
			rowsNumber,
			static_cast<SQLDOUBLE*>(expectedData[1]),
			static_cast<SQLDOUBLE*>(data[1]),
			expectedStrLen_or_Ind[1],
			strLen_or_Ind[1]);
		CheckStringDataEquality(
			rowsNumber,
			static_cast<char*>(expectedData[2]),
			static_cast<char*>(data[2]),
			expectedStrLen_or_Ind[2],
			strLen_or_Ind[2]);
		 Test the data obtained is what is present in OutputDataSet.
		string createDictScript = m_outputDataNameString + ".to_dict()";
		bp::dict outputDataSet = bp::extract<bp::dict>(
			bp::eval(createDictScript.c_str(), m_mainNamespace));
		EXPECT_EQ(outputschemaColumnsNumber, bp::len(outputDataSet.keys()));
		bp::dict intColumn = bp::extract<bp::dict>(outputDataSet[integerColumnName]);
		CheckColumnEquality<SQLDOUBLE>(
			rowsNumber,
			intColumn,
			data[0],
			strLen_or_Ind[0]);
		bp::dict doubleColumn = bp::extract<bp::dict>(outputDataSet[doubleColumnName]);
		CheckColumnEquality<SQLDOUBLE>(
			rowsNumber,
			doubleColumn,
			data[1],
			strLen_or_Ind[1]);
		bp::dict stringColumn = bp::extract<bp::dict>(outputDataSet[stringColumnName]);
		CheckStringColumnEquality(
			rowsNumber,
			stringColumn,
			data[2],
			strLen_or_Ind[2]);
	}
TEST_F ( PythonExtensionApiTests , GetDifferentColumnResultsTest ) { int inputSchemaColumnsNumber = 3 ; InitializeSession ( 0 , inputSchemaColumnsNumber , m_scriptString ) ; string integerColumnName = " " ; InitializeColumn ( 0 , integerColumnName , SQL_C_SLONG , m_IntSize ) ; string doubleColumnName = " " ; InitializeColumn ( 1 , doubleColumnName , SQL_C_DOUBLE , m_DoubleSize ) ; string stringColumnName = " " ; InitializeColumn ( 2 , stringColumnName , SQL_C_CHAR , m_CharSize ) ; SQLULEN expectedRowsNumber = 5 ; vector < SQLINTEGER > intColData { m_MaxInt , m_MinInt , 0 , 0 , -1 } ; vector < SQLDOUBLE > doubleColData { m_MinDouble , 1.33 , 83.98 , 72.45 , m_MaxDouble } ; vector < const char * > stringCol { " " , " " , " " , " " , " " } ; vector < SQLINTEGER > strLenOrIndCol1 = { m_IntSize , m_IntSize , SQL_NULL_DATA , SQL_NULL_DATA , m_IntSize } ; vector < SQLINTEGER > strLenOrIndCol2 ( expectedRowsNumber , m_DoubleSize ) ; vector < SQLINTEGER > strLenOrIndCol3 = { static_cast < SQLINTEGER > ( strlen ( stringCol [ 0 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol [ 1 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol [ 2 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol [ 3 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol [ 4 ] ) ) } ; vector < SQLINTEGER * > expectedStrLen_or_Ind { strLenOrIndCol1 . data ( ) , strLenOrIndCol2 . data ( ) , strLenOrIndCol3 . data ( ) } ; vector < char > stringColData = GenerateContiguousData ( stringCol , strLenOrIndCol3 . data ( ) ) ; vector < void * > expectedData { intColData . data ( ) , doubleColData . data ( ) , stringColData . data ( ) } ; SQLUSMALLINT outputschemaColumnsNumber = 0 ; SQLRETURN result = Execute ( * m_sessionId , m_taskId , expectedRowsNumber , expectedData . data ( ) , expectedStrLen_or_Ind . data ( ) , & outputschemaColumnsNumber ) ; ASSERT_EQ ( result , SQL_SUCCESS ) ; SQLULEN rowsNumber = 0 ; SQLPOINTER * data = nullptr ; SQLINTEGER * * strLen_or_Ind = nullptr ; result = GetResults ( * m_sessionId , m_taskId , & rowsNumber , & data , & strLen_or_Ind ) ; ASSERT_EQ ( result , SQL_SUCCESS ) ; EXPECT_EQ ( rowsNumber , expectedRowsNumber ) ; vector < SQLINTEGER > outputStrLenOrIndCol1 = { m_DoubleSize , m_DoubleSize , SQL_NULL_DATA , SQL_NULL_DATA , m_DoubleSize } ; CheckColumnDataEqualityForNullable < SQLINTEGER , SQLDOUBLE > ( rowsNumber , static_cast < SQLINTEGER * > ( expectedData [ 0 ] ) , static_cast < SQLINTEGER * > ( data [ 0 ] ) , outputStrLenOrIndCol1 . data ( ) , strLen_or_Ind [ 0 ] ) ; CheckColumnDataEquality < SQLDOUBLE > ( rowsNumber , static_cast < SQLDOUBLE * > ( expectedData [ 1 ] ) , static_cast < SQLDOUBLE * > ( data [ 1 ] ) , expectedStrLen_or_Ind [ 1 ] , strLen_or_Ind [ 1 ] ) ; CheckStringDataEquality ( rowsNumber , static_cast < char * > ( expectedData [ 2 ] ) , static_cast < char * > ( data [ 2 ] ) , expectedStrLen_or_Ind [ 2 ] , strLen_or_Ind [ 2 ] ) ; string createDictScript = m_outputDataNameString + " " ; bp :: dict outputDataSet = bp :: extract < bp :: dict > ( bp :: eval ( createDictScript . c_str ( ) , m_mainNamespace ) ) ; EXPECT_EQ ( outputschemaColumnsNumber , bp :: len ( outputDataSet . keys ( ) ) ) ; bp :: dict intColumn = bp :: extract < bp :: dict > ( outputDataSet [ integerColumnName ] ) ; CheckColumnEquality < SQLDOUBLE > ( rowsNumber , intColumn , data [ 0 ] , strLen_or_Ind [ 0 ] ) ; bp :: dict doubleColumn = bp :: extract < bp :: dict > ( outputDataSet [ doubleColumnName ] ) ; CheckColumnEquality < SQLDOUBLE > ( rowsNumber , doubleColumn , data [ 1 ] , strLen_or_Ind [ 1 ] ) ; bp :: dict stringColumn = bp :: extract < bp :: dict > ( outputDataSet [ stringColumnName ] ) ; CheckStringColumnEquality ( rowsNumber , stringColumn , data [ 2 ] , strLen_or_Ind [ 2 ] ) ; }
Name: GetDifferentResultsTest
Description:
Test GetResults with default script using an OutputDataSet of different column types.
Name : GetDifferentResultsTest Description : Test GetResults with default script using an OutputDataSet of different column types .
// Initialize with a default Session that prints Hello PythonExtension // and assigns InputDataSet to OutputDataSet // // parametersNumber // Test the data returned. // // Test the data obtained is what is present in OutputDataSet. //