Skip to content

Commit

Permalink
Build listEntries table in SQL file for #71
Browse files Browse the repository at this point in the history
  • Loading branch information
jteresco committed Jun 25, 2024
1 parent b5694a9 commit a4d1d07
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const size_t DBFieldLength::systemFullName = 60;
const size_t DBFieldLength::systemName = 10;
const size_t DBFieldLength::traveler = 48;
const size_t DBFieldLength::updateText = 1024;
const size_t DBFieldLength::listDescription = 1024;
// sums of other constants
const size_t DBFieldLength::countryRegion = DBFieldLength::countryName + DBFieldLength::regionName + 3;
const size_t DBFieldLength::dcErrValue = DBFieldLength::root + DBFieldLength::label + 1;;
1 change: 1 addition & 0 deletions siteupdate/cplusplus/classes/DBFieldLength/DBFieldLength.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DBFieldLength
static const size_t systemName;
static const size_t traveler;
static const size_t updateText;
static const size_t listDescription;
// sums of other constants
static const size_t countryRegion;
static const size_t dcErrValue;
Expand Down
30 changes: 30 additions & 0 deletions siteupdate/cplusplus/functions/sql_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void sqlfile1
sqlfile << "DROP TABLE IF EXISTS clinchedRoutes;\n";
sqlfile << "DROP TABLE IF EXISTS clinchedOverallMileageByRegion;\n";
sqlfile << "DROP TABLE IF EXISTS clinchedSystemMileageByRegion;\n";
sqlfile << "DROP TABLE IF EXISTS listEntries;\n";
sqlfile << "DROP TABLE IF EXISTS overallMileageByRegion;\n";
sqlfile << "DROP TABLE IF EXISTS systemMileageByRegion;\n";
sqlfile << "DROP TABLE IF EXISTS clinched;\n";
Expand Down Expand Up @@ -389,6 +390,35 @@ void sqlfile1
sqlfile << ";\n";
}

// list entries
#ifndef threading_enabled
std::cout << et->et() << "...listEntries" << std::endl;
#endif
sqlfile << "CREATE TABLE listEntries (traveler VARCHAR(" << DBFieldLength::traveler
<< "), description VARCHAR(" << DBFieldLength::listDescription
<< "), includeInRanks BOOLEAN);\n";
sqlfile << "INSERT INTO listEntries VALUES\n";
first = 1;
for (TravelerList& t : TravelerList::allusers)
{ if (!first) sqlfile << ',';
first = 0;
// look for this traveler in the listinfo map
auto it = TravelerList::listinfo.find(t.traveler_name);
// if found, use the description and includeInRanks values from the map
if (it != TravelerList::listinfo.end())
{ sqlfile << "('" << t.traveler_name << "','" << double_quotes(it->second[0]) << "'," << (it->second[1] == "1" ? "TRUE" : "FALSE") << ")\n";
// remove it from the map
TravelerList::listinfo.erase(it);
}
else
{ // use the defaults
sqlfile << "('" << t.traveler_name << "','" << double_quotes(TravelerList::defaults[0]) << "'," << (TravelerList::defaults[1] == "1" ? "TRUE" : "FALSE") << ")\n";
}
}
sqlfile << ";\n";

// report any remaining entries in the listinfo map as errors (TODO)

// updates entries
#ifndef threading_enabled
std::cout << et->et() << "...updates" << std::endl;
Expand Down

0 comments on commit a4d1d07

Please sign in to comment.