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

Method CreateDatabase

IO/PostgreSQL/vtkPostgreSQLDatabase.cxx:526–597  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

524
525//------------------------------------------------------------------------------
526bool vtkPostgreSQLDatabase::CreateDatabase(const char* dbName, bool dropExisting)
527{
528 if (!dbName)
529 {
530 vtkErrorMacro("Databases must have a non-nullptr name");
531 return false;
532 }
533
534 bool dropCurrentlyConnected = false;
535 if (this->DatabaseName && !strcmp(this->DatabaseName, dbName))
536 {
537 dropCurrentlyConnected = true;
538 if (dropExisting)
539 {
540 // we can't drop a database we're connected to...
541 this->SetDatabaseName("template1");
542 this->Open();
543 }
544 else
545 {
546 // this will fail... let it. then report the error via LastErrorText
547 }
548 }
549
550 if (!this->Connection)
551 {
552 if (this->DatabaseName && !strcmp(this->DatabaseName, dbName))
553 {
554 // we can't connect to a database we haven't created yet and aren't connected to...
555 this->SetDatabaseName("template1");
556 dropCurrentlyConnected = true;
557 }
558 bool err = true;
559 if (this->DatabaseName && this->HostName)
560 {
561 err = !this->Open();
562 }
563 if (err)
564 {
565 vtkErrorMacro("Must be connected to a server to create a database.");
566 return false;
567 }
568 }
569
570 if (dropExisting)
571 {
572 this->DropDatabase(dbName);
573 }
574
575 std::string qstr("CREATE DATABASE \"");
576 qstr += dbName;
577 qstr += "\"";
578 vtkSQLQuery* query = this->GetQueryInstance();
579 query->SetQuery(qstr.c_str());
580 if (!query->Execute())
581 {
582 this->SetLastErrorText(query->GetLastErrorText());
583 vtkErrorMacro(

Callers 2

TestPostgreSQLDatabaseFunction · 0.45

Calls 8

OpenMethod · 0.95
DropDatabaseMethod · 0.95
GetQueryInstanceMethod · 0.95
GetLastErrorTextMethod · 0.95
DeleteMethod · 0.65
SetQueryMethod · 0.45
c_strMethod · 0.45
ExecuteMethod · 0.45

Tested by 2

TestPostgreSQLDatabaseFunction · 0.36