language-extensions/python/test/src/PythonGetResultColumnTests.cpp
// Name: GetStringResultColumnsTest
//
// Description:
//  Test GetResultColumn with default script using an OutputDataSet of String columns.
//

GetStringResultColumnsTest
Description:
Test GetResultColumn with default script using an OutputDataSet of String columns.
GetStringResultColumnsTest Description : Test GetResultColumn with default script using an OutputDataSet of String columns .
TEST_F(PythonExtensionApiTests, GetStringResultColumnsTest)
	{
		SQLUSMALLINT inputSchemaColumnsNumber = 3;
		InitializeSession(0, 
			inputSchemaColumnsNumber,
			m_scriptString);
		string stringColumn1Name = "StringColumn1";
		InitializeColumn(0, stringColumn1Name, SQL_C_CHAR, m_CharSize);
		string stringColumn2Name = "StringColumn2";
		InitializeColumn(1, stringColumn2Name, SQL_C_CHAR, m_CharSize);
		string stringColumn3Name = "StringColumn3";
		InitializeColumn(2, stringColumn3Name, SQL_C_CHAR, m_CharSize);
		vector<const char *> stringCol1{ "Hello", "test", "data", "World", "-123" };
		vector<const char *> stringCol2{ "", 0, nullptr, "verify", "-1" };
		vector<SQLINTEGER> strLenOrIndCol1 =
		{ static_cast<SQLINTEGER>(strlen(stringCol1[0])),
		  static_cast<SQLINTEGER>(strlen(stringCol1[1])),
		  static_cast<SQLINTEGER>(strlen(stringCol1[2])),
		  static_cast<SQLINTEGER>(strlen(stringCol1[3])),
		  static_cast<SQLINTEGER>(strlen(stringCol1[4])) };
		vector<SQLINTEGER> strLenOrIndCol2 =
		{ 0, SQL_NULL_DATA, SQL_NULL_DATA,
		  static_cast<SQLINTEGER>(strlen(stringCol2[3])),
		  static_cast<SQLINTEGER>(strlen(stringCol2[4])) };
		vector<SQLINTEGER *> strLen_or_Ind{ strLenOrIndCol1.data(),
			strLenOrIndCol2.data(), nullptr };
		vector<char> stringCol1Data = GenerateContiguousData<char>(stringCol1, strLenOrIndCol1.data());
		vector<char> stringCol2Data = GenerateContiguousData<char>(stringCol2, strLenOrIndCol2.data());
		void *dataSet[] = { stringCol1Data.data(),
							stringCol2Data.data(),
							nullptr };
		int rowsNumber = stringCol1.size();
		vector<string> columnNames{ stringColumn1Name, stringColumn2Name, stringColumn3Name };
		TestExecute<SQLCHAR, SQL_C_CHAR>(
			rowsNumber,
			dataSet,
			strLen_or_Ind.data(),
			columnNames,
			false); 
		SQLULEN maxCol1Len = GetMaxLength(strLenOrIndCol1.data(), rowsNumber);
		SQLULEN maxCol2Len = GetMaxLength(strLenOrIndCol2.data(), rowsNumber);
		TestGetResultColumn(0, 
			SQL_C_CHAR,        
			maxCol1Len,        
			0,                 
			SQL_NO_NULLS);     
		TestGetResultColumn(1, 
			SQL_C_CHAR,        
			maxCol2Len,        
			0,                 
			SQL_NULLABLE);     
		TestGetResultColumn(2, 
			SQL_C_CHAR,        
			sizeof(SQLCHAR),   
			0,                 
			SQL_NULLABLE);     
	}
TEST_F ( PythonExtensionApiTests , GetStringResultColumnsTest ) { SQLUSMALLINT inputSchemaColumnsNumber = 3 ; InitializeSession ( 0 , inputSchemaColumnsNumber , m_scriptString ) ; string stringColumn1Name = " " ; InitializeColumn ( 0 , stringColumn1Name , SQL_C_CHAR , m_CharSize ) ; string stringColumn2Name = " " ; InitializeColumn ( 1 , stringColumn2Name , SQL_C_CHAR , m_CharSize ) ; string stringColumn3Name = " " ; InitializeColumn ( 2 , stringColumn3Name , SQL_C_CHAR , m_CharSize ) ; vector < const char * > stringCol1 { " " , " " , " " , " " , " " } ; vector < const char * > stringCol2 { " " , 0 , nullptr , " " , " " } ; vector < SQLINTEGER > strLenOrIndCol1 = { static_cast < SQLINTEGER > ( strlen ( stringCol1 [ 0 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol1 [ 1 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol1 [ 2 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol1 [ 3 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol1 [ 4 ] ) ) } ; vector < SQLINTEGER > strLenOrIndCol2 = { 0 , SQL_NULL_DATA , SQL_NULL_DATA , static_cast < SQLINTEGER > ( strlen ( stringCol2 [ 3 ] ) ) , static_cast < SQLINTEGER > ( strlen ( stringCol2 [ 4 ] ) ) } ; vector < SQLINTEGER * > strLen_or_Ind { strLenOrIndCol1 . data ( ) , strLenOrIndCol2 . data ( ) , nullptr } ; vector < char > stringCol1Data = GenerateContiguousData < char > ( stringCol1 , strLenOrIndCol1 . data ( ) ) ; vector < char > stringCol2Data = GenerateContiguousData < char > ( stringCol2 , strLenOrIndCol2 . data ( ) ) ; void * dataSet [ ] = { stringCol1Data . data ( ) , stringCol2Data . data ( ) , nullptr } ; int rowsNumber = stringCol1 . size ( ) ; vector < string > columnNames { stringColumn1Name , stringColumn2Name , stringColumn3Name } ; TestExecute < SQLCHAR , SQL_C_CHAR > ( rowsNumber , dataSet , strLen_or_Ind . data ( ) , columnNames , false ) ; SQLULEN maxCol1Len = GetMaxLength ( strLenOrIndCol1 . data ( ) , rowsNumber ) ; SQLULEN maxCol2Len = GetMaxLength ( strLenOrIndCol2 . data ( ) , rowsNumber ) ; TestGetResultColumn ( 0 , SQL_C_CHAR , maxCol1Len , 0 , SQL_NO_NULLS ) ; TestGetResultColumn ( 1 , SQL_C_CHAR , maxCol2Len , 0 , SQL_NULLABLE ) ; TestGetResultColumn ( 2 , SQL_C_CHAR , sizeof ( SQLCHAR ) , 0 , SQL_NULLABLE ) ; }
Name: GetStringResultColumnsTest
Description:
Test GetResultColumn with default script using an OutputDataSet of String columns.
Name : GetStringResultColumnsTest Description : Test GetResultColumn with default script using an OutputDataSet of String columns .
// Initialize with a default Session that prints Hello PythonExtension
 // and assigns InputDataSet to OutputDataSet
 //
 // parametersNumber
 // Coalesce the arrays of each row of each column
 // into a contiguous array for each column.
 //
 // validate
 // columnNumber
 // dataType
 // columnSize
 // decimalDigits
 // nullable
 // columnNumber
 // dataType
 // columnSize
 // decimalDigits
 // nullable
 // columnNumber
 // dataType
 // columnSize
 // decimalDigits
 // nullable
