mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-24 09:28:54 +02:00
Most files are simple swaps to get rid of extra " as a NULL return will give invalid SQL if used as follows UPDATE x SET y="NULL"; See github issue 121 for more info. Extra changes have been made to the following files: * lib/rdcartslot.cpp - Added a QDateTime variable to prevent EVENT_DATETIME becoming "2016-06-09" "NULL" as it was checked separately for date and time * lib/rdcut.cpp - Reworked START_DATETIME and END_DATETIME to save the SQL ifs. I believe this makes it easier to read and understand. - The >QDate(1900,1,1) and < 8000 is probably not needed but I left it there just in case. * lib/rdescape_string.cpp - Reworked to add extra " if the date is not NULL see issue 121 * lib/rdfeed.cpp && lib/rdpodcast.cpp - Had to add a SetRow for QDateTime as with the string conversion the existing SetRow would add an extra set of " * lib/rdsound_panel.cpp && rdairplay/log_traffic.cpp && utils/rddgimport/rddgimport.cpp - Added a QString to contain EVENT_DATETIME to prevent double checks of date and time separately (similar to lib/rdcartslot.cpp) * rdcatchd/rdcatchd.cpp - Reverted the changes. The RML here is not touching the DB so is fine, plus with the RDCheckDateTime changes you'd have extra " unless it was NULL * tests/sas_switch_torture.cpp && sas_torture.cpp - Included missing rdescape_string.h
93 lines
3.9 KiB
C++
93 lines
3.9 KiB
C++
// log_traffic.cpp
|
|
//
|
|
// Add an entry to the reconciliation table.
|
|
//
|
|
// (C) Copyright 2002-2016 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
|
|
// published by the Free Software Foundation.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public
|
|
// License along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
//
|
|
|
|
#include <qsqldatabase.h>
|
|
|
|
#include <rdconf.h>
|
|
#include <rddb.h>
|
|
#include <rdescape_string.h>
|
|
#include <rdsvc.h>
|
|
|
|
#include <log_traffic.h>
|
|
#include <globals.h>
|
|
|
|
void LogTraffic(const QString &svcname,const QString &logname,
|
|
RDLogLine *logline,RDLogLine::PlaySource src,
|
|
RDAirPlayConf::TrafficAction action,bool onair_flag)
|
|
{
|
|
QString sql;
|
|
RDSqlQuery *q;
|
|
QDateTime datetime=QDateTime(QDate::currentDate(),QTime::currentTime());
|
|
int length=logline->startTime(RDLogLine::Actual).msecsTo(datetime.time());
|
|
if(length<0) { // Event crossed midnight!
|
|
length+=86400000;
|
|
datetime.setDate(datetime.date().addDays(-1));
|
|
}
|
|
|
|
if((logline==NULL)||(svcname.isEmpty())) {
|
|
return;
|
|
}
|
|
|
|
QString eventDateTimeSQL = "NULL";
|
|
|
|
if(datetime.isValid() && logline->startTime(RDLogLine::Actual).isValid())
|
|
eventDateTimeSQL = RDCheckDateTime(QDateTime(datetime.date(),
|
|
logline->startTime(RDLogLine::Actual)), "yyyy-MM-dd hh:mm:ss");
|
|
|
|
sql=QString("insert into `")+RDSvc::svcTableName(svcname)+"` set "+
|
|
QString().sprintf("LENGTH=%d,",length)+
|
|
"LOG_NAME=\""+RDEscapeString(logname.utf8())+"\","+
|
|
QString().sprintf("LOG_ID=%d,",logline->id())+
|
|
QString().sprintf("CART_NUMBER=%u,",logline->cartNumber())+
|
|
"STATION_NAME=\""+RDEscapeString(rdstation_conf->name().utf8())+"\","+
|
|
"EVENT_DATETIME="+eventDateTimeSQL+","+
|
|
QString().sprintf("EVENT_TYPE=%d,",action)+
|
|
QString().sprintf("EVENT_SOURCE=%d,",logline->source())+
|
|
"EXT_START_TIME=\""+RDCheckDateTime(logline->extStartTime(),"hh:mm:ss")+"\","+
|
|
QString().sprintf("EXT_LENGTH=%d,",logline->extLength())+
|
|
"EXT_DATA=\""+RDEscapeString(logline->extData())+"\","+
|
|
"EXT_EVENT_ID=\""+RDEscapeString(logline->extEventId())+"\","+
|
|
"EXT_ANNC_TYPE=\""+RDEscapeString(logline->extAnncType())+"\","+
|
|
QString().sprintf("PLAY_SOURCE=%d,",src)+
|
|
QString().sprintf("CUT_NUMBER=%d,",logline->cutNumber())+
|
|
"EXT_CART_NAME=\""+RDEscapeString(logline->extCartName().utf8())+"\","+
|
|
"TITLE=\""+RDEscapeString(logline->title().utf8())+"\","+
|
|
"ARTIST=\""+RDEscapeString(logline->artist().utf8())+"\","+
|
|
"SCHEDULED_TIME="+RDCheckDateTime(logline->startTime(RDLogLine::Logged),
|
|
"hh:mm:ss")+","+
|
|
"ISRC=\""+RDEscapeString(logline->isrc().utf8())+"\","+
|
|
"PUBLISHER=\""+RDEscapeString(logline->publisher().utf8())+"\","+
|
|
"COMPOSER=\""+RDEscapeString(logline->composer().utf8())+"\","+
|
|
QString().sprintf("USAGE_CODE=%d,",logline->usageCode())+
|
|
QString().sprintf("START_SOURCE=%d,",logline->startSource())+
|
|
"ONAIR_FLAG=\""+RDYesNo(onair_flag)+"\","+
|
|
"ALBUM=\""+RDEscapeString(logline->album().utf8())+"\","+
|
|
"LABEL=\""+RDEscapeString(logline->label().utf8())+"\","+
|
|
"USER_DEFINED=\""+RDEscapeString(logline->userDefined().utf8())+"\","+
|
|
"CONDUCTOR=\""+RDEscapeString(logline->conductor().utf8())+"\","+
|
|
"SONG_ID=\""+RDEscapeString(logline->songId().utf8())+"\","+
|
|
"DESCRIPTION=\""+RDEscapeString(logline->description().utf8())+"\","+
|
|
"OUTCUE=\""+RDEscapeString(logline->outcue().utf8())+"\","+
|
|
"ISCI=\""+RDEscapeString(logline->isci().utf8())+"\"";
|
|
|
|
q=new RDSqlQuery(sql);
|
|
delete q;
|
|
}
|