db_ido: Add idoutils 1.x schema, check required 1.10.0 version.

fixes #4766
This commit is contained in:
Michael Friedrich 2013-09-27 15:30:17 +02:00
parent 518f050544
commit e8bd81bddc
6 changed files with 1575 additions and 1 deletions

View File

@ -24,6 +24,7 @@
#include "db_ido/dbtype.h"
#include "db_ido/dbvalue.h"
#include "db_ido_mysql/idomysqlconnection.h"
#include <boost/exception/diagnostic_information.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
@ -37,6 +38,7 @@ void IdoMysqlConnection::Start(void)
DbConnection::Start();
m_Connected = false;
m_RequiredSchemaVersion = "1.10.0";
m_TxTimer = boost::make_shared<Timer>();
m_TxTimer->SetInterval(5);
@ -112,6 +114,20 @@ void IdoMysqlConnection::ReconnectTimerHandler(void)
m_Connected = true;
String dbVersionName = "idoutils";
Array::Ptr version_rows = Query("SELECT version FROM " + GetTablePrefix() + "dbversion WHERE name='" + Escape(dbVersionName) + "'");
if (version_rows->GetLength() == 0)
BOOST_THROW_EXCEPTION(std::runtime_error("Schema does not provide any valid version! Verify your schema installation."));
Dictionary::Ptr version_row = version_rows->Get(0);
String version = version_row->Get("version");
if (Utility::CompareVersion(m_RequiredSchemaVersion, version) < 0) {
BOOST_THROW_EXCEPTION(std::runtime_error("Schema version '" + version + "' does not match the required version '" +
m_RequiredSchemaVersion + "'! Please check the upgrade documentation."));
}
String instanceName = "default";
if (!m_InstanceName.IsEmpty())
@ -128,7 +144,7 @@ void IdoMysqlConnection::ReconnectTimerHandler(void)
}
std::ostringstream msgbuf;
msgbuf << "MySQL IDO instance id: " << static_cast<long>(m_InstanceID);
msgbuf << "MySQL IDO instance id: " << static_cast<long>(m_InstanceID) << " (schema version: '" + version + "')";
Log(LogInformation, "db_ido_mysql", msgbuf.str());
ClearConfigTables();

View File

@ -68,6 +68,8 @@ private:
bool m_Connected;
MYSQL m_Connection;
String m_RequiredSchemaVersion;
Timer::Ptr m_ReconnectTimer;
Timer::Ptr m_TxTimer;

File diff suppressed because it is too large Load Diff

View File

View File

@ -26,6 +26,8 @@
#include <boost/lexical_cast.hpp>
#include <boost/function.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#if HAVE_GCC_ABI_DEMANGLE
# include <cxxabi.h>
@ -562,3 +564,25 @@ unsigned long Utility::SDBM(const String& str)
return hash;
}
int Utility::CompareVersion(const String& v1, const String& v2)
{
std::vector<String> tokensv1, tokensv2;
boost::algorithm::split(tokensv1, v1, boost::is_any_of("."));
boost::algorithm::split(tokensv2, v2, boost::is_any_of("."));
for (int i = 0; i < tokensv2.size() - tokensv1.size(); i++)
tokensv1.push_back("0");
for (int i = 0; i < tokensv1.size() - tokensv2.size(); i++)
tokensv2.push_back("0");
for (size_t i = 0; i < tokensv1.size(); i++) {
if (Convert::ToLong(tokensv2[i]) > Convert::ToLong(tokensv1[i]))
return 1;
else if (Convert::ToLong(tokensv2[i]) < Convert::ToLong(tokensv1[i]))
return -1;
}
return 0;
}

View File

@ -97,6 +97,8 @@ public:
static unsigned long SDBM(const String& str);
static int CompareVersion(const String& v1, const String& v2);
private:
Utility(void);