Good day,
I need to dynamically build a control file for a SQL loader but when tokenizing line values read from a file i am unable to work/assign the last value to a variable even though i can print the actual token value while in the loop.
Below is the code snippet i have and would appreciate all the help i can get:
Code:
//headElement declared as headElement[42]
//getCol function is used to decode column keys present in line being read
istringstream ss(line);
wfile << "LOAD DATA " << endl <<
"INFILE * " << endl <<
"APPEND INTO TABLE cdruser.x " << endl <<
"FIELDS TERMINATED BY ',' " << endl <<
"(" << endl;
while (getline(ss, token, ','))
{
//cout << arrayCountHeader << " " <<token<<endl;
headElement[arrayCountHeader] = getCol(token);
cout<<token<< " col " <<getCol(t1)<<endl;
if (arrayCountHeader == (sizeof(headElement) / sizeof(headElement[0])) - 1)
{
wfile << headElement[arrayCountHeader] <<",FILENAME) BEGINDATA " << endl;
wfile.close();
}
wfile.open("test.txt", std::ios_base::app | std::ios_base::out);
wfile << headElement[arrayCountHeader] << "," << endl;
wfile.close();
arrayCountHeader ++;
}
I've attached a sample file as well.
Regards,