Skip to content

Commit

Permalink
PrimarySubdivisions starts working
Browse files Browse the repository at this point in the history
  • Loading branch information
d authored and d committed Jun 28, 2024
1 parent 84c9b0d commit b25cd2f
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 44 deletions.
93 changes: 77 additions & 16 deletions src/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ bool DataBase::createDataBase()
return false;
}


if (!createTableSubdivision(true))
if (!createTablePrimarySubdivisions(true))
return false;


Expand Down Expand Up @@ -968,8 +967,7 @@ bool DataBase::createTableAwardWAZ()
}



bool DataBase::createTableSubdivision(const bool NoTmp)
bool DataBase::createTablePrimarySubdivisions(const bool NoTmp)
{
// NoTmp = false => TMP data table to operate and be deleted afterwards
//qDebug() << Q_FUNC_INFO ;
Expand Down Expand Up @@ -1027,6 +1025,53 @@ bool DataBase::createTableSubdivision(const bool NoTmp)
//qDebug() << Q_FUNC_INFO << " - END" ;
}

bool DataBase::populateTablePrimarySubdivisions(const bool NoTmp)
{
if (!doesEntityTablehaveData())
return false;
DB_ADIF_Primary_Subdvisions_data primarySubDivisions(Q_FUNC_INFO);
return primarySubDivisions.addData();
}

bool DataBase::recreateTablePrimarySubdivisions()
{
qDebug() << Q_FUNC_INFO ;
QSqlQuery query;

if (isTheTableExisting("primary_subdivisions"))
{
if (execQuery(Q_FUNC_INFO, "DROP TABLE primary_subdivisions"))
{
if (createTablePrimarySubdivisions(true))
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table created" ;
return populateTablePrimarySubdivisions(true);
}
else
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table NOT created" ;
}
}
else
{
return false;//qDebug() << Q_FUNC_INFO << ": execQuery FAILED" ;
}
}
else
{
if (createTablePrimarySubdivisions(true))
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table created" ;
return populateTablePrimarySubdivisions(true);
}
else
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table NOT created" ;
}
}
//qDebug() << Q_FUNC_INFO << ": END FALSE" ;
return false;
}

int DataBase::getBandIdFromName(const QString &b)
{
Expand Down Expand Up @@ -2093,33 +2138,32 @@ bool DataBase::recreateSatelliteData()
{
if (createTableSatellites(true))
{
//qDebug() << "DataBase::recreateSatelliteData SAT table created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table created" ;
return populateTableSatellites(true);
}
else
{
//qDebug() << "DataBase::recreateSatelliteData SAT table NOT created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table NOT created" ;
}
}
else
{
//qDebug() << "DataBase::recreateSatelliteData execQuery FAILED" ;
//qDebug() << Q_FUNC_INFO << ": execQuery FAILED" ;
}
}
else
{
if (createTableSatellites(true))
{
//qDebug() << "DataBase::recreateSatelliteData SAT table created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table created" ;
return populateTableSatellites(true);
}
else
{
//qDebug() << "DataBase::recreateSatelliteData SAT table NOT created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table NOT created" ;
}
}

//qDebug() << "DataBase::recreateSatelliteData END FALSE" ;
//qDebug() << Q_FUNC_INFO << ": END FALSE" ;
return false;
}

Expand Down Expand Up @@ -2269,18 +2313,18 @@ bool DataBase::createTableLogs(const bool real)
{ // NoTmp = false => TMP data table to operate and be deleted afterwards
//Creating the Sats DB to be able to include satellites to the LOTW

//qDebug() << "DataBase::createTableLogs" ;
qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(real);

QString stringQuery = QString();
//QSqlQuery query;
if (real)
{
//qDebug() << "DataBase::createTableLogs - logs" ;
qDebug() << Q_FUNC_INFO << " - logs" ;
stringQuery = "CREATE TABLE logs" ;
}
else
{
//qDebug() << "DataBase::createTableLogs - logstemp" ;
qDebug() << Q_FUNC_INFO << " - logstemp" ;
stringQuery = "CREATE TABLE logstemp" ;
}

Expand All @@ -2296,7 +2340,7 @@ bool DataBase::createTableLogs(const bool real)



//qDebug() << "DataBase::createTableLogs - END" ;
qDebug() << Q_FUNC_INFO << " - END" ;

return execQuery(Q_FUNC_INFO, stringQuery);
}
Expand Down Expand Up @@ -4973,6 +5017,21 @@ bool DataBase::updateEntity (const QString &_codeString, const int _code)
return execQuery(Q_FUNC_INFO, sq);
}

