|
1 | 1 | #include "DbStructureModel.h" |
2 | 2 | #include "sqlitedb.h" |
| 3 | +#include "sqlitetablemodel.h" |
3 | 4 | #include <QTreeWidgetItem> |
4 | 5 | #include <QMimeData> |
5 | 6 | #include <QMessageBox> |
@@ -183,7 +184,26 @@ QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const |
183 | 184 | { |
184 | 185 | // Only export data for valid indices and only for the SQL column, i.e. only once per row |
185 | 186 | if(index.isValid() && index.column() == 3) |
| 187 | + { |
| 188 | + // Add the SQL code used to create the object |
186 | 189 | d = d.append(data(index, Qt::DisplayRole).toString() + ";\n"); |
| 190 | + |
| 191 | + // If it is a table also add the content |
| 192 | + if(data(index.sibling(index.row(), 1), Qt::DisplayRole).toString() == "table") |
| 193 | + { |
| 194 | + SqliteTableModel tableModel(0, m_db); |
| 195 | + tableModel.setTable(data(index.sibling(index.row(), 0), Qt::DisplayRole).toString()); |
| 196 | + for(int i=0;i<tableModel.rowCount();i++) |
| 197 | + { |
| 198 | + QString insertStatement = "INSERT INTO `" + data(index.sibling(index.row(), 0), Qt::DisplayRole).toString() + "` VALUES("; |
| 199 | + for(int j=1;j<tableModel.columnCount();j++) |
| 200 | + insertStatement += QString("'%1',").arg(tableModel.data(tableModel.index(i, j)).toString()); |
| 201 | + insertStatement.chop(1); |
| 202 | + insertStatement += ");\n"; |
| 203 | + d = d.append(insertStatement); |
| 204 | + } |
| 205 | + } |
| 206 | + } |
187 | 207 | } |
188 | 208 |
|
189 | 209 | // Create the MIME data object |
|
0 commit comments