Skip to content

Commit

Permalink
Don't accept illegal field names in new table dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 30, 2022
1 parent 026f3cd commit 1461a81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/gui/qgsnewvectortabledialog.cpp
Expand Up @@ -107,6 +107,8 @@ QgsNewVectorTableDialog::QgsNewVectorTableDialog( QgsAbstractDatabaseProviderCon
mSpatialIndexLabel->hide();
}

mIllegalFieldNames = mConnection->illegalFieldNames();

// Initial load of table names
updateTableNames( mSchemaCbo->currentText() );

Expand Down Expand Up @@ -385,13 +387,21 @@ void QgsNewVectorTableDialog::validate()
mValidationErrors.push_back( tr( "The table has no geometry column and no fields!" ) );
}
// Check if precision is <= length
const auto cFields { fields() };
for ( const auto &f : cFields )
const QgsFields cFields { fields() };
for ( const QgsField &f : cFields )
{
if ( f.isNumeric() && f.length() >= 0 && f.precision() >= 0 && f.precision() > f.length() )
{
mValidationErrors.push_back( tr( "Field <b>%1</b>: precision cannot be greater than length!" ).arg( f.name() ) );
}

for ( const QString &illegalName : std::as_const( mIllegalFieldNames ) )
{
if ( f.name().compare( illegalName, Qt::CaseInsensitive ) == 0 )
{
mValidationErrors.push_back( tr( "<b>%1</b> is an illegal field name for this format and cannot be used" ).arg( f.name() ) );
}
}
}

const bool isValid { mValidationErrors.isEmpty() };
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsnewvectortabledialog.h
Expand Up @@ -131,6 +131,8 @@ class GUI_EXPORT QgsNewVectorTableDialog : public QDialog, private Ui_QgsNewVect
QStringList mTableNames;
QStringList mValidationErrors;

QSet<QString> mIllegalFieldNames;

void updateButtons();
void selectRow( int row );
void validate();
Expand Down

0 comments on commit 1461a81

Please sign in to comment.