mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-11-26 15:20:29 +01:00
2020-12-07 Fred Gleason <fredg@paravelsystems.com>
* Added a 'RDCart::ensureTitleIsUnique()' static method. * Removed code to make cart titles automatically unique from 'RDCart::setTitle()'. * Refactored rdimport(1) to allow detection of duplicate titles. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
@@ -212,7 +212,7 @@ QString RDCart::title() const
|
||||
|
||||
void RDCart::setTitle(const QString &title)
|
||||
{
|
||||
SetRow("TITLE",VerifyTitle(title));
|
||||
SetRow("TITLE",title);
|
||||
metadata_changed=true;
|
||||
}
|
||||
|
||||
@@ -943,7 +943,7 @@ void RDCart::setMetadata(const RDWaveData *data)
|
||||
{
|
||||
QString sql="update CART set ";
|
||||
if(!data->title().isEmpty()) {
|
||||
sql+=QString("TITLE=\"")+RDEscapeString(VerifyTitle(data->title()))+"\",";
|
||||
sql+=QString("TITLE=\"")+RDEscapeString(data->title())+"\",";
|
||||
}
|
||||
if(!data->artist().isEmpty()) {
|
||||
sql+=QString("ARTIST=\"")+RDEscapeString(data->artist())+"\",";
|
||||
@@ -2153,6 +2153,34 @@ bool RDCart::titleIsUnique(unsigned except_cartnum,const QString &str)
|
||||
}
|
||||
|
||||
|
||||
QString RDCart::ensureTitleIsUnique(unsigned except_cartnum,
|
||||
const QString &str)
|
||||
{
|
||||
QString ret=str;
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
int n=1;
|
||||
|
||||
while(n<1000000) {
|
||||
sql=QString("select ")+
|
||||
"NUMBER "+ // 00
|
||||
"from CART where "+
|
||||
"(TITLE=\""+RDEscapeString(ret)+"\") && "+
|
||||
QString().sprintf("(NUMBER!=%u)",except_cartnum);
|
||||
q=new RDSqlQuery(sql);
|
||||
if(!q->first()) {
|
||||
delete q;
|
||||
return ret;
|
||||
}
|
||||
delete q;
|
||||
ret=str+QString().sprintf(" [%d]",n++);
|
||||
}
|
||||
|
||||
return QString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
QVariant RDCart::GetXmlValue(const QString &tag,const QString &line)
|
||||
{
|
||||
bool ok=false;
|
||||
@@ -2310,33 +2338,6 @@ RDCut::Validity RDCart::ValidateCut(RDSqlQuery *q,bool enforce_length,
|
||||
}
|
||||
|
||||
|
||||
QString RDCart::VerifyTitle(const QString &title) const
|
||||
{
|
||||
QString ret=title;
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
RDSystem *system=new RDSystem();
|
||||
|
||||
if(!system->allowDuplicateCartTitles()) {
|
||||
int n=1;
|
||||
while(1==1) {
|
||||
sql=QString("select NUMBER from CART where ")+
|
||||
"(TITLE=\""+RDEscapeString(ret)+"\")&&"+
|
||||
QString().sprintf("(NUMBER!=%u)",cart_number);
|
||||
q=new RDSqlQuery(sql);
|
||||
if(!q->first()) {
|
||||
delete q;
|
||||
return ret;
|
||||
}
|
||||
delete q;
|
||||
ret=title+QString().sprintf(" [%d]",n++);
|
||||
}
|
||||
}
|
||||
delete system;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void RDCart::SetRow(const QString ¶m,const QString &value) const
|
||||
{
|
||||
RDSqlQuery *q;
|
||||
|
||||
@@ -173,6 +173,8 @@ class RDCart
|
||||
static unsigned readXml(std::vector<RDWaveData> *data,const QString &xml);
|
||||
static QString uniqueCartTitle(unsigned cartnum=0);
|
||||
static bool titleIsUnique(unsigned except_cartnum,const QString &str);
|
||||
static QString ensureTitleIsUnique(unsigned except_cartnum,
|
||||
const QString &str);
|
||||
|
||||
private:
|
||||
static QVariant GetXmlValue(const QString &tag,const QString &line);
|
||||
@@ -180,8 +182,6 @@ class RDCart
|
||||
int GetNextFreeCut() const;
|
||||
RDCut::Validity ValidateCut(RDSqlQuery *q,bool enforce_length,
|
||||
unsigned length,bool *time_ok) const;
|
||||
QString VerifyTitle(const QString &title) const;
|
||||
|
||||
void SetRow(const QString ¶m,const QString &value) const;
|
||||
void SetRow(const QString ¶m,unsigned value) const;
|
||||
void SetRow(const QString ¶m,const QDateTime &value) const;
|
||||
|
||||
Reference in New Issue
Block a user