language-extensions/R/test/src/RExtensionExecuteTests.cpp
//----------------------------------------------------------------------------------------------
// Name: ExecuteNCharColumnsTest
//
// Description:
//  Tests Execute with default script using an InputDataSet of NCHAR/NVARCHAR columns.
//
ExecuteNCharColumnsTest
Description:
Tests Execute with default script using an InputDataSet of NCHAR/NVARCHAR columns.
ExecuteNCharColumnsTest Description : Tests Execute with default script using an InputDataSet of NCHAR / NVARCHAR columns .
TEST_F(RExtensionApiTests, ExecuteNCharColumnsTest)
	{
		SQLUSMALLINT inputSchemaColumnsNumber = 3;
		InitializeSession(
			inputSchemaColumnsNumber,
			m_scriptString);
		string ncharColumn1Name = "NCharColumn1";
		InitializeColumn(0,  columnNumber
			ncharColumn1Name,
			SQL_C_WCHAR,
			m_NCharSize,
			0,               decimalDigits
			SQL_NO_NULLS);
		string ncharColumn2Name = "NCharColumn2";
		InitializeColumn(1,  columnNumber
			ncharColumn2Name,
			SQL_C_WCHAR,
			m_NCharSize,
			0,               decimalDigits
			SQL_NULLABLE);
		string ncharColumn3Name = "NCharColumn3";
		InitializeColumn(2,  columnNumber
			ncharColumn3Name,
			SQL_C_WCHAR,
			m_NCharSize,
			0,               decimalDigits
			SQL_NULLABLE);
		vector<const wchar_t *> ncharCol1{ L"Hello", L"test", L"data", L"World你好", L"你好" };
		vector<const wchar_t *> ncharCol2{ L"", 0, nullptr, L"verify", L"-1" };
		int rowsNumber = ncharCol1.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>(7 * sizeof(wchar_t)),
		  static_cast<SQLINTEGER>(2 * 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() };
		 Coalesce the arrays of each row of each column
		 into a contiguous array for each column.
		vector<wchar_t> ncharCol1Data =
			GenerateContiguousData<wchar_t>(ncharCol1, strLenOrIndCol1.data());
		vector<wchar_t> ncharCol2Data =
			GenerateContiguousData<wchar_t>(ncharCol2, strLenOrIndCol2.data());
		void *dataSet[] = { ncharCol1Data.data(),
							ncharCol2Data.data(),
							nullptr };
		vector<string> columnNames{ ncharColumn1Name, ncharColumn2Name, ncharColumn3Name };
		ExecuteChar<wchar_t>(
			rowsNumber,
			dataSet,
			strLen_or_Ind.data(),
			columnNames);
	}
TEST_F ( RExtensionApiTests , ExecuteNCharColumnsTest ) { SQLUSMALLINT inputSchemaColumnsNumber = 3 ; InitializeSession ( inputSchemaColumnsNumber , m_scriptString ) ; string ncharColumn1Name = " " ; InitializeColumn ( 0 , ncharColumn1Name , SQL_C_WCHAR , m_NCharSize , 0 , SQL_NO_NULLS ) ; string ncharColumn2Name = " " ; InitializeColumn ( 1 , ncharColumn2Name , SQL_C_WCHAR , m_NCharSize , 0 , SQL_NULLABLE ) ; string ncharColumn3Name = " " ; InitializeColumn ( 2 , ncharColumn3Name , SQL_C_WCHAR , m_NCharSize , 0 , SQL_NULLABLE ) ; vector < const wchar_t * > ncharCol1 { L" " , L" " , L" " , L" " 你 "  vector < const wchar_t * > ncharCol2 { L" " , 0 , nullptr , L" " , L" " } ; int rowsNumber = ncharCol1 . 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 > ( 7 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 2 * 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 > ncharCol1Data = GenerateContiguousData < wchar_t > ( ncharCol1 , strLenOrIndCol1 . data ( ) ) ; vector < wchar_t > ncharCol2Data = GenerateContiguousData < wchar_t > ( ncharCol2 , strLenOrIndCol2 . data ( ) ) ; void * dataSet [ ] = { ncharCol1Data . data ( ) , ncharCol2Data . data ( ) , nullptr } ; vector < string > columnNames { ncharColumn1Name , ncharColumn2Name , ncharColumn3Name } ; ExecuteChar < wchar_t > ( rowsNumber , dataSet , strLen_or_Ind . data ( ) , columnNames ) ; }
Name: ExecuteNCharColumnsTest
Description:
Tests Execute with default script using an InputDataSet of NCHAR/NVARCHAR columns.
Name : ExecuteNCharColumnsTest Description : Tests Execute with default script using an InputDataSet of NCHAR / NVARCHAR 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. //