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.
This commit is contained in:
Martin Kleusberg
2018-05-25 22:11:43 +02:00
parent e851c161d6
commit 3995ad2442
2 changed files with 22 additions and 6 deletions

View File

@@ -415,8 +415,8 @@ sqlb::FieldVector ImportCsvDialog::generateFieldList(const QString& filename)
fieldList.push_back(sqlb::FieldPtr(new sqlb::Field(fieldname, "")));
}
// Try to find out a data type for each column
if(!(rowNum == 0 && ui->checkboxHeader->isChecked()))
// Try to find out a data type for each column. Skip the header row if there is one.
if(!ui->checkNoTypeDetection->isChecked() && !(rowNum == 0 && ui->checkboxHeader->isChecked()))
{
for(size_t i=0;i<data.num_fields;i++)
{
@@ -774,6 +774,8 @@ QString ImportCsvDialog::currentEncoding() const
void ImportCsvDialog::toggleAdvancedSection(bool show)
{
ui->labelNoTypeDetection->setVisible(show);
ui->checkNoTypeDetection->setVisible(show);
ui->labelFailOnMissing->setVisible(show);
ui->checkFailOnMissing->setVisible(show);
ui->labelIgnoreDefaults->setVisible(show);

View File

@@ -275,14 +275,14 @@
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QCheckBox" name="checkIgnoreDefaults">
<property name="toolTip">
<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>
</property>
</widget>
</item>
<item row="8" column="0">
<item row="9" column="0">
<widget class="QLabel" name="labelIgnoreDefaults">
<property name="text">
<string>Ignore default &amp;values</string>
@@ -292,14 +292,14 @@
</property>
</widget>
</item>
<item row="9" column="1">
<item row="10" column="1">
<widget class="QCheckBox" name="checkFailOnMissing">
<property name="toolTip">
<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>
</property>
</widget>
</item>
<item row="9" column="0">
<item row="10" column="0">
<widget class="QLabel" name="labelFailOnMissing">
<property name="text">
<string>Fail on missing values </string>
@@ -309,6 +309,20 @@
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelNoTypeDetection">
<property name="text">
<string>Disable data type detection</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="checkNoTypeDetection">
<property name="toolTip">
<string>Disable the automatic data type detection when creating a new table.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>