What's wrong with my code?????

SteveoAtilla

Regular
Joined
Dec 22, 2004
Messages
80
Location
The Frozen Tundra
Hey,

I am in need of help. I have an applet that processes an XML file to do transfer it to a SQL database. It needs to analyze the records to see if they are already in the DB, and do an INSERT or UPDATE.

Here is the code that is trying to process the results of a SELECT query to pull a Primary Key field from the DB:

Code:
// fetch
    CString machineMasterPK;
    rc = g_sqlMgr.Fetch();
    if (SQL_SUCCEEDED(rc)) {
        LPCTSTR fieldname = SQL_MACHINE_MASTER_PK;
        if (*fieldname == _T('~')) ++fieldname;

        // loop to get the last one (just in case of the same MachineMaster data
        // was entered more than once).
        do {
            machineMasterPK = g_sqlMgr.GetCol(SQL_MACHINE_MASTER_PK, _T(""));
            cout << "Loop Field Value: " << machineMasterPK << endl;
        } while ( SQL_SUCCEEDED( rc=g_sqlMgr.Fetch() ));
        cout << "Fieldname value: " << fieldname << endl;
        cout << "MachineMasterPK: " << machineMasterPK << endl;
What I get back is "@", but if I run the SELECT query that is being submitted and (apparently) executed successfully, I get a fully-populated record back.

Here is a part of the appropirate .h file:

Code:
// MachineMaster
#define    SQL_MACHINE_MASTER_PK            _T("~MachineMasterPK")
#define    SQL_PRODUCTION_ORDER_NUMBER        _T("~ProductionOrderNumber")
#define    SQL_SALES_ORDER_NUMBER            _T("SalesOrderNumber")
#define    SQL_SALES_ORDER_ITEM            _T("SalesOrderItem")
#define    SQL_SALES_ORDER_MATERIAL        _T("SalesOrderMaterial")
#define    SQL_MATERIAL_DESCRIPTION        _T("MaterialDescription")
#define    SQL_CUSTOMER_NUMBER                _T("CustomerNumber")
#define    SQL_CUSTOMER_NAME                _T("CustomerName")
C++ is not my primary language, so I'm at a bit of a loss. I'm maintaining an app that I inherited.

HELP!!!
 
Well, I figured out what was going on.

I replaced
Code:
machineMasterPK = g_sqlMgr.GetCol(SQL_MACHINE_MASTER_PK, _T(""));
with

Code:
machineMasterPK = g_sqlMgr.GetCol("MachineMasterPK", _T(""));
and it worked great. And if I were to put in

Code:
machineMasterPK = g_sqlMgr.GetCol(fieldname, _T(""));
I bet it would still work.

Thanks for the views.

Kahuna
 
Back
Top