Usage of GetRow method in TPT API for exporting table data into csv

Tools & Utilities
Enthusiast

Usage of GetRow method in TPT API for exporting table data into csv

Hi
By using Getrow method to export data into a file, resulted in no data in the csv file even though ther is data in the table.
Is there any issue in the format that has to be mentioned while exporting into csv from table data?
Documentation says that getrow and putrow supports indicator mode of format is this the cause for empty file?
Is there any other alternative.
Please find the TPT code below:

int WriteRowData(ofstream& myfile ,char* data, int dataLen)

{

if(dataLen == 0 && data == NULL)

{

myfile<<"Error occurred while processing";

output = -1;

if(myfile.is_open())

{

myfile.close();

}

}

else {

myfile<
}

return output;

}

int main()

{

try

{

int returnValue = 0;

char* errorMsg = NULL;

time_t now, old;

double seconds;

TD_ErrorType errorType;

time(&now);

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

Connection *conn = new Connection();

/**********************************************

* Add Attributes

**********************************************/

/**********************************************

* Add Schema

**********************************************/

/**********************************************

* Initiate

**********************************************/

returnValue = conn->Initiate();

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

/**********************************************

* Acquisition

**********************************************/

int count = 0;

char* data;

int fileRet = 0;

TD_Length dataLen = 0;

int exportStatus = 0;

ofstream myfile;

myfile.open ("output_data.csv"); // Give full path of the file
if(!myfile.is_open())
{
delete schema;
delete conn;
cout << "Error opening file" << endl;
} else {

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(myfile,NULL,0); //user function - close file
//returns -1 when closed
} else if ( returnValue == TD_END_Method ){
cout << "End of Data Reached" << endl;
exportStatus = WriteRowData(myfile,NULL,0); //user function - close file
//returns -1 when closed
count++;
} else {
exportStatus = WriteRowData(myfile,data,dataLen);// user function – writes
// data to external file
// returns 0 if successfull
count++;
}
}

/**********************************************

* Terminate

**********************************************/

/**********************************************

* Clean Up

**********************************************/

Thanks in advance
2 REPLIES
Teradata Employee

Re: Usage of GetRow method in TPT API for exporting table data into csv

TPTAPI does not write out to a file. That is up to your application.

Thus, if your file is empty, you will have to debug your application.

The data that will be provided from a call to GetRow is in binary format.

If you want to write the data out in csv form, you will have to convert the data to character and add the delimiter.

The data is provided in indicator mode and so you will also need to process the indicator bytes so that you know which fields need to be NULLed.

You may want to add some diagnostics to output the data length after the call to GetRow to make sure you are actually getting data.

-- SteveF
Enthusiast

Re: Usage of GetRow method in TPT API for exporting table data into csv

Thanks Steve for your valuable information!