Commit 2540882e authored by phenigma's avatar phenigma

Refs #2648 - automatically fix fields with non-utf8 charsets.

parent dbd78655
......@@ -2683,7 +2683,7 @@ void Table::ValidateTable()
StringUtils::Tokenize(sInput," ",vectString2);
string sFieldName = vectString2[0];
cout << "**** Fixing datetime field of column " << sFieldName << ", in table `" << m_sName << "`" << endl;
cout << "**** Fixing datetime field of column " << sFieldName << ", in table `" << m_sName << "`" << endl;
std::ostringstream sSQL;
sSQL << "UPDATE `" << m_sName << "` set " << sFieldName << "='1970-01-01 00:00:00' WHERE " << sFieldName << "=0";
m_pDatabase->threaded_mysql_query( sSQL.str() );
......@@ -2694,76 +2694,28 @@ cout << "**** Fixing datetime field of column " << sFieldName << ", in table `"
sSQL3 << "UPDATE `" << m_sName << "` set " << sFieldName << "=NULL WHERE " << sFieldName << "='1970-01-01 00:00:00' OR " << sFieldName << "=0";
m_pDatabase->threaded_mysql_query( sSQL3.str() );
}
/*
if( it->find("`Modification_LastGen`")!=string::npos )
{
if( it->find("0000-00-00 00:00:00")!=string::npos )
{
std::ostringstream sSQL;
sSQL << "ALTER TABLE `" << m_sName << "` MODIFY COLUMN `Modification_LastGen` datetime NULL default NULL";
m_pDatabase->threaded_mysql_query( sSQL.str() );
}
std::ostringstream sSQL2;
sSQL2 << "UPDATE `" << m_sName << "` set Modification_LastGen=NULL WHERE Modification_LastGen=0 OR Modification_LastGen='1970-01-01 00:00:00'";
m_pDatabase->threaded_mysql_query( sSQL2.str() );
break;
}
if( it->find("`AutoGeneratedDate`")!=string::npos )
{
if( it->find("0000-00-00 00:00:00")!=string::npos )
{
std::ostringstream sSQL;
sSQL << "ALTER TABLE `" << m_sName << "` MODIFY COLUMN `AutoGeneratedDate` datetime NULL default NULL";
m_pDatabase->threaded_mysql_query( sSQL.str() );
}
std::ostringstream sSQL2;
sSQL2 << "UPDATE `" << m_sName << "` set AutoGeneratedDate=NULL WHERE AutoGeneratedDate=0 OR AutoGeneratedDate='1970-01-01 00:00:00'";
m_pDatabase->threaded_mysql_query( sSQL2.str() );
break;
}
if( it->find("`DetectionTime`")!=string::npos )
{
if( it->find("0000-00-00 00:00:00")!=string::npos )
{
std::ostringstream sSQL;
sSQL << "ALTER TABLE `" << m_sName << "` MODIFY COLUMN `DetectionTime` datetime NULL default NULL";
m_pDatabase->threaded_mysql_query( sSQL.str() );
}
std::ostringstream sSQL2;
sSQL2 << "UPDATE `" << m_sName << "` set DetectionTime=NULL WHERE DetectionTime=0 OR DetectionTime='1970-01-01 00:00:00'";
m_pDatabase->threaded_mysql_query( sSQL2.str() );
break;
}
if( it->find("`ChangeTime`")!=string::npos )
if( it->find("CHARACTER SET")!=string::npos )
{
if( it->find("0000-00-00 00:00:00")!=string::npos )
{
std::ostringstream sSQL;
sSQL << "ALTER TABLE `" << m_sName << "` MODIFY COLUMN `ChangeTime` datetime NULL default NULL";
m_pDatabase->threaded_mysql_query( sSQL.str() );
}
std::ostringstream sSQL2;
sSQL2 << "UPDATE `" << m_sName << "` set ChangeTime=NULL WHERE ChangeTime=0 OR ChangeTime='1970-01-01 00:00:00'";
m_pDatabase->threaded_mysql_query( sSQL2.str() );
break;
}
if( it->find("`NotificationTime`")!=string::npos )
{
if( it->find("0000-00-00 00:00:00")!=string::npos )
{
std::ostringstream sSQL;
sSQL << "ALTER TABLE `" << m_sName << "` MODIFY COLUMN `NotificationTime` datetime NULL default NULL";
m_pDatabase->threaded_mysql_query( sSQL.str() );
}
std::ostringstream sSQL2;
sSQL2 << "UPDATE `" << m_sName << "` set NotificationTime=NULL WHERE NotificationTime=0 OR NotificationTime='1970-01-01 00:00:00'";
m_pDatabase->threaded_mysql_query( sSQL2.str() );
break;
vector<string> vectString2;
string sInput = *it;
StringUtils::Tokenize(sInput," ",vectString2);
string sFieldName = vectString2[0];
cout << "**** Fixing character set field of column " << sFieldName << ", in table `" << m_sName << "`" << endl;
size_t stBegin = it->find("CHARACTER SET");
size_t stEnd = it->find_first_of(" ", stBegin+14) + 1;
it->erase(stBegin, stEnd-stBegin);
std::ostringstream sSQL;
it->resize(it->size()-1);
sSQL << "ALTER TABLE `" << m_sName << "` MODIFY COLUMN " << *it;
//cout << "**** " << sSQL.str() << endl;
m_pDatabase->threaded_mysql_query( sSQL.str() );
}
*/
if( it->find("ENGINE=")!=string::npos && it->find("CHARSET=utf8")==string::npos )
{
cout << "**** Fixing charset in table `" << m_sName << "`" << endl;
cout << "**** Fixing charset in table `" << m_sName << "`" << endl;
// Increase the IP address field size in psc_ tables
std::ostringstream sSQL;
sSQL << "ALTER TABLE `" << m_sName << "` CHARACTER SET utf8";
......@@ -2771,7 +2723,7 @@ cout << "**** Fixing charset in table `" << m_sName << "`" << endl;
}
if( m_sName.find("psc_")!=string::npos && m_sName.rfind("bathdr")!=string::npos && it->find("IPAddress")!=string::npos && it->find("varchar(50)")==string::npos)
{
cout << "**** Fixing IPAddress field in table `" << m_sName << "`" << endl;
cout << "**** Fixing IPAddress field in table `" << m_sName << "`" << endl;
// Increase the IP address field size in psc_ tables
std::ostringstream sSQL;
sSQL << "ALTER TABLE `" << m_sName << "` MODIFY COLUMN `IPAddress` varchar(50) DEFAULT NULL";
......@@ -2781,7 +2733,7 @@ cout << "**** Fixing IPAddress field in table `" << m_sName << "`" << endl;
{
if( it->find("ON UPDATE CURRENT_TIMESTAMP")==string::npos || it->find("timestamp NULL")==string::npos )
{
cout << "**** Fixing timestamp field of column `psc_mod`, in table `" << m_sName << "`" << endl;
cout << "**** Fixing timestamp field of column `psc_mod`, in table `" << m_sName << "`" << endl;
std::ostringstream sSQL;
sSQL << "UPDATE `" << m_sName << "` set psc_mod='1970-01-01 00:00:00' WHERE psc_mod=0";
m_pDatabase->threaded_mysql_query( sSQL.str() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment