From 8fbee785175ba3753900e2d0499e22eb836c5b23 Mon Sep 17 00:00:00 2001 From: Cekis Date: Fri, 1 Sep 2023 01:57:54 -0400 Subject: [PATCH] Fixed bugs related to database inconsistencies between 32 bit and 64 bit. --- .../src/shared/object/ResourcePoolObject.cpp | 2 +- .../serverUtility/src/shared/ServerClock.cpp | 20 +- .../serverUtility/src/shared/ServerClock.h | 22 +- .../src_oci/DbBindableVarray.cpp | 197 ++++++++++++------ .../src_oci/OciQueryImplementation.cpp | 175 +++++++++++----- .../src_oci/OciServer.cpp | 2 +- .../src_oci/OciSession.cpp | 14 +- .../src/shared/queries/ResourceTypeQuery.cpp | 2 +- 8 files changed, 288 insertions(+), 146 deletions(-) diff --git a/engine/server/library/serverGame/src/shared/object/ResourcePoolObject.cpp b/engine/server/library/serverGame/src/shared/object/ResourcePoolObject.cpp index e0835433..92d2404a 100755 --- a/engine/server/library/serverGame/src/shared/object/ResourcePoolObject.cpp +++ b/engine/server/library/serverGame/src/shared/object/ResourcePoolObject.cpp @@ -54,7 +54,7 @@ ResourcePoolObject::~ResourcePoolObject() */ float ResourcePoolObject::harvest(float installedEfficiency, uint32 lastHarvestTime) const { - int elapsedTime=static_cast(std::min(ServerClock::getInstance().getGameTimeSeconds(),static_cast(m_depletedTimestamp)) - lastHarvestTime); + uint32_t elapsedTime=static_cast(std::min(ServerClock::getInstance().getGameTimeSeconds(),static_cast(m_depletedTimestamp)) - lastHarvestTime); if (elapsedTime < 0) return 0; float elapsedTicks =static_cast(elapsedTime) / static_cast(ConfigServerGame::getSecondsPerResourceTick()); diff --git a/engine/server/library/serverUtility/src/shared/ServerClock.cpp b/engine/server/library/serverUtility/src/shared/ServerClock.cpp index a5a13a8a..a8d7c73f 100755 --- a/engine/server/library/serverUtility/src/shared/ServerClock.cpp +++ b/engine/server/library/serverUtility/src/shared/ServerClock.cpp @@ -12,7 +12,7 @@ // ---------------------------------------------------------------------- -const unsigned long ServerClock::cms_endOfTime = static_cast(-1); +const int32_t ServerClock::cms_endOfTime = static_cast(-1); //----------------------------------------------------------------------- @@ -31,10 +31,10 @@ ServerClock::~ServerClock() //----------------------------------------------------------------------- -const unsigned long ServerClock::getGameTimeSeconds() const +const uint32_t ServerClock::getGameTimeSeconds() const { FATAL(!isSet(), ("ServerClock::getGameTimeSeconds: Clock was not set.")); - return int(lastTime - subtractInterval); + return static_cast(lastTime - subtractInterval); } //----------------------------------------------------------------------- @@ -52,16 +52,16 @@ void ServerClock::incrementServerFrame() //----------------------------------------------------------------------- -void ServerClock::setSubtractInterval(const unsigned long newSubtractInterval) +void ServerClock::setSubtractInterval(const uint32_t newSubtractInterval) { subtractInterval = newSubtractInterval; } //----------------------------------------------------------------------- -void ServerClock::setGameTimeSeconds(const unsigned long newGameTime) +void ServerClock::setGameTimeSeconds(const uint32_t newGameTime) { - subtractInterval = int(time(0) - newGameTime); + subtractInterval = static_cast(time(0) - newGameTime); LOG("ServerClock", ("Game time set to %lu (subtract interval %lu)", newGameTime, subtractInterval)); } @@ -79,11 +79,11 @@ ServerClock &ServerClock::getInstance() * Given a time in seconds, make a string that expresses how long it is. * For debug output only. In English, not localized. Not thread-safe. */ -std::string ServerClock::getDebugPrintableTimeframe(unsigned long const timeInSeconds) +std::string ServerClock::getDebugPrintableTimeframe(uint32_t const timeInSeconds) { - unsigned long const dayInSeconds = 60 * 60 * 24; - unsigned long const hourInSeconds = 60 * 60; - unsigned long const minuteInSeconds = 60; + uint32_t const dayInSeconds = 60 * 60 * 24; + uint32_t const hourInSeconds = 60 * 60; + uint32_t const minuteInSeconds = 60; static char buffer[256]; diff --git a/engine/server/library/serverUtility/src/shared/ServerClock.h b/engine/server/library/serverUtility/src/shared/ServerClock.h index 36ee93b9..9f64c3bb 100755 --- a/engine/server/library/serverUtility/src/shared/ServerClock.h +++ b/engine/server/library/serverUtility/src/shared/ServerClock.h @@ -10,36 +10,36 @@ public: static ServerClock &getInstance(); ~ServerClock(); - const unsigned long getGameTimeSeconds () const; - const unsigned long getServerFrame() const; - const unsigned long getSubtractInterval() const; + const uint32_t getGameTimeSeconds () const; + const uint32_t getServerFrame() const; + const uint32_t getSubtractInterval() const; void incrementServerFrame(); - void setSubtractInterval(const unsigned long newSubtractInterval); - void setGameTimeSeconds (unsigned long newGameTime); + void setSubtractInterval(const uint32_t newSubtractInterval); + void setGameTimeSeconds (uint32_t newGameTime); bool isSet () const; - std::string getDebugPrintableTimeframe (const unsigned long timeInSeconds); + std::string getDebugPrintableTimeframe (const uint32_t timeInSeconds); - static const unsigned long cms_endOfTime; + static const int32_t cms_endOfTime; protected: ServerClock(); private: - unsigned long serverFrame; - unsigned long subtractInterval; + uint32_t serverFrame; + uint32_t subtractInterval; mutable time_t lastTime; }; //----------------------------------------------------------------------- -inline const unsigned long ServerClock::getServerFrame() const +inline const uint32_t ServerClock::getServerFrame() const { return serverFrame; } //----------------------------------------------------------------------- -inline const unsigned long ServerClock::getSubtractInterval() const +inline const uint32_t ServerClock::getSubtractInterval() const { return subtractInterval; } diff --git a/engine/shared/library/sharedDatabaseInterface/src_oci/DbBindableVarray.cpp b/engine/shared/library/sharedDatabaseInterface/src_oci/DbBindableVarray.cpp index 956482bf..255c4105 100755 --- a/engine/shared/library/sharedDatabaseInterface/src_oci/DbBindableVarray.cpp +++ b/engine/shared/library/sharedDatabaseInterface/src_oci/DbBindableVarray.cpp @@ -57,8 +57,10 @@ bool BindableVarray::create(DB::Session *session, const std::string &name, const 0, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER, - &m_tdo)))) + &m_tdo)))) { + LOG("DatabaseError", ("Could not create BindableVarray (OCITypeByName) for name - %s", name.c_str())); return false; + } if (! (localSession->m_server->checkerr(*localSession, OCIObjectNew (localSession->envhp, @@ -68,8 +70,10 @@ bool BindableVarray::create(DB::Session *session, const std::string &name, const m_tdo, nullptr, OCI_DURATION_DEFAULT, true, - reinterpret_cast(&m_data))))) - return false; + reinterpret_cast(&m_data))))) { + LOG("DatabaseError", ("Could not create BindableVarray (OCIObjectNew) for name - %s", name.c_str())); + return false; + } NOT_NULL(m_tdo); NOT_NULL(m_data); @@ -83,9 +87,11 @@ void BindableVarray::free() { OCISession *localSession = safe_cast(m_session); - IGNORE_RETURN(localSession->m_server->checkerr(*localSession, + if(!(localSession->m_server->checkerr(*localSession, OCIObjectFree (localSession->envhp, - localSession->errhp, m_data, 0))); + localSession->errhp, m_data, 0)))) { + LOG("DatabaseError", ("Could not free up DB object")); + }; m_initialized = false; m_tdo=nullptr; m_data=nullptr; @@ -99,10 +105,14 @@ void BindableVarray::clear() OCISession *localSession = safe_cast(m_session); sb4 size=0; - if (! (localSession->m_server->checkerr(*localSession, OCICollSize(localSession->envhp, localSession->errhp, m_data, &size)))) - return; - if (! (localSession->m_server->checkerr(*localSession, OCICollTrim(localSession->envhp, localSession->errhp, size, m_data)))) - return; + if (! (localSession->m_server->checkerr(*localSession, OCICollSize(localSession->envhp, localSession->errhp, m_data, &size)))) { + LOG("DatabaseError", ("Could not clear bindablevarray - OCICollSize")); + return; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollTrim(localSession->envhp, localSession->errhp, size, m_data)))) { + LOG("DatabaseError", ("Could not clear bindablevarray - OCICollTrim")); + return; + } } // ---------------------------------------------------------------------- @@ -129,10 +139,14 @@ bool BindableVarrayNumber::push_back(int16_t value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVArray int16 value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVArray int16 value OCICollAppend - %d", value)); + return false; + } return true; } @@ -147,10 +161,14 @@ bool BindableVarrayNumber::push_back(int32_t value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVArray int32 value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVArray int32 value OCINumberFromInt - %d", value)); + return false; + } return true; } @@ -164,10 +182,14 @@ bool BindableVarrayNumber::push_back(int64_t value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVArray int64 value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVArray int64 value OCINumberFromInt - %d", value)); + return false; + } return true; } @@ -195,10 +217,14 @@ bool BindableVarrayNumber::push_back(double value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromReal(localSession->errhp, &value, sizeof(value), &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromReal(localSession->errhp, &value, sizeof(value), &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVArray double value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVArray double value OCINumberFromInt - %d", value)); + return false; + } return true; } @@ -221,10 +247,14 @@ bool BindableVarrayNumber::push_back(bool IsNULL, int16_t value) } OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber int16 value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber int16 value OCINumberFromInt - %d", value)); + return false; + } return true; } @@ -248,10 +278,14 @@ bool BindableVarrayNumber::push_back(bool IsNULL, int32_t value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber int32 value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber int32 value OCINumberFromInt - %d", value)); + return false; + } return true; } @@ -274,10 +308,14 @@ bool BindableVarrayNumber::push_back(bool IsNULL, int64_t value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromInt(localSession->errhp, &value, sizeof(value), OCI_NUMBER_SIGNED, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber int64 value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber int64 value OCINumberFromInt - %d", value)); + return false; + } return true; } @@ -314,10 +352,14 @@ bool BindableVarrayNumber::push_back(bool IsNULL, double value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCINumberFromReal(localSession->errhp, &value, sizeof(value), &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCINumberFromReal(localSession->errhp, &value, sizeof(value), &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber double value OCINumberFromInt - %d", value)); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, &buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayNumber double value OCINumberFromInt - %d", value)); + return false; + } return true; } @@ -338,8 +380,10 @@ std::string BindableVarrayNumber::outputValue() const sb4 size; std::string result("["); - if (! (localSession->m_server->checkerr(*localSession, OCICollSize(localSession->envhp, localSession->errhp, m_data, &size)))) + if (! (localSession->m_server->checkerr(*localSession, OCICollSize(localSession->envhp, localSession->errhp, m_data, &size)))) { + LOG("DatabaseError", ("Could not get outputValue - OCICollSize - %d", size)); return "[*ERROR*]"; + } for (sb4 i=0; i < size; ++i) { @@ -366,15 +410,19 @@ std::string BindableVarrayNumber::outputValue() const buffer[sizeof(buffer)-1]='\0'; result += buffer; } - else + else { + LOG("DatabaseError", ("Could not get output value from OCINumberToReal - %d", value)); result += "*ERROR*"; + } } } else result += "*NO ELEMENT*"; } - else - result += "*ERROR*"; + else { + LOG("DatabaseError", ("Could not get output value from OCICollGetElem")); + result += "*ERROR*"; + } } result+=']'; return result; @@ -420,10 +468,14 @@ bool BindableVarrayString::push_back(const std::string &value) } } - if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), effectiveLength, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), effectiveLength, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString string value (OCIStringAssignText) - %s", value.c_str())); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString string value (OCICollAppend) - %s", value.c_str())); + return false; + } return true; } @@ -442,10 +494,14 @@ bool BindableVarrayString::push_back(bool bvalue) OCIInd buffer_indicator (OCI_IND_NOTNULL); OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), value.length(), &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), value.length(), &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString string value (OCIStringAssignText) - %s", value.c_str())); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString string value (OCICollAppend) - %s", value.c_str())); + return false; + } return true; } @@ -498,10 +554,14 @@ bool BindableVarrayString::push_back(bool IsNULL, const std::string &value) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), effectiveLength, &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) - return false; + if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), effectiveLength, &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString string value (OCIStringAssignText) - %s", value.c_str())); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString string value (OCICollAppend) - %s", value.c_str())); + return false; + } return true; } @@ -529,11 +589,14 @@ bool BindableVarrayString::push_back(bool IsNULL, bool bvalue) OCISession *localSession = safe_cast(m_session); - if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), value.length(), &buffer)))) - return false; - if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) - return false; - + if (! (localSession->m_server->checkerr(*localSession, OCIStringAssignText(localSession->envhp, localSession->errhp, reinterpret_cast(const_cast(value.c_str())), value.length(), &buffer)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString boolean value (OCIStringAssignText) - %s", value.c_str())); + return false; + } + if (! (localSession->m_server->checkerr(*localSession, OCICollAppend(localSession->envhp, localSession->errhp, buffer, &buffer_indicator, m_data)))) { + LOG("DatabaseError", ("Could not push back BindableVarrayString boolean value (OCICollAppend) - %s", value.c_str())); + return false; + } return true; } @@ -552,8 +615,10 @@ std::string BindableVarrayString::outputValue() const sb4 size; std::string result("["); - if (! (localSession->m_server->checkerr(*localSession, OCICollSize(localSession->envhp, localSession->errhp, m_data, &size)))) + if (! (localSession->m_server->checkerr(*localSession, OCICollSize(localSession->envhp, localSession->errhp, m_data, &size)))) { + LOG("DatabaseError", ("Could not get outputValue BindableVarrayString (OCICollSize)")); return "[*ERROR*]"; + } for (sb4 i=0; i < size; ++i) { @@ -582,8 +647,10 @@ std::string BindableVarrayString::outputValue() const else result += "*NO ELEMENT*"; } - else - result += "*ERROR*"; + else { + LOG("DatabaseError", ("Could not get outputValue BindableVarrayString OCICollGetElem")); + return "[*ERROR*]"; + } } result+=']'; return result; diff --git a/engine/shared/library/sharedDatabaseInterface/src_oci/OciQueryImplementation.cpp b/engine/shared/library/sharedDatabaseInterface/src_oci/OciQueryImplementation.cpp index b9bdce1d..18f06e53 100755 --- a/engine/shared/library/sharedDatabaseInterface/src_oci/OciQueryImplementation.cpp +++ b/engine/shared/library/sharedDatabaseInterface/src_oci/OciQueryImplementation.cpp @@ -63,8 +63,10 @@ bool DB::OCIQueryImpl::setup(Session *session) if (!m_server->checkerr(*m_session, OCIHandleAlloc( m_session->envhp, reinterpret_cast(&m_stmthp), - OCI_HTYPE_STMT, 0, 0))) - return false; + OCI_HTYPE_STMT, 0, 0))) { + LOG("DatabaseError", ("Could not setup query")); + return false; + } m_cursorhp=m_stmthp; // later on, we'll separate these two if needed @@ -88,15 +90,19 @@ bool DB::OCIQueryImpl::prepare() reinterpret_cast(const_cast(m_sql.c_str())), m_sql.length(), (ub4) OCI_NTV_SYNTAX, - (ub4) OCI_DEFAULT))) - return false; + (ub4) OCI_DEFAULT))) { + LOG("DatabaseError", ("Could not prepare statement - %s", m_sql.c_str())); + return false; + } if (m_query->getMode()==Query::MODE_PLSQL_REFCURSOR) { m_cursorhp=0; // may not be necessary -- OCI docs unclear if (!m_server->checkerr(*m_session, OCIHandleAlloc( m_session->envhp, (dvoid **) &m_cursorhp, - OCI_HTYPE_STMT, 0, 0))) + OCI_HTYPE_STMT, 0, 0))) { + LOG("DatabaseError", ("Could not prepare statement - could not allocate handle for statement - %s", m_sql.c_str())); return false; - + } + if (!m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, &m_procBind, @@ -110,8 +116,10 @@ bool DB::OCIQueryImpl::prepare() 0, 0, 0, - OCI_DEFAULT))) + OCI_DEFAULT))) { + LOG("DatabaseError", ("Could not prepare statement - could not bind by position on statement - %s", m_sql.c_str())); return false; + } } return true; @@ -189,8 +197,10 @@ bool DB::OCIQueryImpl::exec() { WARNING_STRICT_FATAL(!m_session->isOkToFetch(),("Calling fetch after commit, without an execute in between (may cause Oracle to crash).")); sword status=OCIStmtFetch (m_cursorhp, m_session->errhp, 0, OCI_FETCH_NEXT, OCI_DEFAULT); - if (!m_server->checkerr(*m_session,status)) - return false; + if (!m_server->checkerr(*m_session,status)) { + LOG("DatabaseError", ("Could not establish session when executing statement (NO Data) - %s", m_sql.c_str())); + return false; + } } m_endOfData=true; } @@ -213,8 +223,10 @@ bool DB::OCIQueryImpl::exec() m_dataReady=true; } } - else - return false; + else { + LOG("DatabaseError", ("Could not establish session when executing statement (Data) - %s", m_sql.c_str())); + return false; + } } m_inUse=true; @@ -247,8 +259,10 @@ int DB::OCIQueryImpl::fetch() (dvoid *)& rows, (ub4 *) &sizep, OCI_ATTR_ROWS_FETCHED, m_session->errhp); sword status=OCIStmtFetch (m_cursorhp, m_session->errhp, 0, OCI_FETCH_NEXT, OCI_DEFAULT); // cancel the cursor - if (!m_server->checkerr(*m_session,status)) - return -1; + if (!m_server->checkerr(*m_session,status)) { + LOG("DatabaseError", ("Could not fetch from query (NO Data) - %s", m_sql.c_str())); + return -1; + } m_endOfData=true; if (rows!=0) { @@ -260,8 +274,10 @@ int DB::OCIQueryImpl::fetch() } else { - if (!m_server->checkerr(*m_session,status)) - return -1; + if (!m_server->checkerr(*m_session,status)) { + LOG("DatabaseError", ("Could not fetch from query (Data) - %s", m_sql.c_str())); + return -1; + } } ub4 rows; @@ -324,8 +340,11 @@ void DB::OCIQueryImpl::done() { NOT_NULL(m_stmthp); - if (m_autocommit) - m_server->checkerr(*m_session, OCITransCommit(m_session->svchp, m_session->errhp, 0)); + if (m_autocommit) { + if(!(m_server->checkerr(*m_session, OCITransCommit(m_session->svchp, m_session->errhp, 0)))) { + LOG("DatabaseError", ("Could not complete transaction - %s", m_sql.c_str())); + } + } OCIHandleFree(m_stmthp, OCI_HTYPE_STMT); if (m_cursorhp!=m_stmthp) @@ -355,7 +374,9 @@ int DB::OCIQueryImpl::rowCount() int value; - m_server->checkerr(*m_session, OCIAttrGet (m_cursorhp, OCI_HTYPE_STMT,&value,0,OCI_ATTR_ROW_COUNT,m_session->errhp)); + if(!(m_server->checkerr(*m_session, OCIAttrGet (m_cursorhp, OCI_HTYPE_STMT,&value,0,OCI_ATTR_ROW_COUNT,m_session->errhp)))) { + LOG("DatabaseError", ("Could not get row count from query - %s", m_sql.c_str())); + } return value; } @@ -453,7 +474,7 @@ bool DB::OCIQueryImpl::bindCol(BindableLong &buffer) { BindRec *br=addBindRec(buffer); - m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, + if(!(m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, &(br->defnp), m_session->errhp, nextColumn++, @@ -463,16 +484,20 @@ bool DB::OCIQueryImpl::bindCol(BindableLong &buffer) br->getIndicatorPointer(), br->getLengthPointer(), (ub2 *)0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind column (by position) - %s", m_sql.c_str())); + } if (m_numElements > 1) { - m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, + if(!(m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, m_session->errhp, m_skipSize, br->getIndicatorSkipSize(), br->getLengthSkipSize(), - 0)); + 0)))) { + LOG("DatabaseError", ("Could not bind column (define array) - %s", m_sql.c_str())); + } } return true; } @@ -483,7 +508,7 @@ bool DB::OCIQueryImpl::bindParameter(BindableLong &buffer) { BindRec *br=addBindRec(buffer); - return m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, + if(!(m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, &(br->bindp), m_session->errhp, nextParameter++, @@ -495,7 +520,11 @@ bool DB::OCIQueryImpl::bindParameter(BindableLong &buffer) 0, 0, 0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind parameter of statement - %s", m_sql.c_str())); + return false; + } + return true; } // ---------------------------------------------------------------------- @@ -504,7 +533,7 @@ bool DB::OCIQueryImpl::bindCol(BindableStringBase &buffer) { BindRec *br=addBindRec(buffer); - m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, + if(!(m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, &(br->defnp), m_session->errhp, nextColumn++, @@ -514,16 +543,20 @@ bool DB::OCIQueryImpl::bindCol(BindableStringBase &buffer) br->getIndicatorPointer(), br->getLengthPointer(), (ub2 *)0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind column of statement (by position) - %s", m_sql.c_str())); + } if (m_numElements > 1) { - m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, + if(!(m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, m_session->errhp, m_skipSize, br->getIndicatorSkipSize(), br->getLengthSkipSize(), - 0)); + 0)))) { + LOG("DatabaseError", ("Could not bind column of statement (by array) - %s", m_sql.c_str())); + } } return true; } @@ -535,7 +568,7 @@ bool DB::OCIQueryImpl::bindParameter(BindableStringBase &buffer) BindRec *br=addBindRec(buffer); br->stringAdjust=true; - return m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, + if(!(m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, &(br->bindp), m_session->errhp, nextParameter++, @@ -547,7 +580,11 @@ bool DB::OCIQueryImpl::bindParameter(BindableStringBase &buffer) 0, 0, 0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind parameter of statement (by position) - %s", m_sql.c_str())); + return false; + } + return true; } // ---------------------------------------------------------------------- @@ -556,7 +593,7 @@ bool DB::OCIQueryImpl::bindCol(BindableUnicodeBase &buffer) { BindRec *br=addBindRec(buffer); - m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, + if(!(m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, &(br->defnp), m_session->errhp, nextColumn++, @@ -566,16 +603,20 @@ bool DB::OCIQueryImpl::bindCol(BindableUnicodeBase &buffer) br->getIndicatorPointer(), br->getLengthPointer(), (ub2 *)0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind column of statement (by position) (BindableUnicodeBase) - %s", m_sql.c_str())); + } if (m_numElements > 1) { - m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, + if(!(m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, m_session->errhp, m_skipSize, br->getIndicatorSkipSize(), br->getLengthSkipSize(), - 0)); + 0)))) { + LOG("DatabaseError", ("Could not bind column of statement (by array) (BindableUnicodeBase) - %s", m_sql.c_str())); + } } return true; } @@ -588,7 +629,7 @@ bool DB::OCIQueryImpl::bindParameter(BindableUnicodeBase &buffer) br->stringAdjust=true; br->length=static_cast(*(buffer.getIndicator())); - return m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, + if(!(m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, &(br->bindp), m_session->errhp, nextParameter++, @@ -600,7 +641,11 @@ bool DB::OCIQueryImpl::bindParameter(BindableUnicodeBase &buffer) 0, 0, 0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind parameter of statement (by position) (BindableUnicodeBase) - %s", m_sql.c_str())); + return false; + } + return true; } // ====================================================================== @@ -609,7 +654,7 @@ bool DB::OCIQueryImpl::bindCol(BindableDouble &buffer) { BindRec *br=addBindRec(buffer); - m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, + if(!(m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, &(br->defnp), m_session->errhp, nextColumn++, @@ -619,15 +664,19 @@ bool DB::OCIQueryImpl::bindCol(BindableDouble &buffer) br->getIndicatorPointer(), br->getLengthPointer(), (ub2 *)0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind column of statement (by position) (BindableDouble) - %s", m_sql.c_str())); + } if (m_numElements > 1) { - m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, + if(!(m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, m_session->errhp, m_skipSize, br->getIndicatorSkipSize(), br->getLengthSkipSize(), - 0)); + 0)))) { + LOG("DatabaseError", ("Could not bind column of statement (by array) (BindableDouble) - %s", m_sql.c_str())); + } } return true; } @@ -638,7 +687,7 @@ bool DB::OCIQueryImpl::bindParameter(BindableDouble &buffer) { BindRec *br=addBindRec(buffer); - return m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, + if(!(m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, &(br->bindp), m_session->errhp, nextParameter++, @@ -650,7 +699,11 @@ bool DB::OCIQueryImpl::bindParameter(BindableDouble &buffer) 0, 0, 0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind parameter of statement (by position) (BindableDouble) - %s", m_sql.c_str())); + return false; + } + return true; } // ---------------------------------------------------------------------- @@ -659,7 +712,7 @@ bool DB::OCIQueryImpl::bindCol(BindableBool &buffer) { BindRec *br=addBindRec(buffer); - m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, + if(!(m_server->checkerr(*m_session, OCIDefineByPos(m_cursorhp, &(br->defnp), m_session->errhp, nextColumn++, @@ -669,16 +722,20 @@ bool DB::OCIQueryImpl::bindCol(BindableBool &buffer) br->getIndicatorPointer(), br->getLengthPointer(), (ub2 *)0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind column of statement (by position) (BindableBool) - %s", m_sql.c_str())); + } if (m_numElements > 1) { - m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, + if(!(m_server->checkerr(*m_session, OCIDefineArrayOfStruct(br->defnp, m_session->errhp, m_skipSize, br->getIndicatorSkipSize(), br->getLengthSkipSize(), - 0)); + 0)))) { + LOG("DatabaseError", ("Could not bind column of statement (by array) (BindableBool) - %s", m_sql.c_str())); + } } return true; } @@ -690,7 +747,7 @@ bool DB::OCIQueryImpl::bindParameter(BindableBool &buffer) BindRec *br=addBindRec(buffer); br->stringAdjust=true; - return m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, + if(!(m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, &(br->bindp), m_session->errhp, nextParameter++, @@ -702,7 +759,11 @@ bool DB::OCIQueryImpl::bindParameter(BindableBool &buffer) 0, 0, 0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind parameter of statement (by array) (BindableBool) - %s", m_sql.c_str())); + return false; + } + return true; } // ---------------------------------------------------------------------- @@ -711,7 +772,7 @@ bool DB::OCIQueryImpl::bindParameter(BindableVarray &buffer) { BindRec *br=addBindRec(buffer); - bool result = m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, + if(!(m_server->checkerr(*m_session, OCIBindByPos (m_stmthp, &(br->bindp), m_session->errhp, nextParameter++, @@ -723,18 +784,22 @@ bool DB::OCIQueryImpl::bindParameter(BindableVarray &buffer) 0, 0, 0, - OCI_DEFAULT)); + OCI_DEFAULT)))) { + LOG("DatabaseError", ("Could not bind parameter of statement (by array) (BindableVarray) - %s", m_sql.c_str())); + return false; + } - if (!result) - return false; - - return m_server->checkerr(*m_session, OCIBindObject (br->bindp, + if(!(m_server->checkerr(*m_session, OCIBindObject (br->bindp, m_session->errhp, buffer.getTDO(), reinterpret_cast(buffer.getBuffer()), 0, 0, - 0)); + 0)))) { + LOG("DatabaseError", ("Could not bind parameter of statement (by object) (BindableVarray) - %s", m_sql.c_str())); + return false; + } + return true; } // ---------------------------------------------------------------------- diff --git a/engine/shared/library/sharedDatabaseInterface/src_oci/OciServer.cpp b/engine/shared/library/sharedDatabaseInterface/src_oci/OciServer.cpp index ed5d8ddf..9f821b53 100755 --- a/engine/shared/library/sharedDatabaseInterface/src_oci/OciServer.cpp +++ b/engine/shared/library/sharedDatabaseInterface/src_oci/OciServer.cpp @@ -79,7 +79,7 @@ bool DB::OCIServer::checkerr(OCISession const & session, int status) REPORT_LOG(true,("Database Error - %.*s\n", 512, errbuf)); return false; default: - FATAL(true,("Unhandled Database Error - %.*s\n", 512, errbuf)); + REPORT_LOG(true,("Unhandled Database Error - %.*s\n", 512, errbuf)); break; } diff --git a/engine/shared/library/sharedDatabaseInterface/src_oci/OciSession.cpp b/engine/shared/library/sharedDatabaseInterface/src_oci/OciSession.cpp index f1fee154..e5d6ecbe 100755 --- a/engine/shared/library/sharedDatabaseInterface/src_oci/OciSession.cpp +++ b/engine/shared/library/sharedDatabaseInterface/src_oci/OciSession.cpp @@ -97,6 +97,7 @@ bool DB::OCISession::connect() if (! connected) { ++retryCount; + LOG("DatabaseError", ("Could not connect to the database (DSN=%s) after %d attempts.", m_server->getDSN(), retryCount)); DEBUG_REPORT_LOG(retryCount<5,("Retrying database connection\n")); Os::sleep(1000); } @@ -140,6 +141,7 @@ bool DB::OCISession::connect() } else { + LOG("DatabaseError", ("Invalid password provided when connecting to the database - disconnecting.")); disconnect(); // cleanup connected=false; } @@ -211,12 +213,20 @@ bool DB::OCISession::setAutoCommitMode(bool autocommit) bool DB::OCISession::commitTransaction() { m_okToFetch = false; - return m_server->checkerr(*this, OCITransCommit(svchp, errhp, 0)); + if(!(m_server->checkerr(*this, OCITransCommit(svchp, errhp, 0)))) { + LOG("DatabaseError", ("Unable to commit transaction.")); + return false; + } + return true; } bool DB::OCISession::rollbackTransaction() { - return m_server->checkerr(*this, OCITransRollback(svchp, errhp, 0)); + if(!(m_server->checkerr(*this, OCITransRollback(svchp, errhp, 0)))) { + LOG("DatabaseError", ("Unable to rollback transaction.")); + return false; + } + return true; } bool DB::OCISession::reset() diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.cpp index 2b08edf0..43caa07d 100755 --- a/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.cpp +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.cpp @@ -50,7 +50,7 @@ bool ResourceTypeQuery::addData(DBSchema::ResourceTypeRow const & data) if (!m_resource_classes.push_back(data.resource_class.getValueASCII())) return false; if (!m_attributes.push_back(data.attributes.getValueASCII())) return false; if (!m_fractal_seeds.push_back(data.fractal_seeds.getValueASCII())) return false; - if (!m_depleted_timestamps.push_back(data.depleted_timestamp.isNull(), static_cast(data.depleted_timestamp.getValue()))) return false; + if (!m_depleted_timestamps.push_back(data.depleted_timestamp.isNull(), static_cast(data.depleted_timestamp.getValue()))) return false; m_numItems=m_numItems.getValue() + 1; return true;