Skip to content

Commit 1461a81

Browse files
committedNov 30, 2022
Don't accept illegal field names in new table dialog
1 parent 026f3cd commit 1461a81

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

‎src/gui/qgsnewvectortabledialog.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ QgsNewVectorTableDialog::QgsNewVectorTableDialog( QgsAbstractDatabaseProviderCon
107107
mSpatialIndexLabel->hide();
108108
}
109109

110+
mIllegalFieldNames = mConnection->illegalFieldNames();
111+
110112
// Initial load of table names
111113
updateTableNames( mSchemaCbo->currentText() );
112114

@@ -385,13 +387,21 @@ void QgsNewVectorTableDialog::validate()
385387
mValidationErrors.push_back( tr( "The table has no geometry column and no fields!" ) );
386388
}
387389
// Check if precision is <= length
388-
const auto cFields { fields() };
389-
for ( const auto &f : cFields )
390+
const QgsFields cFields { fields() };
391+
for ( const QgsField &f : cFields )
390392
{
391393
if ( f.isNumeric() && f.length() >= 0 && f.precision() >= 0 && f.precision() > f.length() )
392394
{
393395
mValidationErrors.push_back( tr( "Field <b>%1</b>: precision cannot be greater than length!" ).arg( f.name() ) );
394396
}
397+
398+
for ( const QString &illegalName : std::as_const( mIllegalFieldNames ) )
399+
{
400+
if ( f.name().compare( illegalName, Qt::CaseInsensitive ) == 0 )
401+
{
402+
mValidationErrors.push_back( tr( "<b>%1</b> is an illegal field name for this format and cannot be used" ).arg( f.name() ) );
403+
}
404+
}
395405
}
396406

397407
const bool isValid { mValidationErrors.isEmpty() };

‎src/gui/qgsnewvectortabledialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class GUI_EXPORT QgsNewVectorTableDialog : public QDialog, private Ui_QgsNewVect
131131
QStringList mTableNames;
132132
QStringList mValidationErrors;
133133

134+
QSet<QString> mIllegalFieldNames;
135+
134136
void updateButtons();
135137
void selectRow( int row );
136138
void validate();

0 commit comments

Comments
 (0)
Please sign in to comment.