// Version: 2014.9.2 16:30:14 // File: T_LOV_WELDDBAX.cpp #include #include "T_LOV_WELDDBAX.h" #include "T_LOV_WELD.h" #define NORECORD 100 using namespace log4cplus; extern iDA::Connection cn; extern char sqlErrMsg[4000]; #define DB_EXECUTE() try{ cmd.Execute();}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;} #define DB_UPDEXECUTE() try{ updatecmd.Execute();}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;} #define DB_RDEXECUTE() try{ readcmd.Execute();}catch( iDA::Exception &e){ dbSqlCode=-1;strcpy( sqlErrMsg,e.ErrMsg().c_str());return sqlErrMsg;} #define DB_INSEXECUTE() try{ 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 int db_SGCode; static int db_Value; static short db_ValueZi; static char db_toc[27]; static short db_tocZi; static char db_tom[27]; static short db_tomZi; static char db_mop[121]; static short db_mopZi; static char db_mou[31]; static short db_mouZi; static long rowCnt; // Host arguments for Primary key static int k_db_SGCode; // // constructor // T_LOV_WELDDBAX::T_LOV_WELDDBAX() { } // // destructor // T_LOV_WELDDBAX::~T_LOV_WELDDBAX() { } char* T_LOV_WELDDBAX::execute(const char* sql , long* count ){ dbSqlCode = 0; cmd.SetConnection( &cn); cmd.SetCommandText( sql); DB_EXECUTE(); if( count != NULL) { *count = cmd.RowsAffected(); } return ( NULL ); } char* T_LOV_WELDDBAX::dbCommit(){ dbSqlCode = 0; try{ cn.Commit(); }catch( iDA::Exception &e) { dbSqlCode = -1; strcpy( sqlErrMsg,e.ErrMsg().c_str()); return sqlErrMsg; } return ( NULL ); } char* T_LOV_WELDDBAX::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_LOV_WELDDBAX::copyDB2Attribute( T_LOV_WELD &dbObj ){ dbObj.set_SGCode((long)db_SGCode); dbObj.set_Value((long)db_Value); dbObj.set_ValueZi((short)db_ValueZi); dbObj.set_toc((char*)db_toc); dbObj.set_tocZi((short)db_tocZi ); dbObj.set_tom((char*)db_tom); dbObj.set_tomZi((short)db_tomZi ); dbObj.set_mop((char*)db_mop); dbObj.set_mopZi((short)db_mopZi ); dbObj.set_mou((char*)db_mou); dbObj.set_mouZi((short)db_mouZi ); } // end of methode // // private methode copyAttribute2DB // void T_LOV_WELDDBAX::copyAttribute2DB( T_LOV_WELD &dbObj ){ db_SGCode = dbObj.SGCode(); db_Value = dbObj.Value(); db_ValueZi = dbObj.ValueZi(); } // end of methode // // private methode copyKey2Host // void T_LOV_WELDDBAX::copyKey2Host( T_LOV_WELD &dbObj ){ k_db_SGCode = dbObj.k_SGCode(); } // end of methode // // private methode copyHost2Key // void T_LOV_WELDDBAX::copyHost2Key( T_LOV_WELD &dbObj ){ dbObj.set_k_SGCode((long)db_SGCode); } // end of methode // // public methode readDB // char* T_LOV_WELDDBAX::readDB(T_LOV_WELD &dbObj ){ copyKey2Host( dbObj ); ostringstream ostr; dbSqlCode = 0; ostr << "SELECT "; // all columns ostr << "SGCode"; ostr << ",Value"; ostr << ",TO_CHAR( toc , 'YYYYMMDDHH24MISS')"; ostr << ",TO_CHAR( tom , 'YYYYMMDDHH24MISS')"; ostr << ",mop"; ostr << ",mou"; ostr << " FROM T_LOV_WELD WHERE "; // where ostr << "SGCode = " << k_db_SGCode; readcmd.SetConnection(&cn); readcmd.SetCommandText( ostr.str()); DB_RDEXECUTE(); DB_FETCH(); // Primary Keys db_SGCode = ( long)readcmd.Field(1).AsLong(); // Normal columns // Value if( readcmd.Field(2).IsNull() == false) { db_ValueZi = 0; db_Value = ( long)readcmd.Field(2).AsLong(); } else { db_ValueZi = -1; db_Value = 0; } // toc if( readcmd.Field(3).IsNull() == false) { db_tocZi = 0; strncpy( db_toc, readcmd.Field(3).AsString().c_str(), sizeof( db_toc)); } else { db_tocZi = -1; memset( db_toc, 0x00, sizeof( db_toc)); } // tom if( readcmd.Field(4).IsNull() == false) { db_tomZi = 0; strncpy( db_tom, readcmd.Field(4).AsString().c_str(), sizeof( db_tom)); } else { db_tomZi = -1; memset( db_tom, 0x00, sizeof( db_tom)); } // mop if( readcmd.Field(5).IsNull() == false) { db_mopZi = 0; strncpy( db_mop, readcmd.Field(5).AsString().c_str(), sizeof( db_mop)); } else { db_mopZi = -1; memset( db_mop, 0x00, sizeof( db_mop)); } // mou if( readcmd.Field(6).IsNull() == false) { db_mouZi = 0; strncpy( db_mou, readcmd.Field(6).AsString().c_str(), sizeof( db_mou)); } else { db_mouZi = -1; memset( db_mou, 0x00, sizeof( db_mou)); } // copy host variables into Class attributes copyDB2Attribute( dbObj ); return ( NULL ); } // end of methode // // public methode updateDB // char* T_LOV_WELDDBAX::updateDB(T_LOV_WELD &dbObj ){ copyKey2Host( dbObj ); copyAttribute2DB( dbObj ); dbSqlCode = 0; ostringstream ostr; ostr << "UPDATE T_LOV_WELD SET "; // Material Keys & Primary Keys ostr << "SGCode=" << db_SGCode; // Normal column if( db_ValueZi != -1) ostr << ", Value = " << db_Value; else ostr<<",Value = NULL"; // where ostr << " WHERE "; ostr << "SGCode = " << db_SGCode; updatecmd.SetConnection(&cn); updatecmd.SetCommandText( ostr.str()); DB_UPDEXECUTE(); DB_UPDAFFECTED(); return ( NULL ); } // end of methode // // public methode insertDB // char* T_LOV_WELDDBAX::insertDB(T_LOV_WELD &dbObj ){ copyAttribute2DB( dbObj ); dbSqlCode = 0; m_sql = "INSERT INTO T_LOV_WELD VALUES( :1, :2, :3, :4, :5, :6)"; insertcmd.SetConnection(&cn); insertcmd.SetCommandText( m_sql); // Primary columns insertcmd.Param(1) = ( long)db_SGCode; // Normal columns if( db_ValueZi != -1) insertcmd.Param(2) = ( long)db_Value; else insertcmd.Param(2).SetAsNull(); //TOCTOMMOPMOU insertcmd.Param(3).SetAsNull(); insertcmd.Param(4).SetAsNull(); insertcmd.Param(5).SetAsNull(); insertcmd.Param(6).SetAsNull(); DB_INSEXECUTE(); return ( NULL ); } // end of methode // // public methode deleteDB // char* T_LOV_WELDDBAX::deleteDB(T_LOV_WELD &dbObj ){ ostringstream ostr; dbSqlCode = 0; copyKey2Host( dbObj ); ostr << "DELETE FROM T_LOV_WELD WHERE "; ostr << "SGCode = " << db_SGCode; cmd.SetConnection( &cn); cmd.SetCommandText( ostr.str()); DB_EXECUTE(); return ( NULL ); } // end of methode // // public methode deleteDB delete in case of a where clause // char* T_LOV_WELDDBAX::deleteDB(const char* where , long* count){ dbSqlCode = 0; *(count) = -1L; m_sql = "DELETE FROM T_LOV_WELD "; if ( where != (char*)NULL ) { m_sql.append( where ); } cmd.SetConnection( &cn); cmd.SetCommandText( m_sql); DB_EXECUTE(); if( count != NULL){ *count = cmd.RowsAffected(); } return ( NULL ); } // end of methode // // public methode openSetDB // char* T_LOV_WELDDBAX::openSetDB(const char* where , const char* order){ dbSqlCode = 0; m_sql = "SELECT SGCode, Value, TO_CHAR( toc , 'YYYYMMDDHH24MISS'), TO_CHAR( tom , 'YYYYMMDDHH24MISS'), mop, mou FROM T_LOV_WELD "; if ( where != (char*)NULL ) { m_sql.append( where); m_sql.append( " "); } if (order != (char*)NULL){ m_sql.append( order); } readcmd.SetConnection(&cn); readcmd.SetCommandText( m_sql); DB_RDEXECUTE(); return ( NULL ); } // end of methode // // public methode getSetDB // char* T_LOV_WELDDBAX::getSetDB( T_LOV_WELD &dbObj ){ dbSqlCode = 0; DB_FETCH(); // Primary columns db_SGCode = ( long)readcmd.Field(1).AsLong(); // Normal columns // Value if( readcmd.Field(2).IsNull() == false) { db_ValueZi = 0; db_Value = ( long)readcmd.Field(2).AsLong(); } else { db_ValueZi = -1; db_Value = 0; } // toc if( readcmd.Field(3).IsNull() == false) { db_tocZi = 0; strncpy( db_toc, readcmd.Field(3).AsString().c_str(), sizeof( db_toc)); } else { db_tocZi = -1; memset( db_toc, 0x00, sizeof( db_toc)); } // tom if( readcmd.Field(4).IsNull() == false) { db_tomZi = 0; strncpy( db_tom, readcmd.Field(4).AsString().c_str(), sizeof( db_tom)); } else { db_tomZi = -1; memset( db_tom, 0x00, sizeof( db_tom)); } // mop if( readcmd.Field(5).IsNull() == false) { db_mopZi = 0; strncpy( db_mop, readcmd.Field(5).AsString().c_str(), sizeof( db_mop)); } else { db_mopZi = -1; memset( db_mop, 0x00, sizeof( db_mop)); } // mou if( readcmd.Field(6).IsNull() == false) { db_mouZi = 0; strncpy( db_mou, readcmd.Field(6).AsString().c_str(), sizeof( db_mou)); } else { db_mouZi = -1; memset( db_mou, 0x00, sizeof( db_mou)); } copyDB2Attribute( dbObj ); copyHost2Key( dbObj ); return ( NULL ); } // end of methode // // public methode closeSetDB // char* T_LOV_WELDDBAX::closeSetDB(){ dbSqlCode = 0; return ( NULL ); } // end of methode // // public methode countDB // char* T_LOV_WELDDBAX::countDB(const char* where , long* count){ dbSqlCode = 0; *(count) = -1L; m_sql = "SELECT count(*) FROM T_LOV_WELD "; if ( where != (char*)NULL ) { m_sql.append( where); } readcmd.SetConnection(&cn); readcmd.SetCommandText( m_sql); DB_RDEXECUTE(); DB_FETCH(); *count = ( long)readcmd.Field(1).AsLong(); return ( NULL ); } // end of methode