#include "hgupstoremat.h" #define SQLCA_STORAGE_CLASS extern #define ORACA_STORAGE_CLASS extern #include #include // ************************************************************************ // ---------------------- getMaxIndex ----------------------------------- // ************************************************************************ int HGupStoreMat::getMaxIndex() { // returns maximum MATERIAL_INDEX // returns -1 if error occures EXEC SQL BEGIN DECLARE SECTION; int MaxIndex; short MaxIndex_Ind; EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER SQLERROR DO sqlHandleError("sql error in HGupStoreMat::getMaxIndex"); EXEC SQL WHENEVER NOT FOUND GOTO notfound; EXEC SQL SELECT MAX(MATERIAL_INDEX) INTO :MaxIndex INDICATOR :MaxIndex_Ind FROM HADES_OPER.MATERIALS; if (MaxIndex_Ind>=0) { materialIndex=MaxIndex; return materialIndex; } notfound: return -1; } // ************************************************************************ // ---------------------- storeObj -------------------------------------- // ************************************************************************ long HGupStoreMat::storeObj() { // stores a new object in MATERIALS materialIndex++; if (materialIndex <= 0) { cerr << "error in HGupStoreMat::storeObj: materialIndex = " << materialIndex << endl; return -1; }; EXEC SQL BEGIN DECLARE SECTION; int Material_Index=materialIndex; const char* Material_Name=materialName; float Material_Dens=dens; int Material_Weightpercent=weightpercent; int Vers_Index=versIndex; EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER SQLERROR DO sqlHandleError("sql error in HGupStoreMat::storeObj"); EXEC SQL INSERT INTO HADES_OPER.MATERIALS (MATERIAL_INDEX, MATERIAL_NAME, MATERIAL_DENS, MATERIAL_WEIGHTPERCENT, VERS_INDEX) VALUES (:Material_Index, :Material_Name, :Material_Dens, :Material_Weightpercent, :Vers_Index); return sqlca.sqlcode; notfound: return -1; } // ************************************************************************ // ---------------------- printInput ------------------------------------ // ************************************************************************ void HGupStoreMat::printInput() { cout << "Insert in table MATERIALS" << '\n'; cout << "MATERIAL_INDEX: " << materialIndex << '\n'; cout << "MATERIAL_NAME: " << materialName << '\n'; cout << "MATERIAL_DENS: " << dens << '\n'; cout << "MATERIAL_WEIGHTPERCENT: " << weightpercent << '\n'; cout << "VERS_INDEX: " << versIndex << '\n'; cout << "-------------------------------------------------------"<< '\n'; return; } // ************************************************************************ // ---------------------- writeInput ------------------------------------ // ************************************************************************ void HGupStoreMat::writeInput(ofstream & fout) { // writes input to logfile fout << "Insert in table MATERIALS" << '\n'; fout << "MATERIAL_INDEX: " << materialIndex << '\n'; fout << "MATERIAL_NAME: " << materialName << '\n'; fout << "MATERIAL_DENS: " << dens << '\n'; fout << "MATERIAL_WEIGHTPERCENT: " << weightpercent << '\n'; fout << "VERS_INDEX: " << versIndex << '\n'; fout << "-------------------------------------------------------"<< '\n'; return; }