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

Method WriteData

IO/MySQL/vtkTableToMySQLWriter.cxx:28–129  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

26
27//------------------------------------------------------------------------------
28void 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 {

Callers

nothing calls this directly

Calls 15

GetInputMethod · 0.95
IsAMethod · 0.80
DeleteMethod · 0.65
emptyMethod · 0.45
GetNumberOfColumnsMethod · 0.45
GetNameMethod · 0.45
GetColumnMethod · 0.45
GetClassNameMethod · 0.45
findMethod · 0.45
GetQueryInstanceMethod · 0.45
SetQueryMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected