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

Method WriteData

IO/PostgreSQL/vtkTableToPostgreSQLWriter.cxx:30–132  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

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