------------------------------------------------------------------------------
| 26 | |
| 27 | //------------------------------------------------------------------------------ |
| 28 | int 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()); |
nothing calls this directly
no test coverage detected