17.00 - Code Example - Parallel Transporter

Teradata® Parallel Transporter Application Programming Interface Programmer Guide

prodname
Parallel Transporter
vrm_release
17.00
created_date
June 2020
category
Programming Reference
featnum
B035-2516-220K
#include "connection.h"
#include "schema.h"
#include "DMLGroup.h"

using namespace teradata::client::API;

int returnValue = 0;
char* errorMsg = NULL;
TD_ErrorType errorType;

cout << "*** Export Driver Example ***" << endl;

Connection *conn = new Connection();
/**********************************************
* Set Operator Type and Trace/Log Levels
**********************************************/
conn->AddAttribute(TD_SYSTEM_OPERATOR,TD_EXPORT);
//conn->AddAttribute(TD_TRACE_OUTPUT,"export.txt");
//conn->AddArrayAttribute(TD_TRACE_LEVEL,2,TD_OPER_ALL,TD_OFF,NULL);
/**********************************************
* Add Attributes
**********************************************/
conn->AddAttribute(TD_USER_NAME,"user");
conn->AddAttribute(TD_USER_PASSWORD,"password");
conn->AddAttribute(TD_SELECT_STMT,"sel Associate_Name from tdload;");
conn->AddAttribute(TD_TARGET_TABLE,"tdload");
conn->AddAttribute(TD_TDP_ID,"database");
/**********************************************
* Add Schema
**********************************************/
Schema * schema = new Schema("output");
schema->AddColumn("Associate_Name",TD_CHAR,25);
conn->AddSchema(schema);
/**********************************************
* Initiate
**********************************************/
returnValue = conn->Initiate();

cout << "Driver Initiated with status " << returnValue << endl;

if ( returnValue < TD_Error )
{
    /**********************************************
	* Acquisition
	**********************************************/
	int count = 0;
	char* data;
	TD_Length dataLen = 0;
	int exportStatus = 0;

	while( exportStatus != -1){

		returnValue = conn->GetRow(&data, &dataLen);

		if ( returnValue >= TD_Error )
		{
			cout << "GetRow failed on row " << count+1;
	cout << " with status " << returnValue << endl;
			exportStatus = WriteRowData(NULL,0); //user function - close file
							     			  //returns -1 when closed
		}else if ( returnValue == TD_END_Method ){
			cout << "End of Data Reached" << endl;
			exportStatus = WriteRowData(NULL,0); //user function - close file
							     			  //returns -1 when closed
			count++;
		}else{
			exportStatus = WriteRowData(data,dataLen);// user function – writes
											  // data to external file
								   		    // returns 0 if successful
			count++;
		}

	}

	cout << "Export completed with status " << returnValue << endl;

	if ( returnValue < TD_Error )
	{
		cout << "Export completed successfully" << endl;

	}else{
		//Get Error Information
		cout << "Error occured during Export" << endl;
		conn->GetErrorInfo(&errorMsg,&errorType);
		if ( errorMsg != NULL ){
			cout << errorMsg << endl;
			cout << "Type: " << errorType << endl;
		}else{
			cout << "No Error Info Available" << endl;
		}
	}
}else{
	//Get Error Information
	cout << "Error occured during Initiate" << endl;
	conn->GetErrorInfo(&errorMsg,&errorType);
	if ( errorMsg != NULL ){
		cout << errorMsg << endl;
		cout << "Type: " << errorType << endl;
	}else{
		cout << "No Error Info Available" << endl;
	}
}
/**********************************************
* Terminate
**********************************************/

returnValue = conn->Terminate();

cout << "Driver Terminated with status " << returnValue << endl;

if ( returnValue >= TD_Error )
{
	//Get Error Information
	cout << "Error occured during Terminate" << endl;
	conn->GetErrorInfo(&errorMsg,&errorType);
	if ( errorMsg != NULL ){
		cout << errorMsg << endl;
		cout << "Type: " << errorType << endl;
	}else{
		cout << "No Error Info Available" << endl;
	}
}
/**********************************************
* Clean Up
**********************************************/

cout << "Deleting Objects" << endl;
delete schema;
delete conn;

cout << "*** Export Complete ***" << endl;