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

GetWStringResultColumnsTest
Description:
Test GetResultColumn with default script using an OutputDataSet of wstring columns.
GetWStringResultColumnsTest Description : Test GetResultColumn with default script using an OutputDataSet of wstring columns .
TEST_F(PythonExtensionApiTests, GetWStringResultColumnsTest)
	{
		SQLUSMALLINT inputSchemaColumnsNumber = 3;
		InitializeSession(0, 
			inputSchemaColumnsNumber,
			m_scriptString);
		string wstringColumn1Name = "WstringColumn1";
		InitializeColumn(0, wstringColumn1Name, SQL_C_WCHAR, m_CharSize);
		string wstringColumn2Name = "WstringColumn2";
		InitializeColumn(1, wstringColumn2Name, SQL_C_WCHAR, m_CharSize);
		string wstringColumn3Name = "WstringColumn3";
		InitializeColumn(2, wstringColumn3Name, SQL_C_WCHAR, m_CharSize);
		vector<const wchar_t *> wstringCol1{ L"Hello", L"test", L"data", L"World", L"你" };
		vector<const wchar_t *> wstringCol2{ L"", 0, nullptr, L"verify", L"-1" };
		int rowsNumber = wstringCol1.size();
		vector<SQLINTEGER> strLenOrIndCol1 =
		{ static_cast<SQLINTEGER>(5 * sizeof(wchar_t)),
		  static_cast<SQLINTEGER>(4 * sizeof(wchar_t)),
		  static_cast<SQLINTEGER>(4 * sizeof(wchar_t)),
		  static_cast<SQLINTEGER>(5 * sizeof(wchar_t)),
		  static_cast<SQLINTEGER>(1 * sizeof(wchar_t)) };
		vector<SQLINTEGER> strLenOrIndCol2 =
		{ 0, SQL_NULL_DATA, SQL_NULL_DATA,
		  static_cast<SQLINTEGER>(6 * sizeof(wchar_t)),
		  static_cast<SQLINTEGER>(2 * sizeof(wchar_t)) };
		vector<SQLINTEGER> strLenOrIndCol3(rowsNumber, SQL_NULL_DATA);
		vector<SQLINTEGER *> strLen_or_Ind{ strLenOrIndCol1.data(),
			strLenOrIndCol2.data(), strLenOrIndCol3.data() };
		vector<wchar_t> wstringCol1Data =
			GenerateContiguousData<wchar_t>(wstringCol1, strLenOrIndCol1.data());
		vector<wchar_t> wstringCol2Data =
			GenerateContiguousData<wchar_t>(wstringCol2, strLenOrIndCol2.data());
		void *dataSet[] = { wstringCol1Data.data(),
							wstringCol2Data.data(),
							nullptr };
		vector<string> columnNames{ wstringColumn1Name, wstringColumn2Name, wstringColumn3Name };
		TestExecute<wchar_t, SQL_C_WCHAR>(
			rowsNumber,
			dataSet,
			strLen_or_Ind.data(),
			columnNames,
			false); 
		SQLULEN maxCol1Len = GetMaxLength(strLenOrIndCol1.data(), rowsNumber) / sizeof(wchar_t);
		SQLULEN maxCol2Len = GetMaxLength(strLenOrIndCol2.data(), rowsNumber) / sizeof(wchar_t);
		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 , GetWStringResultColumnsTest ) { SQLUSMALLINT inputSchemaColumnsNumber = 3 ; InitializeSession ( 0 , inputSchemaColumnsNumber , m_scriptString ) ; string wstringColumn1Name = " " ; InitializeColumn ( 0 , wstringColumn1Name , SQL_C_WCHAR , m_CharSize ) ; string wstringColumn2Name = " " ; InitializeColumn ( 1 , wstringColumn2Name , SQL_C_WCHAR , m_CharSize ) ; string wstringColumn3Name = " " ; InitializeColumn ( 2 , wstringColumn3Name , SQL_C_WCHAR , m_CharSize ) ; vector < const wchar_t * > wstringCol1 { L" " , L" " , L" " , L" " , L" } vector < const wchar_t * > wstringCol2 { L" " , 0 , nullptr , L" " , L" " } ; int rowsNumber = wstringCol1 . size ( ) ; vector < SQLINTEGER > strLenOrIndCol1 = { static_cast < SQLINTEGER > ( 5 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 4 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 4 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 5 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 1 * sizeof ( wchar_t ) ) } ; vector < SQLINTEGER > strLenOrIndCol2 = { 0 , SQL_NULL_DATA , SQL_NULL_DATA , static_cast < SQLINTEGER > ( 6 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 2 * sizeof ( wchar_t ) ) } ; vector < SQLINTEGER > strLenOrIndCol3 ( rowsNumber , SQL_NULL_DATA ) ; vector < SQLINTEGER * > strLen_or_Ind { strLenOrIndCol1 . data ( ) , strLenOrIndCol2 . data ( ) , strLenOrIndCol3 . data ( ) } ; vector < wchar_t > wstringCol1Data = GenerateContiguousData < wchar_t > ( wstringCol1 , strLenOrIndCol1 . data ( ) ) ; vector < wchar_t > wstringCol2Data = GenerateContiguousData < wchar_t > ( wstringCol2 , strLenOrIndCol2 . data ( ) ) ; void * dataSet [ ] = { wstringCol1Data . data ( ) , wstringCol2Data . data ( ) , nullptr } ; vector < string > columnNames { wstringColumn1Name , wstringColumn2Name , wstringColumn3Name } ; TestExecute < wchar_t , SQL_C_WCHAR > ( rowsNumber , dataSet , strLen_or_Ind . data ( ) , columnNames , false ) ; SQLULEN maxCol1Len = GetMaxLength ( strLenOrIndCol1 . data ( ) , rowsNumber ) / sizeof ( wchar_t ) ; SQLULEN maxCol2Len = GetMaxLength ( strLenOrIndCol2 . data ( ) , rowsNumber ) / sizeof ( wchar_t ) ; 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: GetWStringResultColumnsTest
Description:
Test GetResultColumn with default script using an OutputDataSet of wstring columns.
Name : GetWStringResultColumnsTest Description : Test GetResultColumn with default script using an OutputDataSet of wstring 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
 // Because Python is UTF-8, we always return UTF-8 strings. 
 // Thus, we expect output result columns to be strings, not wstrings, so we need to resize
 // our expected column size by dividing by the sizeof(wchar_t).
 //
 // columnNumber
 // expectedDataType
 // expectedColumnSize
 // expectedDecimalDigits
 // expectedNullable
 // columnNumber
 // expectedDataType
 // expectedColumnSize
 // expectedDecimalDigits
 // expectedNullable
 // columnNumber
 // expectedDataType
 // expectedColumnSize
 // expectedDecimalDigits
 // expectedNullable
