From 84430a10ef81060b677e84fdf97a43e7653de930 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 31 May 2018 19:11:16 +0000 Subject: [PATCH] 2018-05-31 Fred Gleason * Refactored table drops to use 'RDApplication::dropTable()'. --- ChangeLog | 2 ++ lib/rdfeedlog.cpp | 15 ++++++------- lib/rdlog.cpp | 7 +++--- lib/rdlog_event.cpp | 5 ++--- lib/rdreport.cpp | 26 +++++++++------------- lib/rdsvc.cpp | 42 ++++++++++++++---------------------- rdadmin/list_feeds.cpp | 8 ++----- rdadmin/rdadmin.cpp | 7 +----- rdadmin/test_import.cpp | 5 +---- rdlogmanager/edit_clock.cpp | 4 +--- rdlogmanager/edit_event.cpp | 9 +++----- rdlogmanager/list_clocks.cpp | 12 +++-------- rdlogmanager/list_events.cpp | 17 ++++++--------- 13 files changed, 58 insertions(+), 101 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc5dbba3..85cd65bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17000,3 +17000,5 @@ be generated with the incorrect sample rate. 2018-05-31 Fred Gleason * Cleaned up SQL errors in rdadmin(1). +2018-05-31 Fred Gleason + * Refactored table drops to use 'RDApplication::dropTable()'. diff --git a/lib/rdfeedlog.cpp b/lib/rdfeedlog.cpp index dd9b388e..17079366 100644 --- a/lib/rdfeedlog.cpp +++ b/lib/rdfeedlog.cpp @@ -2,7 +2,7 @@ // // Functions for manipulating RSS feed log tables. // -// (C) Copyright 2007,2016 Fred Gleason +// (C) Copyright 2007,2016-2018 Fred Gleason // // 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 @@ -20,9 +20,11 @@ #include -#include +#include #include -#include +#include + +#include "rdfeedlog.h" void RDCreateFeedLog(QString keyname) { @@ -44,13 +46,8 @@ void RDCreateFeedLog(QString keyname) void RDDeleteFeedLog(QString keyname) { - QString sql; - RDSqlQuery *q; - keyname.replace(" ","_"); - sql=QString().sprintf("drop table %s_FLG",(const char *)keyname); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(keyname+"_FLG"); } diff --git a/lib/rdlog.cpp b/lib/rdlog.cpp index 80ab1d0f..de9ad665 100644 --- a/lib/rdlog.cpp +++ b/lib/rdlog.cpp @@ -20,6 +20,7 @@ #include +#include "rdapplication.h" #include "rddb.h" #include "rdconf.h" #include "rdcreate_log.h" @@ -354,9 +355,9 @@ bool RDLog::remove(RDStation *station,RDUser *user,RDConfig *config) const if(removeTracks(station,user,config)<0) { return false; } - sql=QString("drop table `")+RDLog::tableName(log_name)+"`"; - q=new RDSqlQuery(sql); - delete q; + + rda->dropTable(RDLog::tableName(log_name)); + sql=QString().sprintf("delete from LOGS where (NAME=\"%s\" && TYPE=0)", (const char *)RDEscapeString(log_name)); q=new RDSqlQuery(sql); diff --git a/lib/rdlog_event.cpp b/lib/rdlog_event.cpp index 341a2853..9b4ded78 100644 --- a/lib/rdlog_event.cpp +++ b/lib/rdlog_event.cpp @@ -19,6 +19,7 @@ // #include +#include #include #include #include @@ -150,9 +151,7 @@ void RDLogEvent::save(RDConfig *config,bool update_tracks,int line) } if(line<0) { if(exists()) { - sql=QString().sprintf("drop table `%s`",(const char *)log_name); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(log_name); } RDCreateLogTable(log_name,config); if (log_line.size() > 0) { diff --git a/lib/rdreport.cpp b/lib/rdreport.cpp index 5baf050f..c434473a 100644 --- a/lib/rdreport.cpp +++ b/lib/rdreport.cpp @@ -2,7 +2,7 @@ // // Abstract a Rivendell Report Descriptor // -// (C) Copyright 2002-2004,2016 Fred Gleason +// (C) Copyright 2002-2004,2016-2018 Fred Gleason // // 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 @@ -23,14 +23,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "rdapplication.h" +#include "rdconf.h" +#include "rdcreate_log.h" +#include "rddatedecode.h" +#include "rdescape_string.h" +#include "rdlog_line.h" +#include "rdreport.h" RDReport::RDReport(const QString &rptname,RDStation *station,RDConfig *config, QObject *parent) @@ -437,10 +436,7 @@ bool RDReport::generateReport(const QDate &startdate,const QDate &enddate, // Create Table // QString mixname="MIXDOWN"+station->name(); - sql=QString("drop table `")+mixname+"_SRT`"; - QSqlQuery *p; - p=new QSqlQuery(sql); - delete p; + rda->dropTable(mixname+"_SRT"); sql=RDCreateReconciliationTableSql(mixname+"_SRT",report_config); q=new RDSqlQuery(sql); delete q; @@ -696,9 +692,7 @@ bool RDReport::generateReport(const QDate &startdate,const QDate &enddate, #endif system(post_cmd); // printf("MIXDOWN TABLE: %s_SRT\n",(const char *)mixname); - sql=QString().sprintf("drop table `%s_SRT`",(const char *)mixname); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(mixname+"_SRT"); return ret; } diff --git a/lib/rdsvc.cpp b/lib/rdsvc.cpp index b5312b86..226fed22 100644 --- a/lib/rdsvc.cpp +++ b/lib/rdsvc.cpp @@ -2,7 +2,7 @@ // // Abstract a Rivendell Service. // -// (C) Copyright 2002-2004,2016-2017 Fred Gleason +// (C) Copyright 2002-2004,2016-2018 Fred Gleason // // 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 @@ -20,17 +20,17 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "rdapplication.h" +#include "rdclock.h" +#include "rdconf.h" +#include "rdcreate_log.h" +#include "rddatedecode.h" +#include "rddb.h" +#include "rd.h" +#include "rdescape_string.h" +#include "rdlog.h" +#include "rdsvc.h" +#include "rdweb.h" // // Global Classes @@ -516,10 +516,7 @@ bool RDSvc::import(ImportSource src,const QDate &date,const QString &break_str, // // Setup Data Source and Destination // - sql=QString().sprintf("drop table `%s`",(const char *)dest_table); - QSqlQuery *qq; // Use QSqlQuery so we don't generate a - qq=new QSqlQuery(sql); // spurious error message. - delete qq; + rda->dropTable(dest_table); sql=QString("create table ")+ "`"+dest_table+"` ("+ "ID int primary key,"+ @@ -976,9 +973,7 @@ bool RDSvc::linkLog(RDSvc::ImportSource src,const QDate &date, delete dest_event; // printf("Import Table: %s\n",(const char *)import_name); - sql=QString().sprintf("drop table `%s`",(const char *)import_name); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(import_name); delete log_lock; return true; @@ -1399,7 +1394,6 @@ void RDSvc::remove(const QString &name) { QString sql; RDSqlQuery *q; - RDSqlQuery *q1; QString logname; sql=QString("delete from AUDIO_PERMS where ")+ @@ -1454,12 +1448,8 @@ void RDSvc::remove(const QString &name) while(q->next()) { logname=q->value(0).toString(); logname.replace(" ","_"); - sql=QString("drop table `")+RDLog::tableName(logname)+"`"; - q1=new RDSqlQuery(sql); - delete q1; - sql=QString().sprintf("drop table `%s_REC`",(const char *)logname); - q1=new RDSqlQuery(sql); - delete q1; + rda->dropTable(RDLog::tableName(logname)); + rda->dropTable(logname+"_REC"); } delete q; diff --git a/rdadmin/list_feeds.cpp b/rdadmin/list_feeds.cpp index 9d434909..89c7a14d 100644 --- a/rdadmin/list_feeds.cpp +++ b/rdadmin/list_feeds.cpp @@ -173,9 +173,7 @@ void ListFeeds::addData() delete q; RDDeleteFeedLog(feed); feed.replace(" ","_"); - sql=QString().sprintf("drop table %s_FIELDS",(const char *)feed); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(feed+"_FIELDS"); delete edit_feed; return; } @@ -278,9 +276,7 @@ void ListFeeds::deleteData() delete q; RDDeleteFeedLog(feedname); feedname.replace(" ","_"); - sql=QString().sprintf("drop table %s_FIELDS",(const char *)feedname); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(feedname+"_FIELDS"); item->setSelected(false); pd->reset(); diff --git a/rdadmin/rdadmin.cpp b/rdadmin/rdadmin.cpp index 0ab9e692..5092f74d 100644 --- a/rdadmin/rdadmin.cpp +++ b/rdadmin/rdadmin.cpp @@ -512,15 +512,10 @@ void MainWidget::quitMainWidget() void MainWidget::ClearTables() { - RDSqlQuery *q1; - QString sql="show tables"; RDSqlQuery *q=new RDSqlQuery(sql); while(q->next()) { - sql=QString().sprintf("drop table %s", - (const char *)q->value(0).toString()); - q1=new RDSqlQuery(sql); - delete q1; + rda->dropTable(q->value(0).toString()); } delete q; } diff --git a/rdadmin/test_import.cpp b/rdadmin/test_import.cpp index dd7928f3..37ad2d6c 100644 --- a/rdadmin/test_import.cpp +++ b/rdadmin/test_import.cpp @@ -245,10 +245,7 @@ void TestImport::importData() } delete q; // printf("IMPORT TABLE: %s_TEST_IMP\n",(const char *)test_svc->name()); - sql=QString().sprintf("drop table `%s_TEST_IMP`", - (const char *)test_svc->name()); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(test_svc->name()+"_TEST_IMP"); } diff --git a/rdlogmanager/edit_clock.cpp b/rdlogmanager/edit_clock.cpp index 27f2b956..327d882a 100644 --- a/rdlogmanager/edit_clock.cpp +++ b/rdlogmanager/edit_clock.cpp @@ -771,9 +771,7 @@ void EditClock::AbandonClock(QString name) RDSqlQuery *q=new RDSqlQuery(sql); delete q; - sql=QString("drop table `")+RDClock::tableName(name)+"`"; - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(RDClock::tableName(name)); } diff --git a/rdlogmanager/edit_event.cpp b/rdlogmanager/edit_event.cpp index 98de6874..6b682db0 100644 --- a/rdlogmanager/edit_event.cpp +++ b/rdlogmanager/edit_event.cpp @@ -1654,10 +1654,7 @@ void EditEvent::AbandonEvent(QString name) (const char *)RDEscapeString(name)); q=new RDSqlQuery(sql); delete q; - sql=QString("drop table `")+RDEvent::preimportTableName(name)+"`"; - q=new RDSqlQuery(sql); - delete q; - sql=QString("drop table `")+RDEvent::postimportTableName(name)+"`"; - q=new RDSqlQuery(sql); - delete q; + + rda->dropTable(RDEvent::preimportTableName(name)); + rda->dropTable(RDEvent::postimportTableName(name)); } diff --git a/rdlogmanager/list_clocks.cpp b/rdlogmanager/list_clocks.cpp index 0a1d48ff..b4a8e7ed 100644 --- a/rdlogmanager/list_clocks.cpp +++ b/rdlogmanager/list_clocks.cpp @@ -251,9 +251,7 @@ void ListClocks::addData() clockname_esc=clockname; clockname_esc.replace(" ","_"); clockname_esc+="_CLK"; - sql=QString().sprintf("drop table %s",(const char *)clockname_esc); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(clockname_esc); sql=QString().sprintf("delete from CLOCKS where NAME=\"%s\"", (const char *)clockname); q=new RDSqlQuery(sql); @@ -633,12 +631,8 @@ void ListClocks::DeleteClock(QString clockname) (const char *)clockname); q=new RDSqlQuery(sql); delete q; - sql=QString().sprintf("drop table %s_CLK",(const char *)base_name); - q=new RDSqlQuery(sql); - delete q; - sql=QString().sprintf("drop table %s_RULES",(const char *)base_name); - q=new RDSqlQuery(sql); - delete q; + rda->dropTable(base_name+"_CLK"); + rda->dropTable(base_name+"_RULES"); } diff --git a/rdlogmanager/list_events.cpp b/rdlogmanager/list_events.cpp index bbf0ee00..d2ffcece 100644 --- a/rdlogmanager/list_events.cpp +++ b/rdlogmanager/list_events.cpp @@ -32,11 +32,11 @@ #include #include -#include -#include -#include -#include -#include +#include "add_event.h" +#include "edit_event.h" +#include "globals.h" +#include "list_events.h" +#include "rename_item.h" ListEvents::ListEvents(QString *eventname,QWidget *parent) : QDialog(parent,"",true) @@ -598,11 +598,8 @@ void ListEvents::DeleteEvent(QString event_name) (const char *)event_name); q=new RDSqlQuery(sql); delete q; - sql=QString().sprintf("drop table %s_PRE",(const char *)base_name); - q=new RDSqlQuery(sql); - delete q; - sql=QString().sprintf("drop table %s_POST",(const char *)base_name); - q=new RDSqlQuery(sql); + rda->dropTable(base_name+"_PRE"); + rda->dropTable(base_name+"_POST"); }