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