Given some input values and primary key of an existing row, insert a new row which will supersede the old, according to prescription laid down in <supersede> element of the xml description of the dbs.
Good return value is 0
315 {
316 std::string oldKeyStr;
318
319 if (m_primaryKeyCol.size() == 0) {
320 throw RdbException("Table::supersedeRow No primary key column!");
321 }
322
323
324 row.rowSort();
325 const std::vector<std::string>& forced = m_sup->
getForced();
326 for (unsigned i = 0; i < forced.size(); i++) {
327 if (row.find(forced[i])) {
328
329
330
331 (*m_out) << "Table::supersedeRow bad column in input row '"
332 << forced[i] << "'" << std::endl;
333 m_out->flush();
334 return -1;
335 }
336 }
337 const std::vector<FieldVal>& fixed = m_sup->
getFixed();
338 for (unsigned i = 0; i < fixed.size(); i++) {
339 if (row.find(fixed[i].m_colname)) {
340
341
342
343 (*m_out) << "Table::supersedeRow bad column in input row " <<
344 fixed[i].m_colname;
345 m_out->flush();
346 return -1;
347 }
348 }
349
350
351 if (!isSupersedable(oldKeyStr)) {
352 *m_out << "Row " << oldKey << " is not supersedable" << std::endl;
353 m_out->flush();
354 return -1;
355 }
356
357
358 const std::vector<std::string>& fixedInterp = m_sup->
getFixedInterp();
359 for (unsigned i = 0; i < fixed.size(); i++) {
360
361 FieldVal fv = fixed[i];
362 if (fixedInterp[i].size() > 0) {
364 c->interpret(fixedInterp[i], fv.m_val);
365 }
366 row.addField(fv);
367 }
368 row.rowSort();
369
370
371 Assertion::Operator* whereOp =
372 new Assertion::Operator(
OPTYPEequal, m_primaryKeyCol,
374 Assertion* where = new Assertion(whereOp);
375
376 std::vector<std::string> noCols;
377 const std::vector<std::string>& fromOld = m_sup->
getFromOld();
378 noCols.clear();
379 ResultHandle* results = m_connect->
select(m_name, fromOld,
380 noCols, where);
381
382
383 std::vector<std::string*> vals;
385
387 for (unsigned i = 0; i < nDef; i++) {
388 if (!(row.find(fromOld[i])) ) {
389 if (vals[i] == 0) {
390 row.addField(FieldVal(fromOld[i], "", true));
391 }
392 else {
393 row.addField(FieldVal(fromOld[i], *vals[i]));
394 }
395 row.rowSort();
396 }
397 }
398
399 for (unsigned i = nDef; i < fromOld.size(); i++) {
400 if (vals[i] == 0) {
401 row.addField(FieldVal(fromOld[i], "", true));
402 }
403 else {
404 row.addField(FieldVal(fromOld[i], *vals[i]));
405 }
406 }
407 results->cleanFieldPtrs(vals);
408
409
410 int insRet;
411 try {
413 }
414 catch (RdbException ex) {
415 (*m_out) << ex.getMsg() << std::endl;
416 insRet = -1;
417 }
418
419 if (insRet) {
420 delete where;
421 return insRet;
422 }
423
424
425 const std::vector<Set*>& setOld = m_sup->
getSetOld();
426 std::vector<FieldVal> oldFields;
427 oldFields.reserve(setOld.size());
428 for (unsigned i = 0; i < setOld.size(); i++) {
429 std::string src = setOld[i]->getSrcValue();
430 std::string col = setOld[i]->getDestColName();
431 if (setOld[i]->hasInterp() ) {
433 c->interpret(setOld[i]->getInterp(), src);
434 }
435 oldFields.push_back(FieldVal(col, src));
436 }
437 Row updateArg(oldFields);
438 try {
440 if (iUpdated == 1) return 0;
441 return -1;
442 }
443 catch (RdbException uEx) {
444 (*m_out) << uEx.getMsg() << std::endl;
445 return -1;
446 }
447 }
static const char * itoa(int val, std::string &outStr)
virtual bool getRowPtrs(std::vector< std::string * > &fields, unsigned int i=0, bool clear=true)=0
const std::vector< FieldVal > & getFixed() const
const std::vector< std::string > & getFixedInterp() const
const std::vector< std::string > & getFromOld() const
const std::vector< std::string > & getOldDefaulted() const
const std::vector< Set * > & getSetOld() const
const std::vector< std::string > & getForced() const
int insertRow(Row &row, int *serial=0) const
int updateRows(Row &row, Assertion *where) const
Column * getColumnByName(const std::string &name) const