I'm working with a C++ application that produces a file based on a database query using the RogueWave Tools. The compiler is Visual Studio C++ 6.0. Once the user chooses a "batch", the code runs the CreateFile method below, which runs a query, loading the selected rows from the database table into a vector, which is then loaded into a RogueWave type RWTPtrOrderedVector<RWCString>, which is then printed to the file.
The problem is, field "addr2" in the produced file is sometimes duplicating a previous record's value (usually a the one from 10 records previous, but sometimes 20 records previous). The database query reveals there are no duplicate values in the addr2 field for the batch, so I'm assuming the problem must be in the C++ app. For example...
rownum order addr addr2
------ ----- ---- ----
1 1001 100 Apple St. Suite 4
2 1002 546 Plum Ave.
3 1003 224 Peach Ln. Suite B
4 1004 471 Grape St.
...
13 1013 334 Banana Ct. Suite B (duplicate - should be emply value here)
This problem doesn't appear to be consistent, e.g. doesn't always happen every 10 records, and sometimes doesn't happen at all. I'm wondering if this could be a buffer issue of some sort.
Thanks for any help and/or insight on this!
Code:
// MAIN ROUTINE
CError* CreateFile(const CBatch& aBatch)
{
CError *error = NULL;
int ord_cnt=0;
RWTPtrOrderedVector<COrders> order_vector;
COrd order_ctlr(*m_Db);
ord_cnt = order_ctlr.OrdsForClient(
aBatch.ClientCode(),
aBatch.BatchNumber(),
order_vector,
*m_Connection);
// LOAD EACH VECTOR RECORD INTO m_Holder, WHICH
// IS OF TYPE RWTPtrOrderedVector<RWCString>
for (int i=0; i<ord_cnt; i++)
{
MakeFile(*order_vector[i]);
}
char filename[200];
m_FormFilenameForShippingFile('myfile', aBatch);
error = WriteFile(filename, m_Holder);
m_Holder.clearAndDestroy();
return error;
}
// RUN DB QUERY AND LOAD ROWS INTO VECTOR
int COrd::OrdsForClient (
int client_code,
const RWCString& batch_number,
OrderVector& vec,
const RWDBConnection& aConn)
{
RWCString sBatchNumber = batch_number;
RWDBSelector aSelector = m_Db.selector();
RWDBTable ship_table = m_Db.table("ship_table");
aSelector << m_Table;
aSelector.where (
m_ClientCodeColumn == RWDBBoundExpr(&client_code)
&& m_BatchNumberColumn == RWDBBoundExpr(&sBatchNumber)
&& m_ShippingMethodColumn == ship_table["ship_method"]
);
aSelector.orderBy (shipping_table["priority"]);
aSelector.orderBy (m_StatusCodeColumn);
aSelector.orderBy (m_OrderNumberColumn);
RWDBReader aReader = aSelector.reader(aConn);
while (aReader())
{
COrders *aOrder = new COrders();
aReader >> *aOrder;
vec.insert(aOrder);
}
return vec.entries();
}
//ASSIGN - APPEND FORMATED ROWS TO THE m_Holder vector
// of type RWTPtrOrderedVector<RWCString>
void MakeFile(const COrders& aOrder)
{
char string[500];
sprintf(
string,
"%-11.11s%-10.10s%-44.44s%-35.35s%-35.35s%-35.35s%-30.30s%2.2s%5.5s-%-53.53s%-10.10s%-6.6s",
aOrder.BatchNumber(),
aOrder.OrderNumber(),
aOrder.ShiptoName(),
aOrder.ShiptoCompany(),
aOrder.ShiptoAddress1(),
aOrder.ShiptoAddress2(),
aOrder.ShiptoCity(),
aOrder.ShiptoState(),
aOrder.ShiptoZip5(),
"",
aOrder.ShiptoPhone()
);
m_Holder.append( new RWCString(string) );
}
// Write each line from the Vector to the file
CError* WriteFile(const char *pFileName, const RWTPtrOrderedVector<RWCString>& stringVector)
{
CError *err = NULL;
TRY
{
CStdioFile f( pFileName, CFile::modeCreate | CFile::modeWrite);
CString s;
for (int i = 0; i < (int)stringVector.length(); i++)
{
s.Format("%s\n",*stringVector[i]);
f.WriteString( (const char *)s );
}
s = "OK!\tFile: ";
s += pFileName;
// AfxMessageBox(s);
}
CATCH( CFileException, e )
{
// EXCEPTION CODE HERE
}
END_CATCH
return err;
}