------------------------------------------------------------------------------
| 598 | |
| 599 | //------------------------------------------------------------------------------ |
| 600 | bool vtkPostgreSQLDatabase::DropDatabase(const char* dbName) |
| 601 | { |
| 602 | if (!dbName || strlen(dbName) == 0) |
| 603 | { |
| 604 | vtkErrorMacro("DropDatabase called with an empty database name"); |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | if (!strcmp(dbName, this->DatabaseName)) |
| 609 | { |
| 610 | // Can't drop database we're connected to... connect to the default db. |
| 611 | this->SetDatabaseName("template1"); |
| 612 | } |
| 613 | |
| 614 | if (!this->Connection) |
| 615 | { |
| 616 | bool err = true; |
| 617 | if (this->DatabaseName && this->HostName) |
| 618 | { |
| 619 | err = !this->Open(); |
| 620 | } |
| 621 | if (err) |
| 622 | { |
| 623 | vtkErrorMacro("Must be connected to a server to create a database."); |
| 624 | return false; |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | std::string qstr("DROP DATABASE IF EXISTS \""); |
| 629 | qstr += dbName; |
| 630 | qstr += "\""; |
| 631 | vtkSQLQuery* query = this->GetQueryInstance(); |
| 632 | query->SetQuery(qstr.c_str()); |
| 633 | if (!query->Execute()) |
| 634 | { |
| 635 | this->SetLastErrorText(query->GetLastErrorText()); |
| 636 | vtkErrorMacro(<< "Could not drop database \"" << dbName << "\". " |
| 637 | << query->GetLastErrorText()); |
| 638 | query->Delete(); |
| 639 | return false; |
| 640 | } |
| 641 | this->SetLastErrorText(nullptr); |
| 642 | query->Delete(); |
| 643 | return true; |
| 644 | } |
| 645 | |
| 646 | void vtkPostgreSQLDatabase::NullTrailingWhitespace(char* msg) |
| 647 | { |