language-extensions/python/test/src/PythonGetResultsTests.cpp
// Name: GetStringResultsTest
//
// Description:
//  Test GetResults with default script expecting an OutputDataSet of Character columns.
//
GetStringResultsTest
Description:
Test GetResults with default script expecting an OutputDataSet of Character columns.
GetStringResultsTest Description : Test GetResults with default script expecting an OutputDataSet of Character columns .
TEST_F(PythonExtensionApiTests, GetStringResultsTest)
	{
		SQLUSMALLINT inputSchemaColumnsNumber = 3;
		InitializeSession(0,  parametersNumber
			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);
		string goodUTF8 = string("a") + "\xE2" + "\x82" + "\xAC";
		vector<const char*> stringCol1{ "Hello", "test", "data", "World", "-123" };
		vector<const char*> stringCol2{ "", 0, nullptr, u8"абвг", goodUTF8.c_str() };
		int rowsNumber = stringCol1.size();
		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> strLenOrIndCol3(rowsNumber, SQL_NULL_DATA);
		vector<SQLINTEGER*> strLen_or_Ind{ strLenOrIndCol1.data(),
			strLenOrIndCol2.data(), strLenOrIndCol3.data() };
		 Coalesce the arrays of each row of each column
		 into a contiguous array for each column.
		vector<char> stringCol1Data =
			GenerateContiguousData<char>(stringCol1, strLenOrIndCol1.data());
		vector<char> stringCol2Data =
			GenerateContiguousData<char>(stringCol2, strLenOrIndCol2.data());
		void* dataSet[] = { stringCol1Data.data(),
							stringCol2Data.data(),
							nullptr };
		vector<string> columnNames{ stringColumn1Name, stringColumn2Name, stringColumn3Name };
		TestExecute<SQLCHAR, SQL_C_CHAR>(
			rowsNumber,
			dataSet,
			strLen_or_Ind.data(),
			columnNames,
			false);  validate
		TestGetStringResults(
			rowsNumber,
			dataSet,
			strLen_or_Ind.data(),
			columnNames);
	}
TEST_F ( PythonExtensionApiTests , GetStringResultsTest ) { 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 ) ; string goodUTF8 = string ( " " ) + " \xE2 " + " \x82 " + " \xAC " ; vector < const char * > stringCol1 { " " , " " , " " , " " , " " } ; vector < const char * > stringCol2 { " " , 0 , nullptr , u8" o o UTF8.c_s t r() } ; int rowsNumber = stringCol1 . size ( ) ; 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 > strLenOrIndCol3 ( rowsNumber , SQL_NULL_DATA ) ; vector < SQLINTEGER * > strLen_or_Ind { strLenOrIndCol1 . data ( ) , strLenOrIndCol2 . data ( ) , strLenOrIndCol3 . data ( ) } ; vector < char > stringCol1Data = GenerateContiguousData < char > ( stringCol1 , strLenOrIndCol1 . data ( ) ) ; vector < char > stringCol2Data = GenerateContiguousData < char > ( stringCol2 , strLenOrIndCol2 . data ( ) ) ; void * dataSet [ ] = { stringCol1Data . data ( ) , stringCol2Data . data ( ) , nullptr } ; vector < string > columnNames { stringColumn1Name , stringColumn2Name , stringColumn3Name } ; TestExecute < SQLCHAR , SQL_C_CHAR > ( rowsNumber , dataSet , strLen_or_Ind . data ( ) , columnNames , false ) ; TestGetStringResults ( rowsNumber , dataSet , strLen_or_Ind . data ( ) , columnNames ) ; }
Name: GetStringResultsTest
Description:
Test GetResults with default script expecting an OutputDataSet of Character columns.
Name : GetStringResultsTest Description : Test GetResults with default script expecting an OutputDataSet of Character 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