2018-08-16 Fred Gleason <fredg@paravelsystems.com>

* Added table rewriting when converting tables to a different
	character set in rddbmgr(8).
This commit is contained in:
Fred Gleason 2018-08-16 19:25:50 +00:00
parent c7335075f2
commit 110fdf856f
6 changed files with 96 additions and 12 deletions

View File

@ -17452,3 +17452,6 @@
2018-08-16 Fred Gleason <fredg@paravelsystems.com>
* Fixed a rendering error in the 'Edit RDAirPlay dialog in
rdadmin(1).
2018-08-16 Fred Gleason <fredg@paravelsystems.com>
* Added table rewriting when converting tables to a different
character set in rddbmgr(8).

View File

@ -926,8 +926,8 @@ QString RDCartDialog::StateFile() {
void RDCartDialog::LoadState()
{
QString state_file = StateFile();
if (state_file == NULL) {
QString state_file=StateFile();
if (state_file.isEmpty()) {
return;
}
@ -945,8 +945,8 @@ void RDCartDialog::SaveState()
{
FILE *f=NULL;
QString state_file = StateFile();
if (state_file == NULL) {
QString state_file=StateFile();
if (state_file.isEmpty()) {
return;
}

View File

@ -961,6 +961,14 @@ QString RDHomeDir()
}
QString RDTempDir()
{
char path[PATH_MAX]="/tmp/rddbmgrXXXXXX";
return QString(mkdtemp(path));
}
QString RDTempFile()
{
#ifndef WIN32

View File

@ -100,6 +100,7 @@ QString RDGetHomeDir(bool *found=0);
bool RDTimeSynced();
QString RDTruncateAfterWord(QString str,int word,bool add_dots=false);
QString RDHomeDir();
QString RDTempDir();
QString RDTempFile();
QString RDTimeZoneName(const QDateTime &datetime);
QString RDDowCode(int dow);

View File

@ -26,10 +26,12 @@
#include <sys/types.h>
#include <qdir.h>
#include <qprocess.h>
#include <dbversion.h>
#include <rdcart.h>
#include <rdclock.h>
#include <rdconf.h>
#include <rdcut.h>
#include <rddb.h>
#include <rdescape_string.h>
@ -39,7 +41,7 @@
#include "rddbmgr.h"
bool MainObject::Check(QString *err_msg) const
bool MainObject::Check(QString *err_msg)
{
if(GetCurrentSchema()!=RD_VERSION_DATABASE) {
*err_msg="unsupported schema for checking";
@ -124,7 +126,7 @@ bool MainObject::Check(QString *err_msg) const
}
void MainObject::CheckTableAttributes() const
void MainObject::CheckTableAttributes()
{
QString sql;
RDSqlQuery *q;
@ -163,10 +165,8 @@ void MainObject::CheckTableAttributes() const
(const char *)db_mysql_collation.toUtf8());
fflush(NULL);
if(UserResponse()) {
sql=QString("alter table `")+q->value(0).toString()+"` "+
"character set "+db_mysql_charset+" "+
"collate "+db_mysql_collation;
RDSqlQuery::apply(sql);
RewriteTable(q->value(0).toString(),charset,db_mysql_charset,
db_mysql_collation);
}
}
}
@ -204,6 +204,75 @@ void MainObject::CheckTableAttributes() const
}
void MainObject::RewriteTable(const QString &tblname,const QString &old_charset,
const QString &new_charset,
const QString &new_collation)
{
QProcess *proc=NULL;
QStringList args;
QString tempdir=RDTempDir();
if(tempdir.isEmpty()) {
return;
}
QString filename=tempdir+"/table.sql";
QString out_filename=tempdir+"/table-out.sql";
printf("using: %s\n",(const char *)tempdir.toUtf8());
//
// Dump Table
//
args.clear();
args.push_back("--opt");
args.push_back("-h");
args.push_back(db_mysql_hostname);
args.push_back("-u");
args.push_back(db_mysql_loginname);
args.push_back("-p"+db_mysql_password);
args.push_back(db_mysql_database);
args.push_back(tblname);
proc=new QProcess(this);
proc->setStandardOutputFile(filename);
proc->start("mysqldump",args);
proc->waitForFinished(-1);
delete proc;
//
// Modify Dump
//
args.clear();
args.push_back("s/"+old_charset+"/"+new_charset+"/g");
args.push_back(filename);
proc=new QProcess(this);
proc->setStandardOutputFile(out_filename);
proc->start("sed",args);
proc->waitForFinished(-1);
delete proc;
//
// Push Back Modified Table
//
args.clear();
args.push_back("-h");
args.push_back(db_mysql_hostname);
args.push_back("-u");
args.push_back(db_mysql_loginname);
args.push_back("-p"+db_mysql_password);
args.push_back(db_mysql_database);
proc=new QProcess(this);
proc->setStandardInputFile(out_filename);
proc->start("mysql",args);
proc->waitForFinished(-1);
delete proc;
//
// Clean Up
//
unlink(filename.toUtf8());
unlink(out_filename.toUtf8());
rmdir(tempdir);
}
void MainObject::RelinkAudio(const QString &srcdir) const
{
QString sql;

View File

@ -40,8 +40,11 @@ class MainObject : public QObject
//
// check.cpp
//
bool Check(QString *err_msg) const;
void CheckTableAttributes() const;
bool Check(QString *err_msg);
void CheckTableAttributes();
void RewriteTable(const QString &tblname,const QString &old_charset,
const QString &new_charset,
const QString &new_collation);
void RelinkAudio(const QString &srcdir) const;
void CheckOrphanedTracks() const;
void CheckCutCounts() const;