2018-07-07 Fred Gleason <fredg@paravelsystems.com>

* Added a 'CLOCK_LINES' table to the database.
	* Incremented the database version to 291.
	* Removed the 'RDClock::tableName()' method.
This commit is contained in:
Fred Gleason
2018-07-06 13:52:35 -04:00
parent bd5bd2246b
commit 0c17eb841a
15 changed files with 185 additions and 86 deletions

View File

@@ -24,7 +24,7 @@
/*
* Current Database Version
*/
#define RD_VERSION_DATABASE 290
#define RD_VERSION_DATABASE 291
#endif // DBVERSION_H

View File

@@ -2,7 +2,7 @@
//
// Abstract a Rivendell Log Manager Clock.
//
// (C) Copyright 2002-2004,2008,2016 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2004,2008,2016-2018 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@@ -40,8 +40,6 @@ QString RDClock::name() const
void RDClock::setName(const QString &name)
{
clock_name=name;
clock_name_esc=name;
clock_name_esc.replace(" ","_");
}
@@ -151,9 +149,13 @@ bool RDClock::load()
clock_remarks=q->value(3).toString();
delete q;
sql=QString().sprintf("select EVENT_NAME,START_TIME,LENGTH from %s_CLK\
order by ID",
(const char *)clock_name_esc);
sql=QString("select ")+
"EVENT_NAME,"+ // 00
"START_TIME,"+ // 01
"LENGTH "+ // 02
"from CLOCK_LINES where "+
"CLOCK_NAME=\""+RDEscapeString(clock_name)+"\" "+
"order by START_TIME";
q=new RDSqlQuery(sql);
while(q->next()) {
clock_events.push_back(RDEventLine());
@@ -186,7 +188,8 @@ bool RDClock::save()
(const char *)clock_name);
q=new RDSqlQuery(sql);
delete q;
sql=QString().sprintf("delete from %s_CLK",(const char *)clock_name_esc);
sql=QString("delete from CLOCK_LINES where ")+
"CLOCK_NAME=\""+RDEscapeString(clock_name)+"\"";
q=new RDSqlQuery(sql);
delete q;
}
@@ -204,17 +207,16 @@ bool RDClock::save()
q=new RDSqlQuery(sql);
delete q;
}
sql=QString().sprintf("delete from %s_CLK",
(const char *)clock_name_esc);
sql=QString("delete from CLOCK_LINES where ")+
"CLOCK_NAME=\""+RDEscapeString(clock_name)+"\"";
q=new RDSqlQuery(sql);
delete q;
for(unsigned i=0;i<clock_events.size();i++) {
sql=QString().sprintf("insert into %s_CLK set EVENT_NAME=\"%s\",\
START_TIME=%d,LENGTH=%d",
(const char *)clock_name_esc,
(const char *)clock_events[i].name(),
QTime().msecsTo(clock_events[i].startTime()),
clock_events[i].length());
sql=QString("insert into CLOCK_LINES set ")+
"CLOCK_NAME=\""+RDEscapeString(clock_name)+"\","+
"EVENT_NAME=\""+RDEscapeString(clock_events[i].name())+"\","+
QString().sprintf("START_TIME=%d,",QTime().msecsTo(clock_events[i].startTime()))+
QString().sprintf("LENGTH=%d",clock_events[i].length());
q=new RDSqlQuery(sql);
delete q;
}
@@ -307,29 +309,23 @@ bool RDClock::generateLog(int hour,const QString &logname,
RDSqlQuery *q;
RDEventLine eventline;
sql=QString().sprintf("select EVENT_NAME,START_TIME,LENGTH from %s_CLK\
order by START_TIME",
(const char *)clock_name_esc);
sql=QString("select ")+
"EVENT_NAME,"+ // 00
"START_TIME,"+ // 01
"LENGTH "+ // 02
"from CLOCK_LINES where "+
"CLOCK_NAME=\""+RDEscapeString(clock_name)+"\" "+
"order by START_TIME";
q=new RDSqlQuery(sql);
while(q->next()) {
eventline.setName(q->value(0).toString());
eventline.load();
// eventline.setStartTime(q->value(1).toTime().addSecs(3600*hour));
eventline.setStartTime(QTime().addMSecs(q->value(1).toInt()).
addSecs(3600*hour));
eventline.setLength(q->value(2).toInt());
eventline.generateLog(logname,svc_name,errors,artistsep,clock_name_esc);
eventline.generateLog(logname,svc_name,errors,artistsep,clock_name);
eventline.clear();
}
delete q;
return true;
}
QString RDClock::tableName(const QString &name)
{
QString ret=name;
ret.replace(" ","_");
return ret+"_CLK";
}

View File

@@ -2,7 +2,7 @@
//
// Abstract a Rivendell Log Manager Clock
//
// (C) Copyright 2002-2004,2016 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2004,2016-2018 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@@ -55,11 +55,9 @@ class RDClock
bool validate(const QTime &start_time,int length,int except_line=-1);
bool generateLog(int hour,const QString &logname,const QString &svc_name,
QString *errors);
static QString tableName(const QString &name);
private:
QString clock_name;
QString clock_name_esc;
QString clock_short_name;
QColor clock_color;
QString clock_remarks;
@@ -68,4 +66,4 @@ class RDClock
bool rules_modified;
};
#endif
#endif // RDCLOCK_H

View File

@@ -33,7 +33,7 @@ void RDCreateLogTable(const QString &name,RDConfig *config)
delete q;
}
*/
/*
QString RDCreateLogTableSql(QString name,RDConfig *config)
{
return QString("create table if not exists `")+name+"`"+
@@ -81,8 +81,8 @@ QString RDCreateLogTableSql(QString name,RDConfig *config)
"index LABEL_IDX (LABEL))"+
config->createTablePostfix();
}
*/
/*
QString RDCreateClockTableSql(QString name,RDConfig *config)
{
return QString("create table `")+name+"` ("+
@@ -93,7 +93,7 @@ QString RDCreateClockTableSql(QString name,RDConfig *config)
"INDEX EVENT_NAME_IDX (EVENT_NAME))"+
config->createTablePostfix();
}
*/
/*
QString RDCreateReconciliationTableSql(QString name,RDConfig *config)
{

View File

@@ -24,8 +24,8 @@
#define RDCREATE_LOG_H
//void RDCreateLogTable(const QString &name,RDConfig *config);
QString RDCreateLogTableSql(QString name,RDConfig *config);
QString RDCreateClockTableSql(QString name,RDConfig *config);
//QString RDCreateLogTableSql(QString name,RDConfig *config);
//QString RDCreateClockTableSql(QString name,RDConfig *config);
//QString RDCreateReconciliationTableSql(QString name,RDConfig *config);
QString RDCreateStackTableSql(QString name,RDConfig *config);