Skip to content

Commit 3995ad2

Browse files
committed
Add option to disable automatic type detection in CSV import
Because there are some circumstances under which the automatic type detection can cause problems with the imported data and because it is not accurate when the data changes a lot after the first couple of rows, we need an option to disable it. See issue #1382.
1 parent e851c16 commit 3995ad2

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/ImportCsvDialog.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ sqlb::FieldVector ImportCsvDialog::generateFieldList(const QString& filename)
415415
fieldList.push_back(sqlb::FieldPtr(new sqlb::Field(fieldname, "")));
416416
}
417417

418-
// Try to find out a data type for each column
419-
if(!(rowNum == 0 && ui->checkboxHeader->isChecked()))
418+
// Try to find out a data type for each column. Skip the header row if there is one.
419+
if(!ui->checkNoTypeDetection->isChecked() && !(rowNum == 0 && ui->checkboxHeader->isChecked()))
420420
{
421421
for(size_t i=0;i<data.num_fields;i++)
422422
{
@@ -774,6 +774,8 @@ QString ImportCsvDialog::currentEncoding() const
774774

775775
void ImportCsvDialog::toggleAdvancedSection(bool show)
776776
{
777+
ui->labelNoTypeDetection->setVisible(show);
778+
ui->checkNoTypeDetection->setVisible(show);
777779
ui->labelFailOnMissing->setVisible(show);
778780
ui->checkFailOnMissing->setVisible(show);
779781
ui->labelIgnoreDefaults->setVisible(show);

src/ImportCsvDialog.ui

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,14 @@
275275
</property>
276276
</widget>
277277
</item>
278-
<item row="8" column="1">
278+
<item row="9" column="1">
279279
<widget class="QCheckBox" name="checkIgnoreDefaults">
280280
<property name="toolTip">
281281
<string>When importing an empty value from the CSV file into an existing table with a default value for this column, that default value is inserted. Activate this option to insert an empty value instead.</string>
282282
</property>
283283
</widget>
284284
</item>
285-
<item row="8" column="0">
285+
<item row="9" column="0">
286286
<widget class="QLabel" name="labelIgnoreDefaults">
287287
<property name="text">
288288
<string>Ignore default &amp;values</string>
@@ -292,14 +292,14 @@
292292
</property>
293293
</widget>
294294
</item>
295-
<item row="9" column="1">
295+
<item row="10" column="1">
296296
<widget class="QCheckBox" name="checkFailOnMissing">
297297
<property name="toolTip">
298298
<string>Activate this option to stop the import when trying to import an empty value into a NOT NULL column without a default value.</string>
299299
</property>
300300
</widget>
301301
</item>
302-
<item row="9" column="0">
302+
<item row="10" column="0">
303303
<widget class="QLabel" name="labelFailOnMissing">
304304
<property name="text">
305305
<string>Fail on missing values </string>
@@ -309,6 +309,20 @@
309309
</property>
310310
</widget>
311311
</item>
312+
<item row="8" column="0">
313+
<widget class="QLabel" name="labelNoTypeDetection">
314+
<property name="text">
315+
<string>Disable data type detection</string>
316+
</property>
317+
</widget>
318+
</item>
319+
<item row="8" column="1">
320+
<widget class="QCheckBox" name="checkNoTypeDetection">
321+
<property name="toolTip">
322+
<string>Disable the automatic data type detection when creating a new table.</string>
323+
</property>
324+
</widget>
325+
</item>
312326
</layout>
313327
</item>
314328
<item>

0 commit comments

Comments
 (0)