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

Method Execute

IO/PostgreSQL/vtkPostgreSQLQuery.cxx:216–309  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

214
215//------------------------------------------------------------------------------
216bool vtkPostgreSQLQuery::Execute()
217{
218 if (this->Query == nullptr)
219 {
220 vtkErrorMacro("Cannot execute before a query has been set.");
221 return false;
222 }
223
224 vtkPostgreSQLDatabase* db = vtkPostgreSQLDatabase::SafeDownCast(this->Database);
225 assert(db);
226
227 // If a query is already in progress clear out its results so we can
228 // begin anew.
229 if (this->QueryInternals)
230 {
231 this->DeleteQueryResults();
232 }
233
234 if (!db->IsOpen())
235 {
236 this->SetLastErrorText("Cannot execute query. Database connection is closed.");
237 vtkErrorMacro(<< "Cannot execute query. Database connection is closed.");
238 this->Active = false;
239 return false;
240 }
241
242 this->QueryInternals = new vtkPostgreSQLQueryPrivate;
243 this->QueryInternals->QueryResults = PQexec(db->Connection->Connection, this->Query);
244
245 bool returnStatus;
246 switch (PQresultStatus(this->QueryInternals->QueryResults))
247 {
248 case PGRES_EMPTY_QUERY:
249 {
250 returnStatus = true;
251 this->Active = false;
252 this->DeleteQueryResults();
253 vtkWarningMacro(<< "Query string was set but empty.");
254 this->SetLastErrorText(nullptr);
255 };
256 break;
257
258 case PGRES_COMMAND_OK: // success on a command returning no data
259 {
260 returnStatus = true;
261 this->Active = true;
262 this->DeleteQueryResults();
263 this->SetLastErrorText(nullptr);
264 };
265 break;
266
267 case PGRES_TUPLES_OK:
268 {
269 returnStatus = true;
270 this->Active = true;
271 this->SetLastErrorText(nullptr);
272 };
273 break;

Callers 10

WriteDataMethod · 0.45
GetTablesMethod · 0.45
GetRecordMethod · 0.45
GetDatabasesMethod · 0.45
CreateDatabaseMethod · 0.45
DropDatabaseMethod · 0.45
UpdateDataTypeMapMethod · 0.45
RequestDataMethod · 0.45
TestPostgreSQLDatabaseFunction · 0.45

Calls 6

DeleteQueryResultsMethod · 0.95
GetLastErrorTextMethod · 0.95
assertFunction · 0.50
IsOpenMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45

Tested by 2

TestPostgreSQLDatabaseFunction · 0.36