mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-30 00:29:39 -05:00
Fix error retrieval
This commit is contained in:
parent
118b3d32c1
commit
dfac7df6fa
@ -281,13 +281,15 @@ void QgsOgrProviderConnection::addFieldDomain( const QgsFieldDomain &domain, con
|
||||
{
|
||||
if ( OGRFieldDomainH ogrDomain = QgsOgrUtils::convertFieldDomain( &domain ) )
|
||||
{
|
||||
char **failureReason = nullptr;
|
||||
if ( !GDALDatasetAddFieldDomain( hDS.get(), ogrDomain, failureReason ) )
|
||||
char *failureReason = nullptr;
|
||||
if ( !GDALDatasetAddFieldDomain( hDS.get(), ogrDomain, &failureReason ) )
|
||||
{
|
||||
OGR_FldDomain_Destroy( ogrDomain );
|
||||
QString error( failureReason ? *failureReason : nullptr );
|
||||
QString error( failureReason );
|
||||
CPLFree( failureReason );
|
||||
throw QgsProviderConnectionException( QObject::tr( "Could not create field domain: %1" ).arg( error ) );
|
||||
}
|
||||
CPLFree( failureReason );
|
||||
OGR_FldDomain_Destroy( ogrDomain );
|
||||
}
|
||||
else
|
||||
|
||||
@ -223,6 +223,11 @@ class TestPyQgsProviderConnectionGpkg(unittest.TestCase, TestPyQgsProviderConnec
|
||||
self.assertEqual(res.minimum(), 5)
|
||||
self.assertEqual(res.maximum(), 15)
|
||||
|
||||
# try adding another with a duplicate name, should fail
|
||||
with self.assertRaises(QgsProviderConnectionException) as e:
|
||||
conn.addFieldDomain(domain, '')
|
||||
self.assertEqual(str(e.exception), 'Could not create field domain: A domain of identical name already exists')
|
||||
|
||||
domain = QgsGlobFieldDomain('my new glob domain', 'my new glob desc', QVariant.String, '*aaabc*')
|
||||
conn.addFieldDomain(domain, '')
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user