Skip to content

Commit c8f0203

Browse files
committed
export: Allow exporting only the data in an SQL export
In the SQL Export dialog and process, allow the user to export the data only, i.e. not the schema. See issue sqlitebrowser#556.
1 parent f46b800 commit c8f0203

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

src/ExportSqlDialog.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,17 @@ void ExportSqlDialog::accept()
102102
foreach (const QListWidgetItem * item, ui->listTables->selectedItems())
103103
tables.push_back(item->text());
104104

105+
// Check what to export. The indices here depend on the order of the items in the combobox in the ui file
106+
bool exportSchema = ui->comboWhat->currentIndex() == 0 || ui->comboWhat->currentIndex() == 1;
107+
bool exportData = ui->comboWhat->currentIndex() == 0 || ui->comboWhat->currentIndex() == 2;
108+
109+
// Perform actual export
105110
bool dumpOk = pdb->dump(fileName,
106111
tables,
107112
ui->checkColNames->isChecked(),
108113
ui->checkMultiple->isChecked(),
109-
ui->checkSchemaOnly->isChecked());
114+
exportSchema,
115+
exportData);
110116
if (dumpOk)
111117
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
112118
else

src/ExportSqlDialog.ui

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,22 @@
110110
</spacer>
111111
</item>
112112
<item row="2" column="0">
113-
<widget class="QCheckBox" name="checkSchemaOnly">
114-
<property name="text">
115-
<string>Export schema only</string>
116-
</property>
113+
<widget class="QComboBox" name="comboWhat">
114+
<item>
115+
<property name="text">
116+
<string>Export everything</string>
117+
</property>
118+
</item>
119+
<item>
120+
<property name="text">
121+
<string>Export schema only</string>
122+
</property>
123+
</item>
124+
<item>
125+
<property name="text">
126+
<string>Export data only</string>
127+
</property>
128+
</item>
117129
</widget>
118130
</item>
119131
</layout>
@@ -135,8 +147,8 @@
135147
<slot>accept()</slot>
136148
<hints>
137149
<hint type="sourcelabel">
138-
<x>252</x>
139-
<y>136</y>
150+
<x>258</x>
151+
<y>331</y>
140152
</hint>
141153
<hint type="destinationlabel">
142154
<x>157</x>
@@ -151,8 +163,8 @@
151163
<slot>doDeselectAll()</slot>
152164
<hints>
153165
<hint type="sourcelabel">
154-
<x>20</x>
155-
<y>20</y>
166+
<x>298</x>
167+
<y>150</y>
156168
</hint>
157169
<hint type="destinationlabel">
158170
<x>20</x>
@@ -167,8 +179,8 @@
167179
<slot>doSelectAll()</slot>
168180
<hints>
169181
<hint type="sourcelabel">
170-
<x>20</x>
171-
<y>20</y>
182+
<x>80</x>
183+
<y>150</y>
172184
</hint>
173185
<hint type="destinationlabel">
174186
<x>20</x>

src/sqlitedb.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ bool DBBrowserDB::dump(const QString& filename,
420420
const QStringList & tablesToDump,
421421
bool insertColNames,
422422
bool insertNewSyntx,
423-
bool exportSchemaOnly)
423+
bool exportSchema,
424+
bool exportData)
424425
{
425426
// Open file
426427
QFile file(filename);
@@ -466,9 +467,11 @@ bool DBBrowserDB::dump(const QString& filename,
466467
continue;
467468

468469
// Write the SQL string used to create this table to the output file
469-
stream << it->getsql() << ";\n";
470+
if(exportSchema)
471+
stream << it->getsql() << ";\n";
470472

471-
if (exportSchemaOnly)
473+
// If the user doesn't want the data to be exported skip the rest of the loop block here
474+
if(!exportData)
472475
continue;
473476

474477
// get columns
@@ -557,17 +560,18 @@ bool DBBrowserDB::dump(const QString& filename,
557560
sqlite3_finalize(stmt);
558561
}
559562

560-
// Now dump all the other objects
561-
for(objectMap::ConstIterator it=objMap.begin();it!=objMap.end();++it)
563+
// Now dump all the other objects (but only if we are exporting the schema)
564+
if(exportSchema)
562565
{
563-
// Make sure it's not a table again
564-
if(it.value().gettype() == "table")
565-
continue;
566-
567-
// Write the SQL string used to create this object to the output file
568-
if(!it->getsql().isEmpty())
566+
for(objectMap::ConstIterator it=objMap.begin();it!=objMap.end();++it)
569567
{
570-
stream << it->getsql() << ";\n";
568+
// Make sure it's not a table again
569+
if(it.value().gettype() == "table")
570+
continue;
571+
572+
// Write the SQL string used to create this object to the output file
573+
if(!it->getsql().isEmpty())
574+
stream << it->getsql() << ";\n";
571575
}
572576
}
573577

src/sqlitedb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class DBBrowserDB : public QObject
5454
bool revertToSavepoint(const QString& pointname = "RESTOREPOINT");
5555
bool releaseAllSavepoints();
5656
bool revertAll();
57-
bool dump(const QString & filename, const QStringList &tablesToDump, bool insertColNames, bool insertNew, bool exportSchemaOnly);
57+
bool dump(const QString & filename, const QStringList &tablesToDump, bool insertColNames, bool insertNew, bool exportSchema, bool exportData);
5858
bool executeSQL ( const QString & statement, bool dirtyDB=true, bool logsql=true);
5959
bool executeMultiSQL(const QString& statement, bool dirty = true, bool log = false);
6060

0 commit comments

Comments
 (0)