eis/src/dbax/T_CYC_EXTSEG095DBAX.cpp

520 lines
13 KiB
C++

// Version: 2015.8.8 15:13:13
// File: T_CYC_EXTSEG095DBAX.cpp
#include <log4cplus/LOG.h>
#include "T_CYC_EXTSEG095DBAX.h"
#include "T_CYC_EXTSEG095.h"
#define NORECORD 100
using namespace log4cplus;
extern iDA::Connection cn;
extern char sqlErrMsg[4000];
#define DB_EXECUTE() try{ cmd.SetConnection( &cn);cmd.Execute();}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;}
#define DB_UPDEXECUTE() try{updatecmd.SetConnection( &cn);updatecmd.Execute();}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;}
#define DB_RDEXECUTE() try{readcmd.SetConnection( &cn);readcmd.Execute();}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;}
#define DB_INSEXECUTE() try{insertcmd.SetConnection( &cn);insertcmd.Execute();}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;}
#define DB_FETCH() try{ if( !readcmd.FetchNext()){ dbSqlCode = NORECORD;strcpy( sqlErrMsg, "No record found");return sqlErrMsg;}}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;}
#define DB_UPDAFFECTED() if( updatecmd.RowsAffected() <= 0){ strcpy( sqlErrMsg, "No record affected");return sqlErrMsg;}
//
// Declare DB Hostvariables
//
#define OPENED 1
#define CLOSED 2
/* ****************************************************************************** */
/* */
/* define DB */
/* Hostvariables */
/* */
/* ****************************************************************************** */
static long db_muId;// Material idendification number
static char db_muCreator[3];// Material owner
static short db_musId;// Line status
static long db_SeqNo;
static char db_EnCoilId[21+1];
static short db_EnCoilIdZi;
static char db_ExCoilId[21+1];
static short db_ExCoilIdZi;
static double db_DLPTension;
static short db_DLPTensionZi;
static char db_TC[27];
static short db_TCZi;
static long rowCnt;
// Host arguments for Primary key
static long k_db_muId;// Material idendification number
static char k_db_muCreator[3];// Material owner
static short k_db_musId;// Line status
static long k_db_SeqNo;
//
// constructor
//
T_CYC_EXTSEG095DBAX::T_CYC_EXTSEG095DBAX()
{
}
//
// destructor
//
T_CYC_EXTSEG095DBAX::~T_CYC_EXTSEG095DBAX()
{
}
char* T_CYC_EXTSEG095DBAX::execute(const char* sql , long* count ){
dbSqlCode = 0;
cmd.SetCommandText( sql);
DB_EXECUTE();
if( count != NULL)
{
*count = cmd.RowsAffected();
}
return ( NULL );
}
char* T_CYC_EXTSEG095DBAX::dbCommit(){
dbSqlCode = 0;
try{
cn.Commit();
}catch( iDA::Exception &e)
{
dbSqlCode = -1;
strcpy( sqlErrMsg,e.ErrMsg().c_str());
return sqlErrMsg;
}
return ( NULL );
}
char* T_CYC_EXTSEG095DBAX::dbRollback(){
dbSqlCode = 0;
try{
cn.Rollback();
}catch( iDA::Exception &e)
{
dbSqlCode = -1;
strcpy( sqlErrMsg,e.ErrMsg().c_str());
return sqlErrMsg;
}
return ( NULL );
}
//
// private methode copyDB2Attribute
//
void T_CYC_EXTSEG095DBAX::copyDB2Attribute( T_CYC_EXTSEG095 &dbObj ){
dbObj.set_muId((long)db_muId );
dbObj.set_muCreator( (char*)db_muCreator);
dbObj.set_musId((short)db_musId );
dbObj.set_SeqNo((long)db_SeqNo);
dbObj.set_EnCoilId((char*)db_EnCoilId);
dbObj.set_EnCoilIdZi((short)db_EnCoilIdZi);
dbObj.set_ExCoilId((char*)db_ExCoilId);
dbObj.set_ExCoilIdZi((short)db_ExCoilIdZi);
dbObj.set_DLPTension((double)db_DLPTension);
dbObj.set_DLPTensionZi((short)db_DLPTensionZi);
dbObj.set_TC((char*)db_TC);
dbObj.set_TCZi((short)db_TCZi);
} // end of methode
//
// private methode copyAttribute2DB
//
void T_CYC_EXTSEG095DBAX::copyAttribute2DB( T_CYC_EXTSEG095 &dbObj ){
db_muId = dbObj.muId();
if(strlen(dbObj.muCreator()) < sizeof(db_muCreator)){
strncpy ((char*)db_muCreator , dbObj.muCreator() ,sizeof(db_muCreator));
}
db_musId = dbObj.musId();
db_SeqNo = dbObj.SeqNo();
if (strlen(dbObj.EnCoilId()) < sizeof(db_EnCoilId)){
strncpy ((char*)db_EnCoilId, dbObj.EnCoilId(), sizeof(db_EnCoilId));
}
db_EnCoilIdZi = dbObj.EnCoilIdZi();
if (strlen(dbObj.ExCoilId()) < sizeof(db_ExCoilId)){
strncpy ((char*)db_ExCoilId, dbObj.ExCoilId(), sizeof(db_ExCoilId));
}
db_ExCoilIdZi = dbObj.ExCoilIdZi();
db_DLPTension = dbObj.DLPTension();
db_DLPTensionZi = dbObj.DLPTensionZi();
if (strlen(dbObj.TC()) < sizeof(db_TC)){
strncpy ((char*)db_TC, dbObj.TC(), sizeof(db_TC));
}
db_TCZi = dbObj.TCZi();
} // end of methode
//
// private methode copyKey2Host
//
void T_CYC_EXTSEG095DBAX::copyKey2Host( T_CYC_EXTSEG095 &dbObj ){
k_db_muId = dbObj.k_muId();
if (strlen(dbObj.k_muCreator()) < sizeof(k_db_muCreator)){
strncpy ((char*)k_db_muCreator , dbObj.k_muCreator() ,sizeof(k_db_muCreator));
}
k_db_musId = dbObj.k_musId();
k_db_SeqNo = dbObj.k_SeqNo();
} // end of methode
//
// private methode copyHost2Key
//
void T_CYC_EXTSEG095DBAX::copyHost2Key( T_CYC_EXTSEG095 &dbObj ){
dbObj.set_k_muId((long)db_muId);
dbObj.set_k_muCreator((char*)db_muCreator);
dbObj.set_k_musId((short)db_musId);
dbObj.set_k_SeqNo((long)db_SeqNo);
} // end of methode
//
// public methode readDB
//
char* T_CYC_EXTSEG095DBAX::readDB(T_CYC_EXTSEG095 &dbObj ){
copyKey2Host( dbObj );
ostringstream ostr;
dbSqlCode = 0;
ostr << "SELECT ";
// all columns
ostr << "muId";
ostr << ",muCreator";
ostr << ",musId";
ostr << ",SeqNo";
ostr << ",EnCoilId";
ostr << ",ExCoilId";
ostr << ",DLPTension";
ostr << ",TO_CHAR(TC, 'YYYYMMDDHH24MISS')";
ostr << " FROM T_CYC_EXTSEG095 WHERE ";
// where
ostr << "muId = " << k_db_muId;
ostr << " AND muCreator = '" << k_db_muCreator << "'";
ostr << " AND musId = " << k_db_musId;
ostr << " AND SeqNo = " << k_db_SeqNo;
readcmd.SetCommandText( ostr.str());
DB_RDEXECUTE();
DB_FETCH();
// Material Keys
db_muId = ( long)readcmd.Field(1).AsLong();
strncpy( db_muCreator, readcmd.Field(2).AsString().c_str(), sizeof( db_muCreator));
db_musId = ( short)readcmd.Field(3).AsLong();
// Primary Keys
db_SeqNo = ( long)readcmd.Field(4).AsLong();
// Normal columns
// EnCoilId
if( readcmd.Field(5).IsNull() == false)
{
db_EnCoilIdZi = 0;
strncpy( db_EnCoilId, readcmd.Field(5).AsString().c_str(), sizeof( db_EnCoilId));
}
else
{
db_EnCoilIdZi = -1;
memset( db_EnCoilId, 0x00, sizeof( db_EnCoilId));
}
// Normal columns
// ExCoilId
if( readcmd.Field(6).IsNull() == false)
{
db_ExCoilIdZi = 0;
strncpy( db_ExCoilId, readcmd.Field(6).AsString().c_str(), sizeof( db_ExCoilId));
}
else
{
db_ExCoilIdZi = -1;
memset( db_ExCoilId, 0x00, sizeof( db_ExCoilId));
}
// Normal columns
// DLPTension
if( readcmd.Field(7).IsNull() == false)
{
db_DLPTensionZi = 0;
db_DLPTension = ( double)readcmd.Field(7).AsDouble();
}
else
{
db_DLPTensionZi = -1;
db_DLPTension = 0;
}
// Normal columns
// TC
if( readcmd.Field(8).IsNull() == false)
{
db_TCZi = 0;
strncpy( db_TC, readcmd.Field(8).AsString().c_str(), sizeof( db_TC));
}
else
{
db_TCZi = -1;
memset( db_TC, 0x00, sizeof( db_TC));
}
// copy host variables into Class attributes
copyDB2Attribute( dbObj );
return ( NULL );
} // end of methode
//
// public methode updateDB
//
char* T_CYC_EXTSEG095DBAX::updateDB(T_CYC_EXTSEG095 &dbObj ){
copyKey2Host( dbObj );
copyAttribute2DB( dbObj );
dbSqlCode = 0;
ostringstream ostr;
ostr << "UPDATE T_CYC_EXTSEG095 SET ";
// Material Keys & Primary Keys
ostr << "muId = " << db_muId;
ostr << ", muCreator = '" << db_muCreator << "'";
ostr << ", musId = " << db_musId;
ostr << ", SeqNo=" << db_SeqNo;
// Normal column
if( db_EnCoilIdZi != -1) ostr << ", EnCoilId = '" << db_EnCoilId << "'"; else ostr<<",EnCoilId = NULL";
if( db_ExCoilIdZi != -1) ostr << ", ExCoilId = '" << db_ExCoilId << "'"; else ostr<<",ExCoilId = NULL";
if( db_DLPTensionZi != -1) ostr << ", DLPTension = " << db_DLPTension; else ostr<<",DLPTension = NULL";
if( db_TCZi != -1) ostr << ", TC = TO_DATE('" << db_TC << "','YYYYMMDDHH24MISS')"; else ostr<<",TC = NULL";
// where
ostr << " WHERE ";
ostr << "muId = " << db_muId;
ostr << " AND muCreator = '" << db_muCreator << "'";
ostr << " AND musId = " << db_musId;
ostr << " AND SeqNo = " << db_SeqNo;
updatecmd.SetCommandText( ostr.str());
DB_UPDEXECUTE();
DB_UPDAFFECTED();
return ( NULL );
} // end of methode
//
// public methode insertDB
//
char* T_CYC_EXTSEG095DBAX::insertDB(T_CYC_EXTSEG095 &dbObj ){
copyAttribute2DB( dbObj );
dbSqlCode = 0;
m_sql = "INSERT INTO T_CYC_EXTSEG095 VALUES( :1, :2, :3, :4, :5, :6, :7, :8)";
insertcmd.SetCommandText( m_sql);
// Material Keys
insertcmd.Param(1) = ( long)db_muId;
insertcmd.Param(2) = ( char *)db_muCreator;
insertcmd.Param(3) = ( long)db_musId;
// Primary columns
insertcmd.Param(4) = ( long)db_SeqNo;
// Normal columns
if( db_EnCoilIdZi != -1) insertcmd.Param(5) = ( char *)db_EnCoilId; else insertcmd.Param(5).SetAsNull();
// Normal columns
if( db_ExCoilIdZi != -1) insertcmd.Param(6) = ( char *)db_ExCoilId; else insertcmd.Param(6).SetAsNull();
// Normal columns
if( db_DLPTensionZi != -1) insertcmd.Param(7) = ( double)db_DLPTension; else insertcmd.Param(7).SetAsNull();
// Normal columns
if( db_TCZi != -1) insertcmd.Param(8) = DateTime( db_TC); else insertcmd.Param(8).SetAsNull();
DB_INSEXECUTE();
return ( NULL );
} // end of methode
//
// public methode deleteDB
//
char* T_CYC_EXTSEG095DBAX::deleteDB(T_CYC_EXTSEG095 &dbObj ){
ostringstream ostr;
dbSqlCode = 0;
copyKey2Host( dbObj );
ostr << "DELETE FROM T_CYC_EXTSEG095 WHERE ";
ostr << "muId = " << db_muId;
ostr << " AND muCreator = '" << db_muCreator << "'";
ostr << " AND musId = " << db_musId;
ostr << " AND SeqNo = " << db_SeqNo;
cmd.SetCommandText( ostr.str());
DB_EXECUTE();
return ( NULL );
} // end of methode
//
// public methode deleteDB delete in case of a where clause
//
char* T_CYC_EXTSEG095DBAX::deleteDB(const char* where , long* count){
dbSqlCode = 0;
*(count) = -1L;
m_sql = "DELETE FROM T_CYC_EXTSEG095 ";
if ( where != (char*)NULL ) {
m_sql.append( where );
}
cmd.SetCommandText( m_sql);
DB_EXECUTE();
if( count != NULL){
*count = cmd.RowsAffected();
}
return ( NULL );
} // end of methode
//
// public methode openSetDB
//
char* T_CYC_EXTSEG095DBAX::openSetDB(const char* where , const char* order){
dbSqlCode = 0;
m_sql = "SELECT muId, muCreator, musId, SeqNo, EnCoilId, ExCoilId, DLPTension, TO_CHAR(TC, 'YYYYMMDDHH24MISS') FROM T_CYC_EXTSEG095 ";
if ( where != (char*)NULL ) {
m_sql.append( where);
m_sql.append( " ");
}
if (order != (char*)NULL){
m_sql.append( order);
}
readcmd.SetCommandText( m_sql);
DB_RDEXECUTE();
return ( NULL );
} // end of methode
//
// public methode getSetDB
//
char* T_CYC_EXTSEG095DBAX::getSetDB( T_CYC_EXTSEG095 &dbObj ){
dbSqlCode = 0;
DB_FETCH();
// Material Keys
db_muId = ( long)readcmd.Field(1).AsLong();
strncpy( db_muCreator, readcmd.Field(2).AsString().c_str(), sizeof( db_muCreator));
db_musId = ( short)readcmd.Field(3).AsLong();
// Primary columns
db_SeqNo = ( long)readcmd.Field(4).AsLong();
// Normal columns
// EnCoilId
if( readcmd.Field(5).IsNull() == false)
{
db_EnCoilIdZi = 0;
strncpy( db_EnCoilId, readcmd.Field(5).AsString().c_str(), sizeof( db_EnCoilId));
}
else
{
db_EnCoilIdZi = -1;
memset( db_EnCoilId, 0x00, sizeof( db_EnCoilId));
}
// Normal columns
// ExCoilId
if( readcmd.Field(6).IsNull() == false)
{
db_ExCoilIdZi = 0;
strncpy( db_ExCoilId, readcmd.Field(6).AsString().c_str(), sizeof( db_ExCoilId));
}
else
{
db_ExCoilIdZi = -1;
memset( db_ExCoilId, 0x00, sizeof( db_ExCoilId));
}
// Normal columns
// DLPTension
if( readcmd.Field(7).IsNull() == false)
{
db_DLPTensionZi = 0;
db_DLPTension = ( double)readcmd.Field(7).AsDouble();
}
else
{
db_DLPTensionZi = -1;
db_DLPTension = 0;
}
// Normal columns
// TC
if( readcmd.Field(8).IsNull() == false)
{
db_TCZi = 0;
strncpy( db_TC, readcmd.Field(8).AsString().c_str(), sizeof( db_TC));
}
else
{
db_TCZi = -1;
memset( db_TC, 0x00, sizeof( db_TC));
}
copyDB2Attribute( dbObj );
copyHost2Key( dbObj );
return ( NULL );
} // end of methode
//
// public methode closeSetDB
//
char* T_CYC_EXTSEG095DBAX::closeSetDB(){
dbSqlCode = 0;
return ( NULL );
} // end of methode
//
// public methode countDB
//
char* T_CYC_EXTSEG095DBAX::countDB(const char* where , long* count){
dbSqlCode = 0;
*(count) = -1L;
m_sql = "SELECT count(*) FROM T_CYC_EXTSEG095 ";
if ( where != (char*)NULL ) {
m_sql.append( where);
}
readcmd.SetCommandText( m_sql);
DB_RDEXECUTE();
DB_FETCH();
*count = ( long)readcmd.Field(1).AsLong();
return ( NULL );
} // end of methode