LCOV - code coverage report
Current view: top level - EnergyPlus - SQLiteProcedures.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 95.1 % 1458 1386
Test Date: 2025-05-22 16:09:37 Functions: 96.8 % 124 120

            Line data    Source code
       1              : // EnergyPlus, Copyright (c) 1996-2025, The Board of Trustees of the University of Illinois,
       2              : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
       3              : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
       4              : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
       5              : // contributors. All rights reserved.
       6              : //
       7              : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
       8              : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
       9              : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
      10              : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
      11              : // derivative works, and perform publicly and display publicly, and to permit others to do so.
      12              : //
      13              : // Redistribution and use in source and binary forms, with or without modification, are permitted
      14              : // provided that the following conditions are met:
      15              : //
      16              : // (1) Redistributions of source code must retain the above copyright notice, this list of
      17              : //     conditions and the following disclaimer.
      18              : //
      19              : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
      20              : //     conditions and the following disclaimer in the documentation and/or other materials
      21              : //     provided with the distribution.
      22              : //
      23              : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
      24              : //     the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
      25              : //     used to endorse or promote products derived from this software without specific prior
      26              : //     written permission.
      27              : //
      28              : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
      29              : //     without changes from the version obtained under this License, or (ii) Licensee makes a
      30              : //     reference solely to the software portion of its product, Licensee must refer to the
      31              : //     software as "EnergyPlus version X" software, where "X" is the version number Licensee
      32              : //     obtained under this License and may not use a different name for the software. Except as
      33              : //     specifically required in this Section (4), Licensee shall not use in a company name, a
      34              : //     product name, in advertising, publicity, or other promotional activities any name, trade
      35              : //     name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
      36              : //     similar designation, without the U.S. Department of Energy's prior written consent.
      37              : //
      38              : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
      39              : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      40              : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      41              : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      42              : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      43              : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      44              : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      45              : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      46              : // POSSIBILITY OF SUCH DAMAGE.
      47              : 
      48              : // C++ headers
      49              : #include <ios>
      50              : #include <memory>
      51              : #include <sstream>
      52              : #include <stdexcept>
      53              : 
      54              : // EnergyPlus Headers
      55              : #include <EnergyPlus/Construction.hh>
      56              : #include <EnergyPlus/ConvectionConstants.hh>
      57              : #include <EnergyPlus/Data/EnergyPlusData.hh>
      58              : #include <EnergyPlus/DataEnvironment.hh>
      59              : #include <EnergyPlus/DataHeatBalance.hh>
      60              : #include <EnergyPlus/DataRoomAirModel.hh>
      61              : #include <EnergyPlus/DataStringGlobals.hh>
      62              : #include <EnergyPlus/FileSystem.hh>
      63              : #include <EnergyPlus/General.hh>
      64              : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      65              : #include <EnergyPlus/Material.hh>
      66              : #include <EnergyPlus/OutputReportTabular.hh>
      67              : #include <EnergyPlus/SQLiteProcedures.hh>
      68              : #include <EnergyPlus/ScheduleManager.hh>
      69              : #include <EnergyPlus/UtilityRoutines.hh>
      70              : 
      71              : namespace EnergyPlus {
      72              : 
      73              : constexpr std::array<int, (int)OutputProcessor::ReportFreq::Num> reportFreqInts = {
      74              :     -1, // EachCall
      75              :     0,  // TimeStep
      76              :     1,  // Hour
      77              :     2,  // Day
      78              :     3,  // Month
      79              :     4,  // Simulation
      80              :     5   // Year
      81              : };
      82              : 
      83              : const int SQLite::ReportNameId = 1;
      84              : const int SQLite::ReportForStringId = 2;
      85              : const int SQLite::TableNameId = 3;
      86              : const int SQLite::RowNameId = 4;
      87              : const int SQLite::ColumnNameId = 5;
      88              : const int SQLite::UnitsId = 6;
      89              : 
      90          115 : bool ParseSQLiteInput(EnergyPlusData &state, bool &writeOutputToSQLite, bool &writeTabularDataToSQLite)
      91              : {
      92          115 :     auto &ip = state.dataInputProcessing->inputProcessor;
      93          230 :     auto const instances = ip->epJSON.find("Output:SQLite");
      94          115 :     if (instances != ip->epJSON.end()) {
      95              : 
      96           22 :         auto find_input = [=, &state](nlohmann::json const &fields, std::string const &field_name) -> std::string {
      97           22 :             std::string input;
      98           22 :             auto found = fields.find(field_name);
      99           22 :             if (found != fields.end()) {
     100           14 :                 input = found.value().get<std::string>();
     101              :             } else {
     102           24 :                 state.dataInputProcessing->inputProcessor->getDefaultValue(state, "Output:SQLite", field_name, input);
     103              :             }
     104           44 :             return input;
     105            0 :         };
     106              : 
     107              :         // There can only be 1 "Output:SQLite"
     108           11 :         auto const instance = instances.value().begin();
     109           11 :         auto const &fields = instance.value();
     110           33 :         ip->markObjectAsUsed("Output:SQLite", instance.key());
     111              : 
     112              :         { // "option_type"
     113           11 :             std::string outputType = find_input(fields, "option_type");
     114           11 :             if ("SimpleAndTabular" == outputType) {
     115           10 :                 writeTabularDataToSQLite = true;
     116           10 :                 writeOutputToSQLite = true;
     117            1 :             } else if ("Simple" == outputType) {
     118            1 :                 writeTabularDataToSQLite = false;
     119            1 :                 writeOutputToSQLite = true;
     120              :             }
     121           11 :         }
     122              :         { // "unit_conversion_for_tabular_data"
     123           11 :             std::string tabularDataUnitConversion = find_input(fields, "unit_conversion_for_tabular_data");
     124           11 :             auto const &sql_ort = state.dataOutRptTab;
     125              : 
     126           11 :             if ("UseOutputControlTableStyles" == tabularDataUnitConversion) {
     127              :                 // Jan 2021 Note: Since here we do not know weather sql_ort->unitsStyle has been processed or not,
     128              :                 // the value "NotFound" is used for the option "UseOutputControlTableStyles" at this point;
     129              :                 // This will be updated again and got concretely assigned first thing in OutputReportTabular::WriteTabularReports().
     130            0 :                 sql_ort->unitsStyle_SQLite = OutputReportTabular::UnitsStyle::NotFound;
     131           11 :             } else if ("None" == tabularDataUnitConversion) {
     132            1 :                 sql_ort->unitsStyle_SQLite = OutputReportTabular::UnitsStyle::None;
     133           10 :             } else if ("JtoKWH" == tabularDataUnitConversion) {
     134            0 :                 sql_ort->unitsStyle_SQLite = OutputReportTabular::UnitsStyle::JtoKWH;
     135           10 :             } else if ("JtoMJ" == tabularDataUnitConversion) {
     136            0 :                 sql_ort->unitsStyle_SQLite = OutputReportTabular::UnitsStyle::JtoMJ;
     137           10 :             } else if ("JtoGJ" == tabularDataUnitConversion) {
     138            0 :                 sql_ort->unitsStyle_SQLite = OutputReportTabular::UnitsStyle::JtoGJ;
     139           10 :             } else if ("InchPound" == tabularDataUnitConversion) {
     140            1 :                 sql_ort->unitsStyle_SQLite = OutputReportTabular::UnitsStyle::InchPound;
     141            9 :             } else if ("InchPoundExceptElectricity" == tabularDataUnitConversion) {
     142            0 :                 sql_ort->unitsStyle_SQLite = OutputReportTabular::UnitsStyle::InchPoundExceptElectricity;
     143              :             }
     144           11 :         }
     145           11 :         return true;
     146              :     }
     147          104 :     return false;
     148              : }
     149              : 
     150           73 : std::unique_ptr<SQLite> CreateSQLiteDatabase(EnergyPlusData &state)
     151              : {
     152           73 :     if (!state.files.outputControl.sqlite) {
     153            2 :         return nullptr;
     154              :     }
     155              :     try {
     156           71 :         bool writeOutputToSQLite = false;
     157           71 :         bool writeTabularDataToSQLite = false;
     158           71 :         bool parsedSQLite = ParseSQLiteInput(state, writeOutputToSQLite, writeTabularDataToSQLite);
     159           71 :         if (!parsedSQLite) {
     160           68 :             state.files.outputControl.sqlite = false;
     161           68 :             return nullptr;
     162              :         }
     163            3 :         auto errorStream = std::make_shared<std::ofstream>(state.dataStrGlobals->outputSqliteErrFilePath, std::ofstream::out | std::ofstream::trunc);
     164              :         return std::make_unique<SQLite>(errorStream,
     165            6 :                                         state.dataStrGlobals->outputSqlFilePath,
     166            3 :                                         state.dataStrGlobals->outputSqliteErrFilePath,
     167              :                                         writeOutputToSQLite,
     168            3 :                                         writeTabularDataToSQLite);
     169            3 :     } catch (const std::runtime_error &error) {
     170            0 :         ShowFatalError(state, error.what());
     171            0 :         return nullptr;
     172            0 :     }
     173              : }
     174              : 
     175           73 : void CreateSQLiteZoneExtendedOutput(EnergyPlusData &state)
     176              : {
     177           73 :     if (state.dataSQLiteProcedures->sqlite && state.dataSQLiteProcedures->sqlite->writeOutputToSQLite()) {
     178           12 :         for (int zoneNum = 1; zoneNum <= state.dataGlobal->NumOfZones; ++zoneNum) {
     179            7 :             state.dataSQLiteProcedures->sqlite->addZoneData(zoneNum, state.dataHeatBal->Zone(zoneNum));
     180              :         }
     181            5 :         for (int listNum = 1; listNum <= state.dataHeatBal->NumOfZoneLists; ++listNum) {
     182            0 :             state.dataSQLiteProcedures->sqlite->addZoneListData(listNum, state.dataHeatBal->ZoneList(listNum));
     183              :         }
     184            5 :         for (int groupNum = 1; groupNum <= state.dataHeatBal->NumOfZoneGroups; ++groupNum) {
     185            0 :             state.dataSQLiteProcedures->sqlite->addZoneGroupData(groupNum, state.dataHeatBal->ZoneGroup(groupNum));
     186              :         }
     187           49 :         for (auto *sched : state.dataSched->schedules) {
     188           88 :             state.dataSQLiteProcedures->sqlite->addScheduleData(
     189              :                 sched->Num,
     190              :                 sched->Name,
     191          108 :                 (sched->schedTypeNum == -1) ? "" : state.dataSched->scheduleTypes[sched->schedTypeNum]->Name,
     192              :                 sched->getMinVal(state),
     193              :                 sched->getMaxVal(state));
     194              :         }
     195           52 :         for (int surfaceNumber = 1; surfaceNumber <= state.dataSurface->TotSurfaces; ++surfaceNumber) {
     196           47 :             auto const &surface = state.dataSurface->Surface(surfaceNumber);
     197           47 :             state.dataSQLiteProcedures->sqlite->addSurfaceData(surfaceNumber, surface, DataSurfaces::cSurfaceClass(surface.Class));
     198              :         }
     199           36 :         for (int materialNum = 1; materialNum <= state.dataMaterial->materials.isize(); ++materialNum) {
     200           31 :             state.dataSQLiteProcedures->sqlite->addMaterialData(materialNum, state.dataMaterial->materials(materialNum));
     201              :         }
     202           20 :         for (int constructNum = 1; constructNum <= state.dataHeatBal->TotConstructs; ++constructNum) {
     203           15 :             auto const &construction = state.dataConstruction->Construct(constructNum);
     204           15 :             if (construction.TotGlassLayers == 0) {
     205           12 :                 state.dataSQLiteProcedures->sqlite->addConstructionData(constructNum, construction, construction.UValue);
     206              :             } else {
     207            3 :                 state.dataSQLiteProcedures->sqlite->addConstructionData(constructNum, construction, state.dataHeatBal->NominalU(constructNum));
     208              :             }
     209              :         }
     210            9 :         for (int lightNum = 1; lightNum <= state.dataHeatBal->TotLights; ++lightNum) {
     211            4 :             state.dataSQLiteProcedures->sqlite->addNominalLightingData(lightNum, state.dataHeatBal->Lights(lightNum));
     212              :         }
     213            8 :         for (int peopleNum = 1; peopleNum <= state.dataHeatBal->TotPeople; ++peopleNum) {
     214            3 :             state.dataSQLiteProcedures->sqlite->addNominalPeopleData(peopleNum, state.dataHeatBal->People(peopleNum));
     215              :         }
     216           10 :         for (int elecEquipNum = 1; elecEquipNum <= state.dataHeatBal->TotElecEquip; ++elecEquipNum) {
     217            5 :             state.dataSQLiteProcedures->sqlite->addNominalElectricEquipmentData(elecEquipNum, state.dataHeatBal->ZoneElectric(elecEquipNum));
     218              :         }
     219            5 :         for (int gasEquipNum = 1; gasEquipNum <= state.dataHeatBal->TotGasEquip; ++gasEquipNum) {
     220            0 :             state.dataSQLiteProcedures->sqlite->addNominalGasEquipmentData(gasEquipNum, state.dataHeatBal->ZoneGas(gasEquipNum));
     221              :         }
     222            5 :         for (int steamEquipNum = 1; steamEquipNum <= state.dataHeatBal->TotStmEquip; ++steamEquipNum) {
     223            0 :             state.dataSQLiteProcedures->sqlite->addNominalSteamEquipmentData(steamEquipNum, state.dataHeatBal->ZoneSteamEq(steamEquipNum));
     224              :         }
     225            5 :         for (int hWEquipNum = 1; hWEquipNum <= state.dataHeatBal->TotHWEquip; ++hWEquipNum) {
     226            0 :             state.dataSQLiteProcedures->sqlite->addNominalHotWaterEquipmentData(hWEquipNum, state.dataHeatBal->ZoneHWEq(hWEquipNum));
     227              :         }
     228            5 :         for (int otherEquipNum = 1; otherEquipNum <= state.dataHeatBal->TotOthEquip; ++otherEquipNum) {
     229            0 :             state.dataSQLiteProcedures->sqlite->addNominalOtherEquipmentData(otherEquipNum, state.dataHeatBal->ZoneOtherEq(otherEquipNum));
     230              :         }
     231            5 :         for (int bBHeatNum = 1; bBHeatNum <= state.dataHeatBal->TotBBHeat; ++bBHeatNum) {
     232            0 :             state.dataSQLiteProcedures->sqlite->addNominalBaseboardData(bBHeatNum, state.dataHeatBal->ZoneBBHeat(bBHeatNum));
     233              :         }
     234            7 :         for (int infilNum = 1; infilNum <= state.dataHeatBal->TotInfiltration; ++infilNum) {
     235            2 :             state.dataSQLiteProcedures->sqlite->addInfiltrationData(infilNum, state.dataHeatBal->Infiltration(infilNum));
     236              :         }
     237            5 :         for (int ventNum = 1; ventNum <= state.dataHeatBal->TotVentilation; ++ventNum) {
     238            0 :             state.dataSQLiteProcedures->sqlite->addVentilationData(ventNum, state.dataHeatBal->Ventilation(ventNum));
     239              :         }
     240           12 :         for (int zoneNum = 1; zoneNum <= state.dataGlobal->NumOfZones; ++zoneNum) {
     241            7 :             state.dataSQLiteProcedures->sqlite->addRoomAirModelData(zoneNum, state.dataRoomAir->AirModel(zoneNum));
     242              :         }
     243              : 
     244            5 :         state.dataSQLiteProcedures->sqlite->createZoneExtendedOutput();
     245              :     }
     246           73 : }
     247              : 
     248          113 : SQLite::SQLite(std::shared_ptr<std::ostream> errorStream,
     249              :                fs::path const &dbName,
     250              :                fs::path const &errorFilePath,
     251              :                bool writeOutputToSQLite,
     252          113 :                bool writeTabularDataToSQLite)
     253          113 :     : SQLiteProcedures(errorStream, writeOutputToSQLite, dbName, errorFilePath), m_writeTabularDataToSQLite(writeTabularDataToSQLite),
     254          226 :       m_sqlDBTimeIndex(0), m_reportDataInsertStmt(nullptr), m_reportExtendedDataInsertStmt(nullptr), m_reportDictionaryInsertStmt(nullptr),
     255          113 :       m_timeIndexInsertStmt(nullptr), m_zoneInfoInsertStmt(nullptr), m_zoneInfoZoneListInsertStmt(nullptr), m_nominalLightingInsertStmt(nullptr),
     256          113 :       m_nominalElectricEquipmentInsertStmt(nullptr), m_nominalGasEquipmentInsertStmt(nullptr), m_nominalSteamEquipmentInsertStmt(nullptr),
     257          113 :       m_nominalHotWaterEquipmentInsertStmt(nullptr), m_nominalOtherEquipmentInsertStmt(nullptr), m_nominalBaseboardHeatInsertStmt(nullptr),
     258          113 :       m_surfaceInsertStmt(nullptr), m_constructionInsertStmt(nullptr), m_constructionLayerInsertStmt(nullptr), m_materialInsertStmt(nullptr),
     259          113 :       m_zoneListInsertStmt(nullptr), m_zoneGroupInsertStmt(nullptr), m_infiltrationInsertStmt(nullptr), m_ventilationInsertStmt(nullptr),
     260          113 :       m_nominalPeopleInsertStmt(nullptr), m_zoneSizingInsertStmt(nullptr), m_systemSizingInsertStmt(nullptr), m_componentSizingInsertStmt(nullptr),
     261          113 :       m_roomAirModelInsertStmt(nullptr), m_groundTemperatureInsertStmt(nullptr), m_weatherFileInsertStmt(nullptr), m_scheduleInsertStmt(nullptr),
     262          113 :       m_daylightMapTitleInsertStmt(nullptr), m_daylightMapHourlyTitleInsertStmt(nullptr), m_daylightMapHourlyDataInsertStmt(nullptr),
     263          113 :       m_environmentPeriodInsertStmt(nullptr), m_simulationsInsertStmt(nullptr), m_tabularDataInsertStmt(nullptr), m_stringsInsertStmt(nullptr),
     264          113 :       m_stringsLookUpStmt(nullptr), m_errorInsertStmt(nullptr), m_errorUpdateStmt(nullptr), m_simulationUpdateStmt(nullptr),
     265          113 :       m_simulationDataUpdateStmt(nullptr), m_rollbackToSavepointStmt(nullptr), m_createSavepointStmt(nullptr), m_releaseSavepointStmt(nullptr)
     266              : {
     267          113 :     if (m_writeOutputToSQLite) {
     268          113 :         sqliteExecuteCommand("PRAGMA locking_mode = EXCLUSIVE;");
     269          113 :         sqliteExecuteCommand("PRAGMA journal_mode = OFF;");
     270          113 :         sqliteExecuteCommand("PRAGMA synchronous = OFF;");
     271          113 :         sqliteExecuteCommand("PRAGMA encoding=\"UTF-8\";");
     272              : 
     273              :         // Turn this to ON for Foreign Key constraints.
     274              :         // This must be turned ON for every connection
     275              :         // Currently, inserting into daylighting tables does not work with this ON. The ZoneIndex referenced by DaylightMaps does not exist in
     276              :         // the database at the time data is inserted.
     277          113 :         sqliteExecuteCommand("PRAGMA foreign_keys = OFF;");
     278              : 
     279          113 :         initializeSimulationsTable();
     280          113 :         initializeEnvironmentPeriodsTable();
     281          113 :         initializeErrorsTable();
     282          113 :         initializeTimeIndicesTable();
     283          113 :         initializeZoneInfoTable();
     284          113 :         initializeZoneListTable();
     285          113 :         initializeZoneGroupTable();
     286          113 :         initializeZoneInfoZoneListTable();
     287          113 :         initializeSchedulesTable();
     288          113 :         initializeMaterialsTable();
     289          113 :         initializeConstructionsTables();
     290          113 :         initializeSurfacesTable();
     291          113 :         initializeReportDataDictionaryTable();
     292          113 :         initializeReportDataTables();
     293          113 :         initializeNominalPeopleTable();
     294          113 :         initializeNominalLightingTable();
     295          113 :         initializeNominalElectricEquipmentTable();
     296          113 :         initializeNominalGasEquipmentTable();
     297          113 :         initializeNominalSteamEquipmentTable();
     298          113 :         initializeNominalHotWaterEquipmentTable();
     299          113 :         initializeNominalOtherEquipmentTable();
     300          113 :         initializeNominalBaseboardHeatTable();
     301          113 :         initializeNominalInfiltrationTable();
     302          113 :         initializeNominalVentilationTable();
     303          113 :         initializeZoneSizingTable();
     304          113 :         initializeSystemSizingTable();
     305          113 :         initializeComponentSizingTable();
     306          113 :         initializeRoomAirModelTable();
     307          113 :         initializeDaylightMapTables();
     308          113 :         initializeViews();
     309              : 
     310          113 :         if (m_writeTabularDataToSQLite) {
     311          112 :             initializeTabularDataTable();
     312          112 :             initializeTabularDataView();
     313              :         }
     314              :     }
     315          113 : }
     316              : 
     317          226 : SQLite::~SQLite()
     318              : {
     319          113 :     sqlite3_finalize(m_reportDataInsertStmt);
     320          113 :     sqlite3_finalize(m_reportExtendedDataInsertStmt);
     321          113 :     sqlite3_finalize(m_reportDictionaryInsertStmt);
     322          113 :     sqlite3_finalize(m_timeIndexInsertStmt);
     323          113 :     sqlite3_finalize(m_zoneInfoInsertStmt);
     324          113 :     sqlite3_finalize(m_zoneListInsertStmt);
     325          113 :     sqlite3_finalize(m_zoneGroupInsertStmt);
     326          113 :     sqlite3_finalize(m_zoneInfoZoneListInsertStmt);
     327          113 :     sqlite3_finalize(m_nominalLightingInsertStmt);
     328          113 :     sqlite3_finalize(m_nominalElectricEquipmentInsertStmt);
     329          113 :     sqlite3_finalize(m_nominalGasEquipmentInsertStmt);
     330          113 :     sqlite3_finalize(m_nominalSteamEquipmentInsertStmt);
     331          113 :     sqlite3_finalize(m_nominalHotWaterEquipmentInsertStmt);
     332          113 :     sqlite3_finalize(m_nominalOtherEquipmentInsertStmt);
     333          113 :     sqlite3_finalize(m_nominalBaseboardHeatInsertStmt);
     334          113 :     sqlite3_finalize(m_surfaceInsertStmt);
     335          113 :     sqlite3_finalize(m_constructionInsertStmt);
     336          113 :     sqlite3_finalize(m_constructionLayerInsertStmt);
     337          113 :     sqlite3_finalize(m_materialInsertStmt);
     338          113 :     sqlite3_finalize(m_infiltrationInsertStmt);
     339          113 :     sqlite3_finalize(m_ventilationInsertStmt);
     340          113 :     sqlite3_finalize(m_nominalPeopleInsertStmt);
     341          113 :     sqlite3_finalize(m_zoneSizingInsertStmt);
     342          113 :     sqlite3_finalize(m_systemSizingInsertStmt);
     343          113 :     sqlite3_finalize(m_componentSizingInsertStmt);
     344          113 :     sqlite3_finalize(m_roomAirModelInsertStmt);
     345          113 :     sqlite3_finalize(m_groundTemperatureInsertStmt);
     346          113 :     sqlite3_finalize(m_weatherFileInsertStmt);
     347          113 :     sqlite3_finalize(m_scheduleInsertStmt);
     348          113 :     sqlite3_finalize(m_daylightMapTitleInsertStmt);
     349          113 :     sqlite3_finalize(m_daylightMapHourlyTitleInsertStmt);
     350          113 :     sqlite3_finalize(m_daylightMapHourlyDataInsertStmt);
     351          113 :     sqlite3_finalize(m_environmentPeriodInsertStmt);
     352          113 :     sqlite3_finalize(m_simulationsInsertStmt);
     353          113 :     sqlite3_finalize(m_tabularDataInsertStmt);
     354          113 :     sqlite3_finalize(m_stringsInsertStmt);
     355          113 :     sqlite3_finalize(m_stringsLookUpStmt);
     356          113 :     sqlite3_finalize(m_errorInsertStmt);
     357          113 :     sqlite3_finalize(m_errorUpdateStmt);
     358          113 :     sqlite3_finalize(m_simulationUpdateStmt);
     359          113 :     sqlite3_finalize(m_simulationDataUpdateStmt);
     360          113 :     sqlite3_finalize(m_rollbackToSavepointStmt);
     361          113 :     sqlite3_finalize(m_createSavepointStmt);
     362          113 :     sqlite3_finalize(m_releaseSavepointStmt);
     363          226 : }
     364              : 
     365          120 : bool SQLite::writeOutputToSQLite() const
     366              : {
     367          120 :     return m_writeOutputToSQLite;
     368              : }
     369              : 
     370          115 : bool SQLite::writeTabularDataToSQLite() const
     371              : {
     372          115 :     return m_writeTabularDataToSQLite;
     373              : }
     374              : 
     375          106 : void SQLite::sqliteBegin()
     376              : {
     377          106 :     if (m_writeOutputToSQLite) {
     378          106 :         sqliteExecuteCommand("BEGIN;");
     379              :     }
     380          106 : }
     381              : 
     382          106 : void SQLite::sqliteCommit()
     383              : {
     384          106 :     if (m_writeOutputToSQLite) {
     385          106 :         sqliteExecuteCommand("COMMIT;");
     386              :     }
     387          106 : }
     388              : 
     389            0 : void SQLite::sqliteRollback()
     390              : {
     391            0 :     if (m_writeOutputToSQLite) {
     392            0 :         sqliteExecuteCommand("ROLLBACK;");
     393              :     }
     394            0 : }
     395              : 
     396            0 : void SQLite::sqliteRollbackToSavepoint(std::string_view savepoint_name)
     397              : {
     398            0 :     if (m_writeOutputToSQLite) {
     399              :         static constexpr std::string_view rollbackToSavepointSQL("ROLLBACK TO SAVEPOINT ?;");
     400              : 
     401            0 :         sqlitePrepareStatement(m_rollbackToSavepointStmt, rollbackToSavepointSQL);
     402            0 :         sqliteBindText(m_rollbackToSavepointStmt, 1, savepoint_name);
     403            0 :         sqliteStepCommand(m_rollbackToSavepointStmt);
     404            0 :         sqliteResetCommand(m_rollbackToSavepointStmt);
     405              :     }
     406            0 : }
     407              : 
     408            0 : void SQLite::sqliteReleaseSavepoint(std::string_view savepoint_name)
     409              : {
     410            0 :     if (m_writeOutputToSQLite) {
     411              :         static constexpr std::string_view releaseSavepointSQL("RELEASE SAVEPOINT ?;");
     412              : 
     413            0 :         sqlitePrepareStatement(m_releaseSavepointStmt, releaseSavepointSQL);
     414            0 :         sqliteBindText(m_releaseSavepointStmt, 1, savepoint_name);
     415            0 :         sqliteStepCommand(m_releaseSavepointStmt);
     416            0 :         sqliteResetCommand(m_releaseSavepointStmt);
     417              :     }
     418            0 : }
     419              : 
     420            0 : void SQLite::sqliteCreateSavepoint(std::string_view savepoint_name)
     421              : {
     422            0 :     if (m_writeOutputToSQLite) {
     423              :         static constexpr std::string_view createSavepointSQL("SAVEPOINT ?;");
     424              : 
     425            0 :         sqlitePrepareStatement(m_createSavepointStmt, createSavepointSQL);
     426            0 :         sqliteBindText(m_createSavepointStmt, 1, savepoint_name);
     427            0 :         sqliteStepCommand(m_createSavepointStmt);
     428            0 :         sqliteResetCommand(m_createSavepointStmt);
     429              :     }
     430            0 : }
     431              : 
     432            3 : bool SQLite::sqliteWithinTransaction()
     433              : {
     434            3 :     if (m_writeOutputToSQLite) {
     435            3 :         return SQLiteProcedures::sqliteWithinTransaction();
     436              :     }
     437            0 :     return false;
     438              : }
     439              : 
     440           23 : void SQLite::sqliteWriteMessage(std::string_view message)
     441              : {
     442           23 :     if (m_writeOutputToSQLite) {
     443           23 :         *m_errorStream << "SQLite3 message, " << message << std::endl;
     444              :     }
     445           23 : }
     446              : 
     447          113 : void SQLite::initializeReportDataDictionaryTable()
     448              : {
     449          113 :     constexpr std::string_view newTableSQL = "CREATE TABLE ReportDataDictionary("
     450              :                                              "ReportDataDictionaryIndex INTEGER PRIMARY KEY, "
     451              :                                              "IsMeter INTEGER, "
     452              :                                              "Type TEXT, "
     453              :                                              "IndexGroup TEXT, "
     454              :                                              "TimestepType TEXT, "
     455              :                                              "KeyValue TEXT, "
     456              :                                              "Name TEXT, "
     457              :                                              "ReportingFrequency TEXT, "
     458              :                                              "ScheduleName TEXT, "
     459              :                                              "Units TEXT);";
     460              : 
     461          113 :     sqliteExecuteCommand(newTableSQL);
     462              : 
     463          113 :     constexpr std::string_view preparedSQL = "INSERT INTO ReportDataDictionary ("
     464              :                                              "ReportDataDictionaryIndex, "
     465              :                                              "IsMeter, "
     466              :                                              "Type, "
     467              :                                              "IndexGroup, "
     468              :                                              "TimestepType, "
     469              :                                              "KeyValue, "
     470              :                                              "Name, "
     471              :                                              "ReportingFrequency, "
     472              :                                              "ScheduleName, "
     473              :                                              "Units) "
     474              :                                              "VALUES(?,?,?,?,?,?,?,?,?,?);";
     475              : 
     476          113 :     sqlitePrepareStatement(m_reportDictionaryInsertStmt, preparedSQL);
     477          113 : }
     478              : 
     479          113 : void SQLite::initializeReportDataTables()
     480              : {
     481          113 :     constexpr std::string_view reportDataTableSQL =
     482              :         "CREATE TABLE ReportData ("
     483              :         "ReportDataIndex INTEGER PRIMARY KEY, "
     484              :         "TimeIndex INTEGER, "
     485              :         "ReportDataDictionaryIndex INTEGER, "
     486              :         "Value REAL, "
     487              :         "FOREIGN KEY(TimeIndex) REFERENCES Time(TimeIndex) "
     488              :         "ON DELETE CASCADE ON UPDATE CASCADE "
     489              :         "FOREIGN KEY(ReportDataDictionaryIndex) REFERENCES ReportDataDictionary(ReportDataDictionaryIndex) "
     490              :         "ON DELETE CASCADE ON UPDATE CASCADE "
     491              :         ");";
     492              : 
     493          113 :     sqliteExecuteCommand(reportDataTableSQL);
     494              : 
     495          113 :     constexpr std::string_view reportDataInsertSQL = "INSERT INTO ReportData ("
     496              :                                                      "ReportDataIndex, "
     497              :                                                      "TimeIndex, "
     498              :                                                      "ReportDataDictionaryIndex, "
     499              :                                                      "Value) "
     500              :                                                      "VALUES(?,?,?,?);";
     501              : 
     502          113 :     sqlitePrepareStatement(m_reportDataInsertStmt, reportDataInsertSQL);
     503              : 
     504          113 :     constexpr std::string_view reportExtendedDataTableSQL = "CREATE TABLE ReportExtendedData ("
     505              :                                                             "ReportExtendedDataIndex INTEGER PRIMARY KEY, "
     506              :                                                             "ReportDataIndex INTEGER, "
     507              :                                                             "MaxValue REAL, "
     508              :                                                             "MaxMonth INTEGER, "
     509              :                                                             "MaxDay INTEGER, "
     510              :                                                             "MaxHour INTEGER, "
     511              :                                                             "MaxStartMinute INTEGER, "
     512              :                                                             "MaxMinute INTEGER, "
     513              :                                                             "MinValue REAL, "
     514              :                                                             "MinMonth INTEGER, "
     515              :                                                             "MinDay INTEGER, "
     516              :                                                             "MinHour INTEGER, "
     517              :                                                             "MinStartMinute INTEGER, "
     518              :                                                             "MinMinute INTEGER, "
     519              :                                                             "FOREIGN KEY(ReportDataIndex) REFERENCES ReportData(ReportDataIndex) "
     520              :                                                             "ON DELETE CASCADE ON UPDATE CASCADE "
     521              :                                                             ");";
     522              : 
     523          113 :     sqliteExecuteCommand(reportExtendedDataTableSQL);
     524              : 
     525          113 :     constexpr std::string_view reportExtendedDataInsertSQL = "INSERT INTO ReportExtendedData ("
     526              :                                                              "ReportExtendedDataIndex, "
     527              :                                                              "ReportDataIndex, "
     528              :                                                              "MaxValue, "
     529              :                                                              "MaxMonth, "
     530              :                                                              "MaxDay, "
     531              :                                                              "MaxHour, "
     532              :                                                              "MaxStartMinute, "
     533              :                                                              "MaxMinute, "
     534              :                                                              "MinValue, "
     535              :                                                              "MinMonth, "
     536              :                                                              "MinDay, "
     537              :                                                              "MinHour, "
     538              :                                                              "MinStartMinute, "
     539              :                                                              "MinMinute) "
     540              :                                                              "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
     541              : 
     542          113 :     sqlitePrepareStatement(m_reportExtendedDataInsertStmt, reportExtendedDataInsertSQL);
     543          113 : }
     544              : 
     545          113 : void SQLite::initializeTimeIndicesTable()
     546              : {
     547          113 :     constexpr std::string_view timeTableSQL = "CREATE TABLE Time ("
     548              :                                               "TimeIndex INTEGER PRIMARY KEY, "
     549              :                                               "Year INTEGER, "
     550              :                                               "Month INTEGER, "
     551              :                                               "Day INTEGER, "
     552              :                                               "Hour INTEGER, "
     553              :                                               "Minute INTEGER, "
     554              :                                               "Dst INTEGER, "
     555              :                                               "Interval INTEGER, "
     556              :                                               "IntervalType INTEGER, "
     557              :                                               "SimulationDays INTEGER, "
     558              :                                               "DayType TEXT, "
     559              :                                               "EnvironmentPeriodIndex INTEGER, "
     560              :                                               "WarmupFlag INTEGER);";
     561              : 
     562          113 :     sqliteExecuteCommand(timeTableSQL);
     563              : 
     564          113 :     constexpr std::string_view timeIndexInsertSQL = "INSERT INTO Time ("
     565              :                                                     "TimeIndex, "
     566              :                                                     "Year, "
     567              :                                                     "Month, "
     568              :                                                     "Day, "
     569              :                                                     "Hour, "
     570              :                                                     "Minute, "
     571              :                                                     "DST, "
     572              :                                                     "Interval, "
     573              :                                                     "IntervalType, "
     574              :                                                     "SimulationDays, "
     575              :                                                     "DayType, "
     576              :                                                     "EnvironmentPeriodIndex, "
     577              :                                                     "WarmupFlag) "
     578              :                                                     "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);";
     579              : 
     580          113 :     sqlitePrepareStatement(m_timeIndexInsertStmt, timeIndexInsertSQL);
     581          113 : }
     582              : 
     583          113 : void SQLite::initializeZoneInfoTable()
     584              : {
     585          113 :     constexpr std::string_view zonesTableSQL = "CREATE TABLE Zones ("
     586              :                                                "ZoneIndex INTEGER PRIMARY KEY, "
     587              :                                                "ZoneName TEXT, "
     588              :                                                "RelNorth REAL, "
     589              :                                                "OriginX REAL, "
     590              :                                                "OriginY REAL, "
     591              :                                                "OriginZ REAL, "
     592              :                                                "CentroidX REAL, "
     593              :                                                "CentroidY REAL, "
     594              :                                                "CentroidZ REAL, "
     595              :                                                "OfType INTEGER, "
     596              :                                                "Multiplier REAL, "
     597              :                                                "ListMultiplier REAL, "
     598              :                                                "MinimumX REAL, "
     599              :                                                "MaximumX REAL, "
     600              :                                                "MinimumY REAL, "
     601              :                                                "MaximumY REAL, "
     602              :                                                "MinimumZ REAL, "
     603              :                                                "MaximumZ REAL, "
     604              :                                                "CeilingHeight REAL, "
     605              :                                                "Volume REAL, "
     606              :                                                "InsideConvectionAlgo INTEGER, "
     607              :                                                "OutsideConvectionAlgo INTEGER, "
     608              :                                                "FloorArea REAL, "
     609              :                                                "ExtGrossWallArea REAL, "
     610              :                                                "ExtNetWallArea REAL, "
     611              :                                                "ExtWindowArea REAL, "
     612              :                                                "IsPartOfTotalArea INTEGER);";
     613              : 
     614          113 :     sqliteExecuteCommand(zonesTableSQL);
     615              : 
     616          113 :     constexpr std::string_view zoneInfoInsertSQL = "INSERT INTO Zones ("
     617              :                                                    "ZoneIndex, "
     618              :                                                    "ZoneName, "
     619              :                                                    "RelNorth, "
     620              :                                                    "OriginX, "
     621              :                                                    "OriginY, "
     622              : 
     623              :                                                    "OriginZ, "
     624              :                                                    "CentroidX, "
     625              :                                                    "CentroidY, "
     626              :                                                    "CentroidZ, "
     627              :                                                    "OfType, "
     628              : 
     629              :                                                    "Multiplier, "
     630              :                                                    "ListMultiplier, "
     631              :                                                    "MinimumX, "
     632              :                                                    "MaximumX, "
     633              :                                                    "MinimumY, "
     634              : 
     635              :                                                    "MaximumY, "
     636              :                                                    "MinimumZ, "
     637              :                                                    "MaximumZ, "
     638              :                                                    "CeilingHeight, "
     639              :                                                    "Volume, "
     640              : 
     641              :                                                    "InsideConvectionAlgo, "
     642              :                                                    "OutsideConvectionAlgo, "
     643              :                                                    "FloorArea, "
     644              :                                                    "ExtGrossWallArea, "
     645              :                                                    "ExtNetWallArea, "
     646              : 
     647              :                                                    "ExtWindowArea, "
     648              :                                                    "IsPartOfTotalArea) "
     649              :                                                    "VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?);";
     650              : 
     651          113 :     sqlitePrepareStatement(m_zoneInfoInsertStmt, zoneInfoInsertSQL);
     652          113 : }
     653              : 
     654          113 : void SQLite::initializeZoneInfoZoneListTable()
     655              : {
     656          113 :     constexpr std::string_view zoneInfoZoneListTableSQL = "CREATE TABLE ZoneInfoZoneLists ("
     657              :                                                           "ZoneListIndex INTEGER NOT NULL, "
     658              :                                                           "ZoneIndex INTEGER NOT NULL, "
     659              :                                                           "PRIMARY KEY(ZoneListIndex, ZoneIndex), "
     660              :                                                           "FOREIGN KEY(ZoneListIndex) REFERENCES ZoneLists(ZoneListIndex) "
     661              :                                                           "ON DELETE CASCADE ON UPDATE CASCADE, "
     662              :                                                           "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     663              :                                                           "ON DELETE CASCADE ON UPDATE CASCADE "
     664              :                                                           ");";
     665              : 
     666          113 :     sqliteExecuteCommand(zoneInfoZoneListTableSQL);
     667              : 
     668          113 :     constexpr std::string_view zoneInfoZoneListInsertSQL = "INSERT INTO ZoneInfoZoneLists ("
     669              :                                                            "ZoneListIndex, "
     670              :                                                            "ZoneIndex) "
     671              :                                                            "VALUES (?,?);";
     672              : 
     673          113 :     sqlitePrepareStatement(m_zoneInfoZoneListInsertStmt, zoneInfoZoneListInsertSQL);
     674          113 : }
     675              : 
     676          113 : void SQLite::initializeNominalPeopleTable()
     677              : {
     678          113 :     constexpr std::string_view nominalPeopleTableSQL =
     679              :         "CREATE TABLE NominalPeople ( "
     680              :         "NominalPeopleIndex INTEGER PRIMARY KEY, ObjectName TEXT, ZoneIndex INTEGER,"
     681              :         "NumberOfPeople INTEGER, NumberOfPeopleScheduleIndex INTEGER, ActivityScheduleIndex INTEGER, FractionRadiant REAL, "
     682              :         "FractionConvected REAL, WorkEfficiencyScheduleIndex INTEGER, ClothingEfficiencyScheduleIndex INTEGER, "
     683              :         "AirVelocityScheduleIndex INTEGER, Fanger INTEGER, Pierce INTEGER, KSU INTEGER, "
     684              :         "MRTCalcType INTEGER, SurfaceIndex INTEGER, "
     685              :         "AngleFactorListName TEXT, AngleFactorList INTEGER, UserSpecifeidSensibleFraction REAL, Show55Warning INTEGER, "
     686              :         "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     687              :         "ON DELETE CASCADE ON UPDATE CASCADE, "
     688              :         "FOREIGN KEY(NumberOfPeopleScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     689              :         "ON UPDATE CASCADE, "
     690              :         "FOREIGN KEY(ActivityScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     691              :         "ON UPDATE CASCADE, "
     692              :         "FOREIGN KEY(WorkEfficiencyScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     693              :         "ON UPDATE CASCADE, "
     694              :         "FOREIGN KEY(ClothingEfficiencyScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     695              :         "ON UPDATE CASCADE, "
     696              :         "FOREIGN KEY(AirVelocityScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     697              :         "ON UPDATE CASCADE, "
     698              :         "FOREIGN KEY(SurfaceIndex) REFERENCES Surfaces(SurfaceIndex) "
     699              :         "ON UPDATE CASCADE "
     700              :         ");";
     701              : 
     702          113 :     sqliteExecuteCommand(nominalPeopleTableSQL);
     703              : 
     704          113 :     constexpr std::string_view nominalPeopleInsertSQL = "INSERT INTO NominalPeople VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
     705              : 
     706          113 :     sqlitePrepareStatement(m_nominalPeopleInsertStmt, nominalPeopleInsertSQL);
     707          113 : }
     708              : 
     709          113 : void SQLite::initializeNominalLightingTable()
     710              : {
     711          113 :     constexpr std::string_view nominalLightingTableSQL =
     712              :         "CREATE TABLE NominalLighting ( "
     713              :         "NominalLightingIndex INTEGER PRIMARY KEY, ObjectName TEXT, "
     714              :         "ZoneIndex INTEGER, ScheduleIndex INTEGER, DesignLevel REAL, FractionReturnAir REAL, FractionRadiant REAL, "
     715              :         "FractionShortWave REAL, FractionReplaceable REAL, FractionConvected REAL, EndUseSubcategory TEXT, "
     716              :         "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     717              :         "ON DELETE CASCADE ON UPDATE CASCADE, "
     718              :         "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     719              :         "ON UPDATE CASCADE "
     720              :         ");";
     721              : 
     722          113 :     sqliteExecuteCommand(nominalLightingTableSQL);
     723              : 
     724          113 :     constexpr std::string_view nominalLightingInsertSQL = "INSERT INTO NominalLighting VALUES(?,?,?,?,?,?,?,?,?,?,?);";
     725              : 
     726          113 :     sqlitePrepareStatement(m_nominalLightingInsertStmt, nominalLightingInsertSQL);
     727          113 : }
     728              : 
     729          113 : void SQLite::initializeNominalElectricEquipmentTable()
     730              : {
     731          113 :     constexpr std::string_view nominalElectricEquipmentTableSQL = "CREATE TABLE NominalElectricEquipment ("
     732              :                                                                   "NominalElectricEquipmentIndex INTEGER PRIMARY KEY, "
     733              :                                                                   "ObjectName TEXT, "
     734              :                                                                   "ZoneIndex INTEGER, ScheduleIndex INTEGER, DesignLevel REAL, "
     735              :                                                                   "FractionLatent REAL, FractionRadiant REAL, FractionLost REAL, "
     736              :                                                                   "FractionConvected REAL, EndUseSubcategory TEXT, "
     737              :                                                                   "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     738              :                                                                   "ON DELETE CASCADE ON UPDATE CASCADE, "
     739              :                                                                   "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     740              :                                                                   "ON UPDATE CASCADE "
     741              :                                                                   ");";
     742              : 
     743          113 :     sqliteExecuteCommand(nominalElectricEquipmentTableSQL);
     744              : 
     745          113 :     constexpr std::string_view nominalElectricEquipmentInsertSQL = "INSERT INTO NominalElectricEquipment VALUES(?,?,?,?,?,?,?,?,?,?);";
     746              : 
     747          113 :     sqlitePrepareStatement(m_nominalElectricEquipmentInsertStmt, nominalElectricEquipmentInsertSQL);
     748          113 : }
     749              : 
     750          113 : void SQLite::initializeNominalGasEquipmentTable()
     751              : {
     752          113 :     constexpr std::string_view nominalGasEquipmentTableSQL = "CREATE TABLE NominalGasEquipment( "
     753              :                                                              "NominalGasEquipmentIndex INTEGER PRIMARY KEY, ObjectName TEXT, "
     754              :                                                              "ZoneIndex INTEGER, ScheduleIndex INTEGER, "
     755              :                                                              "DesignLevel REAL, FractionLatent REAL, FractionRadiant REAL, FractionLost REAL, "
     756              :                                                              "FractionConvected REAL, EndUseSubcategory TEXT, "
     757              :                                                              "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     758              :                                                              "ON DELETE CASCADE ON UPDATE CASCADE, "
     759              :                                                              "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     760              :                                                              "ON UPDATE CASCADE "
     761              :                                                              ");";
     762              : 
     763          113 :     sqliteExecuteCommand(nominalGasEquipmentTableSQL);
     764              : 
     765          113 :     constexpr std::string_view nominalGasEquipmentInsertSQL = "INSERT INTO NominalGasEquipment VALUES(?,?,?,?,?,?,?,?,?,?);";
     766              : 
     767          113 :     sqlitePrepareStatement(m_nominalGasEquipmentInsertStmt, nominalGasEquipmentInsertSQL);
     768          113 : }
     769              : 
     770          113 : void SQLite::initializeNominalSteamEquipmentTable()
     771              : {
     772          113 :     constexpr std::string_view nominalSteamEquipmentTableSQL = "CREATE TABLE NominalSteamEquipment( "
     773              :                                                                "NominalSteamEquipmentIndex INTEGER PRIMARY KEY, ObjectName TEXT, "
     774              :                                                                "ZoneIndex INTEGER, ScheduleIndex INTEGER, DesignLevel REAL, "
     775              :                                                                "FractionLatent REAL, FractionRadiant REAL, FractionLost REAL, "
     776              :                                                                "FractionConvected REAL, EndUseSubcategory TEXT, "
     777              :                                                                "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     778              :                                                                "ON DELETE CASCADE ON UPDATE CASCADE, "
     779              :                                                                "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     780              :                                                                "ON UPDATE CASCADE "
     781              :                                                                ");";
     782              : 
     783          113 :     sqliteExecuteCommand(nominalSteamEquipmentTableSQL);
     784              : 
     785          113 :     constexpr std::string_view nominalSteamEquipmentInsertSQL = "INSERT INTO NominalSteamEquipment VALUES(?,?,?,?,?,?,?,?,?,?);";
     786              : 
     787          113 :     sqlitePrepareStatement(m_nominalSteamEquipmentInsertStmt, nominalSteamEquipmentInsertSQL);
     788          113 : }
     789              : 
     790          113 : void SQLite::initializeNominalHotWaterEquipmentTable()
     791              : {
     792          113 :     constexpr std::string_view nominalHotWaterEquipmentTableSQL =
     793              :         "CREATE TABLE NominalHotWaterEquipment("
     794              :         "NominalHotWaterEquipmentIndex INTEGER PRIMARY KEY, "
     795              :         "ObjectName TEXT, "
     796              :         "ZoneIndex INTEGER, SchedNo INTEGER, DesignLevel REAL, FractionLatent REAL, FractionRadiant REAL, FractionLost REAL, "
     797              :         "FractionConvected REAL, EndUseSubcategory TEXT, "
     798              :         "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     799              :         "ON DELETE CASCADE ON UPDATE CASCADE, "
     800              :         "FOREIGN KEY(SchedNo) REFERENCES Schedules(ScheduleIndex) "
     801              :         "ON UPDATE CASCADE "
     802              :         ");";
     803              : 
     804          113 :     sqliteExecuteCommand(nominalHotWaterEquipmentTableSQL);
     805              : 
     806          113 :     constexpr std::string_view nominalHotWaterEquipmentInsertSQL = "INSERT INTO NominalHotWaterEquipment VALUES(?,?,?,?,?,?,?,?,?,?);";
     807              : 
     808          113 :     sqlitePrepareStatement(m_nominalHotWaterEquipmentInsertStmt, nominalHotWaterEquipmentInsertSQL);
     809          113 : }
     810              : 
     811          113 : void SQLite::initializeNominalOtherEquipmentTable()
     812              : {
     813          113 :     constexpr std::string_view nominalOtherEquipmentTableSQL = "CREATE TABLE NominalOtherEquipment( "
     814              :                                                                "NominalOtherEquipmentIndex INTEGER PRIMARY KEY, ObjectName TEXT, "
     815              :                                                                "ZoneIndex INTEGER, ScheduleIndex INTEGER, DesignLevel REAL, FractionLatent REAL, "
     816              :                                                                "FractionRadiant REAL, FractionLost REAL, "
     817              :                                                                "FractionConvected REAL, EndUseSubcategory TEXT, "
     818              :                                                                "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     819              :                                                                "ON DELETE CASCADE ON UPDATE CASCADE, "
     820              :                                                                "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     821              :                                                                "ON UPDATE CASCADE "
     822              :                                                                ");";
     823              : 
     824          113 :     sqliteExecuteCommand(nominalOtherEquipmentTableSQL);
     825              : 
     826          113 :     constexpr std::string_view nominalOtherEquipmentInsertSQL = "INSERT INTO NominalOtherEquipment VALUES(?,?,?,?,?,?,?,?,?,?);";
     827              : 
     828          113 :     sqlitePrepareStatement(m_nominalOtherEquipmentInsertStmt, nominalOtherEquipmentInsertSQL);
     829          113 : }
     830              : 
     831          113 : void SQLite::initializeNominalBaseboardHeatTable()
     832              : {
     833          113 :     constexpr std::string_view nominalBaseboardHeatersTableSQL =
     834              :         "CREATE TABLE NominalBaseboardHeaters ( "
     835              :         "NominalBaseboardHeaterIndex INTEGER PRIMARY KEY, ObjectName TEXT, "
     836              :         "ZoneIndex INTEGER, ScheduleIndex INTEGER, CapatLowTemperature REAL, LowTemperature REAL, CapatHighTemperature REAL, "
     837              :         "HighTemperature REAL, FractionRadiant REAL, FractionConvected REAL, EndUseSubcategory TEXT, "
     838              :         "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     839              :         "ON DELETE CASCADE ON UPDATE CASCADE, "
     840              :         "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     841              :         "ON UPDATE CASCADE "
     842              :         ");";
     843              : 
     844          113 :     sqliteExecuteCommand(nominalBaseboardHeatersTableSQL);
     845              : 
     846          113 :     constexpr std::string_view nominalBaseboardHeatInsertSQL = "INSERT INTO NominalBaseboardHeaters VALUES(?,?,?,?,?,?,?,?,?,?,?);";
     847              : 
     848          113 :     sqlitePrepareStatement(m_nominalBaseboardHeatInsertStmt, nominalBaseboardHeatInsertSQL);
     849          113 : }
     850              : 
     851          113 : void SQLite::initializeSurfacesTable()
     852              : {
     853          113 :     constexpr std::string_view surfacesTableSQL = "CREATE TABLE Surfaces ( "
     854              :                                                   "SurfaceIndex INTEGER PRIMARY KEY, SurfaceName TEXT, ConstructionIndex INTEGER, "
     855              :                                                   "ClassName TEXT, Area REAL, GrossArea REAL, Perimeter REAL, "
     856              :                                                   "Azimuth REAL, Height REAL, Reveal REAL, "
     857              :                                                   "Shape INTEGER, Sides INTEGER, Tilt REAL, Width REAL, HeatTransferSurf INTEGER, "
     858              :                                                   "BaseSurfaceIndex INTEGER, ZoneIndex INTEGER, ExtBoundCond INTEGER,  "
     859              :                                                   "ExtSolar INTEGER, ExtWind INTEGER, "
     860              :                                                   "FOREIGN KEY(ConstructionIndex) REFERENCES Constructions(ConstructionIndex) "
     861              :                                                   "ON UPDATE CASCADE, "
     862              :                                                   "FOREIGN KEY(BaseSurfaceIndex) REFERENCES Surfaces(SurfaceIndex) "
     863              :                                                   "ON UPDATE CASCADE, "
     864              :                                                   "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     865              :                                                   "ON DELETE CASCADE ON UPDATE CASCADE "
     866              :                                                   ");";
     867              : 
     868          113 :     sqliteExecuteCommand(surfacesTableSQL);
     869              : 
     870          113 :     constexpr std::string_view surfaceInsertSQL = "INSERT INTO Surfaces VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
     871              : 
     872          113 :     sqlitePrepareStatement(m_surfaceInsertStmt, surfaceInsertSQL);
     873          113 : }
     874              : 
     875          113 : void SQLite::initializeConstructionsTables()
     876              : {
     877          113 :     constexpr std::string_view constructionsTableSQL =
     878              :         "CREATE TABLE Constructions ( "
     879              :         "ConstructionIndex INTEGER PRIMARY KEY, Name TEXT, TotalLayers INTEGER, "
     880              :         "TotalSolidLayers INTEGER, TotalGlassLayers INTEGER, InsideAbsorpVis REAL, OutsideAbsorpVis REAL, "
     881              :         "InsideAbsorpSolar REAL, OutsideAbsorpSolar REAL, InsideAbsorpThermal REAL, OutsideAbsorpThermal REAL, "
     882              :         "OutsideRoughness INTEGER, TypeIsWindow INTEGER, Uvalue REAL"
     883              :         ");";
     884              : 
     885          113 :     sqliteExecuteCommand(constructionsTableSQL);
     886              : 
     887          113 :     constexpr std::string_view constructionInsertSQL = "INSERT INTO Constructions VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
     888              : 
     889          113 :     sqlitePrepareStatement(m_constructionInsertStmt, constructionInsertSQL);
     890              : 
     891          113 :     constexpr std::string_view constructionLayersTableSQL = "CREATE TABLE ConstructionLayers ( "
     892              :                                                             "ConstructionLayersIndex INTEGER PRIMARY KEY, "
     893              :                                                             "ConstructionIndex INTEGER, LayerIndex INTEGER, MaterialIndex INTEGER, "
     894              :                                                             "FOREIGN KEY(ConstructionIndex) REFERENCES Constructions(ConstructionIndex) "
     895              :                                                             "ON DELETE CASCADE ON UPDATE CASCADE, "
     896              :                                                             "FOREIGN KEY(MaterialIndex) REFERENCES Materials(MaterialIndex) "
     897              :                                                             "ON UPDATE CASCADE "
     898              :                                                             ");";
     899              : 
     900          113 :     sqliteExecuteCommand(constructionLayersTableSQL);
     901              : 
     902          113 :     constexpr std::string_view constructionLayerInsertSQL =
     903              :         "INSERT INTO ConstructionLayers(ConstructionIndex, LayerIndex, MaterialIndex) VALUES(?,?,?);";
     904              : 
     905          113 :     sqlitePrepareStatement(m_constructionLayerInsertStmt, constructionLayerInsertSQL);
     906          113 : }
     907              : 
     908          113 : void SQLite::initializeMaterialsTable()
     909              : {
     910          113 :     constexpr std::string_view materialsTableSQL = "CREATE TABLE Materials ( "
     911              :                                                    "MaterialIndex INTEGER PRIMARY KEY, "
     912              :                                                    "Name TEXT, MaterialType INTEGER, Roughness INTEGER, "
     913              :                                                    "Conductivity REAL, Density REAL, IsoMoistCap REAL, Porosity REAL, Resistance REAL, "
     914              :                                                    "ROnly INTEGER, SpecHeat REAL, ThermGradCoef REAL, Thickness REAL, VaporDiffus REAL "
     915              :                                                    ");";
     916              : 
     917          113 :     sqliteExecuteCommand(materialsTableSQL);
     918              : 
     919          113 :     constexpr std::string_view materialInsertSQL = "INSERT INTO Materials VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
     920              : 
     921          113 :     sqlitePrepareStatement(m_materialInsertStmt, materialInsertSQL);
     922          113 : }
     923              : 
     924          113 : void SQLite::initializeZoneListTable()
     925              : {
     926          113 :     constexpr std::string_view zoneListsTableSQL = "CREATE TABLE ZoneLists ( "
     927              :                                                    "ZoneListIndex INTEGER PRIMARY KEY, Name TEXT);";
     928              : 
     929          113 :     sqliteExecuteCommand(zoneListsTableSQL);
     930              : 
     931          113 :     constexpr std::string_view zoneListInsertSQL = "INSERT INTO ZoneLists VALUES(?,?);";
     932              : 
     933          113 :     sqlitePrepareStatement(m_zoneListInsertStmt, zoneListInsertSQL);
     934          113 : }
     935              : 
     936          113 : void SQLite::initializeZoneGroupTable()
     937              : {
     938          113 :     constexpr std::string_view zoneGroupsTableSQL = "CREATE TABLE ZoneGroups ( "
     939              :                                                     "ZoneGroupIndex INTEGER PRIMARY KEY, "
     940              :                                                     "ZoneGroupName TEXT, "
     941              :                                                     "ZoneListIndex INTEGER, "
     942              :                                                     "ZoneListMultiplier INTEGER, "
     943              :                                                     "FOREIGN KEY(ZoneListIndex) REFERENCES ZoneLists(ZoneListIndex) "
     944              :                                                     "ON UPDATE CASCADE "
     945              :                                                     ");";
     946              : 
     947          113 :     sqliteExecuteCommand(zoneGroupsTableSQL);
     948              : 
     949          113 :     constexpr std::string_view zoneGroupInsertSQL = "INSERT INTO ZoneGroups VALUES(?,?,?,?);";
     950              : 
     951          113 :     sqlitePrepareStatement(m_zoneGroupInsertStmt, zoneGroupInsertSQL);
     952          113 : }
     953              : 
     954          113 : void SQLite::initializeNominalInfiltrationTable()
     955              : {
     956          113 :     constexpr std::string_view nominalInfiltrationTableSQL = "CREATE TABLE NominalInfiltration ( "
     957              :                                                              "NominalInfiltrationIndex INTEGER PRIMARY KEY, "
     958              :                                                              "ObjectName TEXT, "
     959              :                                                              "ZoneIndex INTEGER, ScheduleIndex INTEGER, DesignLevel REAL, "
     960              :                                                              "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     961              :                                                              "ON DELETE CASCADE ON UPDATE CASCADE, "
     962              :                                                              "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     963              :                                                              "ON UPDATE CASCADE "
     964              :                                                              ");";
     965              : 
     966          113 :     sqliteExecuteCommand(nominalInfiltrationTableSQL);
     967              : 
     968          113 :     constexpr std::string_view infiltrationInsertSQL =
     969              :         "INSERT INTO NominalInfiltration (NominalInfiltrationIndex, ObjectName, ZoneIndex, ScheduleIndex, DesignLevel)"
     970              :         "VALUES (?,?,?,?,?);";
     971              : 
     972          113 :     sqlitePrepareStatement(m_infiltrationInsertStmt, infiltrationInsertSQL);
     973          113 : }
     974              : 
     975          113 : void SQLite::initializeNominalVentilationTable()
     976              : {
     977          113 :     constexpr std::string_view nominalVentilationTableSQL = "CREATE TABLE NominalVentilation ( "
     978              :                                                             "NominalVentilationIndex INTEGER PRIMARY KEY, "
     979              :                                                             "ObjectName TEXT, "
     980              :                                                             "ZoneIndex INTEGER, ScheduleIndex INTEGER, DesignLevel REAL, "
     981              :                                                             "FOREIGN KEY(ZoneIndex) REFERENCES Zones(ZoneIndex) "
     982              :                                                             "ON DELETE CASCADE ON UPDATE CASCADE, "
     983              :                                                             "FOREIGN KEY(ScheduleIndex) REFERENCES Schedules(ScheduleIndex) "
     984              :                                                             "ON UPDATE CASCADE "
     985              :                                                             ");";
     986              : 
     987          113 :     sqliteExecuteCommand(nominalVentilationTableSQL);
     988              : 
     989          113 :     constexpr std::string_view ventilationInsertSQL = "INSERT INTO NominalVentilation VALUES(?,?,?,?,?);";
     990              : 
     991          113 :     sqlitePrepareStatement(m_ventilationInsertStmt, ventilationInsertSQL);
     992          113 : }
     993              : 
     994          113 : void SQLite::initializeZoneSizingTable()
     995              : {
     996          113 :     constexpr std::string_view zoneSizesTableSQL =
     997              :         "CREATE TABLE ZoneSizes ( "
     998              :         "ZoneSizesIndex INTEGER PRIMARY KEY, ZoneName TEXT, LoadType TEXT, "
     999              :         "CalcDesLoad REAL, UserDesLoad REAL, CalcDesFlow REAL, UserDesFlow REAL, DesDayName TEXT, PeakHrMin TEXT, "
    1000              :         "PeakTemp REAL, PeakHumRat REAL, CalcOutsideAirFlow REAL, DOASHeatAddRate REAL"
    1001              :         ");";
    1002              : 
    1003          113 :     sqliteExecuteCommand(zoneSizesTableSQL);
    1004              : 
    1005          113 :     constexpr std::string_view zoneSizingInsertSQL = "INSERT INTO ZoneSizes VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);";
    1006              : 
    1007          113 :     sqlitePrepareStatement(m_zoneSizingInsertStmt, zoneSizingInsertSQL);
    1008          113 : }
    1009              : 
    1010          113 : void SQLite::initializeSystemSizingTable()
    1011              : {
    1012          113 :     constexpr std::string_view systemSizesTableSQL =
    1013              :         "CREATE TABLE SystemSizes (SystemSizesIndex INTEGER PRIMARY KEY, SystemName TEXT, LoadType TEXT, PeakLoadType TEXT, "
    1014              :         "UserDesCap REAL, CalcDesVolFlow REAL, UserDesVolFlow REAL, DesDayName TEXT, PeakHrMin TEXT);";
    1015              : 
    1016          113 :     sqliteExecuteCommand(systemSizesTableSQL);
    1017              : 
    1018          113 :     constexpr std::string_view systemSizingInsertSQL = "INSERT INTO SystemSizes VALUES(?,?,?,?,?,?,?,?,?);";
    1019              : 
    1020          113 :     sqlitePrepareStatement(m_systemSizingInsertStmt, systemSizingInsertSQL);
    1021          113 : }
    1022              : 
    1023          113 : void SQLite::initializeComponentSizingTable()
    1024              : {
    1025          113 :     constexpr std::string_view componentSizesTableSQL = "CREATE TABLE ComponentSizes (ComponentSizesIndex INTEGER PRIMARY KEY, "
    1026              :                                                         "CompType TEXT, CompName TEXT, Description TEXT, Value REAL, Units TEXT);";
    1027              : 
    1028          113 :     sqliteExecuteCommand(componentSizesTableSQL);
    1029              : 
    1030          113 :     constexpr std::string_view componentSizingInsertSQL = "INSERT INTO ComponentSizes VALUES (?,?,?,?,?,?);";
    1031              : 
    1032          113 :     sqlitePrepareStatement(m_componentSizingInsertStmt, componentSizingInsertSQL);
    1033          113 : }
    1034              : 
    1035          113 : void SQLite::initializeRoomAirModelTable()
    1036              : {
    1037          113 :     constexpr std::string_view roomAirModelsTableSQL =
    1038              :         "CREATE TABLE RoomAirModels (ZoneIndex INTEGER PRIMARY KEY, AirModelName TEXT, AirModelType INTEGER, "
    1039              :         "TempCoupleScheme INTEGER, SimAirModel INTEGER);";
    1040              : 
    1041          113 :     sqliteExecuteCommand(roomAirModelsTableSQL);
    1042              : 
    1043          113 :     constexpr std::string_view roomAirModelInsertSQL = "INSERT INTO RoomAirModels VALUES(?,?,?,?,?);";
    1044              : 
    1045          113 :     sqlitePrepareStatement(m_roomAirModelInsertStmt, roomAirModelInsertSQL);
    1046          113 : }
    1047              : 
    1048          113 : void SQLite::initializeSchedulesTable()
    1049              : {
    1050          113 :     constexpr std::string_view scheduleTableSQL = "CREATE TABLE Schedules (ScheduleIndex INTEGER PRIMARY KEY, ScheduleName TEXT, "
    1051              :                                                   "ScheduleType TEXT, ScheduleMinimum REAL, ScheduleMaximum REAL);";
    1052              : 
    1053          113 :     sqliteExecuteCommand(scheduleTableSQL);
    1054              : 
    1055          113 :     constexpr std::string_view scheduleInsertSQL = "INSERT INTO Schedules VALUES(?,?,?,?,?);";
    1056              : 
    1057          113 :     sqlitePrepareStatement(m_scheduleInsertStmt, scheduleInsertSQL);
    1058          113 : }
    1059              : 
    1060          113 : void SQLite::initializeDaylightMapTables()
    1061              : {
    1062          113 :     constexpr std::string_view daylightMapsTableSQL = "CREATE TABLE DaylightMaps ( "
    1063              :                                                       "MapNumber INTEGER PRIMARY KEY, MapName TEXT, "
    1064              :                                                       "Environment TEXT, Zone INTEGER, ReferencePts TEXT, Z REAL, "
    1065              :                                                       "FOREIGN KEY(Zone) REFERENCES Zones(ZoneIndex) "
    1066              :                                                       "ON DELETE CASCADE ON UPDATE CASCADE "
    1067              :                                                       ");";
    1068              : 
    1069          113 :     sqliteExecuteCommand(daylightMapsTableSQL);
    1070              : 
    1071          113 :     constexpr std::string_view daylightMapTitleInsertSQL = "INSERT INTO DaylightMaps VALUES(?,?,?,?,?,?);";
    1072              : 
    1073          113 :     sqlitePrepareStatement(m_daylightMapTitleInsertStmt, daylightMapTitleInsertSQL);
    1074              : 
    1075          113 :     constexpr std::string_view daylightMapHourlyReportsTableSQL = "CREATE TABLE DaylightMapHourlyReports ( "
    1076              :                                                                   "HourlyReportIndex INTEGER PRIMARY KEY, "
    1077              :                                                                   "MapNumber INTEGER, Year INTEGER, Month INTEGER, DayOfMonth INTEGER, Hour INTEGER, "
    1078              :                                                                   "FOREIGN KEY(MapNumber) REFERENCES DaylightMaps(MapNumber) "
    1079              :                                                                   "ON DELETE CASCADE ON UPDATE CASCADE "
    1080              :                                                                   ");";
    1081              : 
    1082          113 :     sqliteExecuteCommand(daylightMapHourlyReportsTableSQL);
    1083              : 
    1084          113 :     constexpr std::string_view daylightMapHourlyTitleInsertSQL = "INSERT INTO DaylightMapHourlyReports VALUES(?,?,?,?,?,?);";
    1085              : 
    1086          113 :     sqlitePrepareStatement(m_daylightMapHourlyTitleInsertStmt, daylightMapHourlyTitleInsertSQL);
    1087              : 
    1088          113 :     constexpr std::string_view daylightMapHourlyDataTableSQL =
    1089              :         "CREATE TABLE DaylightMapHourlyData ( "
    1090              :         "HourlyDataIndex INTEGER PRIMARY KEY, HourlyReportIndex INTEGER, "
    1091              :         "X REAL, Y REAL, Illuminance REAL, "
    1092              :         "FOREIGN KEY(HourlyReportIndex) REFERENCES DaylightMapHourlyReports(HourlyReportIndex) "
    1093              :         "ON DELETE CASCADE ON UPDATE CASCADE "
    1094              :         ");";
    1095              : 
    1096          113 :     sqliteExecuteCommand(daylightMapHourlyDataTableSQL);
    1097              : 
    1098          113 :     constexpr std::string_view daylightMapHourlyDataInsertSQL = "INSERT INTO DaylightMapHourlyData VALUES(?,?,?,?,?);";
    1099              : 
    1100          113 :     sqlitePrepareStatement(m_daylightMapHourlyDataInsertStmt, daylightMapHourlyDataInsertSQL);
    1101          113 : }
    1102              : 
    1103          113 : void SQLite::initializeViews()
    1104              : {
    1105          113 :     constexpr std::string_view reportVariableWithTimeViewSQL =
    1106              :         "CREATE VIEW ReportVariableWithTime AS "
    1107              :         "SELECT rd.ReportDataIndex, rd.TimeIndex, rd.ReportDataDictionaryIndex, red.ReportExtendedDataIndex, rd.Value, "
    1108              :         "t.Month, t.Day, t.Hour, t.Minute, t.Dst, t.Interval, t.IntervalType, t.SimulationDays, t.DayType, t.EnvironmentPeriodIndex, t.WarmupFlag, "
    1109              :         "rdd.IsMeter, rdd.Type, rdd.IndexGroup, rdd.TimestepType, rdd.KeyValue, rdd.Name, rdd.ReportingFrequency, rdd.ScheduleName, rdd.Units, "
    1110              :         "red.MaxValue, red.MaxMonth, red.MaxDay, red.MaxStartMinute, red.MaxMinute, red.MinValue, red.MinMonth, red.MinDay, red.MinStartMinute, "
    1111              :         "red.MinMinute "
    1112              :         "FROM ReportData As rd "
    1113              :         "INNER JOIN ReportDataDictionary As rdd "
    1114              :         "ON rd.ReportDataDictionaryIndex = rdd.ReportDataDictionaryIndex "
    1115              :         "LEFT OUTER JOIN ReportExtendedData As red "
    1116              :         "ON rd.ReportDataIndex = red.ReportDataIndex "
    1117              :         "INNER JOIN Time As t "
    1118              :         "ON rd.TimeIndex = t.TimeIndex;";
    1119              : 
    1120          113 :     sqliteExecuteCommand(reportVariableWithTimeViewSQL);
    1121              : 
    1122          113 :     constexpr std::string_view reportVariableDataViewSQL =
    1123              :         "CREATE VIEW ReportVariableData AS "
    1124              :         "SELECT rd.ReportDataIndex As rowid, rd.TimeIndex, rd.ReportDataDictionaryIndex As ReportVariableDataDictionaryIndex, "
    1125              :         "rd.Value As VariableValue, red.ReportExtendedDataIndex As ReportVariableExtendedDataIndex "
    1126              :         "FROM ReportData As rd "
    1127              :         "LEFT OUTER JOIN ReportExtendedData As red "
    1128              :         "ON rd.ReportDataIndex = red.ReportDataIndex;";
    1129              : 
    1130          113 :     sqliteExecuteCommand(reportVariableDataViewSQL);
    1131              : 
    1132          113 :     constexpr std::string_view reportVariableDataDictionaryViewSQL =
    1133              :         "CREATE VIEW ReportVariableDataDictionary AS "
    1134              :         "SELECT rdd.ReportDataDictionaryIndex As ReportVariableDataDictionaryIndex, rdd.Type As VariableType, rdd.IndexGroup, rdd.TimestepType, "
    1135              :         "rdd.KeyValue, rdd.Name As VariableName, rdd.ReportingFrequency, rdd.ScheduleName, rdd.Units As VariableUnits "
    1136              :         "FROM ReportDataDictionary As rdd;";
    1137              : 
    1138          113 :     sqliteExecuteCommand(reportVariableDataDictionaryViewSQL);
    1139              : 
    1140          113 :     constexpr std::string_view reportVariableExtendedDataViewSQL =
    1141              :         "CREATE VIEW ReportVariableExtendedData AS "
    1142              :         "SELECT red.ReportExtendedDataIndex As ReportVariableExtendedDataIndex, red.MaxValue, red.MaxMonth, red.MaxDay, "
    1143              :         "red.MaxStartMinute, red.MaxMinute, red.MinValue, red.MinMonth, red.MinDay, red.MinStartMinute, red.MinMinute "
    1144              :         "FROM ReportExtendedData As red;";
    1145              : 
    1146          113 :     sqliteExecuteCommand(reportVariableExtendedDataViewSQL);
    1147              : 
    1148          113 :     constexpr std::string_view reportMeterDataViewSQL =
    1149              :         "CREATE VIEW ReportMeterData AS "
    1150              :         "SELECT rd.ReportDataIndex As rowid, rd.TimeIndex, rd.ReportDataDictionaryIndex As ReportMeterDataDictionaryIndex, "
    1151              :         "rd.Value As VariableValue, red.ReportExtendedDataIndex As ReportVariableExtendedDataIndex "
    1152              :         "FROM ReportData As rd "
    1153              :         "LEFT OUTER JOIN ReportExtendedData As red "
    1154              :         "ON rd.ReportDataIndex = red.ReportDataIndex "
    1155              :         "INNER JOIN ReportDataDictionary As rdd "
    1156              :         "ON rd.ReportDataDictionaryIndex = rdd.ReportDataDictionaryIndex "
    1157              :         "WHERE rdd.IsMeter = 1;";
    1158              : 
    1159          113 :     sqliteExecuteCommand(reportMeterDataViewSQL);
    1160              : 
    1161          113 :     constexpr std::string_view reportMeterDataDictionaryViewSQL =
    1162              :         "CREATE VIEW ReportMeterDataDictionary AS "
    1163              :         "SELECT rdd.ReportDataDictionaryIndex As ReportMeterDataDictionaryIndex, rdd.Type As VariableType, rdd.IndexGroup, rdd.TimestepType, "
    1164              :         "rdd.KeyValue, rdd.Name As VariableName, rdd.ReportingFrequency, rdd.ScheduleName, rdd.Units As VariableUnits "
    1165              :         "FROM ReportDataDictionary As rdd "
    1166              :         "WHERE rdd.IsMeter = 1;";
    1167              : 
    1168          113 :     sqliteExecuteCommand(reportMeterDataDictionaryViewSQL);
    1169              : 
    1170          113 :     constexpr std::string_view reportMeterExtendedDataViewSQL =
    1171              :         "CREATE VIEW ReportMeterExtendedData AS "
    1172              :         "SELECT red.ReportExtendedDataIndex As ReportMeterExtendedDataIndex, red.MaxValue, red.MaxMonth, red.MaxDay, "
    1173              :         "red.MaxStartMinute, red.MaxMinute, red.MinValue, red.MinMonth, red.MinDay, red.MinStartMinute, red.MinMinute "
    1174              :         "FROM ReportExtendedData As red "
    1175              :         "LEFT OUTER JOIN ReportData As rd "
    1176              :         "ON rd.ReportDataIndex = red.ReportDataIndex "
    1177              :         "INNER JOIN ReportDataDictionary As rdd "
    1178              :         "ON rd.ReportDataDictionaryIndex = rdd.ReportDataDictionaryIndex "
    1179              :         "WHERE rdd.IsMeter = 1;";
    1180              : 
    1181          113 :     sqliteExecuteCommand(reportMeterExtendedDataViewSQL);
    1182          113 : }
    1183              : 
    1184          113 : void SQLite::initializeSimulationsTable()
    1185              : {
    1186          113 :     constexpr std::string_view simulationsTableSQL = "CREATE TABLE Simulations (SimulationIndex INTEGER PRIMARY KEY, "
    1187              :                                                      "EnergyPlusVersion TEXT, TimeStamp TEXT, NumTimestepsPerHour INTEGER, Completed BOOL, "
    1188              :                                                      "CompletedSuccessfully BOOL);";
    1189              : 
    1190          113 :     sqliteExecuteCommand(simulationsTableSQL);
    1191              : 
    1192          113 :     constexpr std::string_view simulationsInsertSQL =
    1193              :         "INSERT INTO Simulations(SimulationIndex, EnergyPlusVersion, TimeStamp, Completed, CompletedSuccessfully) "
    1194              :         "VALUES(?,?,?,'FALSE','FALSE');";
    1195              : 
    1196          113 :     sqlitePrepareStatement(m_simulationsInsertStmt, simulationsInsertSQL);
    1197              : 
    1198          113 :     constexpr std::string_view simulationUpdateSQL = "UPDATE Simulations SET "
    1199              :                                                      "Completed = ?, CompletedSuccessfully = ? "
    1200              :                                                      "WHERE SimulationIndex = ?";
    1201              : 
    1202          113 :     sqlitePrepareStatement(m_simulationUpdateStmt, simulationUpdateSQL);
    1203              : 
    1204          113 :     constexpr std::string_view simulationDataUpdateSQL = "UPDATE Simulations SET "
    1205              :                                                          "NumTimestepsPerHour = ? "
    1206              :                                                          "WHERE SimulationIndex = ?";
    1207              : 
    1208          113 :     sqlitePrepareStatement(m_simulationDataUpdateStmt, simulationDataUpdateSQL);
    1209          113 : }
    1210              : 
    1211          113 : void SQLite::initializeErrorsTable()
    1212              : {
    1213          113 :     constexpr std::string_view errorsTableSQL = "CREATE TABLE Errors ( "
    1214              :                                                 "ErrorIndex INTEGER PRIMARY KEY, SimulationIndex INTEGER, "
    1215              :                                                 "ErrorType INTEGER, ErrorMessage TEXT, Count INTEGER, "
    1216              :                                                 "FOREIGN KEY(SimulationIndex) REFERENCES Simulations(SimulationIndex) "
    1217              :                                                 "ON DELETE CASCADE ON UPDATE CASCADE "
    1218              :                                                 ");";
    1219              : 
    1220          113 :     sqliteExecuteCommand(errorsTableSQL);
    1221              : 
    1222          113 :     constexpr std::string_view errorInsertSQL = "INSERT INTO Errors VALUES(?,?,?,?,?);";
    1223              : 
    1224          113 :     sqlitePrepareStatement(m_errorInsertStmt, errorInsertSQL);
    1225              : 
    1226          113 :     constexpr std::string_view errorUpdateSQL =
    1227              :         "UPDATE Errors SET "
    1228              :         "ErrorMessage = ErrorMessage || ? WHERE ErrorIndex = (SELECT ErrorIndex FROM Errors ORDER BY ErrorIndex DESC LIMIT 1)";
    1229              : 
    1230          113 :     sqlitePrepareStatement(m_errorUpdateStmt, errorUpdateSQL);
    1231          113 : }
    1232              : 
    1233          113 : void SQLite::initializeEnvironmentPeriodsTable()
    1234              : {
    1235          113 :     constexpr std::string_view environmentPeriodsTableSQL = "CREATE TABLE EnvironmentPeriods ( "
    1236              :                                                             "EnvironmentPeriodIndex INTEGER PRIMARY KEY, "
    1237              :                                                             "SimulationIndex INTEGER, EnvironmentName TEXT, EnvironmentType INTEGER, "
    1238              :                                                             "FOREIGN KEY(SimulationIndex) REFERENCES Simulations(SimulationIndex) "
    1239              :                                                             "ON DELETE CASCADE ON UPDATE CASCADE "
    1240              :                                                             ");";
    1241              : 
    1242          113 :     sqliteExecuteCommand(environmentPeriodsTableSQL);
    1243              : 
    1244          113 :     constexpr std::string_view environmentPeriodInsertSQL = "INSERT INTO EnvironmentPeriods VALUES(?,?,?,?);";
    1245              : 
    1246          113 :     sqlitePrepareStatement(m_environmentPeriodInsertStmt, environmentPeriodInsertSQL);
    1247          113 : }
    1248              : 
    1249          112 : void SQLite::initializeTabularDataTable()
    1250              : {
    1251          112 :     constexpr std::string_view sql = "CREATE TABLE StringTypes ( "
    1252              :                                      "StringTypeIndex INTEGER PRIMARY KEY, "
    1253              :                                      "Value TEXT"
    1254              :                                      ");";
    1255              : 
    1256          112 :     sqliteExecuteCommand(sql);
    1257              : 
    1258          112 :     sqliteExecuteCommand(format("INSERT INTO StringTypes VALUES({},'ReportName');", ReportNameId));
    1259          112 :     sqliteExecuteCommand(format("INSERT INTO StringTypes VALUES({},'ReportForString');", ReportForStringId));
    1260          112 :     sqliteExecuteCommand(format("INSERT INTO StringTypes VALUES({},'TableName');", TableNameId));
    1261          112 :     sqliteExecuteCommand(format("INSERT INTO StringTypes VALUES({},'RowName');", RowNameId));
    1262          112 :     sqliteExecuteCommand(format("INSERT INTO StringTypes VALUES({},'ColumnName');", ColumnNameId));
    1263          112 :     sqliteExecuteCommand(format("INSERT INTO StringTypes VALUES({},'Units');", UnitsId));
    1264              : 
    1265          112 :     constexpr std::string_view sql2 = "CREATE TABLE Strings ( "
    1266              :                                       "StringIndex INTEGER PRIMARY KEY, "
    1267              :                                       "StringTypeIndex INTEGER, "
    1268              :                                       "Value TEXT, "
    1269              :                                       "UNIQUE(StringTypeIndex, Value), "
    1270              :                                       "FOREIGN KEY(StringTypeIndex) REFERENCES StringTypes(StringTypeIndex) "
    1271              :                                       "ON UPDATE CASCADE "
    1272              :                                       ");";
    1273              : 
    1274          112 :     sqliteExecuteCommand(sql2);
    1275              : 
    1276          112 :     constexpr std::string_view sql3 = "INSERT INTO Strings (StringIndex,StringTypeIndex,Value) VALUES(?,?,?);";
    1277              : 
    1278          112 :     sqlitePrepareStatement(m_stringsInsertStmt, sql3);
    1279              : 
    1280          112 :     constexpr std::string_view sql4 = "SELECT StringIndex FROM Strings WHERE StringTypeIndex=? AND Value=?;";
    1281              : 
    1282          112 :     sqlitePrepareStatement(m_stringsLookUpStmt, sql4);
    1283              : 
    1284          112 :     constexpr std::string_view sql5 = "CREATE TABLE TabularData ( "
    1285              :                                       "TabularDataIndex INTEGER PRIMARY KEY, "
    1286              :                                       "ReportNameIndex INTEGER, "
    1287              :                                       "ReportForStringIndex INTEGER, "
    1288              :                                       "TableNameIndex INTEGER, "
    1289              :                                       "RowNameIndex INTEGER, "
    1290              :                                       "ColumnNameIndex INTEGER, "
    1291              :                                       "UnitsIndex INTEGER, "
    1292              :                                       "SimulationIndex INTEGER, "
    1293              :                                       "RowId INTEGER, "
    1294              :                                       "ColumnId INTEGER, "
    1295              :                                       "Value TEXT, "
    1296              :                                       "FOREIGN KEY(ReportNameIndex) REFERENCES Strings(StringIndex) "
    1297              :                                       "ON UPDATE CASCADE "
    1298              :                                       "FOREIGN KEY(ReportForStringIndex) REFERENCES Strings(StringIndex) "
    1299              :                                       "ON UPDATE CASCADE "
    1300              :                                       "FOREIGN KEY(TableNameIndex) REFERENCES Strings(StringIndex) "
    1301              :                                       "ON UPDATE CASCADE "
    1302              :                                       "FOREIGN KEY(RowNameIndex) REFERENCES Strings(StringIndex) "
    1303              :                                       "ON UPDATE CASCADE "
    1304              :                                       "FOREIGN KEY(ColumnNameIndex) REFERENCES Strings(StringIndex) "
    1305              :                                       "ON UPDATE CASCADE "
    1306              :                                       "FOREIGN KEY(UnitsIndex) REFERENCES Strings(StringIndex) "
    1307              :                                       "ON UPDATE CASCADE "
    1308              :                                       "FOREIGN KEY(SimulationIndex) REFERENCES Simulations(SimulationIndex) "
    1309              :                                       "ON DELETE CASCADE ON UPDATE CASCADE "
    1310              :                                       ");";
    1311              : 
    1312          112 :     sqliteExecuteCommand(sql5);
    1313              : 
    1314          112 :     constexpr std::string_view sql6 = "INSERT INTO TabularData VALUES(?,?,?,?,?,?,?,?,?,?,?);";
    1315              : 
    1316          112 :     sqlitePrepareStatement(m_tabularDataInsertStmt, sql6);
    1317          112 : }
    1318              : 
    1319          112 : void SQLite::initializeTabularDataView()
    1320              : {
    1321          112 :     constexpr std::string_view sql = "CREATE VIEW TabularDataWithStrings AS SELECT "
    1322              :                                      "td.TabularDataIndex, "
    1323              :                                      "td.Value As Value, "
    1324              :                                      "reportn.Value As ReportName, "
    1325              :                                      "fs.Value As ReportForString, "
    1326              :                                      "tn.Value As TableName, "
    1327              :                                      "rn.Value As RowName, "
    1328              :                                      "cn.Value As ColumnName, "
    1329              :                                      "u.Value As Units "
    1330              :                                      "FROM TabularData As td "
    1331              :                                      "INNER JOIN Strings As reportn ON reportn.StringIndex=td.ReportNameIndex "
    1332              :                                      "INNER JOIN Strings As fs ON fs.StringIndex=td.ReportForStringIndex "
    1333              :                                      "INNER JOIN Strings As tn ON tn.StringIndex=td.TableNameIndex "
    1334              :                                      "INNER JOIN Strings As rn ON rn.StringIndex=td.RowNameIndex "
    1335              :                                      "INNER JOIN Strings As cn ON cn.StringIndex=td.ColumnNameIndex "
    1336              :                                      "INNER JOIN Strings As u ON u.StringIndex=td.UnitsIndex;";
    1337              : 
    1338          112 :     sqliteExecuteCommand(sql);
    1339          112 : }
    1340              : 
    1341            8 : void SQLite::initializeIndexes()
    1342              : {
    1343            8 :     if (m_writeOutputToSQLite) {
    1344            8 :         sqliteExecuteCommand("CREATE INDEX rddMTR ON ReportDataDictionary (IsMeter);");
    1345            8 :         sqliteExecuteCommand("CREATE INDEX redRD ON ReportExtendedData (ReportDataIndex);");
    1346              : 
    1347              :         // These following indexes could potentially be used by sqlite, but for a narrow range of queries
    1348              :         // There are no built in views that use these indexes in their queries.
    1349              :         // sqliteExecuteCommand("CREATE INDEX dmhdHRI ON DaylightMapHourlyData (HourlyReportIndex);");
    1350              :         // sqliteExecuteCommand("CREATE INDEX dmhrMNI ON DaylightMapHourlyReports (MapNumber);");
    1351              : 
    1352              :         // This following index is used by sqlite, but doesn't seem to increase performance in my testing
    1353              :         // sqliteExecuteCommand("CREATE INDEX tdI ON TabularData (ReportNameIndex, ReportForStringIndex, TableNameIndex, RowNameIndex,
    1354              :         // ColumnNameIndex, UnitsIndex, Value);");
    1355              :     }
    1356            8 : }
    1357              : 
    1358          375 : void SQLite::adjustReportingHourAndMinutes(int &hour, int &minutes)
    1359              : {
    1360          375 :     switch (minutes) {
    1361          124 :     case 60:
    1362          124 :         minutes = 0;
    1363          124 :         break;
    1364          251 :     default:
    1365          251 :         --hour;
    1366              :     }
    1367          375 : }
    1368              : 
    1369        28703 : void SQLite::parseUnitsAndDescription(std::string_view combinedString, std::string &units, std::string &description)
    1370              : {
    1371        28703 :     std::size_t leftPos = combinedString.find("[");
    1372        28703 :     std::size_t rightPos = combinedString.find("]");
    1373              : 
    1374        28703 :     if ((leftPos < rightPos) && (leftPos != std::string::npos) && (rightPos != std::string::npos)) {
    1375         3759 :         units = combinedString.substr(leftPos + 1, rightPos - leftPos - 1);
    1376         3759 :         description = combinedString.substr(0, leftPos - 1);
    1377              :     } else {
    1378        24944 :         units = "";
    1379        24944 :         description = combinedString;
    1380              :     }
    1381        28703 : }
    1382              : 
    1383            2 : int SQLite::logicalToInteger(const bool value)
    1384              : {
    1385            2 :     return value ? 1 : 0;
    1386              : }
    1387              : 
    1388          230 : void SQLite::createSQLiteReportDictionaryRecord(int const reportVariableReportID,
    1389              :                                                 OutputProcessor::StoreType const storeType,
    1390              :                                                 std::string_view indexGroup,
    1391              :                                                 std::string_view keyedValueString,
    1392              :                                                 std::string_view const variableName,
    1393              :                                                 OutputProcessor::TimeStepType timeStepType,
    1394              :                                                 std::string_view units,
    1395              :                                                 OutputProcessor::ReportFreq const reportFreq,
    1396              :                                                 bool isMeter,
    1397              :                                                 std::string_view const scheduleName)
    1398              : {
    1399              :     static constexpr std::array<std::string_view, (int)OutputProcessor::ReportFreq::Num> reportFreqStrings = {
    1400              :         "HVAC System Timestep", "Zone Timestep", "Hourly", "Daily", "Monthly", "Run Period", "Annual"};
    1401              : 
    1402              :     static constexpr std::array<std::string_view, (int)OutputProcessor::StoreType::Num> storeTypeStrings = {// "Dummy",
    1403              :                                                                                                             "Avg",
    1404              :                                                                                                             "Sum"};
    1405              : 
    1406              :     static constexpr std::array<std::string_view, (int)OutputProcessor::TimeStepType::Num> timeStepTypeStrings = {// "Dummy",
    1407              :                                                                                                                   "Zone",
    1408              :                                                                                                                   "HVAC System"};
    1409              : 
    1410          230 :     if (m_writeOutputToSQLite) {
    1411          230 :         sqliteBindInteger(m_reportDictionaryInsertStmt, 1, reportVariableReportID);
    1412          230 :         sqliteBindLogical(m_reportDictionaryInsertStmt, 2, isMeter);
    1413          458 :         sqliteBindText(
    1414          228 :             m_reportDictionaryInsertStmt, 3, (storeType == OutputProcessor::StoreType::Invalid) ? "Unknown!!!" : storeTypeStrings[(int)storeType]);
    1415          230 :         sqliteBindText(m_reportDictionaryInsertStmt, 4, indexGroup);
    1416          459 :         sqliteBindText(m_reportDictionaryInsertStmt,
    1417              :                        5,
    1418          229 :                        (timeStepType == OutputProcessor::TimeStepType::Invalid) ? "Unknown!!!" : timeStepTypeStrings[(int)timeStepType]);
    1419          230 :         sqliteBindText(m_reportDictionaryInsertStmt, 6, keyedValueString);
    1420          230 :         sqliteBindText(m_reportDictionaryInsertStmt, 7, variableName);
    1421          458 :         sqliteBindText(m_reportDictionaryInsertStmt,
    1422              :                        8,
    1423          228 :                        (reportFreq == OutputProcessor::ReportFreq::Invalid) ? "Unknown!!!" : reportFreqStrings[(int)reportFreq]);
    1424              : 
    1425          230 :         if (!scheduleName.empty()) {
    1426            7 :             sqliteBindText(m_reportDictionaryInsertStmt, 9, scheduleName);
    1427              :         } else {
    1428          223 :             sqliteBindNULL(m_reportDictionaryInsertStmt, 9);
    1429              :         }
    1430              : 
    1431          230 :         sqliteBindText(m_reportDictionaryInsertStmt, 10, units);
    1432              : 
    1433          230 :         sqliteStepCommand(m_reportDictionaryInsertStmt);
    1434          230 :         sqliteResetCommand(m_reportDictionaryInsertStmt);
    1435              :     }
    1436          230 : }
    1437              : 
    1438         3324 : void SQLite::createSQLiteReportDataRecord(int const recordIndex,
    1439              :                                           Real64 const value,
    1440              :                                           OutputProcessor::ReportFreq const reportFreq,
    1441              :                                           Real64 const minValue,
    1442              :                                           int const minValueDate,
    1443              :                                           Real64 const maxValue,
    1444              :                                           int const maxValueDate,
    1445              :                                           int const minutesPerTimeStep)
    1446              : {
    1447              : 
    1448         3324 :     if (!m_writeOutputToSQLite) {
    1449            0 :         return;
    1450              :     }
    1451              : 
    1452         3324 :     ++m_dataIndex;
    1453              : 
    1454         3324 :     sqliteBindInteger(m_reportDataInsertStmt, 1, m_dataIndex);
    1455         3324 :     sqliteBindForeignKey(m_reportDataInsertStmt, 2, m_sqlDBTimeIndex);
    1456         3324 :     sqliteBindForeignKey(m_reportDataInsertStmt, 3, recordIndex);
    1457         3324 :     sqliteBindDouble(m_reportDataInsertStmt, 4, value);
    1458              : 
    1459         3324 :     sqliteStepCommand(m_reportDataInsertStmt);
    1460         3324 :     sqliteResetCommand(m_reportDataInsertStmt);
    1461              : 
    1462         3324 :     if (minValueDate != -1 && maxValueDate != -1) {
    1463              :         int minMonth;
    1464              :         int minDay;
    1465              :         int minHour;
    1466              :         int minMinute;
    1467              :         int maxMonth;
    1468              :         int maxDay;
    1469              :         int maxHour;
    1470              :         int maxMinute;
    1471              : 
    1472           85 :         General::DecodeMonDayHrMin(minValueDate, minMonth, minDay, minHour, minMinute);
    1473           85 :         General::DecodeMonDayHrMin(maxValueDate, maxMonth, maxDay, maxHour, maxMinute);
    1474              : 
    1475           85 :         adjustReportingHourAndMinutes(minHour, minMinute);
    1476           85 :         adjustReportingHourAndMinutes(maxHour, maxMinute);
    1477              : 
    1478           85 :         ++m_extendedDataIndex;
    1479              : 
    1480           85 :         if (minutesPerTimeStep != -1) { // This is for data created by a 'Report Meter' statement
    1481           50 :             switch (reportFreq) {
    1482           43 :             case OutputProcessor::ReportFreq::Hour:
    1483              :             case OutputProcessor::ReportFreq::Day:
    1484              :             case OutputProcessor::ReportFreq::Month:
    1485              :             case OutputProcessor::ReportFreq::Simulation:
    1486              :             case OutputProcessor::ReportFreq::Year: {
    1487           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 1, m_extendedDataIndex);
    1488           43 :                 sqliteBindForeignKey(m_reportExtendedDataInsertStmt, 2, m_dataIndex);
    1489              : 
    1490           43 :                 sqliteBindDouble(m_reportExtendedDataInsertStmt, 3, maxValue);
    1491           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 4, maxMonth);
    1492           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 5, maxDay);
    1493           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 6, maxHour);
    1494           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 7, maxMinute - minutesPerTimeStep + 1);
    1495           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 8, maxMinute);
    1496              : 
    1497           43 :                 sqliteBindDouble(m_reportExtendedDataInsertStmt, 9, minValue);
    1498           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 10, minMonth);
    1499           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 11, minDay);
    1500           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 12, minHour);
    1501           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 13, minMinute - minutesPerTimeStep + 1);
    1502           43 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 14, minMinute);
    1503              : 
    1504           43 :                 sqliteStepCommand(m_reportExtendedDataInsertStmt);
    1505           43 :                 sqliteResetCommand(m_reportExtendedDataInsertStmt);
    1506           43 :             } break;
    1507              : 
    1508            6 :             case OutputProcessor::ReportFreq::TimeStep:
    1509              :             case OutputProcessor::ReportFreq::EachCall: {
    1510            6 :                 --m_extendedDataIndex; // Reset the data index to account for the error
    1511            6 :             } break;
    1512              : 
    1513            1 :             default: {
    1514            1 :                 --m_extendedDataIndex; // Reset the data index to account for the error
    1515            1 :                 std::stringstream ss;
    1516            1 :                 ss << "Illegal reportingInterval passed to CreateSQLiteMeterRecord: " << (int)reportFreq;
    1517            1 :                 sqliteWriteMessage(ss.str());
    1518            1 :             } break;
    1519              :             } // switch (reportFreq)
    1520              : 
    1521              :         } else { // This is for data created by a 'Report Variable' statement
    1522           35 :             switch (reportFreq) {
    1523           20 :             case OutputProcessor::ReportFreq::Day:
    1524              :             case OutputProcessor::ReportFreq::Month:
    1525              :             case OutputProcessor::ReportFreq::Simulation:
    1526              :             case OutputProcessor::ReportFreq::Year: {
    1527           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 1, m_extendedDataIndex);
    1528           20 :                 sqliteBindForeignKey(m_reportExtendedDataInsertStmt, 2, m_dataIndex);
    1529              : 
    1530           20 :                 sqliteBindDouble(m_reportExtendedDataInsertStmt, 3, maxValue);
    1531           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 4, maxMonth);
    1532           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 5, maxDay);
    1533           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 6, maxHour);
    1534           20 :                 sqliteBindNULL(m_reportExtendedDataInsertStmt, 7);
    1535           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 8, maxMinute);
    1536              : 
    1537           20 :                 sqliteBindDouble(m_reportExtendedDataInsertStmt, 9, minValue);
    1538           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 10, minMonth);
    1539           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 11, minDay);
    1540           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 12, minHour);
    1541           20 :                 sqliteBindNULL(m_reportExtendedDataInsertStmt, 13);
    1542           20 :                 sqliteBindInteger(m_reportExtendedDataInsertStmt, 14, minMinute);
    1543              : 
    1544           20 :                 sqliteStepCommand(m_reportExtendedDataInsertStmt);
    1545           20 :                 sqliteResetCommand(m_reportExtendedDataInsertStmt);
    1546           20 :             } break;
    1547              : 
    1548           14 :             case OutputProcessor::ReportFreq::TimeStep:
    1549              :             case OutputProcessor::ReportFreq::EachCall:
    1550              :             case OutputProcessor::ReportFreq::Hour: {
    1551           14 :                 --m_extendedDataIndex; // Reset the data index to account for the error
    1552           14 :             } break;
    1553            1 :             default: {
    1554            1 :                 --m_extendedDataIndex; // Reset the data index to account for the error
    1555            1 :                 std::stringstream ss;
    1556            1 :                 ss << "Illegal reportingInterval passed to CreateSQLiteMeterRecord: " << (int)reportFreq;
    1557            1 :                 sqliteWriteMessage(ss.str());
    1558            1 :             } break;
    1559              :             } // switch (reportFreq)
    1560              :         }     // if (minutesPerTimeStep != -1)
    1561              :     }         // if (minDataValue != 0)
    1562              : } // SQLite::createSQLiteReportDataRecord()
    1563              : 
    1564          308 : void SQLite::createSQLiteTimeIndexRecord(OutputProcessor::ReportFreq const reportFreq,
    1565              :                                          [[maybe_unused]] int const recordIndex,
    1566              :                                          int const cumlativeSimulationDays,
    1567              :                                          int const curEnvirNum,
    1568              :                                          int const simulationYear,
    1569              :                                          bool const curYearIsLeapYear,
    1570              :                                          int const month,
    1571              :                                          int const dayOfMonth,
    1572              :                                          int const hour,
    1573              :                                          Real64 const endMinute,
    1574              :                                          Real64 const startMinute,
    1575              :                                          int const dst,
    1576              :                                          std::string_view const dayType,
    1577              :                                          bool const warmupFlag)
    1578              : {
    1579          308 :     if (m_writeOutputToSQLite) {
    1580          308 :         int intervalInMinutes = 60;
    1581              : 
    1582          358 :         static std::vector<int> lastDayOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    1583          308 :         if (curYearIsLeapYear) {
    1584            5 :             lastDayOfMonth[1] = 29;
    1585              :         }
    1586              : 
    1587          308 :         switch (reportFreq) {
    1588          209 :         case OutputProcessor::ReportFreq::EachCall:
    1589              :         case OutputProcessor::ReportFreq::TimeStep: {
    1590          209 :             if (month == -1 || dayOfMonth == -1 || hour == -1 || endMinute == -1.0 || startMinute == -1.0 || dst == -1 || dayType == "") {
    1591            7 :                 sqliteWriteMessage("Empty month, dayOfMonth, hour, endMinute, startMinute, dst, or dayType passed to CreateSQLiteTimeIndexRecord");
    1592            7 :                 break;
    1593              :             }
    1594          202 :             ++m_sqlDBTimeIndex;
    1595              : 
    1596          202 :             int intEndMinute = static_cast<int>(endMinute + 0.5);
    1597          202 :             int intStartMinute = static_cast<int>(startMinute + 0.5);
    1598          202 :             int t_hour = hour;
    1599          202 :             intervalInMinutes = intEndMinute - intStartMinute;
    1600          202 :             adjustReportingHourAndMinutes(t_hour, intEndMinute);
    1601              : 
    1602          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 1, m_sqlDBTimeIndex);
    1603          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 2, simulationYear);
    1604          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 3, month);
    1605          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 4, dayOfMonth);
    1606          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 5, t_hour);
    1607          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 6, intEndMinute);
    1608          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 7, dst);
    1609          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 8, intervalInMinutes);
    1610          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 9, reportFreqInts[(int)reportFreq]);
    1611          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 10, cumlativeSimulationDays);
    1612          202 :             sqliteBindText(m_timeIndexInsertStmt, 11, dayType);
    1613          202 :             sqliteBindInteger(m_timeIndexInsertStmt, 12, curEnvirNum);
    1614          202 :             sqliteBindLogical(m_timeIndexInsertStmt, 13, warmupFlag);
    1615              : 
    1616          202 :             sqliteStepCommand(m_timeIndexInsertStmt);
    1617          202 :             sqliteResetCommand(m_timeIndexInsertStmt);
    1618              : 
    1619          202 :             break;
    1620              :         }
    1621           58 :         case OutputProcessor::ReportFreq::Hour: {
    1622           58 :             if (month == -1 || dayOfMonth == -1 || hour == -1 || dst == -1 || dayType == "") {
    1623            5 :                 sqliteWriteMessage("Empty month, dayOfMonth, hour, dst, or dayType passed to CreateSQLiteTimeIndexRecord");
    1624            5 :                 break;
    1625              :             }
    1626           53 :             ++m_sqlDBTimeIndex;
    1627              : 
    1628           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 1, m_sqlDBTimeIndex);
    1629           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 2, simulationYear);
    1630           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 3, month);
    1631           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 4, dayOfMonth);
    1632           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 5, hour);
    1633           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 6, 0);
    1634           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 7, dst);
    1635           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 8, intervalInMinutes);
    1636           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 9, reportFreqInts[(int)reportFreq]);
    1637           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 10, cumlativeSimulationDays);
    1638           53 :             sqliteBindText(m_timeIndexInsertStmt, 11, dayType);
    1639           53 :             sqliteBindInteger(m_timeIndexInsertStmt, 12, curEnvirNum);
    1640              : 
    1641           53 :             sqliteStepCommand(m_timeIndexInsertStmt);
    1642           53 :             sqliteResetCommand(m_timeIndexInsertStmt);
    1643              : 
    1644           53 :             break;
    1645              :         }
    1646           10 :         case OutputProcessor::ReportFreq::Day: {
    1647           10 :             if (month == -1 || dayOfMonth == -1 || dst == -1 || dayType == "") {
    1648            4 :                 sqliteWriteMessage("Empty month, dayOfMonth, dst, or dayType passed to CreateSQLiteTimeIndexRecord");
    1649            4 :                 break;
    1650              :             }
    1651            6 :             ++m_sqlDBTimeIndex;
    1652              : 
    1653            6 :             intervalInMinutes = 60 * 24;
    1654            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 1, m_sqlDBTimeIndex);
    1655            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 2, simulationYear);
    1656            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 3, month);
    1657            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 4, dayOfMonth);
    1658            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 5, 24);
    1659            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 6, 0);
    1660            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 7, dst);
    1661            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 8, intervalInMinutes);
    1662            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 9, reportFreqInts[(int)reportFreq]);
    1663            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 10, cumlativeSimulationDays);
    1664            6 :             sqliteBindText(m_timeIndexInsertStmt, 11, dayType);
    1665            6 :             sqliteBindInteger(m_timeIndexInsertStmt, 12, curEnvirNum);
    1666              : 
    1667            6 :             sqliteStepCommand(m_timeIndexInsertStmt);
    1668            6 :             sqliteResetCommand(m_timeIndexInsertStmt);
    1669              : 
    1670            6 :             break;
    1671              :         }
    1672           14 :         case OutputProcessor::ReportFreq::Month: {
    1673           14 :             if (month == -1) {
    1674            1 :                 sqliteWriteMessage("Empty month passed to CreateSQLiteTimeIndexRecord");
    1675            1 :                 break;
    1676              :             }
    1677           13 :             ++m_sqlDBTimeIndex;
    1678              : 
    1679           13 :             intervalInMinutes = 60 * 24 * lastDayOfMonth[month - 1];
    1680           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 1, m_sqlDBTimeIndex);
    1681           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 2, simulationYear);
    1682           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 3, month);
    1683           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 4, lastDayOfMonth[month - 1]);
    1684           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 5, 24);
    1685           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 6, 0);
    1686           13 :             sqliteBindNULL(m_timeIndexInsertStmt, 7);
    1687           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 8, intervalInMinutes);
    1688           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 9, reportFreqInts[(int)reportFreq]);
    1689           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 10, cumlativeSimulationDays);
    1690           13 :             sqliteBindNULL(m_timeIndexInsertStmt, 11);
    1691           13 :             sqliteBindInteger(m_timeIndexInsertStmt, 12, curEnvirNum);
    1692              : 
    1693           13 :             sqliteStepCommand(m_timeIndexInsertStmt);
    1694           13 :             sqliteResetCommand(m_timeIndexInsertStmt);
    1695              : 
    1696           13 :             break;
    1697              :         }
    1698           16 :         case OutputProcessor::ReportFreq::Simulation: {
    1699           16 :             ++m_sqlDBTimeIndex;
    1700              : 
    1701           16 :             intervalInMinutes = 60 * 24 * cumlativeSimulationDays;
    1702           16 :             sqliteBindInteger(m_timeIndexInsertStmt, 1, m_sqlDBTimeIndex);
    1703           16 :             sqliteBindNULL(m_timeIndexInsertStmt, 2);
    1704           16 :             sqliteBindNULL(m_timeIndexInsertStmt, 3);
    1705           16 :             sqliteBindNULL(m_timeIndexInsertStmt, 4);
    1706           16 :             sqliteBindNULL(m_timeIndexInsertStmt, 5);
    1707           16 :             sqliteBindNULL(m_timeIndexInsertStmt, 6);
    1708           16 :             sqliteBindNULL(m_timeIndexInsertStmt, 7);
    1709           16 :             sqliteBindInteger(m_timeIndexInsertStmt, 8, intervalInMinutes);
    1710           16 :             sqliteBindInteger(m_timeIndexInsertStmt, 9, reportFreqInts[(int)reportFreq]);
    1711           16 :             sqliteBindInteger(m_timeIndexInsertStmt, 10, cumlativeSimulationDays);
    1712           16 :             sqliteBindNULL(m_timeIndexInsertStmt, 11);
    1713           16 :             sqliteBindInteger(m_timeIndexInsertStmt, 12, curEnvirNum);
    1714              : 
    1715           16 :             sqliteStepCommand(m_timeIndexInsertStmt);
    1716           16 :             sqliteResetCommand(m_timeIndexInsertStmt);
    1717              : 
    1718           16 :             break;
    1719              :         }
    1720            1 :         default: {
    1721            1 :             std::stringstream ss;
    1722            1 :             ss << "Illegal reportingInterval passed to CreateSQLiteTimeIndexRecord: " << (int)reportFreq;
    1723            1 :             sqliteWriteMessage(ss.str());
    1724            1 :         }
    1725              :         }
    1726              :     }
    1727          308 : } // SQLite::createSQLiteTimeIndexRecord()
    1728              : 
    1729            1 : void SQLite::createYearlyTimeIndexRecord(int const simulationYear, int const curEnvirNum)
    1730              : {
    1731            1 :     if (m_writeOutputToSQLite) {
    1732              : 
    1733            1 :         ++m_sqlDBTimeIndex;
    1734              : 
    1735            1 :         sqliteBindInteger(m_timeIndexInsertStmt, 1, m_sqlDBTimeIndex);
    1736            1 :         sqliteBindInteger(m_timeIndexInsertStmt, 2, simulationYear);
    1737            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 3);
    1738            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 4);
    1739            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 5);
    1740            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 6);
    1741            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 7);
    1742            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 8);
    1743            1 :         sqliteBindInteger(m_timeIndexInsertStmt, 9, reportFreqInts[(int)OutputProcessor::ReportFreq::Year]);
    1744            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 10);
    1745            1 :         sqliteBindNULL(m_timeIndexInsertStmt, 11);
    1746            1 :         sqliteBindInteger(m_timeIndexInsertStmt, 12, curEnvirNum);
    1747              : 
    1748            1 :         sqliteStepCommand(m_timeIndexInsertStmt);
    1749            1 :         sqliteResetCommand(m_timeIndexInsertStmt);
    1750              :     }
    1751            1 : }
    1752              : 
    1753           10 : void SQLite::addSQLiteZoneSizingRecord(std::string_view zoneName,   // the name of the zone
    1754              :                                        std::string_view loadType,   // the description of the input variable
    1755              :                                        Real64 const calcDesLoad,    // the value from the sizing calculation [W]
    1756              :                                        Real64 const userDesLoad,    // the value from the sizing calculation modified by user input [W]
    1757              :                                        Real64 const calcDesFlow,    // calculated design air flow rate [m3/s]
    1758              :                                        Real64 const userDesFlow,    // user input or modified design air flow rate [m3/s]
    1759              :                                        std::string_view desDayName, // the name of the design day that produced the peak
    1760              :                                        std::string_view peakHrMin,  // time stamp of the peak
    1761              :                                        Real64 const peakTemp,       // temperature at peak [C]
    1762              :                                        Real64 const peakHumRat,     // humidity ratio at peak [kg water/kg dry air]
    1763              :                                        Real64 const minOAVolFlow,   // zone design minimum outside air flow rate [m3/s]
    1764              :                                        Real64 const DOASHeatAddRate // zone design heat addition rate from the DOAS [W]
    1765              : )
    1766              : {
    1767           10 :     if (m_writeOutputToSQLite) {
    1768           10 :         ++m_zoneSizingIndex;
    1769           10 :         sqliteBindInteger(m_zoneSizingInsertStmt, 1, m_zoneSizingIndex);
    1770           10 :         sqliteBindText(m_zoneSizingInsertStmt, 2, zoneName);
    1771           10 :         sqliteBindText(m_zoneSizingInsertStmt, 3, loadType);
    1772              : 
    1773           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 4, calcDesLoad);
    1774           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 5, userDesLoad);
    1775           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 6, calcDesFlow);
    1776           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 7, userDesFlow);
    1777              : 
    1778           10 :         sqliteBindText(m_zoneSizingInsertStmt, 8, desDayName);
    1779           10 :         sqliteBindText(m_zoneSizingInsertStmt, 9, peakHrMin);
    1780              : 
    1781           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 10, peakTemp);
    1782           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 11, peakHumRat);
    1783           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 12, minOAVolFlow);
    1784           10 :         sqliteBindDouble(m_zoneSizingInsertStmt, 13, DOASHeatAddRate);
    1785              : 
    1786           10 :         sqliteStepCommand(m_zoneSizingInsertStmt);
    1787           10 :         sqliteResetCommand(m_zoneSizingInsertStmt);
    1788              :     }
    1789           10 : }
    1790              : 
    1791            5 : void SQLite::addSQLiteSystemSizingRecord(std::string_view SysName,      // the name of the system
    1792              :                                          std::string_view LoadType,     // either "Cooling" or "Heating"
    1793              :                                          std::string_view PeakLoadType, // either "Sensible" or "Total"
    1794              :                                          Real64 const UserDesCap,       // User  Design Capacity
    1795              :                                          Real64 const CalcDesVolFlow,   // Calculated Cooling Design Air Flow Rate
    1796              :                                          Real64 const UserDesVolFlow,   // User Cooling Design Air Flow Rate
    1797              :                                          std::string_view DesDayName,   // the name of the design day that produced the peak
    1798              :                                          std::string_view PeakHrMin     // time stamp of the peak
    1799              : )
    1800              : {
    1801            5 :     if (m_writeOutputToSQLite) {
    1802            5 :         ++m_systemSizingIndex;
    1803            5 :         sqliteBindInteger(m_systemSizingInsertStmt, 1, m_systemSizingIndex);
    1804            5 :         sqliteBindText(m_systemSizingInsertStmt, 2, SysName);
    1805            5 :         sqliteBindText(m_systemSizingInsertStmt, 3, LoadType);
    1806            5 :         sqliteBindText(m_systemSizingInsertStmt, 4, PeakLoadType);
    1807              : 
    1808            5 :         sqliteBindDouble(m_systemSizingInsertStmt, 5, UserDesCap);
    1809            5 :         sqliteBindDouble(m_systemSizingInsertStmt, 6, CalcDesVolFlow);
    1810            5 :         sqliteBindDouble(m_systemSizingInsertStmt, 7, UserDesVolFlow);
    1811            5 :         sqliteBindText(m_systemSizingInsertStmt, 8, DesDayName);
    1812            5 :         sqliteBindText(m_systemSizingInsertStmt, 9, PeakHrMin);
    1813              : 
    1814            5 :         sqliteStepCommand(m_systemSizingInsertStmt);
    1815            5 :         sqliteResetCommand(m_systemSizingInsertStmt);
    1816              :     }
    1817            5 : }
    1818              : 
    1819          179 : void SQLite::addSQLiteComponentSizingRecord(std::string_view compType, // the type of the component
    1820              :                                             std::string_view compName, // the name of the component
    1821              :                                             std::string_view varDesc,  // the description of the input variable
    1822              :                                             Real64 const varValue      // the value from the sizing calculation
    1823              : )
    1824              : {
    1825          179 :     if (m_writeOutputToSQLite) {
    1826          179 :         ++m_componentSizingIndex;
    1827              : 
    1828          179 :         std::string description;
    1829          179 :         std::string units;
    1830              : 
    1831          179 :         parseUnitsAndDescription(varDesc, units, description);
    1832              : 
    1833          179 :         sqliteBindInteger(m_componentSizingInsertStmt, 1, m_componentSizingIndex);
    1834          179 :         sqliteBindText(m_componentSizingInsertStmt, 2, compType);
    1835          179 :         sqliteBindText(m_componentSizingInsertStmt, 3, compName);
    1836          179 :         sqliteBindText(m_componentSizingInsertStmt, 4, description);
    1837          179 :         sqliteBindDouble(m_componentSizingInsertStmt, 5, varValue);
    1838          179 :         sqliteBindText(m_componentSizingInsertStmt, 6, units);
    1839              : 
    1840          179 :         sqliteStepCommand(m_componentSizingInsertStmt);
    1841          179 :         sqliteResetCommand(m_componentSizingInsertStmt);
    1842          179 :     }
    1843          179 : }
    1844              : 
    1845            3 : void SQLite::createSQLiteDaylightMapTitle(
    1846              :     int const mapNum, std::string_view mapName, std::string_view environmentName, int const zone, std::string_view refPts, Real64 const zCoord)
    1847              : {
    1848            3 :     if (m_writeOutputToSQLite) {
    1849              :         // for some reason it is adding extra mapNumbers that are getting UNIQUE constraint ignored.
    1850              :         // Might need to look into it, basically I think something is getting double inserted (12/06/14)
    1851            3 :         sqliteBindInteger(m_daylightMapTitleInsertStmt, 1, mapNum);
    1852            3 :         sqliteBindText(m_daylightMapTitleInsertStmt, 2, mapName);
    1853            3 :         sqliteBindText(m_daylightMapTitleInsertStmt, 3, environmentName);
    1854            3 :         sqliteBindForeignKey(m_daylightMapTitleInsertStmt, 4, zone);
    1855            3 :         sqliteBindText(m_daylightMapTitleInsertStmt, 5, refPts);
    1856            3 :         sqliteBindDouble(m_daylightMapTitleInsertStmt, 6, zCoord);
    1857              : 
    1858            3 :         sqliteStepCommand(m_daylightMapTitleInsertStmt);
    1859            3 :         sqliteResetCommand(m_daylightMapTitleInsertStmt);
    1860              :     }
    1861            3 : }
    1862              : 
    1863            2 : void SQLite::createSQLiteDaylightMap(int const mapNum,
    1864              :                                      int const year,
    1865              :                                      int const month,
    1866              :                                      int const dayOfMonth,
    1867              :                                      int const hourOfDay,
    1868              :                                      int const nX,
    1869              :                                      Array1D<Real64> const &x,
    1870              :                                      int const nY,
    1871              :                                      Array1D<Real64> const &y,
    1872              :                                      Array2<Real64> const &illuminance)
    1873              : {
    1874            2 :     if (m_writeOutputToSQLite) {
    1875            2 :         ++m_hourlyReportIndex;
    1876            2 :         int b = 0;
    1877            2 :         sqliteBindInteger(m_daylightMapHourlyTitleInsertStmt, ++b, m_hourlyReportIndex);
    1878            2 :         sqliteBindForeignKey(m_daylightMapHourlyTitleInsertStmt, ++b, mapNum);
    1879            2 :         sqliteBindForeignKey(m_daylightMapHourlyTitleInsertStmt, ++b, year);
    1880            2 :         sqliteBindInteger(m_daylightMapHourlyTitleInsertStmt, ++b, month);
    1881            2 :         sqliteBindInteger(m_daylightMapHourlyTitleInsertStmt, ++b, dayOfMonth);
    1882            2 :         sqliteBindInteger(m_daylightMapHourlyTitleInsertStmt, ++b, hourOfDay);
    1883              : 
    1884            2 :         sqliteStepCommand(m_daylightMapHourlyTitleInsertStmt);
    1885            2 :         sqliteResetCommand(m_daylightMapHourlyTitleInsertStmt);
    1886              : 
    1887            6 :         for (int yIndex = 1; yIndex <= nY; ++yIndex) {
    1888           12 :             for (int xIndex = 1; xIndex <= nX; ++xIndex) {
    1889            8 :                 ++m_hourlyDataIndex;
    1890            8 :                 sqliteBindInteger(m_daylightMapHourlyDataInsertStmt, 1, m_hourlyDataIndex);
    1891            8 :                 sqliteBindForeignKey(m_daylightMapHourlyDataInsertStmt, 2, m_hourlyReportIndex);
    1892            8 :                 sqliteBindDouble(m_daylightMapHourlyDataInsertStmt, 3, x(xIndex));
    1893            8 :                 sqliteBindDouble(m_daylightMapHourlyDataInsertStmt, 4, y(yIndex));
    1894            8 :                 sqliteBindDouble(m_daylightMapHourlyDataInsertStmt, 5, illuminance(xIndex, yIndex));
    1895              : 
    1896            8 :                 sqliteStepCommand(m_daylightMapHourlyDataInsertStmt);
    1897            8 :                 sqliteResetCommand(m_daylightMapHourlyDataInsertStmt);
    1898              :             }
    1899              :         }
    1900              :     }
    1901            2 : }
    1902              : 
    1903          822 : void SQLite::createSQLiteTabularDataRecords(Array2D_string const &body, // html table row, html table column
    1904              :                                             Array1D_string const &rowLabels,
    1905              :                                             Array1D_string const &columnLabels,
    1906              :                                             std::string_view reportName,
    1907              :                                             std::string_view reportForString,
    1908              :                                             std::string_view tableName)
    1909              : {
    1910          822 :     if (m_writeTabularDataToSQLite) {
    1911          625 :         size_t sizeColumnLabels = columnLabels.size();
    1912          625 :         size_t sizeRowLabels = rowLabels.size();
    1913              : 
    1914          625 :         int const reportNameIndex = createSQLiteStringTableRecord(reportName, ReportNameId);
    1915          625 :         int const reportForStringIndex = createSQLiteStringTableRecord(reportForString, ReportForStringId);
    1916          625 :         int const tableNameIndex = createSQLiteStringTableRecord(tableName, TableNameId);
    1917              :         int unitsIndex;
    1918              : 
    1919         5412 :         for (size_t iCol = 0, k = body.index(1, 1); iCol < sizeColumnLabels; ++iCol) {
    1920         4787 :             std::string colUnits;
    1921         4787 :             std::string colDescription;
    1922         4787 :             parseUnitsAndDescription(columnLabels[iCol], colUnits, colDescription);
    1923              : 
    1924         4787 :             int const columnLabelIndex = createSQLiteStringTableRecord(colDescription, ColumnNameId);
    1925              : 
    1926         4787 :             if (!colUnits.empty()) {
    1927         2784 :                 unitsIndex = createSQLiteStringTableRecord(colUnits, UnitsId);
    1928              :             }
    1929              : 
    1930        28524 :             for (size_t iRow = 0; iRow < sizeRowLabels; ++iRow) {
    1931        23737 :                 ++m_tabularDataIndex;
    1932        23737 :                 std::string rowUnits;
    1933        23737 :                 std::string rowDescription;
    1934        23737 :                 parseUnitsAndDescription(rowLabels[iRow], rowUnits, rowDescription);
    1935              : 
    1936        23737 :                 int const rowLabelIndex = createSQLiteStringTableRecord(rowDescription, RowNameId);
    1937              : 
    1938        23737 :                 if (colUnits.empty()) {
    1939         4961 :                     unitsIndex = createSQLiteStringTableRecord(rowUnits, UnitsId);
    1940              :                 }
    1941              : 
    1942        23737 :                 sqliteBindInteger(m_tabularDataInsertStmt, 1, m_tabularDataIndex);
    1943        23737 :                 sqliteBindForeignKey(m_tabularDataInsertStmt, 2, reportNameIndex);
    1944        23737 :                 sqliteBindForeignKey(m_tabularDataInsertStmt, 3, reportForStringIndex);
    1945        23737 :                 sqliteBindForeignKey(m_tabularDataInsertStmt, 4, tableNameIndex);
    1946        23737 :                 sqliteBindForeignKey(m_tabularDataInsertStmt, 5, rowLabelIndex);
    1947        23737 :                 sqliteBindForeignKey(m_tabularDataInsertStmt, 6, columnLabelIndex);
    1948        23737 :                 sqliteBindForeignKey(m_tabularDataInsertStmt, 7, unitsIndex);
    1949        23737 :                 sqliteBindForeignKey(m_tabularDataInsertStmt, 8, 1);
    1950        23737 :                 sqliteBindInteger(m_tabularDataInsertStmt, 9, iRow);
    1951        23737 :                 sqliteBindInteger(m_tabularDataInsertStmt, 10, iCol);
    1952        23737 :                 sqliteBindText(m_tabularDataInsertStmt, 11, body[k]);
    1953              : 
    1954        23737 :                 sqliteStepCommand(m_tabularDataInsertStmt);
    1955        23737 :                 sqliteResetCommand(m_tabularDataInsertStmt);
    1956              : 
    1957        23737 :                 ++k;
    1958        23737 :             }
    1959         4787 :         }
    1960              :     }
    1961          822 : }
    1962              : 
    1963        38144 : int SQLite::createSQLiteStringTableRecord(std::string_view stringValue, int const stringType)
    1964              : {
    1965        38144 :     int rowId = -1;
    1966        38144 :     if (m_writeOutputToSQLite) {
    1967              : 
    1968        38144 :         auto ret = m_tabularStrings.emplace(make_pair(stringValue, stringType), 0);
    1969              : 
    1970        38144 :         if (!ret.second) {
    1971        33007 :             rowId = ret.first->second;
    1972              :         } else {
    1973         5137 :             sqliteBindInteger(m_stringsInsertStmt, 1, m_stringIndex);
    1974         5137 :             sqliteBindForeignKey(m_stringsInsertStmt, 2, stringType);
    1975         5137 :             sqliteBindText(m_stringsInsertStmt, 3, stringValue);
    1976              : 
    1977         5137 :             int errorcode = sqliteStepCommand(m_stringsInsertStmt);
    1978         5137 :             sqliteResetCommand(m_stringsInsertStmt);
    1979              : 
    1980         5137 :             if (errorcode != SQLITE_CONSTRAINT) {
    1981         5137 :                 rowId = m_stringIndex++;
    1982              :             } else {
    1983            0 :                 sqliteBindInteger(m_stringsLookUpStmt, 1, stringType);
    1984            0 :                 sqliteBindText(m_stringsLookUpStmt, 2, stringValue);
    1985            0 :                 sqliteStepCommand(m_stringsLookUpStmt);
    1986            0 :                 rowId = sqlite3_column_int(m_stringsLookUpStmt, 0);
    1987            0 :                 sqliteResetCommand(m_stringsLookUpStmt);
    1988              :             }
    1989         5137 :             ret.first->second = rowId;
    1990              :         }
    1991              :     }
    1992        38144 :     return rowId;
    1993              : }
    1994              : 
    1995           42 : void SQLite::createSQLiteSimulationsRecord(int const id, std::string_view verString, std::string_view currentDateTime)
    1996              : {
    1997           42 :     if (m_writeOutputToSQLite) {
    1998           42 :         sqliteBindInteger(m_simulationsInsertStmt, 1, id);
    1999           42 :         sqliteBindText(m_simulationsInsertStmt, 2, verString);
    2000           42 :         sqliteBindText(m_simulationsInsertStmt, 3, currentDateTime);
    2001              : 
    2002           42 :         sqliteStepCommand(m_simulationsInsertStmt);
    2003           42 :         sqliteResetCommand(m_simulationsInsertStmt);
    2004              :     }
    2005           42 : }
    2006              : 
    2007          120 : void SQLite::createSQLiteErrorRecord(int const simulationIndex, int const errorType, std::string_view errorMessage, int const cnt)
    2008              : {
    2009          120 :     if (m_writeOutputToSQLite) {
    2010          120 :         ++m_errorIndex;
    2011              : 
    2012          120 :         sqliteBindInteger(m_errorInsertStmt, 1, m_errorIndex);
    2013          120 :         sqliteBindForeignKey(m_errorInsertStmt, 2, simulationIndex);
    2014          120 :         sqliteBindInteger(m_errorInsertStmt, 3, errorType);
    2015          120 :         sqliteBindText(m_errorInsertStmt, 4, errorMessage);
    2016          120 :         sqliteBindInteger(m_errorInsertStmt, 5, cnt);
    2017              : 
    2018          120 :         sqliteStepCommand(m_errorInsertStmt);
    2019          120 :         sqliteResetCommand(m_errorInsertStmt);
    2020              :     }
    2021          120 : }
    2022              : 
    2023           87 : void SQLite::updateSQLiteErrorRecord(std::string const &errorMessage)
    2024              : {
    2025           87 :     if (m_writeOutputToSQLite) {
    2026           87 :         sqliteBindText(m_errorUpdateStmt, 1, "  " + errorMessage);
    2027              : 
    2028           87 :         sqliteStepCommand(m_errorUpdateStmt);
    2029           87 :         sqliteResetCommand(m_errorUpdateStmt);
    2030              :     }
    2031           87 : }
    2032              : 
    2033            6 : void SQLite::updateSQLiteSimulationRecord(int const id, int const numOfTimeStepInHour)
    2034              : {
    2035            6 :     if (m_writeOutputToSQLite) {
    2036            6 :         sqliteBindInteger(m_simulationDataUpdateStmt, 1, numOfTimeStepInHour);
    2037            6 :         sqliteBindForeignKey(m_simulationDataUpdateStmt, 2, id);
    2038              : 
    2039            6 :         sqliteStepCommand(m_simulationDataUpdateStmt);
    2040            6 :         sqliteResetCommand(m_simulationDataUpdateStmt);
    2041              :     }
    2042            6 : }
    2043              : 
    2044            3 : void SQLite::updateSQLiteSimulationRecord(bool const completed, bool const completedSuccessfully, int const id)
    2045              : {
    2046            3 :     if (m_writeOutputToSQLite) {
    2047            3 :         sqliteBindLogical(m_simulationUpdateStmt, 1, completed);
    2048            3 :         sqliteBindLogical(m_simulationUpdateStmt, 2, completedSuccessfully);
    2049            3 :         sqliteBindForeignKey(m_simulationUpdateStmt, 3, id); // seems to always be 1, SimulationManager::ManageSimulation()
    2050              : 
    2051            3 :         sqliteStepCommand(m_simulationUpdateStmt);
    2052            3 :         sqliteResetCommand(m_simulationUpdateStmt);
    2053              :     }
    2054            3 : }
    2055              : 
    2056            7 : void SQLite::createZoneExtendedOutput()
    2057              : {
    2058            7 :     if (m_writeOutputToSQLite) {
    2059           17 :         for (auto const &zone : zones) {
    2060           10 :             zone->insertIntoSQLite(m_zoneInfoInsertStmt);
    2061              :         }
    2062            9 :         for (auto const &zoneList : zoneLists) {
    2063            2 :             zoneList->insertIntoSQLite(m_zoneListInsertStmt, m_zoneInfoZoneListInsertStmt);
    2064              :         }
    2065            9 :         for (auto const &zoneGroup : zoneGroups) {
    2066            2 :             zoneGroup->insertIntoSQLite(m_zoneGroupInsertStmt);
    2067              :         }
    2068           53 :         for (auto const &schedule : schedules) {
    2069           46 :             schedule->insertIntoSQLite(m_scheduleInsertStmt);
    2070              :         }
    2071           40 :         for (auto const &material : materials) {
    2072           33 :             material->insertIntoSQLite(m_materialInsertStmt);
    2073              :         }
    2074           24 :         for (auto const &construction : constructions) {
    2075           17 :             construction->insertIntoSQLite(m_constructionInsertStmt, m_constructionLayerInsertStmt);
    2076              :         }
    2077           56 :         for (auto const &surface : surfaces) {
    2078           49 :             surface->insertIntoSQLite(m_surfaceInsertStmt);
    2079              :         }
    2080           13 :         for (auto const &nominalLighting : nominalLightings) {
    2081            6 :             nominalLighting->insertIntoSQLite(m_nominalLightingInsertStmt);
    2082              :         }
    2083           12 :         for (auto const &nominalPeople : nominalPeoples) {
    2084            5 :             nominalPeople->insertIntoSQLite(m_nominalPeopleInsertStmt);
    2085              :         }
    2086           14 :         for (auto const &nominalElectricEquipment : nominalElectricEquipments) {
    2087            7 :             nominalElectricEquipment->insertIntoSQLite(m_nominalElectricEquipmentInsertStmt);
    2088              :         }
    2089            9 :         for (auto const &nominalGasEquipment : nominalGasEquipments) {
    2090            2 :             nominalGasEquipment->insertIntoSQLite(m_nominalGasEquipmentInsertStmt);
    2091              :         }
    2092            9 :         for (auto const &nominalSteamEquipment : nominalSteamEquipments) {
    2093            2 :             nominalSteamEquipment->insertIntoSQLite(m_nominalSteamEquipmentInsertStmt);
    2094              :         }
    2095            9 :         for (auto const &nominalHotWaterEquipment : nominalHotWaterEquipments) {
    2096            2 :             nominalHotWaterEquipment->insertIntoSQLite(m_nominalHotWaterEquipmentInsertStmt);
    2097              :         }
    2098            9 :         for (auto const &nominalOtherEquipment : nominalOtherEquipments) {
    2099            2 :             nominalOtherEquipment->insertIntoSQLite(m_nominalOtherEquipmentInsertStmt);
    2100              :         }
    2101            9 :         for (auto const &nominalBaseboardHeat : nominalBaseboardHeats) {
    2102            2 :             nominalBaseboardHeat->insertIntoSQLite(m_nominalBaseboardHeatInsertStmt);
    2103              :         }
    2104           11 :         for (auto const &infiltration : infiltrations) {
    2105            4 :             infiltration->insertIntoSQLite(m_infiltrationInsertStmt);
    2106              :         }
    2107            9 :         for (auto const &ventilation : ventilations) {
    2108            2 :             ventilation->insertIntoSQLite(m_ventilationInsertStmt);
    2109              :         }
    2110           16 :         for (auto const &roomAirModel : roomAirModels) {
    2111            9 :             roomAirModel->insertIntoSQLite(m_roomAirModelInsertStmt);
    2112              :         }
    2113              :     }
    2114            7 : }
    2115              : 
    2116           14 : void SQLite::createSQLiteEnvironmentPeriodRecord(const int curEnvirNum,
    2117              :                                                  std::string_view environmentName,
    2118              :                                                  const Constant::KindOfSim kindOfSim,
    2119              :                                                  const int simulationIndex)
    2120              : {
    2121           14 :     if (m_writeOutputToSQLite) {
    2122           14 :         sqliteBindInteger(m_environmentPeriodInsertStmt, 1, curEnvirNum);
    2123           14 :         sqliteBindForeignKey(m_environmentPeriodInsertStmt, 2, simulationIndex);
    2124           14 :         sqliteBindText(m_environmentPeriodInsertStmt, 3, environmentName);
    2125           14 :         sqliteBindInteger(m_environmentPeriodInsertStmt, 4, static_cast<int>(kindOfSim));
    2126              : 
    2127           14 :         sqliteStepCommand(m_environmentPeriodInsertStmt);
    2128           14 :         sqliteResetCommand(m_environmentPeriodInsertStmt);
    2129              :     }
    2130           14 : }
    2131              : 
    2132           46 : void SQLite::addScheduleData(int const number, std::string_view name, std::string_view type, double const minValue, double const maxValue)
    2133              : {
    2134           46 :     schedules.push_back(std::make_unique<Schedule>(m_errorStream, m_db, number, name, type, minValue, maxValue));
    2135           46 : }
    2136              : 
    2137           10 : void SQLite::addZoneData(int const number, DataHeatBalance::ZoneData const &zoneData)
    2138              : {
    2139           10 :     zones.push_back(std::make_unique<Zone>(m_errorStream, m_db, number, zoneData));
    2140           10 : }
    2141              : 
    2142            2 : void SQLite::addZoneListData(int const number, DataHeatBalance::ZoneListData const &zoneListData)
    2143              : {
    2144            2 :     zoneLists.push_back(std::make_unique<ZoneList>(m_errorStream, m_db, number, zoneListData));
    2145            2 : }
    2146              : 
    2147           49 : void SQLite::addSurfaceData(int const number, DataSurfaces::SurfaceData const &surfaceData, std::string_view surfaceClass)
    2148              : {
    2149           49 :     surfaces.push_back(std::make_unique<Surface>(m_errorStream, m_db, number, surfaceData, surfaceClass));
    2150           49 : }
    2151              : 
    2152            2 : void SQLite::addZoneGroupData(int const number, DataHeatBalance::ZoneGroupData const &zoneGroupData)
    2153              : {
    2154            2 :     zoneGroups.push_back(std::make_unique<ZoneGroup>(m_errorStream, m_db, number, zoneGroupData));
    2155            2 : }
    2156              : 
    2157           33 : void SQLite::addMaterialData(int const number, EnergyPlus::Material::MaterialBase const *materialData)
    2158              : {
    2159           33 :     materials.push_back(std::make_unique<Material>(m_errorStream, m_db, number, materialData));
    2160           33 : }
    2161           17 : void SQLite::addConstructionData(int const number,
    2162              :                                  EnergyPlus::Construction::ConstructionProps const &constructionData,
    2163              :                                  double const &constructionUValue)
    2164              : {
    2165           17 :     constructions.push_back(std::make_unique<Construction>(m_errorStream, m_db, number, constructionData, constructionUValue));
    2166           17 : }
    2167            6 : void SQLite::addNominalLightingData(int const number, DataHeatBalance::LightsData const &nominalLightingData)
    2168              : {
    2169            6 :     nominalLightings.push_back(std::make_unique<NominalLighting>(m_errorStream, m_db, number, nominalLightingData));
    2170            6 : }
    2171            5 : void SQLite::addNominalPeopleData(int const number, DataHeatBalance::PeopleData const &nominalPeopleData)
    2172              : {
    2173            5 :     nominalPeoples.push_back(std::make_unique<NominalPeople>(m_errorStream, m_db, number, nominalPeopleData));
    2174            5 : }
    2175            7 : void SQLite::addNominalElectricEquipmentData(int const number, DataHeatBalance::ZoneEquipData const &nominalElectricEquipmentData)
    2176              : {
    2177            7 :     nominalElectricEquipments.push_back(std::make_unique<NominalElectricEquipment>(m_errorStream, m_db, number, nominalElectricEquipmentData));
    2178            7 : }
    2179            2 : void SQLite::addNominalGasEquipmentData(int const number, DataHeatBalance::ZoneEquipData const &nominalGasEquipmentData)
    2180              : {
    2181            2 :     nominalGasEquipments.push_back(std::make_unique<NominalGasEquipment>(m_errorStream, m_db, number, nominalGasEquipmentData));
    2182            2 : }
    2183            2 : void SQLite::addNominalSteamEquipmentData(int const number, DataHeatBalance::ZoneEquipData const &nominalSteamEquipmentData)
    2184              : {
    2185            2 :     nominalSteamEquipments.push_back(std::make_unique<NominalSteamEquipment>(m_errorStream, m_db, number, nominalSteamEquipmentData));
    2186            2 : }
    2187            2 : void SQLite::addNominalHotWaterEquipmentData(int const number, DataHeatBalance::ZoneEquipData const &nominalHotWaterEquipmentData)
    2188              : {
    2189            2 :     nominalHotWaterEquipments.push_back(std::make_unique<NominalHotWaterEquipment>(m_errorStream, m_db, number, nominalHotWaterEquipmentData));
    2190            2 : }
    2191            2 : void SQLite::addNominalOtherEquipmentData(int const number, DataHeatBalance::ZoneEquipData const &nominalOtherEquipmentData)
    2192              : {
    2193            2 :     nominalOtherEquipments.push_back(std::make_unique<NominalOtherEquipment>(m_errorStream, m_db, number, nominalOtherEquipmentData));
    2194            2 : }
    2195            2 : void SQLite::addNominalBaseboardData(int const number, DataHeatBalance::BBHeatData const &nominalBaseboardData)
    2196              : {
    2197            2 :     nominalBaseboardHeats.push_back(std::make_unique<NominalBaseboardHeat>(m_errorStream, m_db, number, nominalBaseboardData));
    2198            2 : }
    2199            4 : void SQLite::addInfiltrationData(int const number, DataHeatBalance::InfiltrationData const &infiltrationData)
    2200              : {
    2201            4 :     infiltrations.push_back(std::make_unique<Infiltration>(m_errorStream, m_db, number, infiltrationData));
    2202            4 : }
    2203            2 : void SQLite::addVentilationData(int const number, DataHeatBalance::VentilationData const &ventilationData)
    2204              : {
    2205            2 :     ventilations.push_back(std::make_unique<Ventilation>(m_errorStream, m_db, number, ventilationData));
    2206            2 : }
    2207            9 : void SQLite::addRoomAirModelData(int const number, RoomAir::AirModelData const &roomAirModelData)
    2208              : {
    2209            9 :     roomAirModels.push_back(std::make_unique<RoomAirModel>(m_errorStream, m_db, number, roomAirModelData));
    2210            9 : }
    2211              : 
    2212            2 : bool SQLite::ZoneGroup::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2213              : {
    2214            2 :     sqliteBindInteger(insertStmt, 1, number);
    2215            2 :     sqliteBindText(insertStmt, 2, name);
    2216            2 :     sqliteBindForeignKey(insertStmt, 3, zoneList);
    2217            2 :     sqliteBindInteger(insertStmt, 4, multiplier);
    2218              : 
    2219            2 :     int rc = sqliteStepCommand(insertStmt);
    2220            2 :     bool validInsert = sqliteStepValidity(rc);
    2221            2 :     sqliteResetCommand(insertStmt);
    2222            2 :     return validInsert;
    2223              : }
    2224           33 : bool SQLite::Material::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2225              : {
    2226           33 :     double isoMoistCap = 0.0;
    2227           33 :     double thermGradCoef = 0.0;
    2228           33 :     sqliteBindInteger(insertStmt, 1, number);
    2229           33 :     sqliteBindText(insertStmt, 2, name);
    2230           33 :     sqliteBindInteger(insertStmt, 3, static_cast<int>(group));
    2231           33 :     sqliteBindInteger(insertStmt, 4, static_cast<int>(roughness));
    2232           33 :     sqliteBindDouble(insertStmt, 5, conductivity);
    2233           33 :     sqliteBindDouble(insertStmt, 6, density);
    2234           33 :     sqliteBindDouble(insertStmt, 7, isoMoistCap);
    2235           33 :     sqliteBindDouble(insertStmt, 8, porosity);
    2236           33 :     sqliteBindDouble(insertStmt, 9, resistance);
    2237           33 :     sqliteBindLogical(insertStmt, 10, rOnly);
    2238           33 :     sqliteBindDouble(insertStmt, 11, specHeat);
    2239           33 :     sqliteBindDouble(insertStmt, 12, thermGradCoef);
    2240           33 :     sqliteBindDouble(insertStmt, 13, thickness);
    2241           33 :     sqliteBindDouble(insertStmt, 14, vaporDiffus);
    2242              : 
    2243           33 :     int rc = sqliteStepCommand(insertStmt);
    2244           33 :     bool validInsert = sqliteStepValidity(rc);
    2245           33 :     sqliteResetCommand(insertStmt);
    2246           33 :     return validInsert;
    2247              : }
    2248           17 : bool SQLite::Construction::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2249              : {
    2250           17 :     sqliteBindInteger(insertStmt, 1, number);
    2251           17 :     sqliteBindText(insertStmt, 2, name);
    2252           17 :     sqliteBindInteger(insertStmt, 3, totLayers);
    2253           17 :     sqliteBindInteger(insertStmt, 4, totSolidLayers);
    2254           17 :     sqliteBindInteger(insertStmt, 5, totGlassLayers);
    2255           17 :     sqliteBindDouble(insertStmt, 6, insideAbsorpVis);
    2256           17 :     sqliteBindDouble(insertStmt, 7, outsideAbsorpVis);
    2257           17 :     sqliteBindDouble(insertStmt, 8, insideAbsorpSolar);
    2258           17 :     sqliteBindDouble(insertStmt, 9, outsideAbsorpSolar);
    2259           17 :     sqliteBindDouble(insertStmt, 10, insideAbsorpThermal);
    2260           17 :     sqliteBindDouble(insertStmt, 11, outsideAbsorpThermal);
    2261           17 :     sqliteBindInteger(insertStmt, 12, static_cast<int>(outsideRoughness));
    2262           17 :     sqliteBindLogical(insertStmt, 13, typeIsWindow);
    2263           17 :     sqliteBindDouble(insertStmt, 14, uValue);
    2264              : 
    2265           17 :     int rc = sqliteStepCommand(insertStmt);
    2266           17 :     bool validInsert = sqliteStepValidity(rc);
    2267           17 :     sqliteResetCommand(insertStmt);
    2268           17 :     return validInsert;
    2269              : }
    2270           17 : bool SQLite::Construction::insertIntoSQLite(sqlite3_stmt *insertStmt, sqlite3_stmt *subInsertStmt)
    2271              : {
    2272           17 :     bool constructionInsertValid = insertIntoSQLite(insertStmt);
    2273           17 :     if (!constructionInsertValid) return false;
    2274              : 
    2275           17 :     bool valid = true;
    2276           51 :     for (auto const &constructionLayer : constructionLayers) {
    2277           34 :         bool validInsert = constructionLayer->insertIntoSQLite(subInsertStmt);
    2278           34 :         if (valid && !validInsert) valid = false;
    2279              :     }
    2280           17 :     return valid;
    2281              : }
    2282           34 : bool SQLite::Construction::ConstructionLayer::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2283              : {
    2284           34 :     sqliteBindForeignKey(insertStmt, 1, constructNumber);
    2285           34 :     sqliteBindInteger(insertStmt, 2, layerNumber);
    2286           34 :     sqliteBindForeignKey(insertStmt, 3, layerPoint);
    2287              : 
    2288           34 :     int rc = sqliteStepCommand(insertStmt);
    2289           34 :     bool validInsert = sqliteStepValidity(rc);
    2290           34 :     sqliteResetCommand(insertStmt);
    2291           34 :     return validInsert;
    2292              : }
    2293            6 : bool SQLite::NominalLighting::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2294              : {
    2295            6 :     sqliteBindInteger(insertStmt, 1, number);
    2296            6 :     sqliteBindText(insertStmt, 2, name);
    2297            6 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2298            6 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2299            6 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2300            6 :     sqliteBindDouble(insertStmt, 6, fractionReturnAir);
    2301            6 :     sqliteBindDouble(insertStmt, 7, fractionRadiant);
    2302            6 :     sqliteBindDouble(insertStmt, 8, fractionShortWave);
    2303            6 :     sqliteBindDouble(insertStmt, 9, fractionReplaceable);
    2304            6 :     sqliteBindDouble(insertStmt, 10, fractionConvected);
    2305            6 :     sqliteBindText(insertStmt, 11, endUseSubcategory);
    2306              : 
    2307            6 :     int rc = sqliteStepCommand(insertStmt);
    2308            6 :     bool validInsert = sqliteStepValidity(rc);
    2309            6 :     sqliteResetCommand(insertStmt);
    2310            6 :     return validInsert;
    2311              : }
    2312            5 : bool SQLite::NominalPeople::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2313              : {
    2314            5 :     sqliteBindInteger(insertStmt, 1, number);
    2315            5 :     sqliteBindText(insertStmt, 2, name);
    2316            5 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2317            5 :     sqliteBindDouble(insertStmt, 4, numberOfPeople);
    2318            5 :     sqliteBindForeignKey(insertStmt, 5, numberOfPeopleSched ? numberOfPeopleSched->Num : -1);
    2319            5 :     sqliteBindForeignKey(insertStmt, 6, activityLevelSched ? activityLevelSched->Num : -1);
    2320            5 :     sqliteBindDouble(insertStmt, 7, fractionRadiant);
    2321            5 :     sqliteBindDouble(insertStmt, 8, fractionConvected);
    2322            5 :     sqliteBindForeignKey(insertStmt, 9, workEffSched ? workEffSched->Num : -1);
    2323            5 :     sqliteBindForeignKey(insertStmt, 10, clothingSched ? clothingSched->Num : -1);
    2324            5 :     sqliteBindForeignKey(insertStmt, 11, airVelocitySched ? airVelocitySched->Num : -1);
    2325            5 :     sqliteBindLogical(insertStmt, 12, fanger);
    2326            5 :     sqliteBindLogical(insertStmt, 13, pierce);
    2327            5 :     sqliteBindLogical(insertStmt, 14, ksu);
    2328            5 :     sqliteBindInteger(insertStmt, 15, static_cast<int>(mrtCalcType));
    2329            5 :     sqliteBindForeignKey(insertStmt, 16, surfacePtr);
    2330            5 :     sqliteBindText(insertStmt, 17, angleFactorListName);
    2331            5 :     sqliteBindInteger(insertStmt, 18, angleFactorListPtr);
    2332            5 :     sqliteBindDouble(insertStmt, 19, userSpecSensFrac);
    2333            5 :     sqliteBindLogical(insertStmt, 20, show55Warning);
    2334              : 
    2335            5 :     int rc = sqliteStepCommand(insertStmt);
    2336            5 :     bool validInsert = sqliteStepValidity(rc);
    2337            5 :     sqliteResetCommand(insertStmt);
    2338            5 :     return validInsert;
    2339              : }
    2340            7 : bool SQLite::NominalElectricEquipment::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2341              : {
    2342            7 :     sqliteBindInteger(insertStmt, 1, number);
    2343            7 :     sqliteBindText(insertStmt, 2, name);
    2344            7 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2345            7 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2346            7 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2347            7 :     sqliteBindDouble(insertStmt, 6, fractionLatent);
    2348            7 :     sqliteBindDouble(insertStmt, 7, fractionRadiant);
    2349            7 :     sqliteBindDouble(insertStmt, 8, fractionLost);
    2350            7 :     sqliteBindDouble(insertStmt, 9, fractionConvected);
    2351            7 :     sqliteBindText(insertStmt, 10, endUseSubcategory);
    2352              : 
    2353            7 :     int rc = sqliteStepCommand(insertStmt);
    2354            7 :     bool validInsert = sqliteStepValidity(rc);
    2355            7 :     sqliteResetCommand(insertStmt);
    2356            7 :     return validInsert;
    2357              : }
    2358            2 : bool SQLite::NominalGasEquipment::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2359              : {
    2360            2 :     sqliteBindInteger(insertStmt, 1, number);
    2361            2 :     sqliteBindText(insertStmt, 2, name);
    2362            2 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2363            2 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2364            2 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2365            2 :     sqliteBindDouble(insertStmt, 6, fractionLatent);
    2366            2 :     sqliteBindDouble(insertStmt, 7, fractionRadiant);
    2367            2 :     sqliteBindDouble(insertStmt, 8, fractionLost);
    2368            2 :     sqliteBindDouble(insertStmt, 9, fractionConvected);
    2369            2 :     sqliteBindText(insertStmt, 10, endUseSubcategory);
    2370              : 
    2371            2 :     int rc = sqliteStepCommand(insertStmt);
    2372            2 :     bool validInsert = sqliteStepValidity(rc);
    2373            2 :     sqliteResetCommand(insertStmt);
    2374            2 :     return validInsert;
    2375              : }
    2376            2 : bool SQLite::NominalSteamEquipment::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2377              : {
    2378            2 :     sqliteBindInteger(insertStmt, 1, number);
    2379            2 :     sqliteBindText(insertStmt, 2, name);
    2380            2 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2381            2 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2382            2 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2383            2 :     sqliteBindDouble(insertStmt, 6, fractionLatent);
    2384            2 :     sqliteBindDouble(insertStmt, 7, fractionRadiant);
    2385            2 :     sqliteBindDouble(insertStmt, 8, fractionLost);
    2386            2 :     sqliteBindDouble(insertStmt, 9, fractionConvected);
    2387            2 :     sqliteBindText(insertStmt, 10, endUseSubcategory);
    2388              : 
    2389            2 :     int rc = sqliteStepCommand(insertStmt);
    2390            2 :     bool validInsert = sqliteStepValidity(rc);
    2391            2 :     sqliteResetCommand(insertStmt);
    2392            2 :     return validInsert;
    2393              : }
    2394            2 : bool SQLite::NominalHotWaterEquipment::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2395              : {
    2396            2 :     sqliteBindInteger(insertStmt, 1, number);
    2397            2 :     sqliteBindText(insertStmt, 2, name);
    2398            2 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2399            2 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2400            2 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2401            2 :     sqliteBindDouble(insertStmt, 6, fractionLatent);
    2402            2 :     sqliteBindDouble(insertStmt, 7, fractionRadiant);
    2403            2 :     sqliteBindDouble(insertStmt, 8, fractionLost);
    2404            2 :     sqliteBindDouble(insertStmt, 9, fractionConvected);
    2405            2 :     sqliteBindText(insertStmt, 10, endUseSubcategory);
    2406              : 
    2407            2 :     int rc = sqliteStepCommand(insertStmt);
    2408            2 :     bool validInsert = sqliteStepValidity(rc);
    2409            2 :     sqliteResetCommand(insertStmt);
    2410            2 :     return validInsert;
    2411              : }
    2412            2 : bool SQLite::NominalOtherEquipment::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2413              : {
    2414            2 :     sqliteBindInteger(insertStmt, 1, number);
    2415            2 :     sqliteBindText(insertStmt, 2, name);
    2416            2 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2417            2 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2418            2 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2419            2 :     sqliteBindDouble(insertStmt, 6, fractionLatent);
    2420            2 :     sqliteBindDouble(insertStmt, 7, fractionRadiant);
    2421            2 :     sqliteBindDouble(insertStmt, 8, fractionLost);
    2422            2 :     sqliteBindDouble(insertStmt, 9, fractionConvected);
    2423            2 :     sqliteBindText(insertStmt, 10, endUseSubcategory);
    2424              : 
    2425            2 :     int rc = sqliteStepCommand(insertStmt);
    2426            2 :     bool validInsert = sqliteStepValidity(rc);
    2427            2 :     sqliteResetCommand(insertStmt);
    2428            2 :     return validInsert;
    2429              : }
    2430            2 : bool SQLite::NominalBaseboardHeat::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2431              : {
    2432            2 :     sqliteBindInteger(insertStmt, 1, number);
    2433            2 :     sqliteBindText(insertStmt, 2, name);
    2434            2 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2435            2 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2436            2 :     sqliteBindDouble(insertStmt, 5, capatLowTemperature);
    2437            2 :     sqliteBindDouble(insertStmt, 6, lowTemperature);
    2438            2 :     sqliteBindDouble(insertStmt, 7, capatHighTemperature);
    2439            2 :     sqliteBindDouble(insertStmt, 8, highTemperature);
    2440            2 :     sqliteBindDouble(insertStmt, 9, fractionRadiant);
    2441            2 :     sqliteBindDouble(insertStmt, 10, fractionConvected);
    2442            2 :     sqliteBindText(insertStmt, 11, endUseSubcategory);
    2443              : 
    2444            2 :     int rc = sqliteStepCommand(insertStmt);
    2445            2 :     bool validInsert = sqliteStepValidity(rc);
    2446            2 :     sqliteResetCommand(insertStmt);
    2447            2 :     return validInsert;
    2448              : }
    2449            4 : bool SQLite::Infiltration::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2450              : {
    2451            4 :     sqliteBindInteger(insertStmt, 1, number);
    2452            4 :     sqliteBindText(insertStmt, 2, name);
    2453            4 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2454            4 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2455            4 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2456              : 
    2457            4 :     int rc = sqliteStepCommand(insertStmt);
    2458            4 :     bool validInsert = sqliteStepValidity(rc);
    2459            4 :     sqliteResetCommand(insertStmt);
    2460            4 :     return validInsert;
    2461              : }
    2462            2 : bool SQLite::Ventilation::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2463              : {
    2464            2 :     sqliteBindInteger(insertStmt, 1, number);
    2465            2 :     sqliteBindText(insertStmt, 2, name);
    2466            2 :     sqliteBindForeignKey(insertStmt, 3, zonePtr);
    2467            2 :     sqliteBindForeignKey(insertStmt, 4, sched->Num);
    2468            2 :     sqliteBindDouble(insertStmt, 5, designLevel);
    2469              : 
    2470            2 :     int rc = sqliteStepCommand(insertStmt);
    2471            2 :     bool validInsert = sqliteStepValidity(rc);
    2472            2 :     sqliteResetCommand(insertStmt);
    2473            2 :     return validInsert;
    2474              : }
    2475            9 : bool SQLite::RoomAirModel::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2476              : {
    2477            9 :     sqliteBindInteger(insertStmt, 1, number);
    2478            9 :     sqliteBindText(insertStmt, 2, airModelName);
    2479            9 :     sqliteBindInteger(insertStmt, 3, static_cast<int>(airModel));
    2480            9 :     sqliteBindInteger(insertStmt, 4, static_cast<int>(tempCoupleScheme));
    2481            9 :     sqliteBindLogical(insertStmt, 5, simAirModel);
    2482              : 
    2483            9 :     int rc = sqliteStepCommand(insertStmt);
    2484            9 :     bool validInsert = sqliteStepValidity(rc);
    2485            9 :     sqliteResetCommand(insertStmt);
    2486            9 :     return validInsert;
    2487              : }
    2488              : 
    2489           49 : bool SQLite::Surface::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2490              : {
    2491           49 :     sqliteBindInteger(insertStmt, 1, number);
    2492           49 :     sqliteBindText(insertStmt, 2, name);
    2493           49 :     sqliteBindForeignKey(insertStmt, 3, construction);
    2494           49 :     sqliteBindText(insertStmt, 4, surfaceClass);
    2495           49 :     sqliteBindDouble(insertStmt, 5, area);
    2496           49 :     sqliteBindDouble(insertStmt, 6, grossArea);
    2497           49 :     sqliteBindDouble(insertStmt, 7, perimeter);
    2498           49 :     sqliteBindDouble(insertStmt, 8, azimuth);
    2499           49 :     sqliteBindDouble(insertStmt, 9, height);
    2500           49 :     sqliteBindDouble(insertStmt, 10, reveal);
    2501           49 :     sqliteBindInteger(insertStmt, 11, static_cast<int>(shape));
    2502           49 :     sqliteBindInteger(insertStmt, 12, sides);
    2503           49 :     sqliteBindDouble(insertStmt, 13, tilt);
    2504           49 :     sqliteBindDouble(insertStmt, 14, width);
    2505           49 :     sqliteBindLogical(insertStmt, 15, heatTransSurf);
    2506           49 :     sqliteBindForeignKey(insertStmt, 16, baseSurf);
    2507           49 :     sqliteBindForeignKey(insertStmt, 17, zone);
    2508           49 :     sqliteBindInteger(insertStmt, 18, extBoundCond);
    2509           49 :     sqliteBindLogical(insertStmt, 19, extSolar);
    2510           49 :     sqliteBindLogical(insertStmt, 20, extWind);
    2511              : 
    2512           49 :     int rc = sqliteStepCommand(insertStmt);
    2513           49 :     bool validInsert = sqliteStepValidity(rc);
    2514           49 :     sqliteResetCommand(insertStmt);
    2515           49 :     return validInsert;
    2516              : }
    2517              : 
    2518            2 : bool SQLite::ZoneList::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2519              : {
    2520            2 :     sqliteBindInteger(insertStmt, 1, number);
    2521            2 :     sqliteBindText(insertStmt, 2, name);
    2522              : 
    2523            2 :     int rc = sqliteStepCommand(insertStmt);
    2524            2 :     bool validInsert = sqliteStepValidity(rc);
    2525            2 :     sqliteResetCommand(insertStmt);
    2526            2 :     return validInsert;
    2527              : }
    2528              : 
    2529            2 : bool SQLite::ZoneList::insertIntoSQLite(sqlite3_stmt *insertStmt, sqlite3_stmt *subInsertStmt)
    2530              : {
    2531            2 :     bool zoneListInsertValid = insertIntoSQLite(insertStmt);
    2532            2 :     if (!zoneListInsertValid) return false;
    2533            2 :     bool valid = true;
    2534            5 :     for (size_t i = 1; i <= zones.size(); ++i) {
    2535            3 :         sqliteBindForeignKey(subInsertStmt, 1, number);
    2536            3 :         sqliteBindForeignKey(subInsertStmt, 2, zones(i));
    2537            3 :         int rc = sqliteStepCommand(subInsertStmt);
    2538            3 :         bool validInsert = sqliteStepValidity(rc);
    2539            3 :         sqliteResetCommand(subInsertStmt);
    2540            3 :         if (valid && !validInsert) valid = false;
    2541              :     }
    2542            2 :     return valid;
    2543              : }
    2544              : 
    2545           46 : bool SQLite::Schedule::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2546              : {
    2547           46 :     sqliteBindInteger(insertStmt, 1, number);
    2548           46 :     sqliteBindText(insertStmt, 2, name);
    2549           46 :     sqliteBindText(insertStmt, 3, type);
    2550           46 :     sqliteBindDouble(insertStmt, 4, minValue);
    2551           46 :     sqliteBindDouble(insertStmt, 5, maxValue);
    2552              : 
    2553           46 :     int rc = sqliteStepCommand(insertStmt);
    2554           46 :     bool validInsert = sqliteStepValidity(rc);
    2555           46 :     sqliteResetCommand(insertStmt);
    2556           46 :     return validInsert;
    2557              : }
    2558              : 
    2559           10 : bool SQLite::Zone::insertIntoSQLite(sqlite3_stmt *insertStmt)
    2560              : {
    2561           10 :     sqliteBindInteger(insertStmt, 1, number);
    2562           10 :     sqliteBindText(insertStmt, 2, name);
    2563           10 :     sqliteBindDouble(insertStmt, 3, relNorth);
    2564           10 :     sqliteBindDouble(insertStmt, 4, originX);
    2565           10 :     sqliteBindDouble(insertStmt, 5, originY);
    2566           10 :     sqliteBindDouble(insertStmt, 6, originZ);
    2567           10 :     sqliteBindDouble(insertStmt, 7, centroidX);
    2568           10 :     sqliteBindDouble(insertStmt, 8, centroidY);
    2569           10 :     sqliteBindDouble(insertStmt, 9, centroidZ);
    2570           10 :     sqliteBindInteger(insertStmt, 10, ofType);
    2571           10 :     sqliteBindInteger(insertStmt, 11, multiplier);
    2572           10 :     sqliteBindInteger(insertStmt, 12, listMultiplier);
    2573           10 :     sqliteBindDouble(insertStmt, 13, minimumX);
    2574           10 :     sqliteBindDouble(insertStmt, 14, maximumX);
    2575           10 :     sqliteBindDouble(insertStmt, 15, minimumY);
    2576           10 :     sqliteBindDouble(insertStmt, 16, maximumY);
    2577           10 :     sqliteBindDouble(insertStmt, 17, minimumZ);
    2578           10 :     sqliteBindDouble(insertStmt, 18, maximumZ);
    2579           10 :     sqliteBindDouble(insertStmt, 19, ceilingHeight);
    2580           10 :     sqliteBindDouble(insertStmt, 20, volume);
    2581           10 :     sqliteBindInteger(insertStmt, 21, Convect::HcIntReportVals[static_cast<int>(insideConvectionAlgo)]);
    2582           10 :     sqliteBindInteger(insertStmt, 22, Convect::HcExtReportVals[static_cast<int>(outsideConvectionAlgo)]);
    2583           10 :     sqliteBindDouble(insertStmt, 23, floorArea);
    2584           10 :     sqliteBindDouble(insertStmt, 24, extGrossWallArea);
    2585           10 :     sqliteBindDouble(insertStmt, 25, extNetWallArea);
    2586           10 :     sqliteBindDouble(insertStmt, 26, extWindowArea);
    2587           10 :     sqliteBindLogical(insertStmt, 27, isPartOfTotalArea);
    2588              : 
    2589           10 :     int rc = sqliteStepCommand(insertStmt);
    2590           10 :     bool validInsert = sqliteStepValidity(rc);
    2591           10 :     sqliteResetCommand(insertStmt);
    2592           10 :     return validInsert;
    2593              : }
    2594              : 
    2595          236 : SQLite::SQLiteData::SQLiteData(std::shared_ptr<std::ostream> const &errorStream, std::shared_ptr<sqlite3> const &db)
    2596          236 :     : SQLiteProcedures(errorStream, db)
    2597              : {
    2598          236 : }
    2599              : 
    2600          236 : SQLiteProcedures::SQLiteProcedures(std::shared_ptr<std::ostream> const &errorStream, std::shared_ptr<sqlite3> const &db)
    2601          236 :     : m_writeOutputToSQLite(true), m_errorStream(errorStream), m_db(db)
    2602              : {
    2603          236 : }
    2604              : 
    2605          113 : SQLiteProcedures::SQLiteProcedures(std::shared_ptr<std::ostream> const &errorStream,
    2606              :                                    bool writeOutputToSQLite,
    2607              :                                    fs::path const &dbName,
    2608          113 :                                    fs::path const &errorFilePath)
    2609          113 :     : m_writeOutputToSQLite(writeOutputToSQLite), m_errorStream(errorStream)
    2610              : {
    2611          113 :     sqlite3 *m_connection = nullptr;
    2612          113 :     if (m_writeOutputToSQLite) {
    2613              :         int rc;
    2614          113 :         bool ok = true;
    2615              : 
    2616          113 :         std::string const dbName_utf8 = FileSystem::toGenericString(dbName);
    2617              : 
    2618              :         // Test if we can write to the sqlite error file
    2619              :         //  Does there need to be a separate sqlite.err file at all?  Consider using eplusout.err
    2620          113 :         if (m_errorStream) {
    2621          113 :             *m_errorStream << "SQLite3 message, " << FileSystem::toGenericString(errorFilePath) << " open for processing!" << std::endl;
    2622              :         } else {
    2623            0 :             ok = false;
    2624              :         }
    2625              : 
    2626              :         // Test if we can create a new file named dbName
    2627          113 :         if (ok && dbName != ":memory:") {
    2628            3 :             std::ofstream test(dbName, std::ofstream::out | std::ofstream::trunc);
    2629            3 :             if (test.is_open()) {
    2630            3 :                 test.close();
    2631              :             } else {
    2632            0 :                 ok = false;
    2633              :             }
    2634            3 :         }
    2635              : 
    2636              :         // Test if we can write to the database
    2637              :         // If we can't then there are probably locks on the database
    2638          113 :         if (ok) {
    2639              :             // sqlite3_open_v2 could return SQLITE_BUSY at this point. If so, do not proceed to sqlite3_exec.
    2640          113 :             rc = sqlite3_open_v2(dbName_utf8.c_str(), &m_connection, SQLITE_OPEN_READWRITE, nullptr);
    2641          113 :             if (rc) {
    2642            0 :                 *m_errorStream << "SQLite3 message, can't get exclusive lock to open database: " << sqlite3_errmsg(m_connection) << std::endl;
    2643            0 :                 ok = false;
    2644              :             }
    2645              :         }
    2646              : 
    2647          113 :         if (ok) {
    2648          113 :             char *zErrMsg = nullptr;
    2649              :             // Set journal_mode OFF to avoid creating the file dbName + "-journal" (when dbName is a regular file)
    2650          113 :             rc = sqlite3_exec(m_connection, "PRAGMA journal_mode = OFF;", nullptr, 0, &zErrMsg);
    2651          113 :             if (!rc) {
    2652          113 :                 rc = sqlite3_exec(m_connection, "CREATE TABLE Test(x INTEGER PRIMARY KEY)", nullptr, 0, &zErrMsg);
    2653              :             }
    2654          113 :             sqlite3_close(m_connection);
    2655          113 :             if (rc) {
    2656            0 :                 *m_errorStream << "SQLite3 message, can't get exclusive lock to edit database: " << zErrMsg << std::endl;
    2657            0 :                 ok = false;
    2658              :             } else {
    2659          113 :                 if (dbName != ":memory:") {
    2660              :                     // Remove test db
    2661              :                     // rc = remove(dbName_utf8.c_str());
    2662            3 :                     if (fs::is_regular_file(dbName)) {
    2663            3 :                         std::error_code ec;
    2664            3 :                         if (!fs::remove(dbName, ec)) {
    2665              :                             // File operation failed. SQLite connection is not in an error state.
    2666            0 :                             *m_errorStream << "SQLite3 message, can't remove old database. code=" << ec.value() << ", error: " << ec.message()
    2667            0 :                                            << std::endl;
    2668            0 :                             ok = false;
    2669              :                         }
    2670              :                     }
    2671              :                 }
    2672              :             }
    2673          113 :             sqlite3_free(zErrMsg);
    2674              :         }
    2675              : 
    2676          113 :         if (ok) {
    2677              :             // Now open the output db for the duration of the simulation
    2678          113 :             rc = sqlite3_open_v2(dbName_utf8.c_str(), &m_connection, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
    2679          113 :             m_db = std::shared_ptr<sqlite3>(m_connection, sqlite3_close);
    2680          113 :             if (rc) {
    2681            0 :                 *m_errorStream << "SQLite3 message, can't open new database: " << sqlite3_errmsg(m_connection) << std::endl;
    2682            0 :                 ok = false;
    2683              :             }
    2684              :         }
    2685              : 
    2686          113 :         if (!ok) {
    2687            0 :             throw std::runtime_error("The SQLite database failed to open.");
    2688              :         }
    2689          113 :     }
    2690          113 : }
    2691              : 
    2692         6543 : int SQLiteProcedures::sqliteExecuteCommand(std::string_view commandBuffer)
    2693              : {
    2694         6543 :     char *zErrMsg = 0;
    2695              : 
    2696         6543 :     int rc = sqlite3_exec(m_db.get(), commandBuffer.data(), NULL, 0, &zErrMsg);
    2697         6543 :     if (rc != SQLITE_OK) {
    2698            0 :         *m_errorStream << zErrMsg;
    2699              :     }
    2700         6543 :     sqlite3_free(zErrMsg);
    2701              : 
    2702         6543 :     return rc;
    2703              : }
    2704              : 
    2705         4404 : int SQLiteProcedures::sqlitePrepareStatement(sqlite3_stmt *&stmt, std::string_view stmtBuffer)
    2706              : {
    2707         4404 :     int rc = sqlite3_prepare_v2(m_db.get(), stmtBuffer.data(), stmtBuffer.size(), &stmt, nullptr);
    2708         4404 :     if (rc != SQLITE_OK) {
    2709            0 :         *m_errorStream << "SQLite3 message, sqlite3_prepare_v2 message:\n"
    2710              :                        << stmtBuffer << "\n"
    2711              :                        << sqlite3_errstr(rc) << "\n"
    2712            0 :                        << sqlite3_errmsg(m_db.get()) << std::endl;
    2713              :     }
    2714              : 
    2715         4404 :     return rc;
    2716              : }
    2717              : 
    2718        32172 : int SQLiteProcedures::sqliteBindText(sqlite3_stmt *stmt, const int stmtInsertLocationIndex, std::string_view textBuffer)
    2719              : {
    2720        32172 :     int rc = sqlite3_bind_text(stmt, stmtInsertLocationIndex, textBuffer.data(), textBuffer.size(), SQLITE_TRANSIENT);
    2721        32172 :     if (rc != SQLITE_OK) {
    2722            0 :         *m_errorStream << "SQLite3 message, sqlite3_bind_text failed:\n"
    2723              :                        << textBuffer << "\n"
    2724              :                        << sqlite3_errstr(rc) << "\n"
    2725            0 :                        << sqlite3_errmsg(m_db.get()) << std::endl;
    2726              :     }
    2727              : 
    2728        32172 :     return rc;
    2729              : }
    2730              : 
    2731        85560 : int SQLiteProcedures::sqliteBindInteger(sqlite3_stmt *stmt, const int stmtInsertLocationIndex, const int intToInsert)
    2732              : {
    2733        85560 :     int rc = sqlite3_bind_int(stmt, stmtInsertLocationIndex, intToInsert);
    2734        85560 :     if (rc != SQLITE_OK) {
    2735            0 :         *m_errorStream << "SQLite3 message, sqlite3_bind_int failed: " << intToInsert << std::endl;
    2736              :     }
    2737              : 
    2738        85560 :     return rc;
    2739              : }
    2740              : 
    2741         4990 : int SQLiteProcedures::sqliteBindDouble(sqlite3_stmt *stmt, const int stmtInsertLocationIndex, const double doubleToInsert)
    2742              : {
    2743         4990 :     int rc = sqlite3_bind_double(stmt, stmtInsertLocationIndex, doubleToInsert);
    2744         4990 :     if (rc != SQLITE_OK) {
    2745            0 :         *m_errorStream << "SQLite3 message, sqlite3_bind_double failed: " << doubleToInsert << std::endl;
    2746              :     }
    2747              : 
    2748         4990 :     return rc;
    2749              : }
    2750              : 
    2751          409 : int SQLiteProcedures::sqliteBindNULL(sqlite3_stmt *stmt, const int stmtInsertLocationIndex)
    2752              : {
    2753          409 :     int rc = sqlite3_bind_null(stmt, stmtInsertLocationIndex);
    2754          409 :     if (rc != SQLITE_OK) {
    2755            0 :         *m_errorStream << "SQLite3 message, sqlite3_bind_null failed" << std::endl;
    2756              :     }
    2757              : 
    2758          409 :     return rc;
    2759              : }
    2760              : 
    2761       178481 : int SQLiteProcedures::sqliteBindForeignKey(sqlite3_stmt *stmt, const int stmtInsertLocationIndex, const int intToInsert)
    2762              : {
    2763       178481 :     int rc = -1;
    2764       178481 :     if (intToInsert > 0) {
    2765       178449 :         rc = sqlite3_bind_int(stmt, stmtInsertLocationIndex, intToInsert);
    2766              :     } else {
    2767           32 :         rc = sqlite3_bind_null(stmt, stmtInsertLocationIndex);
    2768              :     }
    2769       178481 :     if (rc != SQLITE_OK) {
    2770            0 :         *m_errorStream << "SQLite3 message, sqliteBindForeignKey failed: " << intToInsert << std::endl;
    2771              :     }
    2772              : 
    2773       178481 :     return rc;
    2774              : }
    2775              : 
    2776          674 : int SQLiteProcedures::sqliteBindLogical(sqlite3_stmt *stmt, const int stmtInsertLocationIndex, const bool valueToInsert)
    2777              : {
    2778          674 :     return sqliteBindInteger(stmt, stmtInsertLocationIndex, valueToInsert ? 1 : 0);
    2779              : }
    2780              : 
    2781          239 : bool SQLiteProcedures::sqliteStepValidity(int const rc)
    2782              : {
    2783          239 :     bool isValid = false;
    2784          239 :     switch (rc) {
    2785          239 :     case SQLITE_DONE:
    2786              :     case SQLITE_OK:
    2787              :     case SQLITE_ROW:
    2788          239 :         isValid = true;
    2789          239 :         break;
    2790            0 :     default:
    2791            0 :         break;
    2792              :     }
    2793          239 :     return isValid;
    2794              : }
    2795              : 
    2796        33500 : int SQLiteProcedures::sqliteStepCommand(sqlite3_stmt *stmt)
    2797              : {
    2798        33500 :     int rc = sqlite3_step(stmt);
    2799        33500 :     switch (rc) {
    2800        33445 :     case SQLITE_DONE:
    2801              :     case SQLITE_OK:
    2802              :     case SQLITE_ROW:
    2803        33445 :         break;
    2804           55 :     default:
    2805           55 :         *m_errorStream << "SQLite3 message, sqlite3_step message: " << sqlite3_errmsg(m_db.get()) << std::endl;
    2806           55 :         break;
    2807              :     }
    2808              : 
    2809        33500 :     return rc;
    2810              : }
    2811              : 
    2812        33500 : int SQLiteProcedures::sqliteResetCommand(sqlite3_stmt *stmt)
    2813              : {
    2814        33500 :     return sqlite3_reset(stmt);
    2815              : }
    2816              : 
    2817            3 : bool SQLiteProcedures::sqliteWithinTransaction()
    2818              : {
    2819            3 :     return (sqlite3_get_autocommit(m_db.get()) == 0);
    2820              : }
    2821              : 
    2822              : // int SQLiteProcedures::sqliteClearBindings(sqlite3_stmt * stmt)
    2823              : // {
    2824              : //     return sqlite3_clear_bindings(stmt);
    2825              : // }
    2826              : 
    2827              : // int SQLiteProcedures::sqliteFinalizeCommand(sqlite3_stmt * stmt)
    2828              : // {
    2829              : //     return sqlite3_finalize(stmt);
    2830              : // }
    2831              : 
    2832              : } // namespace EnergyPlus
        

Generated by: LCOV version 2.0-1