bool DataBase::doesEntityTablehaveData()
{

QString sq = QString("SELECT COUNT(id) FROM entity");
QSqlQuery query;
if (!query.exec(sq))
return false;
else if(!query.next())
return false;
else if (!query.isValid())
return false;

return ((query.value(0)).toInt() > 0);
}

bool DataBase::isTheTableExisting(const QString &_tableName)
{
QSqlQuery query;
Expand Down Expand Up @@ -5709,7 +5768,9 @@ bool DataBase::updateTo018()

// Now I am in the previous version and I can update the DB.

if (!createTableSubdivision(true))
//if (recreateTablePrimarySubdivisions())
// return false;
if (!createTablePrimarySubdivisions(true))
return false;
DB_ADIF_Primary_Subdvisions_data primarySubDivisions(Q_FUNC_INFO);
if (!primarySubDivisions.addData())
Expand Down
6 changes: 5 additions & 1 deletion src/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ class DataBase : public QObject
int getNumberOfQsos(int _logNumber = -1);
int getLastInsertedQSO();
void setLogLevel (const DebugLogLevel _b);
bool populateTablePrimarySubdivisions(const bool NoTmp);
//private slots:
// void slotPrintErrors(QString _func, QString _msg, int _level);

private:
bool execQuery(const QString &function, const QString &stringQuery);
bool updateEntity (const QString &_codeString, const int _code);
bool doesEntityTablehaveData();
bool createDataBase();
bool setPragma(); // Defines the PRAGMA for the DB
bool isTheDBCreated();
Expand Down Expand Up @@ -187,7 +189,9 @@ class DataBase : public QObject
bool recreateTableWAZ();
bool createTableAwardWAZ();

bool createTableSubdivision(const bool NoTmp);
bool createTablePrimarySubdivisions(const bool NoTmp);

bool recreateTablePrimarySubdivisions();

bool recreateSatelliteData();
bool createTableSatellites(const bool NoTmp);
Expand Down
42 changes: 37 additions & 5 deletions src/database/db_adif_primary_subdvisions_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,43 @@ bool DB_ADIF_Primary_Subdvisions_data::addData()
"FOREIGN KEY (dxcc) REFERENCES entity (dxcc) )");
*/

qDebug() << Q_FUNC_INFO << " - Checking if DB exists";
if (!isDBCreated())
return false;
if (!add_EA6_21())

qDebug() << Q_FUNC_INFO << " - Adding 6";
if (!add_USA_6()) // Adds the data for Alaska
return false;
qDebug() << Q_FUNC_INFO << " - Adding 21";
if (!add_EA6_21()) // Adds the data for Balearic Is
return false;
qDebug() << Q_FUNC_INFO << " - Adding 29";
if (!add_EA8_29()) // Adds the data for Canary Is
return false;
qDebug() << Q_FUNC_INFO << " - Adding 32";
if (!add_EA9_32()) // Adds the data for Ceuta y Melilla
return false;
qDebug() << Q_FUNC_INFO << " - Adding 110";
if (!add_USA_110()) // Adds the data for Hawaii
return false;
qDebug() << Q_FUNC_INFO << " - Adding 149";
if (!add_CT_149()) // Adds the data for Azores
return false;
qDebug() << Q_FUNC_INFO << " - Adding 256";
if (!add_CT_256()) // Adds the data for Madeira
return false;
return add_EA_281();
qDebug() << Q_FUNC_INFO << " - Adding 272";
if (!add_CT_272()) // Adds the data for Portugal
return false;
qDebug() << Q_FUNC_INFO << " - Adding 281";
if (!add_EA_281()) // Adds the data for Spain
return false;
qDebug() << Q_FUNC_INFO << " - Adding 291";
if (!add_USA_291()) // Adds the data for United States of America
return false;


