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

Method RequestData

IO/PostgreSQL/vtkPostgreSQLToTableReader.cxx:28–143  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

26
27//------------------------------------------------------------------------------
28int vtkPostgreSQLToTableReader::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("vtkPostgreSQLDatabase"))
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 =
60 "select column_name, data_type FROM information_schema.columns WHERE table_name = '";
61 queryStr += this->TableName;
62 queryStr += "';";
63 vtkPostgreSQLQuery* query = static_cast<vtkPostgreSQLQuery*>(this->Database->GetQueryInstance());
64 query->SetQuery(queryStr.c_str());
65 if (!query->Execute())
66 {
67 vtkErrorMacro(<< "Error performing 'show columns' query");
68 }
69
70 // use the results of the query to create columns of the proper name & type
71 std::vector<std::string> columnTypes;
72 while (query->NextRow())
73 {
74 std::string columnName = query->DataValue(0).ToString();
75 std::string columnType = query->DataValue(1).ToString();
76 if ((columnType.find("int") != std::string::npos) ||
77 (columnType.find("INT") != std::string::npos) ||
78 (columnType.find("serial") != std::string::npos) ||
79 (columnType.find("SERIAL") != std::string::npos))
80 {
81 vtkSmartPointer<vtkIntArray> column = vtkSmartPointer<vtkIntArray>::New();
82 column->SetName(columnName.c_str());
83 output->AddColumn(column);
84 columnTypes.emplace_back("int");
85 }

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