Changeset bf76088 in observatorio for simulacion/SimEscenariosEconomicos
- Timestamp:
- Jan 12, 2015, 8:47:12 AM (9 years ago)
- Branches:
- simulacion
- Children:
- 23daf5e
- Parents:
- 666042a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
simulacion/SimEscenariosEconomicos/queries.C
reac25c3 rbf76088 197 197 } 198 198 199 std::string getSupplierName(const std::string & rif) { 200 201 AutoConnection conn; 202 203 DBQuery query(conn); 204 205 StrQuery strQuery; 206 207 strQuery.addSelect(DB::NAME); 208 strQuery.addFrom(DB::SUPPLIER_TABLE_NAME); 209 strQuery.addWhere(op(DB::RIF, singleQuote(rif))); 210 211 if (not query.exec(strQuery)) { 212 213 std::string msg = "Cannot execute query: " + std::string(strQuery); 214 215 throw std::logic_error(msg); 216 } 217 218 if (not query.next()) { 219 220 std::stringstream msg; 221 222 msg << "Supplier with R.I.F. = " << rif 223 << " does not exists in database"; 224 225 throw std::domain_error(msg.str()); 226 } 227 228 return query.getValue(0); 229 } 230 199 231 void listInputs(const size_t & inputId, const std::string & year, 200 232 List <InputInfo> & inputs) { … … 258 290 query.clear(); 259 291 260 strQuery.addSelect(concatas(DB::SUPPLIER_TABLE_NAME, DB::ID)); 261 strQuery.addSelect(concatas(DB::SUPPLIER_TABLE_NAME, DB::NAME)); 262 strQuery.addSelect(concatas(DB::SUPPLIER_TABLE_NAME, DB::RIF)); 263 strQuery.addSelect(concatas(DB::SUPPLIER_TABLE_NAME, DB::NATIONALITY)); 264 strQuery.addSelect(concatas(DB::INPUT_SUPPLIER_TABLE_NAME, 265 DB::BOUGHT_QUANTITY)); 266 267 strQuery.addFrom(DB::INPUT_SUPPLIER_TABLE_NAME); 268 strQuery.addFrom(DB::SUPPLIER_TABLE_NAME); 269 270 strQuery.addWhere(op(concat(DB::INPUT_SUPPLIER_TABLE_NAME, DB::YEAR_R), 271 year)); 272 strQuery.addWhere(op(concat(DB::INPUT_SUPPLIER_TABLE_NAME, DB::INPUT_ID), 273 idToStr(inputId))); 274 strQuery.addWhere(op(concat(DB::INPUT_SUPPLIER_TABLE_NAME, 275 DB::SUPPLIER_ID), 276 concat(DB::SUPPLIER_TABLE_NAME, DB::ID))); 277 278 if (not query.exec(strQuery)) { 279 280 std::string msg = "Cannot execute query: " + std::string(strQuery); 292 std::string sum = "SUM(" + concat(DB::INPUT_SUPPLIER_TABLE_NAME, 293 DB::BOUGHT_QUANTITY) 294 + ") AS " + 295 concat(DB::INPUT_SUPPLIER_TABLE_NAME, 296 DB::BOUGHT_QUANTITY, '_'); 297 298 std::string strquery = 299 "SELECT " + 300 concatas(DB::SUPPLIER_TABLE_NAME, DB::RIF) + ',' + 301 concatas(DB::SUPPLIER_TABLE_NAME, DB::NATIONALITY) + ',' + sum + 302 " FROM " + 303 DB::INPUT_SUPPLIER_TABLE_NAME + ',' + 304 DB::SUPPLIER_TABLE_NAME + 305 " WHERE " + 306 op(concat(DB::INPUT_SUPPLIER_TABLE_NAME, DB::YEAR_R), year) + " AND " + 307 op(concat(DB::INPUT_SUPPLIER_TABLE_NAME, DB::INPUT_ID), 308 idToStr(inputId)) + " AND " + 309 op(concat(DB::INPUT_SUPPLIER_TABLE_NAME, DB::SUPPLIER_ID), 310 concat(DB::SUPPLIER_TABLE_NAME, DB::ID)) + 311 " GROUP BY " + 312 concat(DB::SUPPLIER_TABLE_NAME, DB::RIF, '_') + ',' + 313 concat(DB::SUPPLIER_TABLE_NAME, DB::NATIONALITY, '_'); 314 315 316 if (not query.exec(strquery)) { 317 318 std::string msg = "Cannot execute query: " + strquery; 281 319 282 320 throw std::logic_error(msg); … … 287 325 inputInfo.companyRif = 288 326 query.getValue(concat(DB::SUPPLIER_TABLE_NAME, DB::RIF, '_')); 289 inputInfo.companyName = 290 query.getValue(concat(DB::SUPPLIER_TABLE_NAME, DB::NAME, '_')); 327 inputInfo.companyName = getSupplierName(inputInfo.companyRif); 291 328 inputInfo.quantity = std::atof( 292 329 query.getValue(concat(DB::INPUT_SUPPLIER_TABLE_NAME,
Note: See TracChangeset
for help on using the changeset viewer.