------------------------------------------------------------------------------
| 26 | |
| 27 | //------------------------------------------------------------------------------ |
| 28 | void vtkTableToMySQLWriter::WriteData() |
| 29 | { |
| 30 | // Make sure we have all the information we need to create a MySQL table |
| 31 | if (!this->Database) |
| 32 | { |
| 33 | vtkErrorMacro(<< "No open database connection"); |
| 34 | return; |
| 35 | } |
| 36 | if (!this->Database->IsA("vtkMySQLDatabase")) |
| 37 | { |
| 38 | vtkErrorMacro(<< "Wrong type of database for this writer"); |
| 39 | return; |
| 40 | } |
| 41 | if (this->TableName.empty()) |
| 42 | { |
| 43 | vtkErrorMacro(<< "No table name specified!"); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // converting this table to MySQL will require two queries: one to create |
| 48 | // the table, and another to populate its rows with data. |
| 49 | std::string createTableQuery = "CREATE table "; |
| 50 | createTableQuery += this->TableName; |
| 51 | createTableQuery += "("; |
| 52 | |
| 53 | std::string insertPreamble = "INSERT into "; |
| 54 | insertPreamble += this->TableName; |
| 55 | insertPreamble += "("; |
| 56 | |
| 57 | // get the columns from the vtkTable to finish the query |
| 58 | int numColumns = this->GetInput()->GetNumberOfColumns(); |
| 59 | for (int i = 0; i < numColumns; i++) |
| 60 | { |
| 61 | // get this column's name |
| 62 | std::string columnName = this->GetInput()->GetColumn(i)->GetName(); |
| 63 | createTableQuery += columnName; |
| 64 | insertPreamble += columnName; |
| 65 | |
| 66 | // figure out what type of data is stored in this column |
| 67 | std::string columnType = this->GetInput()->GetColumn(i)->GetClassName(); |
| 68 | |
| 69 | if ((columnType.find("String") != std::string::npos) || |
| 70 | (columnType.find("Data") != std::string::npos) || |
| 71 | (columnType.find("Variant") != std::string::npos)) |
| 72 | { |
| 73 | createTableQuery += " TEXT"; |
| 74 | } |
| 75 | else if ((columnType.find("Double") != std::string::npos) || |
| 76 | (columnType.find("Float") != std::string::npos)) |
| 77 | { |
| 78 | createTableQuery += " DOUBLE"; |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | createTableQuery += " INTEGER"; |
| 83 | } |
| 84 | if (i == numColumns - 1) |
| 85 | { |
nothing calls this directly
no test coverage detected