language-extensions/R/test/src/RExtensionExecuteTests.cpp
//----------------------------------------------------------------------------------------------
// Name: ExecuteCharColumnsTest
//
// Description:
//  Tests Execute with default script using an InputDataSet of Character columns.
//
ExecuteCharColumnsTest
Description:
Tests Execute with default script using an InputDataSet of Character columns.
ExecuteCharColumnsTest Description : Tests Execute with default script using an InputDataSet of Character columns .
TEST_F(RExtensionApiTests, ExecuteCharColumnsTest)
	{
		SQLUSMALLINT inputSchemaColumnsNumber = 3;
		InitializeSession(inputSchemaColumnsNumber, m_scriptString);
		string charColumn1Name = "CharColumn1";
		InitializeColumn(0,  columnNumber
			charColumn1Name,
			SQL_C_CHAR,
			m_CharSize,
			0,               decimalDigits
			SQL_NO_NULLS);
		string charColumn2Name = "CharColumn2";
		InitializeColumn(1,  columnNumber
			charColumn2Name,
			SQL_C_CHAR,
			m_CharSize,
			0,               decimalDigits
			SQL_NULLABLE);
		string charColumn3Name = "CharColumn3";
		InitializeColumn(2,  columnNumber
			charColumn3Name,
			SQL_C_CHAR,
			m_CharSize,
			0,               decimalDigits
			SQL_NULLABLE);
		SQLULEN rowsNumber = 5;
		vector<const char*> charCol1{ "Hello", "test", "data", "RExtension", "-123" };
		vector<const char*> charCol2{ "", 0, nullptr, "verify", "-1" };
		vector<SQLINTEGER> strLenOrIndCol1=
			{ static_cast<SQLINTEGER>(strlen(charCol1[0])),
			  static_cast<SQLINTEGER>(strlen(charCol1[1])),
			  static_cast<SQLINTEGER>(strlen(charCol1[2])),
			  static_cast<SQLINTEGER>(strlen(charCol1[3])),
			  static_cast<SQLINTEGER>(strlen(charCol1[4])) };
		vector<SQLINTEGER> strLenOrIndCol2 =
			{ 0, SQL_NULL_DATA, SQL_NULL_DATA,
			  static_cast<SQLINTEGER>(strlen(charCol2[3])),
			  static_cast<SQLINTEGER>(strlen(charCol2[4])) };
		vector<SQLINTEGER*> strLen_or_Ind{ strLenOrIndCol1.data(), strLenOrIndCol2.data(), nullptr };
		 Coalesce the arrays of each row of each column
		 into a contiguous array for each column.
		vector<char> charCol1Data = GenerateContiguousData<char>(charCol1, strLenOrIndCol1.data());
		vector<char> charCol2Data = GenerateContiguousData<char>(charCol2, strLenOrIndCol2.data());
		void* dataSet[inputSchemaColumnsNumber] = { charCol1Data.data(), charCol2Data.data(), nullptr};
		vector<string> columnNames{charColumn1Name, charColumn2Name, charColumn3Name};
		ExecuteChar<char>(
			rowsNumber,
			dataSet,
			strLen_or_Ind.data(),
			columnNames);
	}
TEST_F ( RExtensionApiTests , ExecuteCharColumnsTest ) { SQLUSMALLINT inputSchemaColumnsNumber = 3 ; InitializeSession ( inputSchemaColumnsNumber , m_scriptString ) ; string charColumn1Name = " " ; InitializeColumn ( 0 , charColumn1Name , SQL_C_CHAR , m_CharSize , 0 , SQL_NO_NULLS ) ; string charColumn2Name = " " ; InitializeColumn ( 1 , charColumn2Name , SQL_C_CHAR , m_CharSize , 0 , SQL_NULLABLE ) ; string charColumn3Name = " " ; InitializeColumn ( 2 , charColumn3Name , SQL_C_CHAR , m_CharSize , 0 , SQL_NULLABLE ) ; SQLULEN rowsNumber = 5 ; vector < const char * > charCol1 { " " , " " , " " , " " , " " } ; vector < const char * > charCol2 { " " , 0 , nullptr , " " , " " } ; vector < SQLINTEGER > strLenOrIndCol1 = { static_cast < SQLINTEGER > ( strlen ( charCol1 [ 0 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol1 [ 1 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol1 [ 2 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol1 [ 3 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol1 [ 4 ] ) ) } ; vector < SQLINTEGER > strLenOrIndCol2 = { 0 , SQL_NULL_DATA , SQL_NULL_DATA , static_cast < SQLINTEGER > ( strlen ( charCol2 [ 3 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol2 [ 4 ] ) ) } ; vector < SQLINTEGER * > strLen_or_Ind { strLenOrIndCol1 . data ( ) , strLenOrIndCol2 . data ( ) , nullptr } ; vector < char > charCol1Data = GenerateContiguousData < char > ( charCol1 , strLenOrIndCol1 . data ( ) ) ; vector < char > charCol2Data = GenerateContiguousData < char > ( charCol2 , strLenOrIndCol2 . data ( ) ) ; void * dataSet [ inputSchemaColumnsNumber ] = { charCol1Data . data ( ) , charCol2Data . data ( ) , nullptr } ; vector < string > columnNames { charColumn1Name , charColumn2Name , charColumn3Name } ; ExecuteChar < char > ( rowsNumber , dataSet , strLen_or_Ind . data ( ) , columnNames ) ; }
Name: ExecuteCharColumnsTest
Description:
Tests Execute with default script using an InputDataSet of Character columns.
Name : ExecuteCharColumnsTest Description : Tests Execute with default script using an InputDataSet of Character columns .
// Initialize with a default Session that prints Hello RExtension // and assigns InputDataSet to OutputDataSet // // columnNumber // decimalDigits // columnNumber // decimalDigits // columnNumber // decimalDigits // Coalesce the arrays of each row of each column // into a contiguous array for each column. //