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

Method RequestData

IO/MySQL/vtkMySQLToTableReader.cxx:28–141  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

26
27//------------------------------------------------------------------------------
28int vtkMySQLToTableReader::RequestData(
29 vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
30{
31 // Make sure we have all the information we need to provide a vtkTable
32 if (!this->Database)
33 {
34 vtkErrorMacro(<< "No open database connection");
35 return 1;
36 }
37 if (!this->Database->IsA("vtkMySQLDatabase"))
38 {
39 vtkErrorMacro(<< "Wrong type of database for this reader");
40 return 1;
41 }
42 if (this->TableName.empty())
43 {
44 vtkErrorMacro(<< "No table selected");
45 return 1;
46 }
47
48 vtkInformation* outInfo = outputVector->GetInformationObject(0);
49
50 // Return all data in the first piece ...
51 if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0)
52 {
53 return 1;
54 }
55
56 vtkTable* const output = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
57
58 // perform a query to get the names and types of the columns
59 std::string queryStr = "SHOW COLUMNS FROM ";
60 queryStr += this->TableName;
61 vtkMySQLQuery* query = static_cast<vtkMySQLQuery*>(this->Database->GetQueryInstance());
62 query->SetQuery(queryStr.c_str());
63 if (!query->Execute())
64 {
65 vtkErrorMacro(<< "Error performing 'show columns' query");
66 }
67
68 // use the results of the query to create columns of the proper name & type
69 std::vector<std::string> columnTypes;
70 while (query->NextRow())
71 {
72 std::string columnName = query->DataValue(0).ToString();
73 std::string columnType = query->DataValue(1).ToString();
74 if ((columnType.find("int") != std::string::npos) ||
75 (columnType.find("INT") != std::string::npos))
76 {
77 vtkSmartPointer<vtkIntArray> column = vtkSmartPointer<vtkIntArray>::New();
78 column->SetName(columnName.c_str());
79 output->AddColumn(column);
80 columnTypes.emplace_back("int");
81 }
82 else if ((columnType.find("float") != std::string::npos) ||
83 (columnType.find("FLOAT") != std::string::npos) ||
84 (columnType.find("double") != std::string::npos) ||
85 (columnType.find("DOUBLE") != std::string::npos) ||

Callers

nothing calls this directly

Calls 15

IsAMethod · 0.80
GetInformationObjectMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
emptyMethod · 0.45
GetMethod · 0.45
GetQueryInstanceMethod · 0.45
SetQueryMethod · 0.45
c_strMethod · 0.45
ExecuteMethod · 0.45
NextRowMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected