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

Method Open

IO/PostgreSQL/vtkPostgreSQLDatabase.cxx:221–291  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

219
220//------------------------------------------------------------------------------
221bool vtkPostgreSQLDatabase::Open(const char* password)
222{
223 if (!this->HostName || !this->DatabaseName)
224 {
225 this->SetLastErrorText("Cannot open database because HostName and/or DatabaseName are null.");
226 vtkErrorMacro(<< this->GetLastErrorText());
227 return false;
228 }
229
230 if (this->Connection)
231 {
232 if (this->ConnectionMTime > this->URLMTime)
233 {
234 return true; // we already had that database open.
235 }
236 this->Close(); // close the old connection before opening a new one
237 }
238
239 std::string options;
240 options = "dbname=";
241 options += this->DatabaseName;
242
243 if (this->ServerPort > 0)
244 {
245 options += " port=";
246 std::ostringstream stream;
247 stream << this->ServerPort;
248 options += stream.str();
249 }
250 if (this->User && strlen(this->User) > 0)
251 {
252 options += " user=";
253 options += this->User;
254 }
255 if (password && this->Password != password)
256 {
257 delete[] this->Password;
258 this->Password = password ? vtksys::SystemTools::DuplicateString(password) : nullptr;
259 }
260 if (this->Password && strlen(this->Password) > 0)
261 {
262 options += " password=";
263 options += this->Password;
264 }
265 if (this->ConnectOptions && strlen(this->ConnectOptions) > 0)
266 {
267 options += this->ConnectOptions;
268 }
269
270 // If localhost is specified, try the local socket connection
271 // first. Only if that doesn't work will we try the loopback
272 // device.
273 if (!strcmp(this->HostName, "localhost"))
274 {
275 if (this->OpenInternal(options.c_str()))
276 {
277 this->SetLastErrorText(nullptr);
278 return true;

Callers 8

CreateDatabaseMethod · 0.95
DropDatabaseMethod · 0.95
collectMetaDataMethod · 0.45
ply_open_for_readingMethod · 0.45
TestPLYReaderFunction · 0.45
RequestInformationMethod · 0.45
TestPostgreSQLDatabaseFunction · 0.45

Calls 5

GetLastErrorTextMethod · 0.95
CloseMethod · 0.95
OpenInternalMethod · 0.95
strMethod · 0.45
c_strMethod · 0.45

Tested by 3

TestPLYReaderFunction · 0.36
TestPostgreSQLDatabaseFunction · 0.36