return true;
}

bool DB_ADIF_Primary_Subdvisions_data::isDBCreated()
Expand All @@ -52,7 +84,7 @@ bool DB_ADIF_Primary_Subdvisions_data::addValues(const QString &rows, const QStr

foreach (aux, values)
{
oneValue = QString("%1 (%2))").arg(sq).arg(aux);
oneValue = QString("%1 (%2)").arg(sq).arg(aux);
if (!exe.execQuery(Q_FUNC_INFO, oneValue))
return false;
}
Expand Down Expand Up @@ -88,7 +120,7 @@ bool DB_ADIF_Primary_Subdvisions_data::add_EA6_21()
return addValues(rows, values);
}

bool DB_ADIF_Primary_Subdvisions_data::add_EA6_29()
bool DB_ADIF_Primary_Subdvisions_data::add_EA8_29()
{
// This function contains the Primary Subdivision data for Canary island
// Source of data is https://www.adif.org (version 3.1.4)
Expand All @@ -105,7 +137,7 @@ bool DB_ADIF_Primary_Subdvisions_data::add_EA6_29()
return addValues(rows, values);
}

bool DB_ADIF_Primary_Subdvisions_data::add_EA6_32()
bool DB_ADIF_Primary_Subdvisions_data::add_EA9_32()
{
// This function contains the Primary Subdivision data for Ceuta & Melilla
// Source of data is https://www.adif.org (version 3.1.4)
Expand Down
4 changes: 2 additions & 2 deletions src/database/db_adif_primary_subdvisions_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class DB_ADIF_Primary_Subdvisions_data : public QObject
bool addValues(const QString &rows, const QStringList &values);
bool add_USA_6(); // Adds the data for Alaska
bool add_EA6_21(); // Adds the data for Balearic Is
bool add_EA6_29(); // Adds the data for Canary Is
bool add_EA6_32(); // Adds the data for Ceuta y Melilla
bool add_EA8_29(); // Adds the data for Canary Is
bool add_EA9_32(); // Adds the data for Ceuta y Melilla
bool add_EA_281(); // Adds the data for Spain
bool add_USA_110(); // Adds the data for Hawaii
bool add_CT_149(); // Adds the data for Azores
Expand Down
9 changes: 4 additions & 5 deletions src/database/queryexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ void QueryExecutor::queryErrorManagement(const QString &_functionFailed, const Q
Q_UNUSED(errorCodeS);
Q_UNUSED(_nativeError);
Q_UNUSED(_failedQuery);
//qDebug() << Q_FUNC_INFO << ": constrid : " << QString::number(constrid) ;
//qDebug() << Q_FUNC_INFO << ": Function : " << _functionFailed ;
//qDebug() << Q_FUNC_INFO << ": Native : " << _nativeError ;
//qDebug() << Q_FUNC_INFO << ": Error : " << _functionFailed << errorCodeS ;
//qDebug() << Q_FUNC_INFO << ": Query failed: " << _failedQuery ;
qDebug() << Q_FUNC_INFO << ": Function : " << _functionFailed ;
qDebug() << Q_FUNC_INFO << ": Native : " << _nativeError ;
qDebug() << Q_FUNC_INFO << ": Error : " << _functionFailed << errorCodeS ;
qDebug() << Q_FUNC_INFO << ": Query failed: " << _failedQuery ;
}

bool QueryExecutor::execQuery(const QString &function, const QString &stringQuery)
Expand Down
Loading

0 comments on commit b25cd2f

Please sign in to comment.