------------------------------------------------------------------------------
| 438 | |
| 439 | //------------------------------------------------------------------------------ |
| 440 | bool vtkPostgreSQLQuery::BeginTransaction() |
| 441 | { |
| 442 | if (this->TransactionInProgress) |
| 443 | { |
| 444 | vtkErrorMacro(<< "Cannot start a transaction. One is already in progress."); |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | vtkPostgreSQLDatabase* db = vtkPostgreSQLDatabase::SafeDownCast(this->Database); |
| 449 | assert(db); |
| 450 | bool status; |
| 451 | PGresult* result = PQexec(db->Connection->Connection, BEGIN_TRANSACTION); |
| 452 | switch (PQresultStatus(result)) |
| 453 | { |
| 454 | case PGRES_COMMAND_OK: |
| 455 | { |
| 456 | this->SetLastErrorText(nullptr); |
| 457 | this->TransactionInProgress = true; |
| 458 | status = true; |
| 459 | }; |
| 460 | break; |
| 461 | case PGRES_FATAL_ERROR: |
| 462 | { |
| 463 | this->SetLastErrorText(PQresultErrorMessage(result)); |
| 464 | vtkErrorMacro(<< "Error in BeginTransaction: " << this->GetLastErrorText()); |
| 465 | status = false; |
| 466 | }; |
| 467 | break; |
| 468 | default: |
| 469 | { |
| 470 | this->SetLastErrorText(PQresultErrorMessage(result)); |
| 471 | vtkWarningMacro(<< "Unexpected return code " << PQresultStatus(result) << " (" |
| 472 | << PQresStatus(PQresultStatus(result)) << ") with error message " |
| 473 | << (this->LastErrorText ? this->LastErrorText : "(null)")); |
| 474 | status = false; |
| 475 | }; |
| 476 | break; |
| 477 | } |
| 478 | PQclear(result); |
| 479 | return status; |
| 480 | } |
| 481 | |
| 482 | //------------------------------------------------------------------------------ |
| 483 | bool vtkPostgreSQLQuery::CommitTransaction() |
nothing calls this directly
no test coverage detected