Skip to content

Commit 5c27b7d

Browse files
committedNov 12, 2018
[FEATURE] Binary blob support for OGR provider
Instead of converting binary fields to truncated strings, we instead store their contents as QByteArray values, allowing the original binary content to be retrieved. This allows for plugins and scripts to utilise binary fields, such as extracting their contents.
1 parent 8ae1880 commit 5c27b7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+59
-1
lines changed
 

‎src/core/qgsfield.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ QString QgsField::displayString( const QVariant &v ) const
259259
QJsonDocument doc = QJsonDocument::fromVariant( v );
260260
return QString::fromUtf8( doc.toJson().data() );
261261
}
262+
else if ( d->type == QVariant::ByteArray )
263+
{
264+
return QObject::tr( "BLOB" );
265+
}
262266
// Fallback if special rules do not apply
263267
return v.toString();
264268
}

‎src/core/qgsogrutils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField
221221
value = QDateTime( QDate( year, month, day ), QTime( hour, minute, second ) );
222222
}
223223
break;
224+
225+
case QVariant::ByteArray:
226+
{
227+
int size = 0;
228+
const GByte *b = OGR_F_GetFieldAsBinary( ogrFet, attIndex, &size );
229+
QByteArray ba = QByteArray::fromRawData( reinterpret_cast<const char *>( b ), size );
230+
ba.detach();
231+
value = ba;
232+
break;
233+
}
234+
224235
default:
225236
Q_ASSERT_X( false, "QgsOgrUtils::getOgrFeatureAttribute", "unsupported field type" );
226237
if ( ok )

0 commit comments

Comments
 (0)
Please sign in to comment.