First off I am new to C++ and I am trying to learn it to update one of my companies legacy apps. Which is on windows xp and visual c++ 6.0 which is not fun.. any ways I have this select statement that reads my database and searches for a ResourceID like what ever I set my m_operSet. I want to be able to use 4 specific variables in this like statement. problem is when I set it to a specific one it will not find any other resources besides what I set it to. here is my code this is my operations.Set.cpp and my bordDlg.cpp.
This is my list of variables I wish to use for the m_operSet
'COB'
'NIC'
'SIC'
'PRS'
Basically I want to use a if else statement.. say if COB use COB ifelse NIC use NIC ifelse SIC use SIC IFelse PRS use PRS
BordDlg.cpp
// BordDlg.cpp : implementation file
#include "operationSet.h"
#include "custSet.h"
// Initial filter is set in m_custSet Constuctor
m_custSet.setBaseID(baseID);
m_custSet.setLotID(lotID);
// Initial filter is set in m_operSet Constuctor
m_operSet.setBaseID(baseID);
m_operSet.setLotID(lotID);
m_operSet.setSubID(subID);
m_operSet.setSplitID(splitID);
// This is where I set this at and where I want to use either 'COB' 'NIC' 'SIC' 'PRS'
m_operSet.setResourceID("COB");
operationSet.cpp
// operationSet.cpp : implementation file
//
#include "stdafx.h"
#include "operationSet.h"
void operationSet::setBaseID(CString baseID)
{
m_strFilter += "and WORKORDER_BASE_ID LIKE '" + baseID + " ";
}
void operationSet::setLotID(CString lotID)
{
m_strFilter += "and WORKORDER_LOT_ID LIKE '" + lotID + "' ";
}
void operationSet::setSplitID(CString splitID)
{
m_strFilter += "and [WORKORDER_SPLIT_ID] LIKE '" + splitID + "' ";
}
void operationSet::setSubID(CString subID)
{
m_strFilter += "and [WORKORDER_SUB_ID] LIKE '" + subID + "' ";
}
void operationSet::setResourceID(CString resID)
{
m_strFilter += "and [RESOURCE_ID] LIKE '" + resID + "' ";
}
Those functions build a query string like this:
you need to build this:
the quick fix (not recommended) is:
and
This way you end up with some kind of monster where apostrophes are added without consistency both on caller and on called function.
A better way:
things you need to check if your application framework:
CString
andstd::string
. Most likely they didn't write anoperator +
for them. So you have 2 options: use.c_str()
if they have anoperator +
forCString
andc strings
, or just usestd::vector<CString>
The code is written in
c++11
. See if your compiler supportsc++11
. If not you need to replaceauto
withstd::vector<std::string>::const_iterator
and the call with:
CString
also). So you really need to compile withc++11
and use move semantics. There are resources on the net for moving inc++11