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