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

Method RequestData

IO/SQL/vtkSQLiteToTableReader.cxx:28–130  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

26
27//------------------------------------------------------------------------------
28int vtkSQLiteToTableReader::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("vtkSQLiteDatabase"))
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 = "pragma table_info(";
60 queryStr += this->TableName;
61 queryStr += ")";
62 vtkSQLiteQuery* query = static_cast<vtkSQLiteQuery*>(this->Database->GetQueryInstance());
63 query->SetQuery(queryStr.c_str());
64 if (!query->Execute())
65 {
66 vtkErrorMacro(<< "Error performing 'pragma' query");
67 }
68
69 // use the results of the query to create columns of the proper name & type
70 std::vector<std::string> columnTypes;
71 while (query->NextRow())
72 {
73 std::string columnName = query->DataValue(1).ToString();
74 std::string columnType = query->DataValue(2).ToString();
75 columnTypes.push_back(columnType);
76 if (columnType == "INTEGER")
77 {
78 vtkSmartPointer<vtkIntArray> column = vtkSmartPointer<vtkIntArray>::New();
79 column->SetName(columnName.c_str());
80 output->AddColumn(column);
81 }
82 else if (columnType == "REAL")
83 {
84 vtkSmartPointer<vtkDoubleArray> column = vtkSmartPointer<vtkDoubleArray>::New();
85 column->SetName(columnName.c_str());

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