SqlTableModel::SqlTableModel(sql::ResultSet result, Wt::WContainerWidget* parent) : Wt::WStandardItemModel(0, 0, parent) { sql::ResultSetMetaData * rsmd = result.getResultSetMetaData(); int fieldCount = rsmd->getColumnCount(); insertColumns(0, fieldCount); for (int a = 0; a < fieldCount; a++) { /* * for locale support * if(!setHeaderData(a,Wt::WString::tr(rsmd->getColumnName(a).c_str()))){ */ if (!setHeaderData(a, rsmd->getColumnName(a))) { // if(!setHeaderData(a,boost::any(rsmd->getColumnName(a)))){ // if(!setHeaderData(a,boost::any(string("test")))){ std::cout << "Failed" << std::endl; } } for (int a = 0; result.next(); a++) { if (rowCount() <= a) insertRow(rowCount()); for (int b = 0; b < fieldCount; b++) if (!setData(a, b, result.getString(b))) { // if(!setData(a,b,boost::any(result.getString(b)))){ // if(!setData(a,b,boost::any(new string("test")))){ std::cout << "set data Failed" << std::endl; }else { } } // load(result); }
void SqlTableModel::load(sql::ResultSet result) { sql::ResultSetMetaData * rsmd = result.getResultSetMetaData(); int fieldCount = rsmd->getColumnCount(); // insertColumns(0,fieldCount); // for(int a=0;a<fieldCount;a++){ /* * for locale support * if(!setHeaderData(a,Wt::WString::tr(rsmd->getColumnName(a).c_str()))){ */ /* if(!setHeaderData(a,rsmd->getColumnName(a))){ std::cout<<"Failed"<<std::endl; } } */ for (int a = 0; result.next(); a++) { if (rowCount() <= a) insertRow(rowCount()); for (int b = 0; b < fieldCount; b++) if (!setData(a, b, result.getString(b))) { std::cout << "set data Failed" << std::endl; } } }
void CDatabaseReader::ReadRouteStationRow(CTruckRouteStation& routeStation, const sql::ResultSet& rs, const std::auto_ptr<sql::PreparedStatement>& readContractStationTimeStmt) { boost::shared_ptr<CShipmentStation> shipmentStation(new CShipmentStation); ReadCoordinate(shipmentStation->_coord, rs); shipmentStation->_kind = ReadShipmentStationKind(rs); routeStation._shipmentStation = shipmentStation; ReadTimePeriod(routeStation._plannedTimePeriod, rs); routeStation._remainingTruckCapacity._weightKg = rs.getUInt("leftKg"); routeStation._remainingTruckCapacity._liter = getDecimal(rs, "leftM3", 3); // volume routeStation._remainingTruckCapacity._units = rs.getUInt("leftUnits"); if (!rs.isNull("contractStation_id")) { routeStation._contractIndex = CRouteStation::KUnloadedContract; // reading original time period from contract station int contractStationId = rs.getInt("contractStation_id"); readContractStationTimeStmt->setInt(1, contractStationId); std::auto_ptr<sql::ResultSet> contractStationRS(readContractStationTimeStmt->executeQuery()); ReadTimePeriod(routeStation._shipmentStation->_timePeriod, *contractStationRS); } else { routeStation._contractIndex = CRouteStation::KNoContract; } }
void CDatabaseReader::ReadCargoRow(CCargo& cargo, const sql::ResultSet& rs) { cargo._weightKg = rs.getUInt("weightKg"); cargo._liter = getDecimal(rs, "volumeM3", 3); // volume cargo._units = rs.getUInt("volumeUnits"); // paletten; cargo._cargoType = rs.getString("cargoType"); }
void CDatabaseReader::ReadContractRow(CContract& aContract, const sql::ResultSet& rs) { aContract._id = rs.getInt("id"); // _wasSuggestedBefore; // some assignemnt for this contract was already suggested by an earliear run aContract._sealed = rs.getBoolean("sealed"); aContract._price = getDecimal(rs, "price", 2); // cents aContract._loadAmmount._weightKg = rs.getUInt("entireWeightKg"); aContract._loadAmmount._liter = getDecimal(rs, "entireVolumeM3", 3); // volume aContract._loadAmmount._units = rs.getUInt("entireVolumeUnits"); // paletten; }
void CDatabaseReader::ReadCoordinate(CCoordinate& coord, const sql::ResultSet& rs) { coord._lat = getDecimal(rs, "latitude", CCoordinate::KDigitsAfterComma); coord._long = getDecimal(rs, "longitude", CCoordinate::KDigitsAfterComma); if (!coord.IsValid()) { std::string latStr = rs.getString("latitude"); std::string longStr = rs.getString("longitude"); throw new CDBReaderException("read a bad coordinate: (" + latStr + ", " + longStr + ")"); } }
void CDatabaseReader::ReadTruckRow(CTruck& aTruck, const sql::ResultSet& rs) { aTruck._id = rs.getInt("id"); aTruck._capacity._weightKg = rs.getUInt("capacityKg"); aTruck._capacity._liter = getDecimal(rs, "capacityM3", 3); // volume aTruck._capacity._units = rs.getUInt("capacityUnits"); // paletten; aTruck._homeStation._lat = getDecimal(rs, "latHome", 6); aTruck._homeStation._long = getDecimal(rs, "longHome", 6); aTruck._priceHour = getDecimal(rs, "priceHour", 2); aTruck._priceKm = getDecimal(rs, "priceKm", 2); }
void CDatabaseReader::ReadTimePeriod(boost::posix_time::time_period& aTimePeriod, const sql::ResultSet& rs) { using namespace boost::posix_time; using namespace boost::gregorian; std::string startStr = rs.getString("timeFrom"); std::string endStr = rs.getString("timeUntil"); ptime timeFrom = time_from_string(startStr); ptime timeUntil = time_from_string(endStr); if (timeFrom > timeUntil) { throw new CDBReaderException("reading bad time interval: timeFrom (" + startStr + ") is behind the timeUntil (" + endStr + ")"); } aTimePeriod = time_period(timeFrom, timeUntil); }
CShipmentStation::EKind CDatabaseReader::ReadShipmentStationKind(const sql::ResultSet& rs) { std::string kindStr = rs.getString("kind"); boost::algorithm::to_lower(kindStr); if (kindStr == "load") { return CShipmentStation::KLoad; } else if (kindStr == "unload") { return CShipmentStation::KUnload; } else if (kindStr == "driveby") { return CShipmentStation::KDriveby; } else throw new CDBReaderException("Unknown kind of Shipment Station '" + kindStr + "' ??"); }