2019-04-04 Fred Gleason <fredg@paravelsystems.com>

* Fixed a bug in rddbmgr(8) that could cause database corruption
	when altering a table's charset/collation.
This commit is contained in:
Fred Gleason 2019-04-04 14:06:28 -04:00
parent b88565a115
commit 7bfa5c12d9
5 changed files with 44 additions and 16 deletions

View File

@ -18571,3 +18571,6 @@
disallow invalid datetime values.
2019-04-03 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in rddbmgr(8) that broke schema reverting.
2019-04-04 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in rddbmgr(8) that could cause database corruption
when altering a table's charset/collation.

View File

@ -163,8 +163,9 @@ void MainObject::CheckTableAttributes()
(const char *)q->value(2).toString().toUtf8());
fflush(NULL);
if(UserResponse()) {
RewriteTable(q->value(0).toString(),charset,"utf8mb4",
"utf8mb4_general_ci");
RewriteTable(q->value(0).toString(),
charset,q->value(2).toString(),
"utf8mb4","utf8mb4_general_ci");
}
}
}
@ -199,7 +200,9 @@ void MainObject::CheckTableAttributes()
}
void MainObject::RewriteTable(const QString &tblname,const QString &old_charset,
void MainObject::RewriteTable(const QString &tblname,
const QString &old_charset,
const QString &old_collation,
const QString &new_charset,
const QString &new_collation)
{
@ -210,6 +213,7 @@ void MainObject::RewriteTable(const QString &tblname,const QString &old_charset,
return;
}
QString filename=tempdir+"/table.sql";
QString temp_filename=tempdir+"/table-temp.sql";
QString out_filename=tempdir+"/table-out.sql";
/*
printf("table \"%s\" using: %s\n",
@ -236,11 +240,23 @@ void MainObject::RewriteTable(const QString &tblname,const QString &old_charset,
delete proc;
//
// Modify Dump
// Modify COLLATION
//
args.clear();
args.push_back("s/"+old_collation+"/"+new_collation+"/g");
args.push_back(filename);
proc=new QProcess(this);
proc->setStandardOutputFile(temp_filename);
proc->start("sed",args);
proc->waitForFinished(-1);
delete proc;
//
// Modify CHARSET
//
args.clear();
args.push_back("s/"+old_charset+"/"+new_charset+"/g");
args.push_back(filename);
args.push_back(temp_filename);
proc=new QProcess(this);
proc->setStandardOutputFile(out_filename);
proc->start("sed",args);
@ -267,6 +283,7 @@ void MainObject::RewriteTable(const QString &tblname,const QString &old_charset,
// Clean Up
//
unlink(filename.toUtf8());
unlink(temp_filename.toUtf8());
unlink(out_filename.toUtf8());
rmdir(tempdir);
}

View File

@ -88,7 +88,8 @@ bool MainObject::ModifyCharset(const QString &charset,
QStringList f0=q->value(1).toString().split("_");
QString prev_charset=f0.at(0);
if(q->value(1).toString().toLower()!=collation) {
RewriteTable(q->value(0).toString(),prev_charset,charset,collation);
RewriteTable(q->value(0).toString(),
prev_charset,q->value(1).toString(),charset,collation);
}
}
delete q;

View File

@ -42,7 +42,9 @@ class MainObject : public QObject
//
bool Check(QString *err_msg);
void CheckTableAttributes();
void RewriteTable(const QString &tblname,const QString &old_charset,
void RewriteTable(const QString &tblname,
const QString &old_charset,
const QString &old_collation,
const QString &new_charset,
const QString &new_collation);
void RelinkAudio(const QString &srcdir) const;

View File

@ -2320,6 +2320,8 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg)
q1=new RDSqlQuery(sql,false);
while(q1->next()) {
sql=QString("insert into `")+tablename+"` set "+
"SOURCE=0,"+
"TIME_TYPE=0,"+
QString().sprintf("ID=%d,",1+q1->value(0).toInt())+
QString().sprintf("COUNT=%d,",q1->value(0).toInt())+
QString().sprintf("TYPE=%d,",q1->value(1).toInt())+
@ -2397,6 +2399,8 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg)
q1=new RDSqlQuery(sql,false);
while(q1->next()) {
sql=QString("insert into `")+tablename+"` set "+
"SOURCE=0,"+
"TIME_TYPE=0,"+
QString().sprintf("ID=%d,",1+q1->value(0).toInt())+
QString().sprintf("COUNT=%d,",q1->value(0).toInt())+
QString().sprintf("TYPE=%d,",q1->value(1).toInt())+
@ -2528,17 +2532,17 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg)
"ISRC=\""+RDEscapeString(q1->value(17).toString())+"\","+
"ISCI=\""+RDEscapeString(q1->value(18).toString())+"\","+
"STATION_NAME=\""+RDEscapeString(q1->value(19).toString())+"\","+
"EVENT_DATETIME=\""+RDEscapeString(q1->value(20).toDateTime().
toString("yyyy-MM-dd hh:mm:ss"))+"\","+
"SCHEDULED_TIME=\""+RDEscapeString(q1->value(21).toTime().
toString("hh:mm:ss"))+"\","+
"EVENT_DATETIME="+
RDCheckDateTime(q1->value(20).toDateTime(),"yyyy-MM-dd hh:mm:ss")+","+
"SCHEDULED_TIME="+
RDCheckDateTime(q1->value(21).toTime(),"hh:mm:ss")+","+
QString().sprintf("EVENT_TYPE=%d,",q1->value(22).toInt())+
QString().sprintf("EVENT_SOURCE=%d,",q1->value(23).toInt())+
QString().sprintf("PLAY_SOURCE=%d,",q1->value(24).toInt())+
QString().sprintf("START_SOURCE=%d,",q1->value(25).toInt())+
"ONAIR_FLAG=\""+RDEscapeString(q1->value(26).toString())+"\","+
"EXT_START_TIME=\""+RDEscapeString(q1->value(27).toTime().
toString("hh:mm:ss"))+"\","+
"EXT_START_TIME="+
RDCheckDateTime(q1->value(27).toTime(),"hh:mm:ss")+","+
QString().sprintf("EXT_LENGTH=%d,",q1->value(28).toInt())+
"EXT_CART_NAME=\""+RDEscapeString(q1->value(29).toString())+"\","+
"EXT_DATA=\""+RDEscapeString(q1->value(30).toString())+"\","+
@ -2687,8 +2691,8 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg)
"COMMENT=\""+RDEscapeString(q1->value(21).toString())+"\","+
"LABEL=\""+RDEscapeString(q1->value(22).toString())+"\","+
"ORIGIN_USER=\""+RDEscapeString(q1->value(23).toString())+"\","+
"ORIGIN_DATETIME=\""+q1->value(24).toDateTime().
toString("yyyy-MM-dd hh:mm:ss")+"\","+
"ORIGIN_DATETIME="+
RDCheckDateTime(q1->value(24).toDateTime(),"yyyy-MM-dd hh:mm:ss")+","+
QString().sprintf("EVENT_LENGTH=%d,",q1->value(25).toInt())+
"LINK_EVENT_NAME=\""+RDEscapeString(q1->value(26).toString())+"\","+
QString().sprintf("LINK_START_TIME=%d,",q1->value(27).toInt())+
@ -2697,7 +2701,8 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg)
QString().sprintf("LINK_END_SLOP=%d,",q1->value(30).toInt())+
QString().sprintf("LINK_ID=%d,",q1->value(31).toInt())+
"LINK_EMBEDDED=\""+RDEscapeString(q1->value(32).toString())+"\","+
"EXT_START_TIME=\""+q1->value(33).toTime().toString("hh:mm:ss")+"\","+
"EXT_START_TIME="+
RDCheckDateTime(q1->value(33).toTime(),"hh:mm:ss")+","+
QString().sprintf("EXT_LENGTH=%d,",q1->value(34).toInt())+
"EXT_CART_NAME=\""+RDEscapeString(q1->value(35).toString())+"\","+
"EXT_DATA=\""+RDEscapeString(q1->value(36).toString())+"\","+