MCPcopy Create free account
hub / github.com/Kitware/VTK / CommitTransaction

Method CommitTransaction

IO/PostgreSQL/vtkPostgreSQLQuery.cxx:483–526  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

481
482//------------------------------------------------------------------------------
483bool vtkPostgreSQLQuery::CommitTransaction()
484{
485 if (!this->TransactionInProgress)
486 {
487 vtkErrorMacro(<< "Cannot commit: no transaction is in progress.");
488 return false;
489 }
490
491 vtkPostgreSQLDatabase* db = vtkPostgreSQLDatabase::SafeDownCast(this->Database);
492 assert(db);
493
494 PGresult* result = PQexec(db->Connection->Connection, COMMIT_TRANSACTION);
495 bool status;
496 switch (PQresultStatus(result))
497 {
498 case PGRES_COMMAND_OK:
499 {
500 this->SetLastErrorText(nullptr);
501 this->TransactionInProgress = false;
502 status = true;
503 };
504 break;
505 case PGRES_FATAL_ERROR:
506 {
507 this->SetLastErrorText(PQresultErrorMessage(result));
508 vtkErrorMacro(<< "Error in CommitTransaction: " << this->GetLastErrorText());
509 this->TransactionInProgress = false;
510 status = false;
511 };
512 break;
513 default:
514 {
515 this->SetLastErrorText(PQresultErrorMessage(result));
516 vtkWarningMacro(<< "Unexpected return code " << PQresultStatus(result) << " ("
517 << PQresStatus(PQresultStatus(result)) << ") with error message "
518 << (this->LastErrorText ? this->LastErrorText : "(null)"));
519 this->TransactionInProgress = false;
520 status = false;
521 };
522 break;
523 }
524 PQclear(result);
525 return status;
526}
527
528//------------------------------------------------------------------------------
529bool vtkPostgreSQLQuery::RollbackTransaction()

Callers

nothing calls this directly

Calls 2

GetLastErrorTextMethod · 0.95
assertFunction · 0.50

Tested by

no test coverage detected