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

Method Execute

IO/MySQL/vtkMySQLQuery.cxx:489–583  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

487
488//------------------------------------------------------------------------------
489bool vtkMySQLQuery::Execute()
490{
491 this->Active = false;
492
493 if (this->Query == nullptr)
494 {
495 vtkErrorMacro(<< "Cannot execute before a query has been set.");
496 return false;
497 }
498
499 this->Internals->FreeResult();
500
501 vtkMySQLDatabase* dbContainer = static_cast<vtkMySQLDatabase*>(this->Database);
502 assert(dbContainer != nullptr);
503
504 if (!dbContainer->IsOpen())
505 {
506 vtkErrorMacro(<< "Cannot execute query. Database is closed.");
507 return false;
508 }
509
510 vtkDebugMacro(<< "Execute(): Query ready to execute.");
511
512 if (this->Query != nullptr && this->Internals->Statement == nullptr)
513 {
514 MYSQL* db = dbContainer->Private->Connection;
515 assert(db != nullptr);
516
517 int result = mysql_query(db, this->Query);
518 if (result == 0)
519 {
520 // The query probably succeeded.
521 this->Internals->Result = mysql_store_result(db);
522
523 // Statements like INSERT are supposed to return empty result sets,
524 // but sometimes it is an error for mysql_store_result to return null.
525 // If Result is null, but mysql_field_count is non-zero, it is an error.
526 // See: http://dev.mysql.com/doc/refman/5.0/en/null-mysql-store-result.html
527 if (this->Internals->Result || mysql_field_count(db) == 0)
528 {
529 // The query definitely succeeded.
530 this->SetLastErrorText(nullptr);
531 // mysql_field_count will return 0 for statements like INSERT.
532 // set Active to false so that we don't call mysql_fetch_row on a nullptr
533 // argument and segfault
534 this->Active = mysql_field_count(db) != 0;
535 return true;
536 }
537 else
538 {
539 // There was an error in mysql_query or mysql_store_result
540 this->Active = false;
541 this->SetLastErrorText(mysql_error(db));
542 vtkErrorMacro(<< "Query returned an error: " << this->GetLastErrorText());
543 return false;
544 }
545 }
546 else

Callers 9

BeginTransactionMethod · 0.95
CommitTransactionMethod · 0.95
RollbackTransactionMethod · 0.95
WriteDataMethod · 0.45
CreateDatabaseMethod · 0.45
DropDatabaseMethod · 0.45
RequestDataMethod · 0.45
TestMySQLTableReadWriteFunction · 0.45
TestMySQLDatabaseFunction · 0.45

Calls 5

GetLastErrorTextMethod · 0.95
FreeResultMethod · 0.80
assertFunction · 0.50
IsOpenMethod · 0.45

Tested by 2

TestMySQLTableReadWriteFunction · 0.36
TestMySQLDatabaseFunction · 0.36