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

Method WriteData

IO/SQL/vtkTableToSQLiteWriter.cxx:29–131  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

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