Skip to content
Permalink
Browse files

[FEATURE][ogr] Allow creation of binary (blob) fields for compatible …

…filetypes
  • Loading branch information
nyalldawson committed Nov 12, 2018
1 parent 5158720 commit 36379307c462e243e25c8dbaa5bda6429cc21eb3
Showing with 17 additions and 2 deletions.
  1. +6 −2 src/gui/qgsnewgeopackagelayerdialog.cpp
  2. +11 −0 src/providers/ogr/qgsogrprovider.cpp
@@ -96,7 +96,8 @@ QgsNewGeoPackageLayerDialog::QgsNewGeoPackageLayerDialog( QWidget *parent, Qt::W
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldInteger.svg" ) ), tr( "Whole number (integer 64 bit)" ), "integer64" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldFloat.svg" ) ), tr( "Decimal number (real)" ), "real" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDate.svg" ) ), tr( "Date" ), "date" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDateTime.svg" ) ), tr( "Date&time" ), "datetime" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDateTime.svg" ) ), tr( "Datetime" ), "datetime" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldBinary.svg" ) ), tr( "Binary (BLOB)" ), "binary" );

mOkButton = buttonBox->button( QDialogButtonBox::Ok );
mOkButton->setEnabled( false );
@@ -444,11 +445,14 @@ bool QgsNewGeoPackageLayerDialog::apply()
ogrType = OFTDate;
else if ( fieldType == QLatin1String( "datetime" ) )
ogrType = OFTDateTime;
else if ( fieldType == QLatin1String( "binary" ) )
ogrType = OFTBinary;

int ogrWidth = fieldWidth.toInt();

gdal::ogr_field_def_unique_ptr fld( OGR_Fld_Create( fieldName.toUtf8().constData(), ogrType ) );
OGR_Fld_SetWidth( fld.get(), ogrWidth );
if ( ogrType != OFTBinary )
OGR_Fld_SetWidth( fld.get(), ogrWidth );

if ( OGR_L_CreateField( hLayer, fld.get(), true ) != OGRERR_NONE )
{
@@ -475,6 +475,7 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri, const ProviderOptions &optio
bool supportsDate = true;
bool supportsTime = mGDALDriverName != QLatin1String( "ESRI Shapefile" ) && mGDALDriverName != QLatin1String( "GPKG" );
bool supportsDateTime = mGDALDriverName != QLatin1String( "ESRI Shapefile" );
bool supportsBinary = false;
const char *pszDataTypes = nullptr;
if ( mOgrOrigLayer )
{
@@ -488,6 +489,7 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri, const ProviderOptions &optio
supportsDate = CSLFindString( papszTokens, "Date" ) >= 0;
supportsTime = CSLFindString( papszTokens, "Time" ) >= 0;
supportsDateTime = CSLFindString( papszTokens, "DateTime" ) >= 0;
supportsBinary = CSLFindString( papszTokens, "Binary" ) >= 0;
CSLDestroy( papszTokens );
}

@@ -506,6 +508,11 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri, const ProviderOptions &optio
nativeTypes
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), QStringLiteral( "datetime" ), QVariant::DateTime );
}
if ( supportsBinary )
{
nativeTypes
<< QgsVectorDataProvider::NativeType( tr( "Binary object (BLOB)" ), QStringLiteral( "binary" ), QVariant::ByteArray );
}

bool supportsBoolean = false;

@@ -1623,6 +1630,10 @@ bool QgsOgrProvider::addAttributeOGRLevel( const QgsField &field, bool &ignoreEr
case QVariant::String:
type = OFTString;
break;
case QVariant::ByteArray:
type = OFTBinary;
break;

default:
pushError( tr( "type %1 for field %2 not found" ).arg( field.typeName(), field.name() ) );
ignoreErrorOut = true;

0 comments on commit 3637930

Please sign in to comment.
You can’t perform that action at this time.